< prev index next >

test/native/logging/test_logConfiguration.cpp

Print this page
rev 11857 : imported patch 8157948


 272   // Verify that it's possible to configure each individual tag
 273   for (size_t t = 1 /* Skip _NO_TAG */; t < LogTag::Count; t++) {
 274     const LogTagType tag = static_cast<LogTagType>(t);
 275     EXPECT_TRUE(LogConfiguration::parse_log_arguments("stdout", LogTag::name(tag), "", "", &ss));
 276   }
 277   // Same for each level
 278   for (size_t l = 0; l < LogLevel::Count; l++) {
 279     const LogLevelType level = static_cast<LogLevelType>(l);
 280     char expected_buf[256];
 281     int ret = jio_snprintf(expected_buf, sizeof(expected_buf), "all=%s", LogLevel::name(level));
 282     ASSERT_NE(-1, ret);
 283     EXPECT_TRUE(LogConfiguration::parse_log_arguments("stderr", expected_buf, "", "", &ss));
 284   }
 285   // And for each decorator
 286   for (size_t d = 0; d < LogDecorators::Count; d++) {
 287     const LogDecorators::Decorator decorator = static_cast<LogDecorators::Decorator>(d);
 288     EXPECT_TRUE(LogConfiguration::parse_log_arguments("#0", "", LogDecorators::name(decorator), "", &ss));
 289   }
 290   EXPECT_STREQ("", ss.as_string()) << "Error reported while parsing: " << ss.as_string();
 291 }





























 272   // Verify that it's possible to configure each individual tag
 273   for (size_t t = 1 /* Skip _NO_TAG */; t < LogTag::Count; t++) {
 274     const LogTagType tag = static_cast<LogTagType>(t);
 275     EXPECT_TRUE(LogConfiguration::parse_log_arguments("stdout", LogTag::name(tag), "", "", &ss));
 276   }
 277   // Same for each level
 278   for (size_t l = 0; l < LogLevel::Count; l++) {
 279     const LogLevelType level = static_cast<LogLevelType>(l);
 280     char expected_buf[256];
 281     int ret = jio_snprintf(expected_buf, sizeof(expected_buf), "all=%s", LogLevel::name(level));
 282     ASSERT_NE(-1, ret);
 283     EXPECT_TRUE(LogConfiguration::parse_log_arguments("stderr", expected_buf, "", "", &ss));
 284   }
 285   // And for each decorator
 286   for (size_t d = 0; d < LogDecorators::Count; d++) {
 287     const LogDecorators::Decorator decorator = static_cast<LogDecorators::Decorator>(d);
 288     EXPECT_TRUE(LogConfiguration::parse_log_arguments("#0", "", LogDecorators::name(decorator), "", &ss));
 289   }
 290   EXPECT_STREQ("", ss.as_string()) << "Error reported while parsing: " << ss.as_string();
 291 }
 292 
 293 TEST_F(LogConfigurationTest, output_name_normalization) {
 294   const char* patterns[] = { "%s", "file=%s", "\"%s\"", "file=\"%s\"" };
 295   char buf[1 * K];
 296   for (size_t i = 0; i < ARRAY_SIZE(patterns); i++) {
 297     int ret = jio_snprintf(buf, sizeof(buf), patterns[i], TestLogFileName);
 298     ASSERT_NE(-1, ret);
 299     set_log_config(buf, "logging=trace");
 300     EXPECT_TRUE(is_described("#2: "));
 301     EXPECT_TRUE(is_described(TestLogFileName));
 302     EXPECT_FALSE(is_described("#3: "))
 303         << "duplicate file output due to incorrect normalization for pattern: " << patterns[i];
 304   }
 305 
 306   // Make sure prefixes are ignored when used within quotes
 307   // (this should create a log with "file=" in its filename)
 308   int ret = jio_snprintf(buf, sizeof(buf), "\"file=%s\"", TestLogFileName);
 309   ASSERT_NE(-1, ret);
 310   set_log_config(buf, "logging=trace");
 311   EXPECT_TRUE(is_described("#3: ")) << "prefix within quotes not ignored as it should be";
 312   set_log_config(buf, "all=off");
 313 
 314   // Remove the extra log file created
 315   ret = jio_snprintf(buf, sizeof(buf), "file=%s", TestLogFileName);
 316   ASSERT_NE(-1, ret);
 317   delete_file(buf);
 318 }
< prev index next >