Skip to content

Commit 025149a

Browse files
authored
Merge pull request google#331 from NeroBurner/fix_windows_logging_ut
Fix windows logging ut
2 parents 2a9b3ea + 748abc4 commit 025149a

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

src/googletest.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ static const char TEST_SRC_DIR[] = "../..";
9090
static const char TEST_SRC_DIR[] = ".";
9191
#endif
9292

93+
static const uint32_t PTR_TEST_VALUE = 0x12345678;
94+
9395
DEFINE_string(test_tmpdir, GetTempDir(), "Dir we use for temp files");
9496
DEFINE_string(test_srcdir, TEST_SRC_DIR,
9597
"Source-dir root, needed to find glog_unittest_flagfile");
@@ -447,10 +449,12 @@ static inline string Munge(const string& filename) {
447449
while (fgets(buf, 4095, fp)) {
448450
string line = MungeLine(buf);
449451
char null_str[256];
452+
char ptr_str[256];
450453
sprintf(null_str, "%p", static_cast<void*>(NULL));
454+
sprintf(ptr_str, "%p", reinterpret_cast<void*>(PTR_TEST_VALUE));
455+
451456
StringReplace(&line, "__NULLP__", null_str);
452-
// Remove 0x prefix produced by %p. VC++ doesn't put the prefix.
453-
StringReplace(&line, " 0x", " ");
457+
StringReplace(&line, "__PTRTEST__", ptr_str);
454458

455459
StringReplace(&line, "__SUCCESS__", StrError(0));
456460
StringReplace(&line, "__ENOENT__", StrError(ENOENT));
@@ -485,7 +489,11 @@ static inline bool MungeAndDiffTestStderr(const string& golden_filename) {
485489
WriteToFile(golden, munged_golden);
486490
string munged_captured = cap->filename() + ".munged";
487491
WriteToFile(captured, munged_captured);
492+
#ifdef OS_WINDOWS
493+
string diffcmd("fc " + munged_golden + " " + munged_captured);
494+
#else
488495
string diffcmd("diff -u " + munged_golden + " " + munged_captured);
496+
#endif
489497
if (system(diffcmd.c_str()) != 0) {
490498
fprintf(stderr, "diff command was failed.\n");
491499
}

src/logging_unittest.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ void TestRawLogging() {
323323
RAW_LOG(WARNING, "%s", s);
324324
const char const_s[] = "const array";
325325
RAW_LOG(INFO, "%s", const_s);
326-
void* p = reinterpret_cast<void*>(0x12345678);
326+
void* p = reinterpret_cast<void*>(PTR_TEST_VALUE);
327327
RAW_LOG(INFO, "ptr %p", p);
328328
p = NULL;
329329
RAW_LOG(INFO, "ptr %p", p);

src/logging_unittest.err

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ no prefix
8080
IDATE TIME__ THREADID logging_unittest.cc:LINE] RAW: foo bar 10 3.400000
8181
WDATE TIME__ THREADID logging_unittest.cc:LINE] RAW: array
8282
IDATE TIME__ THREADID logging_unittest.cc:LINE] RAW: const array
83-
IDATE TIME__ THREADID logging_unittest.cc:LINE] RAW: ptr 0x12345678
83+
IDATE TIME__ THREADID logging_unittest.cc:LINE] RAW: ptr __PTRTEST__
8484
IDATE TIME__ THREADID logging_unittest.cc:LINE] RAW: ptr __NULLP__
8585
EDATE TIME__ THREADID logging_unittest.cc:LINE] RAW: foo 1000 0000001000 3e8
8686
IDATE TIME__ THREADID logging_unittest.cc:LINE] RAW: foo 1000

src/windows/port.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,11 @@
7070
* 4715: for some reason VC++ stopped realizing you can't return after abort()
7171
* 4800: we know we're casting ints/char*'s to bools, and we're ok with that
7272
* 4996: Yes, we're ok using "unsafe" functions like fopen() and strerror()
73+
* 4312: Converting uint32_t to a pointer when testing %p
74+
* 4267: also subtracting two size_t to int
75+
* 4722: Destructor never returns due to abort()
7376
*/
74-
#pragma warning(disable:4244 4251 4355 4715 4800 4996)
77+
#pragma warning(disable:4244 4251 4355 4715 4800 4996 4267 4312 4722)
7578

7679
/* file I/O */
7780
#define PATH_MAX 1024
@@ -86,6 +89,11 @@
8689
#define pclose _pclose
8790
#define R_OK 04 /* read-only (for access()) */
8891
#define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
92+
93+
#define O_WRONLY _O_WRONLY
94+
#define O_CREAT _O_CREAT
95+
#define O_EXCL _O_EXCL
96+
8997
#ifndef __MINGW32__
9098
enum { STDIN_FILENO = 0, STDOUT_FILENO = 1, STDERR_FILENO = 2 };
9199
#endif

0 commit comments

Comments
 (0)