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
|
#include <stdlib.h>
#include <stdio.h>
#include <check.h>
#include <string.h>
#include <gtk/gtk.h>
#include "geany.h"
#include "geanyprj.h"
GeanyFunctions *geany_functions = NULL;
void
file_setup(void)
{
system("mkdir -p test_list_dir/nested/nested2");
system("mkdir -p test_list_dir/nested/nested3");
system("echo A > test_list_dir/A.txt");
system("echo A > test_list_dir/B.txt");
system("echo A > test_list_dir/nested/C.txt");
system("echo A > test_list_dir/nested/nested2/D.txt");
}
void
file_teardown(void)
{
system("rm -rf test_list_dir");
}
gboolean
true(G_GNUC_UNUSED const gchar * arg)
{
return TRUE;
}
START_TEST(test_get_file_list)
{
GSList *files = get_file_list("test_list_dir", NULL, NULL, NULL);
fail_unless(g_slist_length(files) == 4, "expected %d, get %d", 4, g_slist_length(files));
}
END_TEST;
START_TEST(test_get_full_path)
{
gchar *newpath = get_full_path("/home/yura/src/geanyprj/.geanyprj", "./abc.c");
fail_unless(strcmp(newpath, "/home/yura/src/geanyprj/abc.c") == 0,
"expected %s, get %s", "/home/yura/src/geanyprj/abc.c", newpath);
g_free(newpath);
}
END_TEST;
START_TEST(test_get_relative_path)
{
gchar *newpath = get_relative_path("/home/yura/src/geanyprj/.geanyprj",
"/home/yura/src/geanyprj/src/a.c");
fail_unless(strcmp(newpath, "src/a.c") == 0, "expected %s, get %s", "src/a.c", newpath);
g_free(newpath);
newpath = get_relative_path("/home/yura/src/geanyprj/.geanyprj", "/home/yura/src/geanyprj");
fail_unless(strcmp(newpath, "./") == 0, "expected %s, get %s", "./", newpath);
g_free(newpath);
}
END_TEST;
START_TEST(test_find_file_path)
{
fail_unless(find_file_path("insane_dir", "insane_file!!!!!!!!!!!!!!!2") == NULL);
}
END_TEST;
START_TEST(test_normpath)
{
gchar *newpath = normpath("/a/b");
fail_unless(strcmp(newpath, "/a/b") == 0, "expected %s, get %s", "/a/b", newpath);
g_free(newpath);
newpath = normpath("./a/b");
fail_unless(strcmp(newpath, "./a/b") == 0, "expected %s, get %s", "./a/b", newpath);
g_free(newpath);
newpath = normpath("/a/./b");
fail_unless(strcmp(newpath, "/a/b") == 0, "expected %s, get %s", "/a/b", newpath);
g_free(newpath);
newpath = normpath("/a/.//b");
fail_unless(strcmp(newpath, "/a/b") == 0, "expected %s, get %s", "/a/b", newpath);
g_free(newpath);
newpath = normpath("c:\\a\\.\\b");
fail_unless(strcmp(newpath, "c:/a/b") == 0, "expected %s, get %s", "c:/a/b", newpath);
g_free(newpath);
newpath = normpath("/a/../b");
fail_unless(strcmp(newpath, "/b") == 0, "expected %s, get %s", "/b", newpath);
g_free(newpath);
newpath = normpath("../a");
fail_unless(strcmp(newpath, "../a") == 0, "expected %s, get %s", "../a", newpath);
g_free(newpath);
newpath = normpath("../a/..");
fail_unless(strcmp(newpath, "..") == 0, "expected %s, get %s", "..", newpath);
g_free(newpath);
}
END_TEST;
Suite *
my_suite(void)
{
Suite *s = suite_create("Project");
TCase *tc_core = tcase_create("utils");
suite_add_tcase(s, tc_core);
tcase_add_test(tc_core, test_get_full_path);
tcase_add_test(tc_core, test_get_relative_path);
tcase_add_test(tc_core, test_find_file_path);
tcase_add_test(tc_core, test_normpath);
TCase *tc_file = tcase_create("file_utils");
suite_add_tcase(s, tc_file);
tcase_add_test(tc_file, test_get_file_list);
tcase_add_checked_fixture(tc_file, file_setup, file_teardown);
return s;
}
int
main(void)
{
int nf;
Suite *s = my_suite();
SRunner *sr = srunner_create(s);
srunner_run_all(sr, CK_NORMAL);
nf = srunner_ntests_failed(sr);
srunner_free(sr);
return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
|