diff options
Diffstat (limited to 'lib/x1000-installer/test')
-rw-r--r-- | lib/x1000-installer/test/data/lines_shuffled.txt | 108 | ||||
-rw-r--r-- | lib/x1000-installer/test/data/lines_sorted.txt | 36 | ||||
-rw-r--r-- | lib/x1000-installer/test/main.c | 86 | ||||
-rw-r--r-- | lib/x1000-installer/test/test.h | 39 | ||||
-rw-r--r-- | lib/x1000-installer/test/test_flashmap.c | 140 | ||||
-rw-r--r-- | lib/x1000-installer/test/test_stream.c | 108 |
6 files changed, 0 insertions, 517 deletions
diff --git a/lib/x1000-installer/test/data/lines_shuffled.txt b/lib/x1000-installer/test/data/lines_shuffled.txt deleted file mode 100644 index c138fe7e7c..0000000000 --- a/lib/x1000-installer/test/data/lines_shuffled.txt +++ /dev/null | |||
@@ -1,108 +0,0 @@ | |||
1 | 1234567890abcdefghijklmnopqrstuvw | ||
2 | 1234567890abcdefghijklmnopqrst | ||
3 | 123 | ||
4 | 1234567890abcdef | ||
5 | 1234567890abcdefghijklm | ||
6 | 1234567890abcdefghijklmn | ||
7 | 1234567890abcdefghijk | ||
8 | 1234567890abcdefgh | ||
9 | 123456 | ||
10 | 1234567 | ||
11 | 1234567890a | ||
12 | 1234567890abcdefghijklm | ||
13 | 1 | ||
14 | 1234567890abcdefghijklmnopq | ||
15 | 1234567890abcdefghijkl | ||
16 | 1234567890abcdefghijklmno | ||
17 | 1234567890abcdefghijklmnopqrstuvwxyz | ||
18 | 1234567890abcdefghijklmnopq | ||
19 | 1234567890abcdefghijklmno | ||
20 | 1234567890abcdefghijklmnopq | ||
21 | 1234567890abcdefghijklmn | ||
22 | 1234 | ||
23 | 1234567890abcdefghijklmnop | ||
24 | 123456789 | ||
25 | 1234 | ||
26 | 12345 | ||
27 | 1234567890ab | ||
28 | 1234567890abcdefghijklmnopqrstuvwxy | ||
29 | 1234567890abcdefghijklmnopqrst | ||
30 | 1234567890abcdefghijklmnopqrs | ||
31 | 1234567890abcdefghijklmnopqrs | ||
32 | 12345678 | ||
33 | 1234567890ab | ||
34 | 1234567890a | ||
35 | 1234567890abcdefghijklmnopqr | ||
36 | 123456 | ||
37 | 1234567890abcdefghijkl | ||
38 | 1234567890abcdefghijklm | ||
39 | 1234567890abcdefghijklmnopqrstuvwxy | ||
40 | 1234567890abcdefghijklmnopqrstuvwxy | ||
41 | 1234567890abcdefghijklmnopqrstuv | ||
42 | 1234567890abcdefghijklmnopqrstuv | ||
43 | 1234567890abcdefghijklmnopqrstuvwx | ||
44 | 1234567890abcde | ||
45 | 1 | ||
46 | 1234567890abcdefgh | ||
47 | 1234567890abcdef | ||
48 | 1234567890abcdefghi | ||
49 | 1234567890 | ||
50 | 1 | ||
51 | 12345 | ||
52 | 123456789 | ||
53 | 1234567 | ||
54 | 1234567890abcdefghi | ||
55 | 1234567890abcdefghijklmnopqrstu | ||
56 | 1234567890abcdefghijklmnopqrstuvwx | ||
57 | 1234567890abcdefghijklmnopqrstuv | ||
58 | 1234567890abcd | ||
59 | 12345 | ||
60 | 1234567890abcdefg | ||
61 | 1234567890abcd | ||
62 | 1234567890abcdefghijklmnopqrstuvw | ||
63 | 1234567890abcdefghijklmnopqrstuvwxyz | ||
64 | 12345678 | ||
65 | 1234567890abcd | ||
66 | 1234567890abcdefghijklmnop | ||
67 | 123 | ||
68 | 1234567890abcdefg | ||
69 | 123456 | ||
70 | 1234567890abcdefghij | ||
71 | 1234567890abcdefg | ||
72 | 1234567890abcdefghi | ||
73 | 1234567890 | ||
74 | 1234567890abcdefghijklmno | ||
75 | 1234567890abcdefghij | ||
76 | 1234567890abcdefghijklmn | ||
77 | 1234567890abcde | ||
78 | 1234567890abc | ||
79 | 123456789 | ||
80 | 1234567890abcdefgh | ||
81 | 1234567890abcdefghij | ||
82 | 1234567890abcdefghijklmnopqrstuvwx | ||
83 | 1234567890abcdefghijklmnopqr | ||
84 | 1234567890abcdefghijklmnopqrst | ||
85 | 1234567890abcdefghijklmnopqrs | ||
86 | 1234567890abcdefghijklmnopqrstuvwxyz | ||
87 | 1234567890abcdefghijkl | ||
88 | 1234 | ||
89 | 12 | ||
90 | 12 | ||
91 | 12345678 | ||
92 | 1234567 | ||
93 | 1234567890 | ||
94 | 123 | ||
95 | 1234567890abc | ||
96 | 1234567890abcdefghijklmnopqr | ||
97 | 12 | ||
98 | 1234567890abcde | ||
99 | 1234567890abcdef | ||
100 | 1234567890a | ||
101 | 1234567890ab | ||
102 | 1234567890abcdefghijk | ||
103 | 1234567890abcdefghijklmnopqrstu | ||
104 | 1234567890abcdefghijklmnop | ||
105 | 1234567890abcdefghijk | ||
106 | 1234567890abcdefghijklmnopqrstu | ||
107 | 1234567890abcdefghijklmnopqrstuvw | ||
108 | 1234567890abc | ||
diff --git a/lib/x1000-installer/test/data/lines_sorted.txt b/lib/x1000-installer/test/data/lines_sorted.txt deleted file mode 100644 index 4944efd614..0000000000 --- a/lib/x1000-installer/test/data/lines_sorted.txt +++ /dev/null | |||
@@ -1,36 +0,0 @@ | |||
1 | 1 | ||
2 | 12 | ||
3 | 123 | ||
4 | 1234 | ||
5 | 12345 | ||
6 | 123456 | ||
7 | 1234567 | ||
8 | 12345678 | ||
9 | 123456789 | ||
10 | 1234567890 | ||
11 | 1234567890a | ||
12 | 1234567890ab | ||
13 | 1234567890abc | ||
14 | 1234567890abcd | ||
15 | 1234567890abcde | ||
16 | 1234567890abcdef | ||
17 | 1234567890abcdefg | ||
18 | 1234567890abcdefgh | ||
19 | 1234567890abcdefghi | ||
20 | 1234567890abcdefghij | ||
21 | 1234567890abcdefghijk | ||
22 | 1234567890abcdefghijkl | ||
23 | 1234567890abcdefghijklm | ||
24 | 1234567890abcdefghijklmn | ||
25 | 1234567890abcdefghijklmno | ||
26 | 1234567890abcdefghijklmnop | ||
27 | 1234567890abcdefghijklmnopq | ||
28 | 1234567890abcdefghijklmnopqr | ||
29 | 1234567890abcdefghijklmnopqrs | ||
30 | 1234567890abcdefghijklmnopqrst | ||
31 | 1234567890abcdefghijklmnopqrstu | ||
32 | 1234567890abcdefghijklmnopqrstuv | ||
33 | 1234567890abcdefghijklmnopqrstuvw | ||
34 | 1234567890abcdefghijklmnopqrstuvwx | ||
35 | 1234567890abcdefghijklmnopqrstuvwxy | ||
36 | 1234567890abcdefghijklmnopqrstuvwxyz | ||
diff --git a/lib/x1000-installer/test/main.c b/lib/x1000-installer/test/main.c deleted file mode 100644 index f9bff1b704..0000000000 --- a/lib/x1000-installer/test/main.c +++ /dev/null | |||
@@ -1,86 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2021 Aidan MacDonald | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include <stdio.h> | ||
23 | |||
24 | static int test_num_executed = 0; | ||
25 | static int test_num_failed = 0; | ||
26 | int test_num_asserts_executed = 0; | ||
27 | int test_num_asserts_failed = 0; | ||
28 | |||
29 | void test_failure(const char* file, int line, const char* msg) | ||
30 | { | ||
31 | fprintf(stderr, "%s:%d: ASSERTION FAILED: %s\n", file, line, msg); | ||
32 | ++test_num_asserts_failed; | ||
33 | } | ||
34 | |||
35 | typedef void(*test_t)(void); | ||
36 | |||
37 | struct test_info { | ||
38 | const char* name; | ||
39 | test_t func; | ||
40 | }; | ||
41 | |||
42 | extern void test_stream_read_lines(void); | ||
43 | extern void test_stream_read_line_too_long(void); | ||
44 | extern void test_flashmap_parseline(void); | ||
45 | |||
46 | #define TEST(x) {#x, x} | ||
47 | static const struct test_info all_tests[] = { | ||
48 | TEST(test_stream_read_lines), | ||
49 | TEST(test_stream_read_line_too_long), | ||
50 | TEST(test_flashmap_parseline), | ||
51 | }; | ||
52 | #undef TEST | ||
53 | |||
54 | void run_test(const struct test_info* tinfo) | ||
55 | { | ||
56 | int asserts_now = test_num_asserts_failed; | ||
57 | ++test_num_executed; | ||
58 | |||
59 | fprintf(stderr, "RUN %s\n", tinfo->name); | ||
60 | tinfo->func(); | ||
61 | |||
62 | if(test_num_asserts_failed > asserts_now) { | ||
63 | fprintf(stderr, " %s: FAILED!\n", tinfo->name); | ||
64 | ++test_num_failed; | ||
65 | } | ||
66 | } | ||
67 | |||
68 | int main(int argc, char* argv[]) | ||
69 | { | ||
70 | (void)argc; | ||
71 | (void)argv; | ||
72 | |||
73 | size_t num_tests = sizeof(all_tests) / sizeof(struct test_info); | ||
74 | for(size_t i = 0; i < num_tests; ++i) | ||
75 | run_test(&all_tests[i]); | ||
76 | |||
77 | fprintf(stderr, "------------------------------------------\n"); | ||
78 | fprintf(stderr, "TEST COMPLETE\n"); | ||
79 | fprintf(stderr, " Tests %d failed / %d executed\n", | ||
80 | test_num_failed, test_num_executed); | ||
81 | fprintf(stderr, " Assertions %d failed / %d executed\n", | ||
82 | test_num_asserts_failed, test_num_asserts_executed); | ||
83 | |||
84 | if(test_num_failed > 0) | ||
85 | return 1; | ||
86 | } | ||
diff --git a/lib/x1000-installer/test/test.h b/lib/x1000-installer/test/test.h deleted file mode 100644 index 3d47a19d87..0000000000 --- a/lib/x1000-installer/test/test.h +++ /dev/null | |||
@@ -1,39 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2021 Aidan MacDonald | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #ifndef TEST_H | ||
23 | #define TEST_H | ||
24 | |||
25 | extern int test_num_asserts_executed; | ||
26 | extern int test_num_asserts_failed; | ||
27 | |||
28 | extern void test_failure(const char* file, int line, const char* msg); | ||
29 | |||
30 | #define T_ASSERT(cond) \ | ||
31 | do { \ | ||
32 | ++test_num_asserts_executed; \ | ||
33 | if(!(cond)) { \ | ||
34 | test_failure(__FILE__, __LINE__, #cond); \ | ||
35 | goto cleanup; \ | ||
36 | } \ | ||
37 | } while(0) | ||
38 | |||
39 | #endif | ||
diff --git a/lib/x1000-installer/test/test_flashmap.c b/lib/x1000-installer/test/test_flashmap.c deleted file mode 100644 index 5e7aa39d78..0000000000 --- a/lib/x1000-installer/test/test_flashmap.c +++ /dev/null | |||
@@ -1,140 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2021 Aidan MacDonald | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "test.h" | ||
23 | #include "xf_stream.h" | ||
24 | #include "xf_flashmap.h" | ||
25 | #include "xf_error.h" | ||
26 | #include "file.h" | ||
27 | #include <string.h> | ||
28 | #include <stdbool.h> | ||
29 | #include <stdio.h> | ||
30 | |||
31 | #define MD5SUM \ | ||
32 | "abcdef012345ABCDEF012345abcdef01" | ||
33 | #define MD5SUM_L \ | ||
34 | "abcdef012345abcdef012345abcdef01" | ||
35 | #define LONG_NAME \ | ||
36 | "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | ||
37 | #define OVERLONG_NAME \ | ||
38 | LONG_NAME "a" | ||
39 | |||
40 | static const struct parseline_test { | ||
41 | const char* line; | ||
42 | int rc; | ||
43 | const char* name; | ||
44 | const char* md5; | ||
45 | uint32_t file_length; | ||
46 | uint32_t offset; | ||
47 | uint32_t length; | ||
48 | int flags; | ||
49 | } parseline_tests[] = { | ||
50 | {"test1 " MD5SUM " 1234 0x9876 42", | ||
51 | XF_E_SUCCESS, "test1", MD5SUM_L, 1234, 0x9876, 42, | ||
52 | XF_MAP_HAS_FILE_LENGTH|XF_MAP_HAS_MD5}, | ||
53 | {" test1 " MD5SUM " 1234 0x9876 42", | ||
54 | XF_E_SUCCESS, "test1", MD5SUM_L, 1234, 0x9876, 42, | ||
55 | XF_MAP_HAS_FILE_LENGTH|XF_MAP_HAS_MD5}, | ||
56 | {"test1 " MD5SUM " 1234 0x9876 42 \r", | ||
57 | XF_E_SUCCESS, "test1", MD5SUM_L, 1234, 0x9876, 42, | ||
58 | XF_MAP_HAS_FILE_LENGTH|XF_MAP_HAS_MD5}, | ||
59 | {"test1 " MD5SUM " 1234 0x9876 42 # junk", | ||
60 | XF_E_SYNTAX_ERROR, NULL, NULL, 0, 0, 0, 0}, | ||
61 | {OVERLONG_NAME, | ||
62 | XF_E_FILENAME_TOO_LONG, NULL, NULL, 0, 0, 0, 0}, | ||
63 | {LONG_NAME " " MD5SUM " 1234 0x9876 42", | ||
64 | XF_E_SUCCESS, LONG_NAME, MD5SUM_L, 1234, 0x9876, 42, | ||
65 | XF_MAP_HAS_FILE_LENGTH|XF_MAP_HAS_MD5}, | ||
66 | {"test1 " MD5SUM " 4294967295 0 0xffffffff", | ||
67 | XF_E_SUCCESS, "test1", MD5SUM_L, 4294967295, 0, 0xfffffffful, | ||
68 | XF_MAP_HAS_FILE_LENGTH|XF_MAP_HAS_MD5}, | ||
69 | {"test1 " MD5SUM " 4294967295 1 0xffffffff", | ||
70 | XF_E_INT_OVERFLOW, NULL, NULL, 0, 0, 0, 0}, | ||
71 | {"test1 " MD5SUM " 4294967296 0 0xffffffff", | ||
72 | XF_E_INT_OVERFLOW, NULL, NULL, 0, 0, 0, 0}, | ||
73 | {"test1 " MD5SUM " 100294967295 0 0xffffffff", | ||
74 | XF_E_INT_OVERFLOW, NULL, NULL, 0, 0, 0, 0}, | ||
75 | {"test1 " MD5SUM " 0 0 0xffffffff0", | ||
76 | XF_E_INT_OVERFLOW, NULL, NULL, 0, 0, 0, 0}, | ||
77 | {"test1 " MD5SUM " 0 0 0x100000000", | ||
78 | XF_E_INT_OVERFLOW, NULL, NULL, 0, 0, 0, 0}, | ||
79 | {"test1 " MD5SUM " 0 0 0x100000001", | ||
80 | XF_E_INT_OVERFLOW, NULL, NULL, 0, 0, 0, 0}, | ||
81 | {"<", | ||
82 | XF_E_SYNTAX_ERROR, NULL, NULL, 0, 0, 0, 0}, | ||
83 | {"test1 abcXdef", | ||
84 | XF_E_SYNTAX_ERROR, NULL, NULL, 0, 0, 0, 0}, | ||
85 | {"test1 " MD5SUM "0", | ||
86 | XF_E_SYNTAX_ERROR, NULL, NULL, 0, 0, 0, 0}, | ||
87 | {"test1 - 4567 0xabcd", | ||
88 | XF_E_SUCCESS, "test1", NULL, 0, 4567, 0xabcd, 0}, | ||
89 | {"test1 - 0 0x123456789", | ||
90 | XF_E_INT_OVERFLOW, NULL, NULL, 0, 0, 0, 0}, | ||
91 | {"test1 - 4f", | ||
92 | XF_E_SYNTAX_ERROR, NULL, NULL, 0, 0, 0, 0}, | ||
93 | }; | ||
94 | |||
95 | static void md5_to_string(char* buf, const uint8_t* md5) | ||
96 | { | ||
97 | const char* hex = "0123456789abcdef"; | ||
98 | for(int i = 0; i < 16; ++i) { | ||
99 | uint8_t byte = md5[i]; | ||
100 | buf[2*i] = hex[(byte >> 4) & 0xf]; | ||
101 | buf[2*i+1] = hex[byte & 0xf]; | ||
102 | } | ||
103 | |||
104 | buf[32] = '\0'; | ||
105 | } | ||
106 | |||
107 | int test_flashmap_parseline(void) | ||
108 | { | ||
109 | int rc; | ||
110 | struct xf_map map; | ||
111 | char md5string[33]; | ||
112 | |||
113 | size_t num_cases = sizeof(parseline_tests) / sizeof(struct parseline_test); | ||
114 | const struct parseline_test* test = &parseline_tests[0]; | ||
115 | |||
116 | for(; num_cases > 0; --num_cases, ++test) { | ||
117 | rc = xf_map_parseline(test->line, &map); | ||
118 | |||
119 | T_ASSERT(rc == test->rc); | ||
120 | if(rc != XF_E_SUCCESS) | ||
121 | continue; | ||
122 | |||
123 | T_ASSERT(strcmp(map.name, test->name) == 0); | ||
124 | T_ASSERT(map.offset == test->offset); | ||
125 | T_ASSERT(map.length == test->length); | ||
126 | T_ASSERT(map.flags == test->flags); | ||
127 | |||
128 | if(test->flags & XF_MAP_HAS_MD5) { | ||
129 | md5_to_string(md5string, map.md5); | ||
130 | T_ASSERT(strcmp(md5string, test->md5) == 0); | ||
131 | } | ||
132 | |||
133 | if(test->flags & XF_MAP_HAS_FILE_LENGTH) { | ||
134 | T_ASSERT(map.file_length == test->file_length); | ||
135 | } | ||
136 | } | ||
137 | |||
138 | cleanup: | ||
139 | return rc; | ||
140 | } | ||
diff --git a/lib/x1000-installer/test/test_stream.c b/lib/x1000-installer/test/test_stream.c deleted file mode 100644 index b4a5723b76..0000000000 --- a/lib/x1000-installer/test/test_stream.c +++ /dev/null | |||
@@ -1,108 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2021 Aidan MacDonald | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "test.h" | ||
23 | #include "xf_stream.h" | ||
24 | #include "xf_error.h" | ||
25 | #include "file.h" | ||
26 | #include <string.h> | ||
27 | #include <stdbool.h> | ||
28 | #include <stdio.h> | ||
29 | |||
30 | #define TESTDATADIR "test/data/" | ||
31 | #define TESTFILE_SHUFFLED TESTDATADIR "lines_shuffled.txt" | ||
32 | #define TESTFILE_SORTED TESTDATADIR "lines_sorted.txt" | ||
33 | |||
34 | const char line_string[] = "1234567890abcdefghijklmnopqrstuvwxyz"; | ||
35 | |||
36 | static int read_line_cb(int n, char* buf, void* arg) | ||
37 | { | ||
38 | int* max_n = (int*)arg; | ||
39 | *max_n = n; | ||
40 | |||
41 | T_ASSERT(strlen(buf) > 0); | ||
42 | T_ASSERT(strncmp(line_string, buf, strlen(buf)) == 0); | ||
43 | |||
44 | cleanup: | ||
45 | return 0; | ||
46 | } | ||
47 | |||
48 | void test_stream_read_lines(void) | ||
49 | { | ||
50 | struct xf_stream s; | ||
51 | int rc; | ||
52 | char buf[100]; | ||
53 | bool s_open = false; | ||
54 | |||
55 | for(int bufsz = 38; bufsz <= 100; bufsz += 1) { | ||
56 | rc = xf_open_file(TESTFILE_SHUFFLED, O_RDONLY, &s); | ||
57 | T_ASSERT(rc == 0); | ||
58 | s_open = true; | ||
59 | |||
60 | int max_n = 0; | ||
61 | rc = xf_stream_read_lines(&s, buf, bufsz, &read_line_cb, &max_n); | ||
62 | T_ASSERT(rc == 0); | ||
63 | T_ASSERT(max_n+1 == 108); | ||
64 | |||
65 | xf_stream_close(&s); | ||
66 | s_open = false; | ||
67 | } | ||
68 | |||
69 | cleanup: | ||
70 | if(s_open) | ||
71 | xf_stream_close(&s); | ||
72 | return; | ||
73 | } | ||
74 | |||
75 | void test_stream_read_line_too_long(void) | ||
76 | { | ||
77 | struct xf_stream s; | ||
78 | int rc; | ||
79 | char buf[38]; | ||
80 | bool s_open = false; | ||
81 | |||
82 | for(int bufsz = 0; bufsz <= 38; bufsz += 1) { | ||
83 | rc = xf_open_file(TESTFILE_SORTED, O_RDONLY, &s); | ||
84 | T_ASSERT(rc == 0); | ||
85 | s_open = true; | ||
86 | |||
87 | int max_n = -1; | ||
88 | rc = xf_stream_read_lines(&s, buf, bufsz, &read_line_cb, &max_n); | ||
89 | if(bufsz == 38) { | ||
90 | T_ASSERT(rc == 0); | ||
91 | T_ASSERT(max_n+1 == 36); | ||
92 | } else { | ||
93 | T_ASSERT(rc == XF_E_LINE_TOO_LONG); | ||
94 | if(bufsz <= 1) | ||
95 | T_ASSERT(max_n == -1); | ||
96 | else | ||
97 | T_ASSERT(max_n+1 == bufsz-2); | ||
98 | } | ||
99 | |||
100 | xf_stream_close(&s); | ||
101 | s_open = false; | ||
102 | } | ||
103 | |||
104 | cleanup: | ||
105 | if(s_open) | ||
106 | xf_stream_close(&s); | ||
107 | return; | ||
108 | } | ||