Refix bug causing plover_get_program_directory() to fail when executable is in a root directory
2 * Copyright (C) 2011, 2016 J. Ali Harlow <ali@juiblex.co.uk>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 static void test_tree_model_iter(GtkTreeModel *model,GtkTreeIter *iter)
26 GtkTreePath *path,*path2;
27 GtkTreeIter iter2,child;
28 gchar *string,*string2,*s;
30 if (iter) /* Not all tests make sense on the virtual root */
32 /* Check we can convert to a path and back */
33 path=gtk_tree_model_get_path(model,iter);
35 g_assert(gtk_tree_model_get_iter(model,&iter2,path));
36 path2=gtk_tree_model_get_path(model,&iter2);
37 g_assert(path2!=NULL);
38 g_assert(gtk_tree_path_compare(path,path2)==0);
39 gtk_tree_path_free(path2);
40 /* Check we can convert to a path string and back */
41 string=gtk_tree_model_get_string_from_iter(model,iter);
42 g_assert(string!=NULL);
43 g_assert(gtk_tree_model_get_iter_from_string(model,&iter2,string));
44 string2=gtk_tree_model_get_string_from_iter(model,&iter2);
45 g_assert(string2!=NULL);
46 g_assert(strcmp(string,string2)==0);
55 g_debug("Checking iter %s",string);
57 g_debug("Checking virtual root iter");
58 n=gtk_tree_model_iter_n_children(model,iter);
62 /* Check that GTK_TREE_MODEL_LIST_ONLY is not set inappropriately */
65 gboolean list_only_with_grandchildren;
66 list_only_with_grandchildren=
67 gtk_tree_model_get_flags(model)>K_TREE_MODEL_LIST_ONLY;
68 g_assert(!list_only_with_grandchildren);
70 /* Check that gtk_tree_model_iter_has_child() agrees */
72 g_assert(gtk_tree_model_iter_has_child(model,iter));
73 /* Check that gtk_tree_model_iter_children() returns the first child */
74 g_assert(gtk_tree_model_iter_children(model,&child,iter));
75 string2=gtk_tree_model_get_string_from_iter(model,&child);
76 g_assert(string2!=NULL);
79 g_assert(g_str_has_prefix(string2,string));
80 g_assert(strlen(string2)==strlen(string)+2);
81 g_assert(g_str_has_suffix(string2,":0"));
84 g_assert(strcmp(string2,"0")==0);
89 * Check that gtk_tree_model_iter_nth_child() returns the nth child
91 g_assert(gtk_tree_model_iter_nth_child(model,&child,iter,i));
92 string2=gtk_tree_model_get_string_from_iter(model,&child);
93 g_assert(string2!=NULL);
95 s=g_strdup_printf("%s:%d",string,i);
97 s=g_strdup_printf("%d",i);
98 g_assert(strcmp(string2,s)==0);
101 /* Check that my son's father is me */
104 g_assert(gtk_tree_model_iter_parent(model,&iter2,&child));
105 string2=gtk_tree_model_get_string_from_iter(model,&iter2);
106 g_assert(strcmp(string,string2)==0);
110 g_assert(!gtk_tree_model_iter_parent(model,&iter2,&child));
111 /* Check next sibling */
115 g_assert(gtk_tree_model_iter_next(model,&iter2));
116 string2=gtk_tree_model_get_string_from_iter(model,&iter2);
117 g_assert(string2!=NULL);
119 s=g_strdup_printf("%s:%d",string,i+1);
121 s=g_strdup_printf("%d",i+1);
122 g_assert(strcmp(string2,s)==0);
129 g_assert(!gtk_tree_model_iter_next(model,&iter2));
132 test_tree_model_iter(model,&child);
135 * Check that gtk_tree_model_iter_nth_child() returns no more children
137 g_assert(!gtk_tree_model_iter_nth_child(model,&child,iter,n));
141 /* Check that all APIs agree that iter has no children */
143 g_assert(!gtk_tree_model_iter_has_child(model,iter));
144 g_assert(!gtk_tree_model_iter_children(model,&child,iter));
145 g_assert(!gtk_tree_model_iter_nth_child(model,&child,iter,0));
147 gtk_tree_path_free(path);
151 void test_tree_model(GtkTreeModel *model)
153 GtkTreeModelFlags undefined_flags;
154 undefined_flags=gtk_tree_model_get_flags(model);
155 undefined_flags&=~GTK_TREE_MODEL_ITERS_PERSIST;
156 undefined_flags&=~GTK_TREE_MODEL_LIST_ONLY;
157 g_assert(!undefined_flags);
158 test_tree_model_iter(model,NULL);