2 * Copyright 2004-present Facebook, Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <folly/experimental/logging/LogName.h>
17 #include <folly/portability/GTest.h>
19 using namespace folly;
21 TEST(LogName, canonicalize) {
22 EXPECT_EQ("", LogName::canonicalize("."));
23 EXPECT_EQ("", LogName::canonicalize("..."));
24 EXPECT_EQ("foo.bar", LogName::canonicalize(".foo..bar."));
25 EXPECT_EQ("a.b.c", LogName::canonicalize("a.b.c"));
26 EXPECT_EQ("a.b.c", LogName::canonicalize("a..b.c..."));
27 EXPECT_EQ("a.b.c", LogName::canonicalize("....a.b.c"));
28 EXPECT_EQ("a.b.c", LogName::canonicalize("a.b.c...."));
31 TEST(LogName, getParent) {
32 EXPECT_EQ("", LogName::getParent("foo"));
33 EXPECT_EQ("", LogName::getParent(".foo"));
34 EXPECT_EQ("foo", LogName::getParent("foo.bar"));
35 EXPECT_EQ("foo..bar", LogName::getParent("foo..bar..test"));
36 EXPECT_EQ("..foo..bar", LogName::getParent("..foo..bar..test.."));
40 EXPECT_EQ(LogName::hash("foo"), LogName::hash("foo."));
41 EXPECT_EQ(LogName::hash(".foo..bar"), LogName::hash("foo.bar..."));
42 EXPECT_EQ(LogName::hash("a.b.c..d."), LogName::hash("..a.b.c.d."));
43 EXPECT_EQ(LogName::hash(""), LogName::hash("."));
44 EXPECT_EQ(LogName::hash(""), LogName::hash("...."));
46 // Hashes for different category names should generally be different.
47 // This is not strictly required. This test is mainly to ensure that the
48 // code does not just hash all inputs to the same value.
49 EXPECT_NE(LogName::hash("foo"), LogName::hash("bar"));
50 EXPECT_NE(LogName::hash("a.b.c"), LogName::hash("abc"));
54 EXPECT_EQ(0, LogName::cmp("foo", "foo."));
55 EXPECT_EQ(0, LogName::cmp(".foo..bar", "foo.bar..."));
56 EXPECT_EQ(0, LogName::cmp(".foo.bar", "foo...bar..."));
57 EXPECT_EQ(0, LogName::cmp("a.b.c..d.", "..a.b.c.d."));
58 EXPECT_EQ(0, LogName::cmp("", "."));
59 EXPECT_EQ(0, LogName::cmp("", "...."));
61 EXPECT_GT(LogName::cmp("foo", "bar"), 0);
62 EXPECT_LT(LogName::cmp("a.b.c", "abc"), 0);
63 EXPECT_LT(LogName::cmp("a...b.c", "a.bc"), 0);
64 EXPECT_GT(LogName::cmp("a...b.z", "a.b.c"), 0);
65 EXPECT_LT(LogName::cmp(".foo.bar", "foobar..."), 0);
66 EXPECT_GT(LogName::cmp("foobar", ".foo...bar"), 0);