| 161 | } |
| 162 | |
| 163 | static void |
| 164 | test_has_path_prefix (void) |
| 165 | { |
| 166 | static const struct |
| 167 | { |
| 168 | const char *str; |
| 169 | const char *prefix; |
| 170 | bool expected; |
| 171 | } tests[] = |
| 172 | { |
| 173 | { "/run/host/usr", "/run/host", true }, |
| 174 | { "/run/host/usr", "/run/host/", true }, |
| 175 | { "/run/host", "/run/host", true }, |
| 176 | { "////run///host////usr", "//run//host", true }, |
| 177 | { "////run///host////usr", "//run//host////", true }, |
| 178 | { "/run/hostage", "/run/host", false }, |
| 179 | /* Any number of leading slashes is ignored, even zero */ |
| 180 | { "foo/bar", "/foo", true }, |
| 181 | { "/foo/bar", "foo", true }, |
| 182 | }; |
| 183 | size_t i; |
| 184 | |
| 185 | for (i = 0; i < N_ELEMENTS (tests); i++) |
| 186 | { |
| 187 | const char *str = tests[i].str; |
| 188 | const char *prefix = tests[i].prefix; |
| 189 | bool expected = tests[i].expected; |
| 190 | |
| 191 | if (expected) |
| 192 | g_test_message ("%s should have path prefix %s", str, prefix); |
| 193 | else |
| 194 | g_test_message ("%s should not have path prefix %s", str, prefix); |
| 195 | |
| 196 | if (expected) |
| 197 | g_assert_true (has_path_prefix (str, prefix)); |
| 198 | else |
| 199 | g_assert_false (has_path_prefix (str, prefix)); |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | static void |
| 204 | test_string_builder (void) |
no test coverage detected