Commit 4d94a805 authored by Milo Yip's avatar Milo Yip

Fixes unit testing on Visual Studio.

tmpnam() in VS prepends backslash in the path.
parent 23056aba
/bin/*
/build/*.exe
/build/gmake
/build/vs*/
/thirdparty/lib
/intermediate
......@@ -85,7 +85,7 @@ protected:
template <typename FileEncoding, typename MemoryEncoding>
void TestEncodedOutputStream(const char* expectedFilename, bool putBOM) {
char filename[L_tmpnam];
tmpnam(filename);
TempFilename(filename);
FILE *fp = fopen(filename, "wb");
char buffer[16];
......@@ -114,7 +114,7 @@ protected:
void TestAutoUTFOutputStream(UTFType type, bool putBOM, const char *expectedFilename) {
char filename[L_tmpnam];
tmpnam(filename);
TempFilename(filename);
FILE *fp = fopen(filename, "wb");
char buffer[16];
......
......@@ -70,7 +70,7 @@ TEST_F(FileStreamTest, FileReadStream) {
TEST_F(FileStreamTest, FileWriteStream) {
char filename[L_tmpnam];
tmpnam(filename);
TempFilename(filename);
FILE *fp = fopen(filename, "wb");
char buffer[65536];
......
......@@ -30,4 +30,13 @@ inline Ch* StrDup(const Ch* str) {
return buffer;
}
inline void TempFilename(char *filename) {
tmpnam(filename);
// For Visual Studio, tmpnam() adds a backslash in front. Remove it.
if (filename[0] == '\\')
for (int i = 0; filename[i] != '\0'; i++)
filename[i] = filename[i + 1];
}
#endif // UNITTEST_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment