Fix copyright lines
[folly.git] / folly / experimental / logging / test / XlogTest.cpp
index 4cca9fafd3aa19e646d510e1477ff5a836a06372..551c15056e4868ea0136300f93a9822350601dd7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2004-present Facebook, Inc.
+ * Copyright 2017-present Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@
 #include <folly/experimental/logging/test/XlogHeader2.h>
 #include <folly/experimental/logging/xlog.h>
 #include <folly/portability/GTest.h>
+#include <folly/test/TestUtils.h>
 
 using namespace folly;
 using std::make_shared;
@@ -35,6 +36,11 @@ XLOG_SET_CATEGORY_NAME("xlog_test.main_file");
 // settings for the entire program.  Fortunately all of the other unit tests do
 // use testing LoggerDB objects.
 
+TEST(Xlog, xlogName) {
+  EXPECT_EQ("xlog_test.main_file", XLOG_GET_CATEGORY_NAME());
+  EXPECT_EQ("xlog_test.main_file", XLOG_GET_CATEGORY()->getName());
+}
+
 TEST(Xlog, xlog) {
   auto handler = make_shared<TestLogHandler>();
   LoggerDB::get()->getCategory("xlog_test")->addHandler(handler);
@@ -104,7 +110,7 @@ TEST(Xlog, perFileCategoryHandling) {
       << "unexpected file name: " << messages[0].first.getFileName();
   EXPECT_EQ(LogLevel::DBG3, messages[0].first.getLevel());
   EXPECT_EQ(
-      "folly.experimental.logging.test.XlogHeader2",
+      "folly.experimental.logging.test.XlogHeader2.h",
       messages[0].first.getCategory()->getName());
   EXPECT_EQ("folly.experimental.logging.test", messages[0].second->getName());
   messages.clear();
@@ -117,7 +123,7 @@ TEST(Xlog, perFileCategoryHandling) {
       << "unexpected file name: " << messages[0].first.getFileName();
   EXPECT_EQ(LogLevel::DBG1, messages[0].first.getLevel());
   EXPECT_EQ(
-      "folly.experimental.logging.test.XlogHeader1",
+      "folly.experimental.logging.test.XlogHeader1.h",
       messages[0].first.getCategory()->getName());
   EXPECT_EQ("folly.experimental.logging.test", messages[0].second->getName());
 
@@ -146,7 +152,7 @@ TEST(Xlog, perFileCategoryHandling) {
   ASSERT_EQ(1, messages.size());
   EXPECT_EQ("file1: foobar 1234", messages[0].first.getMessage());
   EXPECT_EQ(
-      "folly.experimental.logging.test.XlogFile1",
+      "folly.experimental.logging.test.XlogFile1.cpp",
       messages[0].first.getCategory()->getName());
   messages.clear();
 
@@ -154,7 +160,7 @@ TEST(Xlog, perFileCategoryHandling) {
   ASSERT_EQ(1, messages.size());
   EXPECT_EQ("file2: hello world", messages[0].first.getMessage());
   EXPECT_EQ(
-      "folly.experimental.logging.test.XlogFile2",
+      "folly.experimental.logging.test.XlogFile2.cpp",
       messages[0].first.getCategory()->getName());
   messages.clear();
 
@@ -174,7 +180,27 @@ TEST(Xlog, perFileCategoryHandling) {
   EXPECT_EQ(
       "file1: this log check should pass now", messages[0].first.getMessage());
   EXPECT_EQ(
-      "folly.experimental.logging.test.XlogFile1",
+      "folly.experimental.logging.test.XlogFile1.cpp",
       messages[0].first.getCategory()->getName());
   messages.clear();
 }
+
+TEST(Xlog, getXlogCategoryName) {
+  EXPECT_EQ("foo.cpp", getXlogCategoryNameForFile("foo.cpp"));
+  EXPECT_EQ("foo.h", getXlogCategoryNameForFile("foo.h"));
+
+  // Directory separators should be translated to "."
+  EXPECT_EQ("src.test.foo.cpp", getXlogCategoryNameForFile("src/test/foo.cpp"));
+  EXPECT_EQ("src.test.foo.h", getXlogCategoryNameForFile("src/test/foo.h"));
+
+  // Buck's directory prefixes for generated source files
+  // should be stripped out
+  EXPECT_EQ(
+      "myproject.generated_header.h",
+      getXlogCategoryNameForFile(
+          "buck-out/gen/myproject#headers/myproject/generated_header.h"));
+  EXPECT_EQ(
+      "foo.bar.test.h",
+      getXlogCategoryNameForFile(
+          "buck-out/gen/foo/bar#header-map,headers/foo/bar/test.h"));
+}