1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "document.h"
#include "documentprivate.h"
#include "keyfile.h"
#include "main.h"
#include "sidebar.h"
#include "ui_utils.h"
#include "utils.h"
#define SIDEBAR_TEST_ADD(path, func) g_test_add_func("/sidebar/" path, func);
static void openfiles_add(const gchar **file_names)
{
const gchar *file;
while ((file = *file_names++))
{
GeanyDocument *doc = g_new0(GeanyDocument, 1);
doc->priv = g_new0(GeanyDocumentPrivate, 1);
doc->file_name = strdup(file);
sidebar_openfiles_add(doc);
}
}
static gboolean tree_count_cb(GtkTreeModel *model, GtkTreePath *path,
GtkTreeIter *iter, gpointer data_in)
{
gint *c = (gint *) data_in;
*c = *c + 1;
return FALSE;
}
static gboolean tree_strings_cb(GtkTreeModel *model, GtkTreePath *path,
GtkTreeIter *iter, gpointer data_in)
{
gchar **data = (gchar **) data_in;
gchar *file;
gtk_tree_model_get(model, iter, DOCUMENTS_SHORTNAME, &file, -1);
data[g_strv_length(data)] = file;
printf("%s\n", file);
return FALSE;
}
static void do_test_sidebar_openfiles(const gchar **test_data, const gchar **expected)
{
#ifdef HAVE_G_STRV_EQUAL
int count = 0;
GtkTreeStore *store;
gchar **data;
store = sidebar_create_store_openfiles();
openfiles_add(test_data);
gtk_tree_model_foreach(GTK_TREE_MODEL(store), tree_count_cb, (gpointer) &count);
data = g_new0(gchar *, count + 1);
gtk_tree_model_foreach(GTK_TREE_MODEL(store), tree_strings_cb, (gpointer) data);
g_assert_true(g_strv_equal(expected, (const gchar * const *) data));
#else
g_test_skip("Need g_strv_equal(), since GLib 2.60");
#endif
}
static void test_sidebar_openfiles_none(void)
{
const gchar *files[] = {
"/tmp/x",
"/tmp/b/a",
"/tmp/b/b",
NULL
};
const gchar *expected[] = {
"a",
"b",
"x",
NULL
};
interface_prefs.openfiles_path_mode = OPENFILES_PATHS_NONE;
do_test_sidebar_openfiles(files, expected);
}
static void test_sidebar_openfiles_path(void)
{
const gchar *files[] = {
"/tmp/x",
"/tmp/b/a",
"/tmp/b/b",
NULL
};
const gchar *expected[] = {
"/tmp",
"x",
"/tmp/b",
"a",
"b",
NULL
};
interface_prefs.openfiles_path_mode = OPENFILES_PATHS_LIST;
do_test_sidebar_openfiles(files, expected);
}
static void test_sidebar_openfiles_tree(void)
{
const gchar *files[] = {
"/tmp/x",
"/tmp/b/a",
"/tmp/b/b",
NULL
};
const gchar *expected[] = {
"/tmp",
"x",
"b",
"a",
"b",
NULL
};
interface_prefs.openfiles_path_mode = OPENFILES_PATHS_TREE;
do_test_sidebar_openfiles(files, expected);
}
int main(int argc, char **argv)
{
g_test_init(&argc, &argv, NULL);
/* Not sure if we can really continue without DISPLAY. Fake X display perhaps?
*
* This test seems to work, at least.
*/
gtk_init_check(&argc, &argv);
main_init_headless();
SIDEBAR_TEST_ADD("openfiles_none", test_sidebar_openfiles_none);
SIDEBAR_TEST_ADD("openfiles_path", test_sidebar_openfiles_path);
SIDEBAR_TEST_ADD("openfiles_tree", test_sidebar_openfiles_tree);
return g_test_run();
}
|