proxygen
LogNameTest.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include <folly/logging/LogName.h>
18 
19 using namespace folly;
20 
21 TEST(LogName, canonicalize) {
23  EXPECT_EQ("", LogName::canonicalize("..."));
26  EXPECT_EQ("", LogName::canonicalize(".//..\\\\./"));
27  EXPECT_EQ("foo.bar", LogName::canonicalize(".foo..bar."));
28  EXPECT_EQ("a.b.c", LogName::canonicalize("a.b.c"));
29  EXPECT_EQ("a.b.c", LogName::canonicalize("a/b/c"));
30  EXPECT_EQ("a.b.c", LogName::canonicalize("a/b/c/"));
31  EXPECT_EQ("a.b.c", LogName::canonicalize("a..b.c..."));
32  EXPECT_EQ("a.b.c", LogName::canonicalize("....a.b.c"));
33  EXPECT_EQ("a.b.c", LogName::canonicalize("a.b.c...."));
34  EXPECT_EQ("a.b.c", LogName::canonicalize("////a.b.c"));
35  EXPECT_EQ("a.b.c", LogName::canonicalize("a.b.c////"));
36  EXPECT_EQ("a.b.c", LogName::canonicalize("/a.b.//.c/"));
37 }
38 
39 TEST(LogName, getParent) {
40  EXPECT_EQ("", LogName::getParent("foo"));
41  EXPECT_EQ("", LogName::getParent(".foo"));
42  EXPECT_EQ("foo", LogName::getParent("foo.bar"));
43  EXPECT_EQ("foo", LogName::getParent("foo/bar"));
44  EXPECT_EQ("foo", LogName::getParent("foo\\bar"));
45  EXPECT_EQ("foo", LogName::getParent("foo\\bar/"));
46  EXPECT_EQ("foo", LogName::getParent("foo\\bar\\"));
47  EXPECT_EQ("foo..bar", LogName::getParent("foo..bar..test"));
48  EXPECT_EQ("..foo..bar", LogName::getParent("..foo..bar..test.."));
49 }
50 
51 TEST(LogName, hash) {
52  EXPECT_EQ(LogName::hash("foo"), LogName::hash("foo."));
53  EXPECT_EQ(LogName::hash(".foo..bar"), LogName::hash("foo.bar..."));
54  EXPECT_EQ(LogName::hash("a.b.c..d."), LogName::hash("..a.b.c.d."));
55  EXPECT_EQ(LogName::hash("a.b.c.d"), LogName::hash("/a/b/c/d/"));
56  EXPECT_EQ(LogName::hash("a.b.c.d"), LogName::hash("a\\b\\c/d/"));
61 
62  // Hashes for different category names should generally be different.
63  // This is not strictly required. This test is mainly to ensure that the
64  // code does not just hash all inputs to the same value.
65  EXPECT_NE(LogName::hash("foo"), LogName::hash("bar"));
66  EXPECT_NE(LogName::hash("a.b.c"), LogName::hash("abc"));
67 }
68 
69 TEST(LogName, cmp) {
70  EXPECT_EQ(0, LogName::cmp("foo", "foo."));
71  EXPECT_EQ(0, LogName::cmp("foo", "foo/"));
72  EXPECT_EQ(0, LogName::cmp(".foo..bar", "foo.bar..."));
73  EXPECT_EQ(0, LogName::cmp(".foo.bar", "foo...bar..."));
74  EXPECT_EQ(0, LogName::cmp("a.b.c..d.", "..a.b.c.d."));
75  EXPECT_EQ(0, LogName::cmp("a.b.c..d.", "\\/a.b/c/d."));
76  EXPECT_EQ(0, LogName::cmp("", "."));
77  EXPECT_EQ(0, LogName::cmp("", "...."));
78 
79  EXPECT_GT(LogName::cmp("foo", "bar"), 0);
80  EXPECT_LT(LogName::cmp("a.b.c", "abc"), 0);
81  EXPECT_LT(LogName::cmp("a...b.c", "a.bc"), 0);
82  EXPECT_GT(LogName::cmp("a...b.z", "a.b.c"), 0);
83  EXPECT_LT(LogName::cmp(".foo.bar", "foobar..."), 0);
84  EXPECT_GT(LogName::cmp("foobar", ".foo...bar"), 0);
85 }
static int cmp(folly::StringPiece nameA, folly::StringPiece nameB)
Definition: LogName.cpp:81
static folly::StringPiece getParent(folly::StringPiece name)
Definition: LogName.cpp:126
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
static size_t hash(folly::StringPiece name)
Definition: LogName.cpp:52
static std::string canonicalize(folly::StringPiece name)
Definition: LogName.cpp:26
#define EXPECT_NE(val1, val2)
Definition: gtest.h:1926
#define EXPECT_LT(val1, val2)
Definition: gtest.h:1930
TEST(SequencedExecutor, CPUThreadPoolExecutor)
#define EXPECT_GT(val1, val2)
Definition: gtest.h:1934