summaryrefslogtreecommitdiff
path: root/src/tests/elementary/elm_code_file_test_load.c
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2016-06-02 17:19:08 -0700
committerCedric BAIL <cedric@osg.samsung.com>2016-06-02 17:19:08 -0700
commitd384012307881898a2df49f68fa6b46a4cd9972d (patch)
tree31706c65b8c56083a151470721cf36e8bb46939d /src/tests/elementary/elm_code_file_test_load.c
parent9f129a8711f9bb71ee7cf6c13f7965926255c975 (diff)
elementary: merging in elm_code widget.
Theme is not there as it should be manually merged into the elementary default theme.
Diffstat (limited to 'src/tests/elementary/elm_code_file_test_load.c')
-rw-r--r--src/tests/elementary/elm_code_file_test_load.c162
1 files changed, 162 insertions, 0 deletions
diff --git a/src/tests/elementary/elm_code_file_test_load.c b/src/tests/elementary/elm_code_file_test_load.c
new file mode 100644
index 0000000..7e21b23
--- /dev/null
+++ b/src/tests/elementary/elm_code_file_test_load.c
@@ -0,0 +1,162 @@
1#ifdef HAVE_CONFIG_H
2# include "elementary_config.h"
3#endif
4
5#define ELM_INTERNAL_API_ARGESFSDFEFC
6
7#include "elm_suite.h"
8#include "Elementary.h"
9
10START_TEST (elm_code_file_load)
11{
12 char *path = TESTS_SRC_DIR "/testfile.txt";
13 char real[EINA_PATH_MAX];
14 Elm_Code_File *file;
15 Elm_Code *code;
16
17 elm_init(1, NULL);
18 code = elm_code_create();
19 file = elm_code_file_open(code, path);
20 realpath(path, real);
21
22 ck_assert_str_eq(basename(path), elm_code_file_filename_get(file));
23 ck_assert_str_eq(real, elm_code_file_path_get(file));
24 elm_code_file_close(file);
25 elm_code_free(code);
26 elm_shutdown();
27}
28END_TEST
29
30START_TEST (elm_code_file_load_lines)
31{
32 char *path = TESTS_SRC_DIR "/testfile.txt";
33 Elm_Code_File *file;
34 Elm_Code *code;
35
36 elm_init(1, NULL);
37 code = elm_code_create();
38 file = elm_code_file_open(code, path);
39
40 ck_assert_uint_eq(4, elm_code_file_lines_get(file));
41 elm_code_file_close(file);
42 elm_code_free(code);
43 elm_shutdown();
44}
45END_TEST
46
47START_TEST (elm_code_file_load_blank_lines)
48{
49 char *path = TESTS_SRC_DIR "/testfile-withblanks.txt";
50 Elm_Code_File *file;
51 Elm_Code *code;
52
53 elm_init(1, NULL);
54 code = elm_code_create();
55 file = elm_code_file_open(code, path);
56
57 ck_assert_uint_eq(8, elm_code_file_lines_get(file));
58 elm_code_file_close(file);
59 elm_code_free(code);
60 elm_shutdown();
61}
62END_TEST
63
64START_TEST (elm_code_file_load_windows)
65{
66 char *path = TESTS_SRC_DIR "/testfile-windows.txt";
67 Elm_Code_File *file;
68 Elm_Code *code;
69
70 elm_init(1, NULL);
71 code = elm_code_create();
72 file = elm_code_file_open(code, path);
73
74 ck_assert_uint_eq(4, elm_code_file_lines_get(file));
75 elm_code_file_close(file);
76 elm_code_free(code);
77 elm_shutdown();
78}
79END_TEST
80
81static void _assert_line_content_eq(const char *content, Elm_Code_Line *line)
82{
83 int length;
84 int c;
85
86 length = strlen(content);
87 ck_assert_int_eq(length, line->length);
88
89 for (c = 0; c < length; c++)
90 ck_assert_uint_eq(content[c], line->content[c]);
91}
92
93START_TEST (elm_code_file_load_content)
94{
95 char *path = TESTS_SRC_DIR "/testfile.txt";
96 Elm_Code_File *file;
97 Elm_Code *code;
98
99 elm_init(1, NULL);
100 code = elm_code_create();
101 file = elm_code_file_open(code, path);
102
103 _assert_line_content_eq("line2", elm_code_file_line_get(file, 2));
104 _assert_line_content_eq("another line", elm_code_file_line_get(file, 4));
105 elm_code_file_close(file);
106 elm_code_free(code);
107 elm_shutdown();
108}
109END_TEST
110
111START_TEST (elm_code_file_line_ending_unix)
112{
113 char *path = TESTS_SRC_DIR "/testfile.txt";
114 Elm_Code_File *file;
115 Elm_Code *code;
116 short len;
117
118 elm_init(1, NULL);
119 code = elm_code_create();
120 file = elm_code_file_open(code, path);
121
122 ck_assert_int_eq(ELM_CODE_FILE_LINE_ENDING_UNIX, elm_code_file_line_ending_get(file));
123 ck_assert_str_eq("\n", elm_code_file_line_ending_chars_get(file, &len));
124 ck_assert_int_eq(1, len);
125
126 elm_code_file_close(file);
127 elm_code_free(code);
128 elm_shutdown();
129}
130END_TEST
131
132START_TEST (elm_code_file_line_ending_windows)
133{
134 char *path = TESTS_SRC_DIR "/testfile-windows.txt";
135 Elm_Code_File *file;
136 Elm_Code *code;
137 short len;
138
139 elm_init(1, NULL);
140 code = elm_code_create();
141 file = elm_code_file_open(code, path);
142
143 ck_assert_int_eq(ELM_CODE_FILE_LINE_ENDING_WINDOWS, elm_code_file_line_ending_get(file));
144 ck_assert_str_eq("\r\n", elm_code_file_line_ending_chars_get(file, &len));
145 ck_assert_int_eq(2, len);
146
147 elm_code_file_close(file);
148 elm_code_free(code);
149 elm_shutdown();
150}
151END_TEST
152
153void elm_code_file_test_load(TCase *tc)
154{
155 tcase_add_test(tc, elm_code_file_load);
156 tcase_add_test(tc, elm_code_file_load_lines);
157 tcase_add_test(tc, elm_code_file_load_blank_lines);
158 tcase_add_test(tc, elm_code_file_load_windows);
159 tcase_add_test(tc, elm_code_file_load_content);
160 tcase_add_test(tc, elm_code_file_line_ending_unix);
161 tcase_add_test(tc, elm_code_file_line_ending_windows);
162}