ali@38: /* ali@38: * Copyright (C) 2011, 2016 J. Ali Harlow ali@38: * ali@38: * This program is free software; you can redistribute it and/or modify ali@38: * it under the terms of the GNU General Public License as published by ali@38: * the Free Software Foundation; either version 2 of the License, or ali@38: * (at your option) any later version. ali@38: * ali@38: * This program is distributed in the hope that it will be useful, ali@38: * but WITHOUT ANY WARRANTY; without even the implied warranty of ali@38: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ali@38: * GNU General Public License for more details. ali@38: * ali@38: * You should have received a copy of the GNU General Public License along ali@38: * with this program; if not, write to the Free Software Foundation, Inc., ali@38: * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ali@38: */ ali@38: ali@38: #include ali@38: #include ali@38: #include ali@38: #include ali@38: ali@38: static void test_tree_model_iter(GtkTreeModel *model,GtkTreeIter *iter) ali@38: { ali@38: GtkTreePath *path,*path2; ali@38: GtkTreeIter iter2,child; ali@38: gchar *string,*string2,*s; ali@38: int i,n; ali@38: if (iter) /* Not all tests make sense on the virtual root */ ali@38: { ali@38: /* Check we can convert to a path and back */ ali@38: path=gtk_tree_model_get_path(model,iter); ali@38: g_assert(path!=NULL); ali@38: g_assert(gtk_tree_model_get_iter(model,&iter2,path)); ali@38: path2=gtk_tree_model_get_path(model,&iter2); ali@38: g_assert(path2!=NULL); ali@38: g_assert(gtk_tree_path_compare(path,path2)==0); ali@38: gtk_tree_path_free(path2); ali@38: /* Check we can convert to a path string and back */ ali@38: string=gtk_tree_model_get_string_from_iter(model,iter); ali@38: g_assert(string!=NULL); ali@38: g_assert(gtk_tree_model_get_iter_from_string(model,&iter2,string)); ali@38: string2=gtk_tree_model_get_string_from_iter(model,&iter2); ali@38: g_assert(string2!=NULL); ali@38: g_assert(strcmp(string,string2)==0); ali@38: g_free(string2); ali@38: } ali@38: else ali@38: { ali@38: path=NULL; ali@38: string=NULL; ali@38: } ali@38: if (string) ali@38: g_debug("Checking iter %s",string); ali@38: else ali@38: g_debug("Checking virtual root iter"); ali@38: n=gtk_tree_model_iter_n_children(model,iter); ali@38: g_assert(n>=0); ali@38: if (n>0) ali@38: { ali@38: /* Check that GTK_TREE_MODEL_LIST_ONLY is not set inappropriately */ ali@38: if (iter) ali@38: { ali@38: gboolean list_only_with_grandchildren; ali@38: list_only_with_grandchildren= ali@38: gtk_tree_model_get_flags(model)>K_TREE_MODEL_LIST_ONLY; ali@38: g_assert(!list_only_with_grandchildren); ali@38: } ali@38: /* Check that gtk_tree_model_iter_has_child() agrees */ ali@38: if (iter) ali@38: g_assert(gtk_tree_model_iter_has_child(model,iter)); ali@38: /* Check that gtk_tree_model_iter_children() returns the first child */ ali@38: g_assert(gtk_tree_model_iter_children(model,&child,iter)); ali@38: string2=gtk_tree_model_get_string_from_iter(model,&child); ali@38: g_assert(string2!=NULL); ali@38: if (string) ali@38: { ali@38: g_assert(g_str_has_prefix(string2,string)); ali@38: g_assert(strlen(string2)==strlen(string)+2); ali@38: g_assert(g_str_has_suffix(string2,":0")); ali@38: } ali@38: else ali@38: g_assert(strcmp(string2,"0")==0); ali@38: g_free(string2); ali@38: for(i=0;i