| 1 | #define SDL_MAIN_HANDLED 1 |
| 2 | #include <cbehave/cbehave.h> |
| 3 | |
| 4 | #include <utils.h> |
| 5 | |
| 6 | #include <SDL_joystick.h> |
| 7 | |
| 8 | #include <sys_config.h> |
| 9 | #include <sys_specifics.h> |
| 10 | |
| 11 | FEATURE(path_funcs, "Path functions") |
| 12 | mkdir("/tmp/path", MKDIR_MODE); |
| 13 | SCENARIO("Relative path") |
| 14 | GIVEN("a relative path") |
| 15 | char to[CDOGS_PATH_MAX]; |
| 16 | strcpy(to, "/tmp/path/to"); |
| 17 | |
| 18 | WHEN("I get the relative path from another path") |
| 19 | char from[CDOGS_PATH_MAX]; |
| 20 | strcpy(from, "/tmp/path/from"); |
| 21 | |
| 22 | THEN("the result should be a relative path from one to the other") |
| 23 | char rel[CDOGS_PATH_MAX]; |
| 24 | RelPath(rel, to, from); |
| 25 | SHOULD_STR_EQUAL(rel, "../to"); |
| 26 | SCENARIO_END |
| 27 | |
| 28 | SCENARIO("Relative path from different path separators") |
| 29 | GIVEN("a relative path with forward slashes") |
| 30 | char to[CDOGS_PATH_MAX]; |
| 31 | strcpy(to, "/tmp/path/to"); |
| 32 | |
| 33 | WHEN("I get the relative path from another path with back slashes") |
| 34 | char from[CDOGS_PATH_MAX]; |
| 35 | strcpy(from, "\\tmp\\path\\from"); |
| 36 | |
| 37 | THEN("the result should be a relative path from one to the other") |
| 38 | char rel[CDOGS_PATH_MAX]; |
| 39 | RelPath(rel, to, from); |
| 40 | SHOULD_STR_EQUAL(rel, "../to"); |
| 41 | SCENARIO_END |
| 42 | |
| 43 | #ifdef _MSC_VER |
| 44 | SCENARIO("Relative path to a different Windows drive") |
| 45 | GIVEN("a path to a drive") |
| 46 | char to[CDOGS_PATH_MAX]; |
| 47 | strcpy(to, "D:\\foo"); |
| 48 | |
| 49 | WHEN("I get the relative path from a different drive") |
| 50 | char from[CDOGS_PATH_MAX]; |
| 51 | strcpy(from, "C:\\foo"); |
| 52 | |
| 53 | THEN("the result should be an absolute path") |
| 54 | char rel[CDOGS_PATH_MAX]; |
| 55 | RelPath(rel, to, from); |
| 56 | SHOULD_STR_EQUAL(rel, "D:\\foo"); |
| 57 | SCENARIO_END |
| 58 | #endif |
| 59 | FEATURE_END |
| 60 | |
| 61 | CBEHAVE_RUN("Pic features are:", TEST_FEATURE(path_funcs)) |