Bug 1426371 - Fix file/path for Windows binjs jsapi-tests;r=Yoric

This patch fixes several errors in Windows file/path management for
the binjs-decoder jsapi-tests:

- under Windows, files should be explicitly opened as "binary",
  otherwise the Windows version of the libc can be creative about
  their contents;
- "*.binjs" should not be part of the path;
- I/O functions don't all have the same return value conventions to
  notify of an error.

MozReview-Commit-ID: 51rVpRlcUai

--HG--
extra : rebase_source : a7d977c7dc0aecb05c4bbbf4547dedffbd4ec974
This commit is contained in:
David Teller 2017-12-19 11:18:41 +01:00
Родитель 02ce5d2807
Коммит 4a5148bb3b
2 изменённых файлов: 15 добавлений и 10 удалений

Просмотреть файл

@ -78,11 +78,12 @@ BEGIN_TEST(testBinASTReaderECMAScript2)
#elif defined(XP_WIN) #elif defined(XP_WIN)
const char PATH[] = "jsapi-tests\\binast\\parser\\tester\\*.binjs"; const char PATTERN[] = "jsapi-tests\\binast\\parser\\tester\\*.binjs";
const char PATH[] = "jsapi-tests\\binast\\parser\\tester\\";
WIN32_FIND_DATA FindFileData; WIN32_FIND_DATA FindFileData;
enterJsDirectory(); enterJsDirectory();
HANDLE hFind = FindFirstFile(PATH, &FindFileData); HANDLE hFind = FindFirstFile(PATTERN, &FindFileData);
exitJsDirectory(); exitJsDirectory();
for (bool found = (hFind != INVALID_HANDLE_VALUE); for (bool found = (hFind != INVALID_HANDLE_VALUE);
found; found;

Просмотреть файл

@ -71,21 +71,25 @@ void enterJsDirectory() {
// Find destination directory, if any. // Find destination directory, if any.
char destination[MAX_PATH]; char destination[MAX_PATH];
if (!GetEnvironmentVariable("CPP_UNIT_TESTS_DIR_JS_SRC", destination, MAX_PATH)) { result = GetEnvironmentVariable("CPP_UNIT_TESTS_DIR_JS_SRC", destination, MAX_PATH);
if (GetLastError() != ERROR_ENVVAR_NOT_FOUND) if (result == 0) {
MOZ_CRASH("Could not get CPP_UNIT_TESTS_DIR_JS_SRC"); if (GetLastError() == ERROR_ENVVAR_NOT_FOUND)
return; // No need to chdir
else else
return; MOZ_CRASH("Could not get CPP_UNIT_TESTS_DIR_JS_SRC");
}
if (result > MAX_PATH) {
MOZ_CRASH_UNSAFE_PRINTF("Could not get CPP_UNIT_TESTS_DIR_JS_SRC: needed %ld bytes, got %ld\n", result, MAX_PATH);
} }
// Go to the directory. // Go to the directory.
if (SetCurrentDirectory(destination) != 0) if (SetCurrentDirectory(destination) == 0)
MOZ_CRASH_UNSAFE_PRINTF("Could not chdir to %s", destination); MOZ_CRASH_UNSAFE_PRINTF("Could not chdir to %s", destination);
} }
void exitJsDirectory() { void exitJsDirectory() {
MOZ_ASSERT(strlen(gJsDirectory) > 0); MOZ_ASSERT(strlen(gJsDirectory) > 0);
if (SetCurrentDirectory(gJsDirectory) != 0) if (SetCurrentDirectory(gJsDirectory) == 0)
MOZ_CRASH("Could not return to original directory"); MOZ_CRASH("Could not return to original directory");
gJsDirectory[0] = 0; gJsDirectory[0] = 0;
} }
@ -95,7 +99,7 @@ void exitJsDirectory() {
void readFull(const char* path, js::Vector<uint8_t>& buf) { void readFull(const char* path, js::Vector<uint8_t>& buf) {
enterJsDirectory(); enterJsDirectory();
buf.shrinkTo(0); buf.shrinkTo(0);
FILE* in = fopen(path, "r"); FILE* in = fopen(path, "rb");
if (!in) if (!in)
MOZ_CRASH_UNSAFE_PRINTF("Could not open %s: %s", path, strerror(errno)); MOZ_CRASH_UNSAFE_PRINTF("Could not open %s: %s", path, strerror(errno));
@ -110,7 +114,7 @@ void readFull(const char* path, js::Vector<uint8_t>& buf) {
if (fclose(in) != 0) if (fclose(in) != 0)
MOZ_CRASH("Could not close input file"); MOZ_CRASH("Could not close input file");
if (result != info.st_size) if (result != info.st_size)
MOZ_CRASH("Read error"); MOZ_CRASH_UNSAFE_PRINTF("Read error while reading %s: expected %llu bytes, got %llu", path, (unsigned long long)info.st_size, (unsigned long long)result);
exitJsDirectory(); exitJsDirectory();
} }