proxygen
LogMessageTest.cpp File Reference

Go to the source code of this file.

Macros

#define CHECK_MSG(expected, value, hasNewlines)
 

Functions

 TEST (LogMessage, sanitize)
 

Macro Definition Documentation

#define CHECK_MSG (   expected,
  value,
  hasNewlines 
)
Value:
{ \
"input string: \"" + folly::backslashify<std::string>(value) + "\""); \
LogMessage checkMsg{category, \
LogLevel::ERR, \
__FILE__, \
__LINE__, \
__func__, \
EXPECT_EQ(expected, checkMsg.getMessage()); \
EXPECT_EQ(static_cast<int>(hasNewlines), checkMsg.containsNewlines()); \
EXPECT_EQ(__FILE__, checkMsg.getFileName()); \
EXPECT_EQ(__LINE__, checkMsg.getLineNumber()); \
}
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define SCOPED_TRACE(message)
Definition: gtest.h:2115
static const char *const value
Definition: Conv.cpp:50
const char * string
Definition: Conv.cpp:212

Definition at line 25 of file LogMessageTest.cpp.

Referenced by TEST().

Function Documentation

TEST ( LogMessage  ,
sanitize   
)

Definition at line 41 of file LogMessageTest.cpp.

References CHECK_MSG, folly::Logger::getCategory(), string, and folly::LoggerDB::TESTING.

41  {
42  LoggerDB db{LoggerDB::TESTING};
43  Logger logger{&db, "test"};
44  auto* category = logger.getCategory();
45 
46  CHECK_MSG("foo", "foo", false);
47  CHECK_MSG("foo\\\\bar", "foo\\bar", false);
48  CHECK_MSG("foo\\x01test", "foo\01test", false);
49  CHECK_MSG("test 1234 ", "test 1234 ", false);
50  CHECK_MSG("\\x07", "\a", false);
51  CHECK_MSG("\n", "\n", true);
52  CHECK_MSG("\t", "\t", false);
53  CHECK_MSG("\n\t\n", "\n\t\n", true);
54  // Test strings containing NUL bytes
55  CHECK_MSG("test\\x00.1234\\x00", std::string("test\0.1234\0", 11), false);
56  CHECK_MSG("test\\x00\n1234\\x00", std::string("test\0\n1234\0", 11), true);
57  // Test all ASCII characters except NUL
58  CHECK_MSG(
59  ("\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08"
60  "\t\n\\x0b\\x0c\\x0d\\x0e\\x0f"
61  "\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17"
62  "\\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f"
63  " !\"#$%&'()*+,-./0123456789:;<=>?"
64  "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_"
65  "`abcdefghijklmnopqrstuvwxyz{|}~\\x7f"),
66  ("\001\002\003\004\005\006\007"
67  "\010\011\012\013\014\015\016\017"
68  "\020\021\022\023\024\025\026\027"
69  "\030\031\032\033\034\035\036\037"
70  " !\"#$%&'()*+,-./0123456789:;<=>?"
71  "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
72  "`abcdefghijklmnopqrstuvwxyz{|}~\177"),
73  true);
74 
75  // Test some high-bit characters
76  CHECK_MSG("\x82\x83", "\x82\x83", false);
77  CHECK_MSG("\x82\n\x83\n", "\x82\n\x83\n", true);
78  CHECK_MSG("\x82\n\\x0c\x83\n", "\x82\n\f\x83\n", true);
79 }
#define CHECK_MSG(expected, value, hasNewlines)
LogCategory * getCategory() const
Definition: Logger.h:183
const char * string
Definition: Conv.cpp:212