Use PLUGIN_SET_INFO instead of PLUGIN_INFO macros
[geanyprj.git] / tests / unittests.c
blob838e4452ecdd11abb02a8b586990080fb5ef01af
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <check.h>
4 #include <string.h>
6 #include <gtk/gtk.h>
7 #include "geany.h"
8 #include "geanyprj.h"
10 void
11 file_setup(void)
13 system("mkdir -p test_list_dir/nested/nested2");
14 system("mkdir -p test_list_dir/nested/nested3");
15 system("echo A > test_list_dir/A.txt");
16 system("echo A > test_list_dir/B.txt");
17 system("echo A > test_list_dir/nested/C.txt");
18 system("echo A > test_list_dir/nested/nested2/D.txt");
21 void
22 file_teardown(void)
24 system("rm -rf test_list_dir");
27 gboolean
28 true(G_GNUC_UNUSED const gchar * arg)
30 return TRUE;
33 START_TEST(test_get_file_list)
35 GSList *files = get_file_list("test_list_dir", NULL, NULL, NULL);
36 fail_unless(g_slist_length(files) == 4, "expected %d, get %d", 4, g_slist_length(files));
39 END_TEST;
41 START_TEST(test_get_full_path)
43 gchar *newpath = get_full_path("/home/yura/src/geanyprj/.geanyprj", "./abc.c");
44 fail_unless(strcmp(newpath, "/home/yura/src/geanyprj/abc.c") == 0,
45 "expected %s, get %s", "/home/yura/src/geanyprj/abc.c", newpath);
46 g_free(newpath);
49 END_TEST;
51 START_TEST(test_get_relative_path)
53 gchar *newpath = get_relative_path("/home/yura/src/geanyprj/.geanyprj",
54 "/home/yura/src/geanyprj/src/a.c");
55 fail_unless(strcmp(newpath, "src/a.c") == 0, "expected %s, get %s", "src/a.c", newpath);
56 g_free(newpath);
58 newpath = get_relative_path("/home/yura/src/geanyprj/.geanyprj", "/home/yura/src/geanyprj");
59 fail_unless(strcmp(newpath, "./") == 0, "expected %s, get %s", "./", newpath);
60 g_free(newpath);
63 END_TEST;
65 START_TEST(test_find_file_path)
67 fail_unless(find_file_path("insane_dir", "insane_file!!!!!!!!!!!!!!!2") == NULL);
70 END_TEST;
73 START_TEST(test_normpath)
75 gchar *newpath = normpath("/a/b");
76 fail_unless(strcmp(newpath, "/a/b") == 0, "expected %s, get %s", "/a/b", newpath);
77 g_free(newpath);
79 newpath = normpath("./a/b");
80 fail_unless(strcmp(newpath, "./a/b") == 0, "expected %s, get %s", "./a/b", newpath);
81 g_free(newpath);
83 newpath = normpath("/a/./b");
84 fail_unless(strcmp(newpath, "/a/b") == 0, "expected %s, get %s", "/a/b", newpath);
85 g_free(newpath);
87 newpath = normpath("/a/.//b");
88 fail_unless(strcmp(newpath, "/a/b") == 0, "expected %s, get %s", "/a/b", newpath);
89 g_free(newpath);
91 newpath = normpath("c:\\a\\.\\b");
92 fail_unless(strcmp(newpath, "c:/a/b") == 0, "expected %s, get %s", "c:/a/b", newpath);
93 g_free(newpath);
95 newpath = normpath("/a/../b");
96 fail_unless(strcmp(newpath, "/b") == 0, "expected %s, get %s", "/b", newpath);
97 g_free(newpath);
99 newpath = normpath("../a");
100 fail_unless(strcmp(newpath, "../a") == 0, "expected %s, get %s", "../a", newpath);
101 g_free(newpath);
103 newpath = normpath("../a/..");
104 fail_unless(strcmp(newpath, "..") == 0, "expected %s, get %s", "..", newpath);
105 g_free(newpath);
108 END_TEST;
110 Suite *
111 my_suite(void)
113 Suite *s = suite_create("Project");
114 TCase *tc_core = tcase_create("utils");
116 suite_add_tcase(s, tc_core);
117 tcase_add_test(tc_core, test_get_full_path);
118 tcase_add_test(tc_core, test_get_relative_path);
119 tcase_add_test(tc_core, test_find_file_path);
120 tcase_add_test(tc_core, test_normpath);
122 TCase *tc_file = tcase_create("file_utils");
123 suite_add_tcase(s, tc_file);
124 tcase_add_test(tc_file, test_get_file_list);
126 tcase_add_checked_fixture(tc_file, file_setup, file_teardown);
127 return s;
131 main(void)
133 int nf;
134 Suite *s = my_suite();
135 SRunner *sr = srunner_create(s);
136 srunner_run_all(sr, CK_NORMAL);
137 nf = srunner_ntests_failed(sr);
138 srunner_free(sr);
139 return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;