From 41a4e2604ba4a4add4dc5f2fd6213ef5c2243ca4 Mon Sep 17 00:00:00 2001 From: Philip Craig Date: Sat, 28 May 2011 09:28:01 +0100 Subject: Tests now build on a native Windows build (tested with VS2010) All tests except SubProcess pass on a native Windows build Tests continue not to build on a platform=mingw build --- src/build_log.cc | 2 +- src/build_log_test.cc | 11 +++++++++++ src/ninja_test.cc | 2 +- src/util.cc | 3 +++ src/util.h | 4 ++++ 5 files changed, 20 insertions(+), 2 deletions(-) mode change 100644 => 100755 src/build_log.cc mode change 100644 => 100755 src/build_log_test.cc mode change 100644 => 100755 src/ninja_test.cc mode change 100644 => 100755 src/util.cc mode change 100644 => 100755 src/util.h diff --git a/src/build_log.cc b/src/build_log.cc old mode 100644 new mode 100755 index 3073f7f..8c45c77 --- a/src/build_log.cc +++ b/src/build_log.cc @@ -54,7 +54,7 @@ bool BuildLog::OpenForWrite(const string& path, string* err) { *err = strerror(errno); return false; } - setvbuf(log_file_, NULL, _IOLBF, 0); + setvbuf(log_file_, NULL, _IOLBF, BUFSIZ); if (ftell(log_file_) == 0) { if (fwrite(kFileSignature, sizeof(kFileSignature) - 1, 1, log_file_) < 1) { diff --git a/src/build_log_test.cc b/src/build_log_test.cc old mode 100644 new mode 100755 index 8bb2bfa..1df28db --- a/src/build_log_test.cc +++ b/src/build_log_test.cc @@ -16,6 +16,10 @@ #include "test.h" +#ifdef WIN32 +#include +#endif + static const char kTestFilename[] = "BuildLogTest-tempfile"; struct BuildLogTest : public StateTestWithBuiltinRules { @@ -90,7 +94,14 @@ TEST_F(BuildLogTest, Truncate) { // For all possible truncations of the input file, assert that we don't // crash or report an error when parsing. for (off_t size = statbuf.st_size; size > 0; --size) { +#ifndef WIN32 ASSERT_EQ(0, truncate(kTestFilename, size)); +#else + int fh; + ASSERT_EQ(0, _sopen_s(&fh, kTestFilename, _O_RDWR | _O_CREAT, _SH_DENYNO, _S_IREAD | _S_IWRITE)); + ASSERT_EQ(0, _chsize(fh, size)); + _close(fh); +#endif BuildLog log2; EXPECT_TRUE(log2.Load(kTestFilename, &err)); diff --git a/src/ninja_test.cc b/src/ninja_test.cc old mode 100644 new mode 100755 index 6e3f549..a5ef3ab --- a/src/ninja_test.cc +++ b/src/ninja_test.cc @@ -217,7 +217,7 @@ TEST_F(StatTest, Middle) { #ifndef _mktemp_s /// mingw has no mktemp. Implement one with the same type as the one /// found in the Windows API. -int _mktemp_s(const char* templ) { +int _mktemp_s(char* templ) { char* ofs = strchr(templ, 'X'); sprintf(ofs, "%d", rand() % 1000000); return 0; diff --git a/src/util.cc b/src/util.cc old mode 100644 new mode 100755 index 14b3379..d5a8f1f --- a/src/util.cc +++ b/src/util.cc @@ -25,7 +25,10 @@ #include #include #include + +#ifndef _WIN32 #include +#endif #include diff --git a/src/util.h b/src/util.h old mode 100644 new mode 100755 index 794177d..c9e06f4 --- a/src/util.h +++ b/src/util.h @@ -46,4 +46,8 @@ int ReadFile(const string& path, string* contents, string* err); /// time. int64_t GetTimeMillis(); +#ifdef _WIN32 +#define snprintf _snprintf +#endif + #endif // NINJA_UTIL_H_ -- cgit v0.12