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

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

Issue 429113002: Webrtc deps roll. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use webrtc version 6825 and rebase and switch back to original workspace. Created 6 years, 4 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/jingle_glue_mock_objects.h ('k') | jingle/glue/mock_task.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Note: this test tests LOG_V and LOG_E since all other logs are expressed 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. 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 7 // Also note that we are only allowed to call InitLogging() twice so the test
8 // cases are more dense than normal. 8 // cases are more dense than normal.
9 9
10 // The following include must be first in this file. It ensures that 10 // The following include must be first in this file. It ensures that
11 // libjingle style logging is used. 11 // libjingle style logging is used.
12 #define LOGGING_INSIDE_LIBJINGLE 12 #define LOGGING_INSIDE_WEBRTC
13 13
14 #include "third_party/libjingle/overrides/talk/base/logging.h" 14 #include "third_party/webrtc/overrides/webrtc/base/logging.h"
15 15
16 #include "base/command_line.h" 16 #include "base/command_line.h"
17 #include "base/file_util.h" 17 #include "base/file_util.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 #if defined(OS_WIN) 20 #if defined(OS_WIN)
21 static const wchar_t* const log_file_name = L"libjingle_logging.log"; 21 static const wchar_t* const log_file_name = L"libjingle_logging.log";
22 #else 22 #else
23 static const char* const log_file_name = "libjingle_logging.log"; 23 static const char* const log_file_name = "libjingle_logging.log";
24 #endif 24 #endif
25 25
26 static const int kDefaultVerbosity = 0; 26 static const int kDefaultVerbosity = 0;
27 27
28 static const char* AsString(talk_base::LoggingSeverity severity) { 28 static const char* AsString(rtc::LoggingSeverity severity) {
29 switch (severity) { 29 switch (severity) {
30 case talk_base::LS_ERROR: 30 case rtc::LS_ERROR:
31 return "LS_ERROR"; 31 return "LS_ERROR";
32 case talk_base::LS_WARNING: 32 case rtc::LS_WARNING:
33 return "LS_WARNING"; 33 return "LS_WARNING";
34 case talk_base::LS_INFO: 34 case rtc::LS_INFO:
35 return "LS_INFO"; 35 return "LS_INFO";
36 case talk_base::LS_VERBOSE: 36 case rtc::LS_VERBOSE:
37 return "LS_VERBOSE"; 37 return "LS_VERBOSE";
38 case talk_base::LS_SENSITIVE: 38 case rtc::LS_SENSITIVE:
39 return "LS_SENSITIVE"; 39 return "LS_SENSITIVE";
40 default: 40 default:
41 return ""; 41 return "";
42 } 42 }
43 } 43 }
44 44
45 static bool ContainsString(const std::string& original, 45 static bool ContainsString(const std::string& original,
46 const char* string_to_match) { 46 const char* string_to_match) {
47 return original.find(string_to_match) != std::string::npos; 47 return original.find(string_to_match) != std::string::npos;
48 } 48 }
(...skipping 19 matching lines...) Expand all
68 } 68 }
69 EXPECT_TRUE(VLOG_IS_ON(verbosity_level)); 69 EXPECT_TRUE(VLOG_IS_ON(verbosity_level));
70 EXPECT_FALSE(VLOG_IS_ON(verbosity_level + 1)); 70 EXPECT_FALSE(VLOG_IS_ON(verbosity_level + 1));
71 return true; 71 return true;
72 } 72 }
73 73
74 TEST(LibjingleLogTest, DefaultConfiguration) { 74 TEST(LibjingleLogTest, DefaultConfiguration) {
75 ASSERT_TRUE(Initialize(kDefaultVerbosity)); 75 ASSERT_TRUE(Initialize(kDefaultVerbosity));
76 76
77 // In the default configuration nothing should be logged. 77 // In the default configuration nothing should be logged.
78 LOG_V(talk_base::LS_ERROR) << AsString(talk_base::LS_ERROR); 78 LOG_V(rtc::LS_ERROR) << AsString(rtc::LS_ERROR);
79 LOG_V(talk_base::LS_WARNING) << AsString(talk_base::LS_WARNING); 79 LOG_V(rtc::LS_WARNING) << AsString(rtc::LS_WARNING);
80 LOG_V(talk_base::LS_INFO) << AsString(talk_base::LS_INFO); 80 LOG_V(rtc::LS_INFO) << AsString(rtc::LS_INFO);
81 LOG_V(talk_base::LS_VERBOSE) << AsString(talk_base::LS_VERBOSE); 81 LOG_V(rtc::LS_VERBOSE) << AsString(rtc::LS_VERBOSE);
82 LOG_V(talk_base::LS_SENSITIVE) << AsString(talk_base::LS_SENSITIVE); 82 LOG_V(rtc::LS_SENSITIVE) << AsString(rtc::LS_SENSITIVE);
83 83
84 // Read file to string. 84 // Read file to string.
85 base::FilePath file_path(log_file_name); 85 base::FilePath file_path(log_file_name);
86 std::string contents_of_file; 86 std::string contents_of_file;
87 base::ReadFileToString(file_path, &contents_of_file); 87 base::ReadFileToString(file_path, &contents_of_file);
88 88
89 // Make sure string contains the expected values. 89 // Make sure string contains the expected values.
90 EXPECT_FALSE(ContainsString(contents_of_file, AsString(talk_base::LS_ERROR))); 90 EXPECT_FALSE(ContainsString(contents_of_file, AsString(rtc::LS_ERROR)));
91 EXPECT_FALSE(ContainsString(contents_of_file, 91 EXPECT_FALSE(ContainsString(contents_of_file,
92 AsString(talk_base::LS_WARNING))); 92 AsString(rtc::LS_WARNING)));
93 EXPECT_FALSE(ContainsString(contents_of_file, AsString(talk_base::LS_INFO))); 93 EXPECT_FALSE(ContainsString(contents_of_file, AsString(rtc::LS_INFO)));
94 EXPECT_FALSE(ContainsString(contents_of_file, 94 EXPECT_FALSE(ContainsString(contents_of_file,
95 AsString(talk_base::LS_VERBOSE))); 95 AsString(rtc::LS_VERBOSE)));
96 EXPECT_FALSE(ContainsString(contents_of_file, 96 EXPECT_FALSE(ContainsString(contents_of_file,
97 AsString(talk_base::LS_SENSITIVE))); 97 AsString(rtc::LS_SENSITIVE)));
98 } 98 }
99 99
100 TEST(LibjingleLogTest, InfoConfiguration) { 100 TEST(LibjingleLogTest, InfoConfiguration) {
101 ASSERT_TRUE(Initialize(talk_base::LS_INFO)); 101 ASSERT_TRUE(Initialize(rtc::LS_INFO));
102 102
103 // In this configuration everything lower or equal to LS_INFO should be 103 // In this configuration everything lower or equal to LS_INFO should be
104 // logged. 104 // logged.
105 LOG_V(talk_base::LS_ERROR) << AsString(talk_base::LS_ERROR); 105 LOG_V(rtc::LS_ERROR) << AsString(rtc::LS_ERROR);
106 LOG_V(talk_base::LS_WARNING) << AsString(talk_base::LS_WARNING); 106 LOG_V(rtc::LS_WARNING) << AsString(rtc::LS_WARNING);
107 LOG_V(talk_base::LS_INFO) << AsString(talk_base::LS_INFO); 107 LOG_V(rtc::LS_INFO) << AsString(rtc::LS_INFO);
108 LOG_V(talk_base::LS_VERBOSE) << AsString(talk_base::LS_VERBOSE); 108 LOG_V(rtc::LS_VERBOSE) << AsString(rtc::LS_VERBOSE);
109 LOG_V(talk_base::LS_SENSITIVE) << AsString(talk_base::LS_SENSITIVE); 109 LOG_V(rtc::LS_SENSITIVE) << AsString(rtc::LS_SENSITIVE);
110 110
111 // Read file to string. 111 // Read file to string.
112 base::FilePath file_path(log_file_name); 112 base::FilePath file_path(log_file_name);
113 std::string contents_of_file; 113 std::string contents_of_file;
114 base::ReadFileToString(file_path, &contents_of_file); 114 base::ReadFileToString(file_path, &contents_of_file);
115 115
116 // Make sure string contains the expected values. 116 // Make sure string contains the expected values.
117 EXPECT_TRUE(ContainsString(contents_of_file, AsString(talk_base::LS_ERROR))); 117 EXPECT_TRUE(ContainsString(contents_of_file, AsString(rtc::LS_ERROR)));
118 EXPECT_TRUE(ContainsString(contents_of_file, 118 EXPECT_TRUE(ContainsString(contents_of_file,
119 AsString(talk_base::LS_WARNING))); 119 AsString(rtc::LS_WARNING)));
120 EXPECT_TRUE(ContainsString(contents_of_file, AsString(talk_base::LS_INFO))); 120 EXPECT_TRUE(ContainsString(contents_of_file, AsString(rtc::LS_INFO)));
121 EXPECT_FALSE(ContainsString(contents_of_file, 121 EXPECT_FALSE(ContainsString(contents_of_file,
122 AsString(talk_base::LS_VERBOSE))); 122 AsString(rtc::LS_VERBOSE)));
123 EXPECT_FALSE(ContainsString(contents_of_file, 123 EXPECT_FALSE(ContainsString(contents_of_file,
124 AsString(talk_base::LS_SENSITIVE))); 124 AsString(rtc::LS_SENSITIVE)));
125 125
126 // Also check that the log is proper. 126 // Also check that the log is proper.
127 EXPECT_TRUE(ContainsString(contents_of_file, "logging_unittest.cc")); 127 EXPECT_TRUE(ContainsString(contents_of_file, "logging_unittest.cc"));
128 EXPECT_FALSE(ContainsString(contents_of_file, "logging.h")); 128 EXPECT_FALSE(ContainsString(contents_of_file, "logging.h"));
129 EXPECT_FALSE(ContainsString(contents_of_file, "logging.cc")); 129 EXPECT_FALSE(ContainsString(contents_of_file, "logging.cc"));
130 } 130 }
131 131
132 TEST(LibjingleLogTest, LogEverythingConfiguration) { 132 TEST(LibjingleLogTest, LogEverythingConfiguration) {
133 ASSERT_TRUE(Initialize(talk_base::LS_SENSITIVE)); 133 ASSERT_TRUE(Initialize(rtc::LS_SENSITIVE));
134 134
135 // In this configuration everything should be logged. 135 // In this configuration everything should be logged.
136 LOG_V(talk_base::LS_ERROR) << AsString(talk_base::LS_ERROR); 136 LOG_V(rtc::LS_ERROR) << AsString(rtc::LS_ERROR);
137 LOG_V(talk_base::LS_WARNING) << AsString(talk_base::LS_WARNING); 137 LOG_V(rtc::LS_WARNING) << AsString(rtc::LS_WARNING);
138 LOG(LS_INFO) << AsString(talk_base::LS_INFO); 138 LOG(LS_INFO) << AsString(rtc::LS_INFO);
139 static const int kFakeError = 1; 139 static const int kFakeError = 1;
140 LOG_E(LS_INFO, EN, kFakeError) << "LOG_E(" << AsString(talk_base::LS_INFO) << 140 LOG_E(LS_INFO, EN, kFakeError) << "LOG_E(" << AsString(rtc::LS_INFO) <<
141 ")"; 141 ")";
142 LOG_V(talk_base::LS_VERBOSE) << AsString(talk_base::LS_VERBOSE); 142 LOG_V(rtc::LS_VERBOSE) << AsString(rtc::LS_VERBOSE);
143 LOG_V(talk_base::LS_SENSITIVE) << AsString(talk_base::LS_SENSITIVE); 143 LOG_V(rtc::LS_SENSITIVE) << AsString(rtc::LS_SENSITIVE);
144 144
145 // Read file to string. 145 // Read file to string.
146 base::FilePath file_path(log_file_name); 146 base::FilePath file_path(log_file_name);
147 std::string contents_of_file; 147 std::string contents_of_file;
148 base::ReadFileToString(file_path, &contents_of_file); 148 base::ReadFileToString(file_path, &contents_of_file);
149 149
150 // Make sure string contains the expected values. 150 // Make sure string contains the expected values.
151 EXPECT_TRUE(ContainsString(contents_of_file, AsString(talk_base::LS_ERROR))); 151 EXPECT_TRUE(ContainsString(contents_of_file, AsString(rtc::LS_ERROR)));
152 EXPECT_TRUE(ContainsString(contents_of_file, 152 EXPECT_TRUE(ContainsString(contents_of_file,
153 AsString(talk_base::LS_WARNING))); 153 AsString(rtc::LS_WARNING)));
154 EXPECT_TRUE(ContainsString(contents_of_file, AsString(talk_base::LS_INFO))); 154 EXPECT_TRUE(ContainsString(contents_of_file, AsString(rtc::LS_INFO)));
155 // LOG_E 155 // LOG_E
156 EXPECT_TRUE(ContainsString(contents_of_file, strerror(kFakeError))); 156 EXPECT_TRUE(ContainsString(contents_of_file, strerror(kFakeError)));
157 EXPECT_TRUE(ContainsString(contents_of_file, 157 EXPECT_TRUE(ContainsString(contents_of_file,
158 AsString(talk_base::LS_VERBOSE))); 158 AsString(rtc::LS_VERBOSE)));
159 EXPECT_TRUE(ContainsString(contents_of_file, 159 EXPECT_TRUE(ContainsString(contents_of_file,
160 AsString(talk_base::LS_SENSITIVE))); 160 AsString(rtc::LS_SENSITIVE)));
161 } 161 }
OLDNEW
« no previous file with comments | « jingle/glue/jingle_glue_mock_objects.h ('k') | jingle/glue/mock_task.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698