Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: jingle/glue/logging_unittest.cc

Issue 8991010: This change updates the libjingle logging so that it writes to chromiums VLOG instead of its own ... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « jingle/glue/DEPS ('k') | jingle/jingle.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2012 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.
4
5 // Note: this test tests LOG_V and LOG_E since all other logs are expressed
6 // in forms of them. LOG is also tested for good measure.
7 // Also note that we are only allowed to call InitLogging() twice so the test
8 // cases are more dense than normal.
9
10 // The following include must be first in this file. It ensures that
11 // libjingle style logging is used.
12 #define LOGGING_INSIDE_LIBJINGLE
13
14 #include "third_party/libjingle/overrides/talk/base/logging.h"
15
16 #include "base/command_line.h"
17 #include "base/file_util.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19
20 #if defined(OS_WIN)
21 static const wchar_t* const log_file_name = L"libjingle_logging.log";
22 #else
23 static const char* const log_file_name = "libjingle_logging.log";
24 #endif
25
26 static const int kDefaultVerbosity = 0;
27
28 static const char* AsString(talk_base::LoggingSeverity severity) {
29 switch (severity) {
30 case talk_base::LS_ERROR:
31 return "LS_ERROR";
32 case talk_base::LS_WARNING:
33 return "LS_WARNING";
34 case talk_base::LS_INFO:
35 return "LS_INFO";
36 case talk_base::LS_VERBOSE:
37 return "LS_VERBOSE";
38 case talk_base::LS_SENSITIVE:
39 return "LS_SENSITIVE";
40 default:
41 return "";
42 }
43 }
44
45 static bool ContainsString(const std::string& original,
46 const char* string_to_match) {
47 return original.find(string_to_match) != std::string::npos;
48 }
49
50 static bool Initialize(int verbosity_level) {
51 if (verbosity_level != kDefaultVerbosity) {
52 // Update the command line with specified verbosity level for this file.
53 CommandLine* command_line = CommandLine::ForCurrentProcess();
54 std::ostringstream value_stream;
55 value_stream << "logging_unittest=" << verbosity_level;
56 const std::string& value = value_stream.str();
57 command_line->AppendSwitchASCII("vmodule", value);
58 }
59
60 // The command line flags are parsed here and the log file name is set.
61 if (!InitLogging(log_file_name, logging::LOG_ONLY_TO_FILE,
62 logging::DONT_LOCK_LOG_FILE, logging::DELETE_OLD_LOG_FILE,
63 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS)) {
64 return false;
65 }
66 EXPECT_TRUE(VLOG_IS_ON(verbosity_level));
67 EXPECT_FALSE(VLOG_IS_ON(verbosity_level + 1));
68 return true;
69 }
70
71 TEST(LibjingleLogTest, DefaultConfiguration) {
72 ASSERT_TRUE(Initialize(kDefaultVerbosity));
73
74 // In the default configuration nothing should be logged.
75 LOG_V(talk_base::LS_ERROR) << AsString(talk_base::LS_ERROR);
76 LOG_V(talk_base::LS_WARNING) << AsString(talk_base::LS_WARNING);
77 LOG_V(talk_base::LS_INFO) << AsString(talk_base::LS_INFO);
78 LOG_V(talk_base::LS_VERBOSE) << AsString(talk_base::LS_VERBOSE);
79 LOG_V(talk_base::LS_SENSITIVE) << AsString(talk_base::LS_SENSITIVE);
80
81 // Read file to string.
82 FilePath file_path(log_file_name);
83 std::string contents_of_file;
84 file_util::ReadFileToString(file_path, &contents_of_file);
85
86 // Make sure string contains the expected values.
87 EXPECT_FALSE(ContainsString(contents_of_file, AsString(talk_base::LS_ERROR)));
88 EXPECT_FALSE(ContainsString(contents_of_file,
89 AsString(talk_base::LS_WARNING)));
90 EXPECT_FALSE(ContainsString(contents_of_file, AsString(talk_base::LS_INFO)));
91 EXPECT_FALSE(ContainsString(contents_of_file,
92 AsString(talk_base::LS_VERBOSE)));
93 EXPECT_FALSE(ContainsString(contents_of_file,
94 AsString(talk_base::LS_SENSITIVE)));
95 }
96
97 TEST(LibjingleLogTest, InfoConfiguration) {
98 ASSERT_TRUE(Initialize(talk_base::LS_INFO));
99
100 // In this configuration everything lower or equal to LS_INFO should be
101 // logged.
102 LOG_V(talk_base::LS_ERROR) << AsString(talk_base::LS_ERROR);
103 LOG_V(talk_base::LS_WARNING) << AsString(talk_base::LS_WARNING);
104 LOG_V(talk_base::LS_INFO) << AsString(talk_base::LS_INFO);
105 LOG_V(talk_base::LS_VERBOSE) << AsString(talk_base::LS_VERBOSE);
106 LOG_V(talk_base::LS_SENSITIVE) << AsString(talk_base::LS_SENSITIVE);
107
108 // Read file to string.
109 FilePath file_path(log_file_name);
110 std::string contents_of_file;
111 file_util::ReadFileToString(file_path, &contents_of_file);
112
113 // Make sure string contains the expected values.
114 EXPECT_TRUE(ContainsString(contents_of_file, AsString(talk_base::LS_ERROR)));
115 EXPECT_TRUE(ContainsString(contents_of_file,
116 AsString(talk_base::LS_WARNING)));
117 EXPECT_TRUE(ContainsString(contents_of_file, AsString(talk_base::LS_INFO)));
118 EXPECT_FALSE(ContainsString(contents_of_file,
119 AsString(talk_base::LS_VERBOSE)));
120 EXPECT_FALSE(ContainsString(contents_of_file,
121 AsString(talk_base::LS_SENSITIVE)));
122
123 // Also check that the log is proper.
124 EXPECT_TRUE(ContainsString(contents_of_file, "logging_unittest.cc"));
125 EXPECT_FALSE(ContainsString(contents_of_file, "logging.h"));
126 EXPECT_FALSE(ContainsString(contents_of_file, "logging.cc"));
127 }
128
129 TEST(LibjingleLogTest, LogEverythingConfiguration) {
130 ASSERT_TRUE(Initialize(talk_base::LS_SENSITIVE));
131
132 // In this configuration everything should be logged.
133 LOG_V(talk_base::LS_ERROR) << AsString(talk_base::LS_ERROR);
134 LOG_V(talk_base::LS_WARNING) << AsString(talk_base::LS_WARNING);
135 LOG(LS_INFO) << AsString(talk_base::LS_INFO);
136 static const int kFakeError = 1;
137 LOG_E(LS_INFO, EN, kFakeError) << "LOG_E(" << AsString(talk_base::LS_INFO) <<
138 ")";
139 LOG_V(talk_base::LS_VERBOSE) << AsString(talk_base::LS_VERBOSE);
140 LOG_V(talk_base::LS_SENSITIVE) << AsString(talk_base::LS_SENSITIVE);
141
142 // Read file to string.
143 FilePath file_path(log_file_name);
144 std::string contents_of_file;
145 file_util::ReadFileToString(file_path, &contents_of_file);
146
147 // Make sure string contains the expected values.
148 EXPECT_TRUE(ContainsString(contents_of_file, AsString(talk_base::LS_ERROR)));
149 EXPECT_TRUE(ContainsString(contents_of_file,
150 AsString(talk_base::LS_WARNING)));
151 EXPECT_TRUE(ContainsString(contents_of_file, AsString(talk_base::LS_INFO)));
152 // LOG_E
153 EXPECT_TRUE(ContainsString(contents_of_file, strerror(kFakeError)));
154 EXPECT_TRUE(ContainsString(contents_of_file,
155 AsString(talk_base::LS_VERBOSE)));
156 EXPECT_TRUE(ContainsString(contents_of_file,
157 AsString(talk_base::LS_SENSITIVE)));
158 }
OLDNEW
« no previous file with comments | « jingle/glue/DEPS ('k') | jingle/jingle.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698