7 #include "documentprivate.h"
14 #define SIDEBAR_TEST_ADD(path, func) g_test_add_func("/sidebar/" path, func);
16 static void openfiles_add(const gchar
**file_names
)
20 while ((file
= *file_names
++))
22 GeanyDocument
*doc
= g_new0(GeanyDocument
, 1);
24 doc
->priv
= g_new0(GeanyDocumentPrivate
, 1);
25 doc
->file_name
= strdup(file
);
27 sidebar_openfiles_add(doc
);
32 static gboolean
tree_count_cb(GtkTreeModel
*model
, GtkTreePath
*path
,
33 GtkTreeIter
*iter
, gpointer data_in
)
35 gint
*c
= (gint
*) data_in
;
42 static gboolean
tree_strings_cb(GtkTreeModel
*model
, GtkTreePath
*path
,
43 GtkTreeIter
*iter
, gpointer data_in
)
45 gchar
**data
= (gchar
**) data_in
;
48 gtk_tree_model_get(model
, iter
, DOCUMENTS_SHORTNAME
, &file
, -1);
49 data
[g_strv_length(data
)] = file
;
55 void do_test_sidebar_openfiles(const gchar
**test_data
, const gchar
**expected
)
57 #ifdef HAVE_G_STRV_EQUAL
62 store
= sidebar_create_store_openfiles();
64 openfiles_add(test_data
);
66 gtk_tree_model_foreach(GTK_TREE_MODEL(store
), tree_count_cb
, (gpointer
) &count
);
67 data
= g_new0(gchar
*, count
+ 1);
68 gtk_tree_model_foreach(GTK_TREE_MODEL(store
), tree_strings_cb
, (gpointer
) data
);
69 g_assert_true(g_strv_equal(expected
, (const gchar
* const *) data
));
71 g_test_skip("Need g_strv_equal(), since GLib 2.60");
75 void test_sidebar_openfiles_none(void)
77 const gchar
*files
[] = {
83 const gchar
*expected
[] = {
90 interface_prefs
.openfiles_path_mode
= OPENFILES_PATHS_NONE
;
91 do_test_sidebar_openfiles(files
, expected
);
95 void test_sidebar_openfiles_path(void)
97 const gchar
*files
[] = {
103 const gchar
*expected
[] = {
112 interface_prefs
.openfiles_path_mode
= OPENFILES_PATHS_LIST
;
113 do_test_sidebar_openfiles(files
, expected
);
117 void test_sidebar_openfiles_tree(void)
119 const gchar
*files
[] = {
125 const gchar
*expected
[] = {
134 interface_prefs
.openfiles_path_mode
= OPENFILES_PATHS_TREE
;
135 do_test_sidebar_openfiles(files
, expected
);
138 int main(int argc
, char **argv
)
140 g_test_init(&argc
, &argv
, NULL
);
141 /* Not sure if we can really continue without DISPLAY. Fake X display perhaps?
143 * This test seems to work, at least.
145 gtk_init_check(&argc
, &argv
);
147 main_init_headless();
149 SIDEBAR_TEST_ADD("openfiles_none", test_sidebar_openfiles_none
);
150 SIDEBAR_TEST_ADD("openfiles_path", test_sidebar_openfiles_path
);
151 SIDEBAR_TEST_ADD("openfiles_tree", test_sidebar_openfiles_tree
);