diff options
author | Cong <congusbongus@gmail.com> | 2016-07-17 06:05:03 +0300 |
---|---|---|
committer | Cong <congusbongus@gmail.com> | 2016-07-17 06:05:03 +0300 |
commit | e33a1dadc7d8f2cc80e50e992b2a596cde1f00e1 (patch) | |
tree | acf87f08269b01fda60355dc3f76f69ef0ffa6c3 /tests | |
parent | fe199959435f04931789ae98cad53a64148c856c (diff) |
Fix tinydir_file_open with filename only failure in Windows (fixes #35)
Implement file_open_test for Windows
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/cbehave/cbehave.h | 2 | ||||
-rw-r--r-- | tests/file_open_test.c | 28 |
3 files changed, 25 insertions, 7 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8322d7b..ddf4a6f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -12,7 +12,7 @@ add_subdirectory(cbehave) if(MSVC) add_definitions(-W4 -WX -wd"4127" -wd"4102" -wd"4996") else() - add_definitions(-fsigned-char -Wall -W -Wshadow -Wpointer-arith -Wcast-qual -Winline -Werror -Wno-unused-label -Wno-unused-parameter) + add_definitions(-fsigned-char -Wall -W -Wshadow -Wpointer-arith -Wcast-qual -Winline -Werror -Wno-unused-label) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wstrict-prototypes") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") if("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") diff --git a/tests/cbehave/cbehave.h b/tests/cbehave/cbehave.h index aeaea99..ae920a6 100644 --- a/tests/cbehave/cbehave.h +++ b/tests/cbehave/cbehave.h @@ -157,7 +157,7 @@ if (!(cond)) {\ } while(0) #define CBEHAVE_RUN(_description, ...)\ -int main(int argc, char *argv[]) {\ +int main() {\ cbehave_feature _cfeatures[] = {__VA_ARGS__};\ return cbehave_runner(_description, _cfeatures);\ } diff --git a/tests/file_open_test.c b/tests/file_open_test.c index 0132ba0..dc238c3 100644 --- a/tests/file_open_test.c +++ b/tests/file_open_test.c @@ -1,16 +1,34 @@ #include <stdio.h> -#include <stdlib.h> -#include <unistd.h> #include <tinydir.h> #include "cbehave.h" +static void make_temp_file(const char *prefix, char *out) +{ +#ifdef _MSC_VER + if (GetTempFileName(".", prefix, 0, out) != 0) + { + // Strip the ".\\" prefix + if (strncmp(out, ".\\", 2) == 0) + { + memmove(out, out + 2, strlen(out)); + } + // Create file + fclose(fopen(out, "w")); + } +#else + #include <stdlib.h> + #include <unistd.h> + sprintf(out, "%sXXXXXX", prefix); + close(mkstemp(out)); +#endif +} + FEATURE(file_open, "File open") SCENARIO("Open file in current directory") GIVEN("a file in the current directory") - char name[] = "fileXXXXXX"; - int fd = mkstemp(name); - close(fd); + char name[4096]; + make_temp_file("temp_file_", name); WHEN("we open it") tinydir_file file; int r = tinydir_file_open(&file, name); |