fixed gcc logging failure
[platform/upstream/glog.git] / src / logging_unittest.cc
index 2a58aae..b8a9a87 100644 (file)
@@ -61,6 +61,7 @@ DECLARE_string(log_backtrace_at);  // logging.cc
 
 #ifdef HAVE_LIB_GFLAGS
 #include <gflags/gflags.h>
+using namespace GFLAGS_NAMESPACE;
 #endif
 
 #ifdef HAVE_LIB_GMOCK
@@ -178,6 +179,9 @@ int main(int argc, char **argv) {
 #ifdef HAVE_LIB_GFLAGS
   ParseCommandLineFlags(&argc, &argv, true);
 #endif
+  // Make sure stderr is not buffered as stderr seems to be buffered
+  // on recent windows.
+  setbuf(stderr, NULL);
 
   // Test some basics before InitGoogleLogging:
   CaptureTestStderr();
@@ -268,17 +272,24 @@ void TestLogging(bool check_counts) {
   LOG(ERROR) << string("foo") << ' '<< j << ' ' << setw(10) << j << " "
              << setw(1) << hex << j;
 
+  {
+    google::LogMessage outer(__FILE__, __LINE__, google::ERROR);
+    outer.stream() << "outer";
+
+    LOG(ERROR) << "inner";
+  }
+
   LogMessage("foo", LogMessage::kNoLogPrefix, GLOG_INFO).stream() << "no prefix";
 
   if (check_counts) {
     CHECK_EQ(base_num_infos   + 14, LogMessage::num_messages(GLOG_INFO));
     CHECK_EQ(base_num_warning + 3,  LogMessage::num_messages(GLOG_WARNING));
-    CHECK_EQ(base_num_errors  + 15, LogMessage::num_messages(GLOG_ERROR));
+    CHECK_EQ(base_num_errors  + 17, LogMessage::num_messages(GLOG_ERROR));
   }
 }
 
 static void NoAllocNewHook() {
-  CHECK(false) << "unexpected new";
+  LOG(FATAL) << "unexpected new";
 }
 
 struct NewHook {
@@ -624,14 +635,15 @@ static void GetFiles(const string& pattern, vector<string>* files) {
     LOG(FATAL) << "No directory separator.";
   }
   const string dirname = pattern.substr(0, index + 1);
-  if (FAILED(handle)) {
+  if (handle == INVALID_HANDLE_VALUE) {
     // Finding no files is OK.
     return;
   }
   do {
     files->push_back(dirname + data.cFileName);
   } while (FindNextFileA(handle, &data));
-  LOG_SYSRESULT(FindClose(handle));
+  BOOL result = FindClose(handle);
+  LOG_SYSRESULT(result);
 #else
 # error There is no way to do glob.
 #endif
@@ -1055,8 +1067,9 @@ TEST(Strerror, logging) {
   CHECK_STREQ(buf, "");
   CHECK_EQ(posix_strerror_r(errcode, buf, buf_size), 0);
   CHECK_STREQ(buf, msg);
-  free(msg);
   delete[] buf;
+  CHECK_EQ(msg, StrError(errcode));
+  free(msg);
 }
 
 // Simple routines to look at the sizes of generated code for LOG(FATAL) and