From 6e81d49b3374c1e8667438056c16ab2f3611c1fd Mon Sep 17 00:00:00 2001 From: kyb Date: Thu, 15 Jun 2017 12:36:20 +0300 Subject: [PATCH] Fixed #985 : Unittest failed with MinGWx64. And few small improvement were done while looking for mistakes. Problem was because of Windows uses backslashes '\', not Unix '/' --- test/unittest/ostreamwrappertest.cpp | 5 +++-- test/unittest/prettywritertest.cpp | 1 + test/unittest/unittest.h | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/test/unittest/ostreamwrappertest.cpp b/test/unittest/ostreamwrappertest.cpp index b1d1cd8..50f8da6 100644 --- a/test/unittest/ostreamwrappertest.cpp +++ b/test/unittest/ostreamwrappertest.cpp @@ -69,14 +69,15 @@ static void TestFileStream() { const char* s = "Hello World!\n"; { - ofstream ofs(filename, ios::out | ios::binary); - BasicOStreamWrapper osw(ofs); + FileStreamType ofs(filename, ios::out | ios::binary); + BasicOStreamWrapper osw(ofs); for (const char* p = s; *p; p++) osw.Put(*p); osw.Flush(); } fp = fopen(filename, "r"); + ASSERT_TRUE( fp != NULL ); for (const char* p = s; *p; p++) EXPECT_EQ(*p, static_cast(fgetc(fp))); fclose(fp); diff --git a/test/unittest/prettywritertest.cpp b/test/unittest/prettywritertest.cpp index 1e1ca1a..43617a2 100644 --- a/test/unittest/prettywritertest.cpp +++ b/test/unittest/prettywritertest.cpp @@ -167,6 +167,7 @@ TEST(PrettyWriter, OStreamWrapper) { TEST(PrettyWriter, FileWriteStream) { char filename[L_tmpnam]; FILE* fp = TempFile(filename); + ASSERT_TRUE(fp!=NULL); char buffer[16]; FileWriteStream os(fp, buffer, sizeof(buffer)); PrettyWriter writer(os); diff --git a/test/unittest/unittest.h b/test/unittest/unittest.h index e125bf8..5837345 100644 --- a/test/unittest/unittest.h +++ b/test/unittest/unittest.h @@ -78,7 +78,7 @@ inline Ch* StrDup(const Ch* str) { } inline FILE* TempFile(char *filename) { -#ifdef _MSC_VER +#if defined(__WIN32__) || defined(_MSC_VER) filename = tmpnam(filename); // For Visual Studio, tmpnam() adds a backslash in front. Remove it.