Browse Source

[1964] added another test case where we can really check the thrown exception.

also clarified the comment: the previous one didn't make perfect sense in
that if it's really about exception we could have simply used EXCEPT_THROW.
JINMEI Tatuya 13 years ago
parent
commit
892f6b266a
1 changed files with 18 additions and 8 deletions
  1. 18 8
      src/lib/log/tests/log_formatter_unittest.cc

+ 18 - 8
src/lib/log/tests/log_formatter_unittest.cc

@@ -100,23 +100,33 @@ TEST_F(FormatterTest, multiArg) {
 
 #ifdef ENABLE_LOGGER_CHECKS
 
-#ifdef EXPECT_DEATH
-// Throws MismatchedPlaceholders exception if number of placeholders
-// don't match number of arguments. This causes it to abort.
 TEST_F(FormatterTest, mismatchedPlaceholders) {
+    // Throws MismatchedPlaceholders exception if the placeholder is missing
+    // for a supplied argument.
+    EXPECT_THROW(Formatter(isc::log::INFO, s("Missing the second %1"), this).
+                 arg("missing").arg("argument"),
+                 isc::log::MismatchedPlaceholders);
+
+#ifdef EXPECT_DEATH
+    // Likewise, if there's a redundant placeholder (or missing argument), the
+    // check detects it and aborts the program.  Due to the restriction of the
+    // current implementation, it doesn't throw.
     EXPECT_DEATH({
         isc::util::unittests::dontCreateCoreDumps();
-        Formatter(isc::log::INFO, s("Missing the first %2"), this).
-            arg("missing").arg("argument");
+        Formatter(isc::log::INFO, s("Too many arguments in %1 %2"), this).
+            arg("only one");
     }, ".*");
 
+    // Mixed case of above two: the exception will be thrown due to the missing
+    // placeholder, but before even it's caught the program will be aborted
+    // due to the unused placeholder as a result of the exception.
     EXPECT_DEATH({
         isc::util::unittests::dontCreateCoreDumps();
-        Formatter(isc::log::INFO, s("Too many arguments in %1 %2"), this).
-            arg("only one");
+        Formatter(isc::log::INFO, s("Missing the first %2"), this).
+            arg("missing").arg("argument");
     }, ".*");
-}
 #endif /* EXPECT_DEATH */
+}
 
 #else