1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 #include "base/basictypes.h"
8 #include "base/logging.h"
9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
10 #include "base/time.h"
11 #include "testing/gtest/include/gtest/gtest.h"
17 TEST(VlogTest
, NoVmodule
) {
18 int min_log_level
= 0;
19 EXPECT_EQ(0, VlogInfo("", "", &min_log_level
).GetVlogLevel("test1"));
20 EXPECT_EQ(0, VlogInfo("0", "", &min_log_level
).GetVlogLevel("test2"));
21 EXPECT_EQ(0, VlogInfo("blah", "", &min_log_level
).GetVlogLevel("test3"));
22 EXPECT_EQ(0, VlogInfo("0blah1", "", &min_log_level
).GetVlogLevel("test4"));
23 EXPECT_EQ(1, VlogInfo("1", "", &min_log_level
).GetVlogLevel("test5"));
24 EXPECT_EQ(5, VlogInfo("5", "", &min_log_level
).GetVlogLevel("test6"));
27 TEST(VlogTest
, MatchVlogPattern
) {
29 EXPECT_TRUE(MatchVlogPattern("", ""));
30 EXPECT_TRUE(MatchVlogPattern("", "****"));
31 EXPECT_FALSE(MatchVlogPattern("", "x"));
32 EXPECT_FALSE(MatchVlogPattern("x", ""));
35 EXPECT_TRUE(MatchVlogPattern("blah", "blah"));
37 // ? should match exactly one character.
38 EXPECT_TRUE(MatchVlogPattern("blah", "bl?h"));
39 EXPECT_FALSE(MatchVlogPattern("blh", "bl?h"));
40 EXPECT_FALSE(MatchVlogPattern("blaah", "bl?h"));
41 EXPECT_TRUE(MatchVlogPattern("blah", "?lah"));
42 EXPECT_FALSE(MatchVlogPattern("lah", "?lah"));
43 EXPECT_FALSE(MatchVlogPattern("bblah", "?lah"));
45 // * can match any number (even 0) of characters.
46 EXPECT_TRUE(MatchVlogPattern("blah", "bl*h"));
47 EXPECT_TRUE(MatchVlogPattern("blabcdefh", "bl*h"));
48 EXPECT_TRUE(MatchVlogPattern("blh", "bl*h"));
49 EXPECT_TRUE(MatchVlogPattern("blah", "*blah"));
50 EXPECT_TRUE(MatchVlogPattern("ohblah", "*blah"));
51 EXPECT_TRUE(MatchVlogPattern("blah", "blah*"));
52 EXPECT_TRUE(MatchVlogPattern("blahhhh", "blah*"));
53 EXPECT_TRUE(MatchVlogPattern("blahhhh", "blah*"));
54 EXPECT_TRUE(MatchVlogPattern("blah", "*blah*"));
55 EXPECT_TRUE(MatchVlogPattern("blahhhh", "*blah*"));
56 EXPECT_TRUE(MatchVlogPattern("bbbblahhhh", "*blah*"));
58 // Multiple *s should work fine.
59 EXPECT_TRUE(MatchVlogPattern("ballaah", "b*la*h"));
60 EXPECT_TRUE(MatchVlogPattern("blah", "b*la*h"));
61 EXPECT_TRUE(MatchVlogPattern("bbbblah", "b*la*h"));
62 EXPECT_TRUE(MatchVlogPattern("blaaah", "b*la*h"));
64 // There should be no escaping going on.
65 EXPECT_TRUE(MatchVlogPattern("bl\\ah", "bl\\?h"));
66 EXPECT_FALSE(MatchVlogPattern("bl?h", "bl\\?h"));
67 EXPECT_TRUE(MatchVlogPattern("bl\\aaaah", "bl\\*h"));
68 EXPECT_FALSE(MatchVlogPattern("bl*h", "bl\\*h"));
70 // Any slash matches any slash.
71 EXPECT_TRUE(MatchVlogPattern("/b\\lah", "/b\\lah"));
72 EXPECT_TRUE(MatchVlogPattern("\\b/lah", "/b\\lah"));
75 TEST(VlogTest
, VmoduleBasic
) {
76 const char kVSwitch
[] = "-1";
77 const char kVModuleSwitch
[] =
78 "foo=,bar=0,baz=blah,,qux=0blah1,quux=1,corge.ext=5";
79 int min_log_level
= 0;
80 VlogInfo
vlog_info(kVSwitch
, kVModuleSwitch
, &min_log_level
);
81 EXPECT_EQ(-1, vlog_info
.GetVlogLevel("/path/to/grault.cc"));
82 EXPECT_EQ(0, vlog_info
.GetVlogLevel("/path/to/foo.cc"));
83 EXPECT_EQ(0, vlog_info
.GetVlogLevel("D:\\Path\\To\\bar-inl.mm"));
84 EXPECT_EQ(-1, vlog_info
.GetVlogLevel("D:\\path\\to what/bar_unittest.m"));
85 EXPECT_EQ(0, vlog_info
.GetVlogLevel("baz.h"));
86 EXPECT_EQ(0, vlog_info
.GetVlogLevel("/another/path/to/qux.h"));
87 EXPECT_EQ(1, vlog_info
.GetVlogLevel("/path/to/quux"));
88 EXPECT_EQ(5, vlog_info
.GetVlogLevel("c:\\path/to/corge.ext.h"));
91 TEST(VlogTest
, VmoduleDirs
) {
92 const char kVModuleSwitch
[] =
93 "foo/bar.cc=1,baz\\*\\qux.cc=2,*quux/*=3,*/*-inl.h=4";
94 int min_log_level
= 0;
95 VlogInfo
vlog_info("", kVModuleSwitch
, &min_log_level
);
96 EXPECT_EQ(0, vlog_info
.GetVlogLevel("/foo/bar.cc"));
97 EXPECT_EQ(0, vlog_info
.GetVlogLevel("bar.cc"));
98 EXPECT_EQ(1, vlog_info
.GetVlogLevel("foo/bar.cc"));
100 EXPECT_EQ(0, vlog_info
.GetVlogLevel("baz/grault/qux.h"));
101 EXPECT_EQ(0, vlog_info
.GetVlogLevel("/baz/grault/qux.cc"));
102 EXPECT_EQ(2, vlog_info
.GetVlogLevel("baz/grault/qux.cc"));
103 EXPECT_EQ(2, vlog_info
.GetVlogLevel("baz/grault/blah/qux.cc"));
104 EXPECT_EQ(2, vlog_info
.GetVlogLevel("baz\\grault\\qux.cc"));
105 EXPECT_EQ(2, vlog_info
.GetVlogLevel("baz\\grault//blah\\qux.cc"));
107 EXPECT_EQ(0, vlog_info
.GetVlogLevel("/foo/bar/baz/quux.cc"));
108 EXPECT_EQ(3, vlog_info
.GetVlogLevel("/foo/bar/baz/quux/grault.cc"));
109 EXPECT_EQ(3, vlog_info
.GetVlogLevel("/foo\\bar/baz\\quux/grault.cc"));
111 EXPECT_EQ(0, vlog_info
.GetVlogLevel("foo/bar/test-inl.cc"));
112 EXPECT_EQ(4, vlog_info
.GetVlogLevel("foo/bar/test-inl.h"));
113 EXPECT_EQ(4, vlog_info
.GetVlogLevel("foo/bar/baz/blah-inl.h"));
118 } // namespace logging