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