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
|
diff --git a/bootloader/src/pyi_launch.c b/bootloader/src/pyi_launch.c
index 70747c13..1e2c9841 100644
--- a/bootloader/src/pyi_launch.c
+++ b/bootloader/src/pyi_launch.c
@@ -53,7 +53,8 @@
*/
/* Constructs the file path from given components and checks that the path exists. */
-static int
+/* NOTE: must be visible outside of this unit (i.e., non-static) due to tests! */
+int
_format_and_check_path(char *buf, const char *fmt, ...)
{
va_list args;
@@ -69,7 +70,8 @@ _format_and_check_path(char *buf, const char *fmt, ...)
}
/* Splits the item in the form path:filename */
-static int
+/* NOTE: must be visible outside of this unit (i.e., non-static) due to tests! */
+int
_split_dependency_name(char *path, char *filename, const char *item)
{
char *p;
diff --git a/bootloader/tests/test_launch.c b/bootloader/tests/test_launch.c
index 39c3809c..bab68ac5 100644
--- a/bootloader/tests/test_launch.c
+++ b/bootloader/tests/test_launch.c
@@ -20,20 +20,20 @@
#include <setjmp.h> // required fo cmocka :-(
#include <cmocka.h>
-int checkFile(char *buf, const char *fmt, ...);
+int _format_and_check_path(char *buf, const char *fmt, ...);
-static void test_checkFile(void **state) {
+static void test__format_and_check_path(void **state) {
char result[PATH_MAX];
// TODO: use some mocks to determine stat() output
errno = 0;
- assert_int_equal(-1, checkFile(result, "%s%s%s.pkg", "a1", "bb", "cc", "dd"));
+ assert_int_equal(-1, _format_and_check_path(result, "%s%s%s.pkg", "a1", "bb", "cc", "dd"));
assert_int_not_equal(errno, 0); // formatting passed, stat failed
assert_string_equal(result, "a1bbcc.pkg");
errno = 0;
- assert_int_equal(-1, checkFile(result, "%s", ""));
+ assert_int_equal(-1, _format_and_check_path(result, "%s", ""));
assert_int_not_equal(errno, 0); // formatting passed, stat failed
assert_string_equal(result, "");
@@ -42,55 +42,55 @@ static void test_checkFile(void **state) {
// a few bytes more
errno = 0;
path2[PATH_MAX+8] = '\0';
- assert_int_equal(-1, checkFile(result, "%s%s%s.pkg", "a1", path2, "ccc"));
+ assert_int_equal(-1, _format_and_check_path(result, "%s%s%s.pkg", "a1", path2, "ccc"));
assert_int_equal(errno, 0); // formatting formatting failed
// exact length
errno = 0;
path2[PATH_MAX] = '\0';
- assert_int_equal(-1, checkFile(result, "%s", path2));
+ assert_int_equal(-1, _format_and_check_path(result, "%s", path2));
assert_int_equal(errno, 0); // formatting formatting failed
// one byte less
errno = 0;
path2[PATH_MAX-1] = '\0';
- assert_int_equal(-1, checkFile(result, "%s", path2));
+ assert_int_equal(-1, _format_and_check_path(result, "%s", path2));
assert_int_not_equal(errno, 0); // formatting passed, stat failed
}
-int splitName(char *path, char *filename, const char *item);
+int _split_dependency_name(char *path, char *filename, const char *item);
-static void test_splitName(void **state) {
+static void test_split_dependency_name(void **state) {
char path[PATH_MAX];
char filename[PATH_MAX];
// TODO: use some mocks to determine
- assert_int_equal(0, splitName(path, filename, "aaa:bbb"));
+ assert_int_equal(0, _split_dependency_name(path, filename, "aaa:bbb"));
assert_string_equal(path, "aaa");
assert_string_equal(filename, "bbb");
- assert_int_equal(-1, splitName(path, filename, ""));
- assert_int_equal(-1, splitName(path, filename, ":"));
- assert_int_equal(-1, splitName(path, filename, "aaa"));
- assert_int_equal(-1, splitName(path, filename, "aaa:"));
- assert_int_equal(-1, splitName(path, filename, ":bbb"));
+ assert_int_equal(-1, _split_dependency_name(path, filename, ""));
+ assert_int_equal(-1, _split_dependency_name(path, filename, ":"));
+ assert_int_equal(-1, _split_dependency_name(path, filename, "aaa"));
+ assert_int_equal(-1, _split_dependency_name(path, filename, "aaa:"));
+ assert_int_equal(-1, _split_dependency_name(path, filename, ":bbb"));
// these cases are not expected to occur in real life
- assert_int_equal(0, splitName(path, filename, "aaa:::"));
+ assert_int_equal(0, _split_dependency_name(path, filename, "aaa:::"));
assert_string_equal(filename, "::");
- assert_int_equal(-1, splitName(path, filename, ":::bbb"));
+ assert_int_equal(-1, _split_dependency_name(path, filename, ":::bbb"));
char *path2 = (char *) malloc(PATH_MAX+10);
memset(path2, 'a', PATH_MAX+8);
path2[10] = ':';
// a few bytes more
path2[PATH_MAX+8] = '\0';
- assert_int_equal(-1, splitName(path, filename, path2));
+ assert_int_equal(-1, _split_dependency_name(path, filename, path2));
// exact length
path2[PATH_MAX] = '\0';
- assert_int_equal(-1, splitName(path, filename, path2));
+ assert_int_equal(-1, _split_dependency_name(path, filename, path2));
// one byte less
path2[PATH_MAX-1] = '\0';
- assert_int_equal(0, splitName(path, filename, path2));
+ assert_int_equal(0, _split_dependency_name(path, filename, path2));
assert_string_equal(path, "aaaaaaaaaa");
}
@@ -101,8 +101,8 @@ int main(void)
#endif
{
const struct CMUnitTest tests[] = {
- cmocka_unit_test(test_checkFile),
- cmocka_unit_test(test_splitName),
+ cmocka_unit_test(test__format_and_check_path),
+ cmocka_unit_test(test_split_dependency_name),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}
--
2.39.1
|