-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add windows unicode test Update .gitignore for VS2015
- Loading branch information
Showing
8 changed files
with
106 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ Win32/ | |
*.vcxproj.user | ||
*.vcxproj | ||
*.vcxproj.filters | ||
*.VC.* | ||
*.sln | ||
|
||
# Linux | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <stdio.h> | ||
|
||
#ifdef _MSC_VER | ||
#define WIN32_LEAN_AND_MEAN | ||
#include <windows.h> | ||
#endif | ||
|
||
|
||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#pragma once | ||
|
||
void make_temp_file(const char *prefix, char *out); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include <stdio.h> | ||
|
||
#define UNICODE | ||
#include <tinydir.h> | ||
#include "cbehave.h" | ||
|
||
|
||
#define TEST_PATH L"windows_unicode_test" | ||
#define TEST_PATH_A "windows_unicode_test" | ||
|
||
void make_temp_file_utf16(const wchar_t *prefix, wchar_t *out) | ||
{ | ||
if (GetTempFileNameW(TEST_PATH, prefix, 0, out) != 0) | ||
{ | ||
// Create file | ||
fclose(_wfopen(out, L"w")); | ||
// Strip the ".\\" prefix | ||
if (wcsncmp(out, TEST_PATH L"\\", wcslen(TEST_PATH) + 1) == 0) | ||
{ | ||
memmove(out, out + wcslen(TEST_PATH) + 1, wcslen(out)); | ||
} | ||
} | ||
} | ||
|
||
FEATURE(windows_unicode, "Windows Unicode") | ||
SCENARIO("Open directory with unicode file names") | ||
GIVEN("a directory with unicode file names") | ||
CreateDirectoryW(TEST_PATH, NULL); | ||
wchar_t name[4096]; | ||
make_temp_file_utf16(L"t📁", name); | ||
WHEN("we open the directory") | ||
tinydir_dir dir; | ||
int r = tinydir_open(&dir, TEST_PATH); | ||
THEN("the result should be successful") | ||
SHOULD_INT_EQUAL(r, 0); | ||
AND("iterating it, we should find the file") | ||
bool found = false; | ||
while (dir.has_next) | ||
{ | ||
tinydir_file file; | ||
tinydir_readfile(&dir, &file); | ||
if (wcscmp((wchar_t *)file.name, name) == 0) | ||
{ | ||
found = true; | ||
} | ||
tinydir_next(&dir); | ||
} | ||
SHOULD_BE_TRUE(found); | ||
tinydir_close(&dir); | ||
_wremove(name); | ||
RemoveDirectoryW(TEST_PATH); | ||
SCENARIO_END | ||
FEATURE_END | ||
|
||
CBEHAVE_RUN("Windows unicode:", TEST_FEATURE(windows_unicode)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters