< prev index next >

src/share/vm/logging/log.cpp

Print this page
rev 10535 : [mq]: 8145934
rev 10536 : [mq]: 8145934.alternative
rev 10537 : [mq]: 8145934.02

@@ -168,10 +168,12 @@
   static void test_long_message();
   static void test_message_with_many_lines();
   static void test_line_order();
   static void test_prefixing();
   static void test_scoped_messages();
+  static void test_scoped_flushing();
+  static void test_scoped_reset();
 
  public:
   static void test();
 };
 

@@ -204,10 +206,12 @@
   test_line_order();
   test_long_message();
   test_message_with_many_lines();
   test_prefixing();
   test_scoped_messages();
+  test_scoped_flushing();
+  test_scoped_reset();
 
   // Stop logging to the files and remove them.
   for (int i = 0; i < LogLevel::Count; i++) {
     LogConfiguration::parse_log_arguments(_level_filename[i], "all=off", NULL, NULL, _log.error_stream());
     remove(_level_filename[i]);

@@ -361,13 +365,46 @@
 
 void LogMessageTest::test_scoped_messages() {
   {
     LogMessage(logging) msg;
     msg.info("scoped info");
+    msg.warning("scoped warn");
+    assert(!file_contains_substring(_level_filename[LogLevel::Info], "scoped info"),
+           "scoped log message written prematurely");
   }
   assert(file_contains_substring(_level_filename[LogLevel::Info], "scoped info"),
          "missing output from scoped log message");
+  assert(file_contains_substring(_level_filename[LogLevel::Warning], "scoped warn"),
+         "missing output from scoped log message");
+}
+
+void LogMessageTest::test_scoped_flushing() {
+  {
+    LogMessage(logging) msg;
+    msg.info("manual flush info");
+    msg.flush();
+    assert(file_contains_substring(_level_filename[LogLevel::Info], "manual flush info"),
+           "missing output from manually flushed scoped log message");
+  }
+  const char* tmp[] = {"manual flush info", "manual flush info", NULL};
+  assert(!file_contains_substrings_in_order(_level_filename[LogLevel::Info], tmp),
+         "log file contains duplicate lines from single scoped log message");
+}
+
+void LogMessageTest::test_scoped_reset() {
+  {
+    LogMessage(logging) msg, partial;
+    msg.info("%s", "info reset msg");
+    msg.reset();
+    partial.info("%s", "info reset msg");
+    partial.reset();
+    partial.trace("%s", "trace reset msg");
+  }
+  assert(!file_contains_substring(_level_filename[LogLevel::Info], "info reset msg"),
+         "reset message written anyway");
+  assert(file_contains_substring(_level_filename[LogLevel::Trace], "trace reset msg"),
+         "missing message from partially reset scoped log message");
 }
 
 
 static int Test_logconfiguration_subscribe_triggered = 0;
 
< prev index next >