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

Side by Side Diff: tools/relocation_packer/src/debug_unittest.cc

Issue 392653002: Upgrade logging to resemble base/logging.h. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update for review feedback Created 6 years, 5 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
« no previous file with comments | « tools/relocation_packer/src/debug.cc ('k') | tools/relocation_packer/src/elf_file.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 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 #include "debug.h"
6
7 #include <sstream>
8 #include <string>
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace relocation_packer {
12
13 TEST(Debug, Log) {
14 Logger::Reset();
15 std::ostringstream info;
16 std::ostringstream error;
17 Logger::SetStreams(&info, &error);
18
19 LOG(INFO) << "INFO log message";
20 LOG(WARNING) << "WARNING log message";
21 LOG(ERROR) << "ERROR log message";
22
23 EXPECT_EQ("INFO: INFO log message\n", info.str());
24 EXPECT_EQ("WARNING: WARNING log message\n"
25 "ERROR: ERROR log message\n", error.str());
26 Logger::Reset();
27 }
28
29 TEST(Debug, LogIf) {
30 Logger::Reset();
31 std::ostringstream info;
32 std::ostringstream error;
33 Logger::SetStreams(&info, &error);
34
35 LOG_IF(INFO, true) << "INFO log message";
36 LOG_IF(INFO, false) << "INFO log message, SHOULD NOT PRINT";
37 LOG_IF(WARNING, true) << "WARNING log message";
38 LOG_IF(WARNING, false) << "WARNING log message, SHOULD NOT PRINT";
39 LOG_IF(ERROR, true) << "ERROR log message";
40 LOG_IF(ERROR, false) << "ERROR log message, SHOULD NOT PRINT";
41 LOG_IF(FATAL, false) << "FATAL log message, SHOULD NOT PRINT";
42
43 EXPECT_EQ("INFO: INFO log message\n", info.str());
44 EXPECT_EQ("WARNING: WARNING log message\n"
45 "ERROR: ERROR log message\n", error.str());
46 Logger::Reset();
47 }
48
49 TEST(Debug, Vlog) {
50 Logger::Reset();
51 std::ostringstream info;
52 std::ostringstream error;
53 Logger::SetStreams(&info, &error);
54
55 VLOG(0) << "VLOG 0 INFO log message, SHOULD NOT PRINT";
56 VLOG(1) << "VLOG 1 INFO log message, SHOULD NOT PRINT";
57 VLOG(2) << "VLOG 2 INFO log message, SHOULD NOT PRINT";
58
59 EXPECT_EQ("", info.str());
60 EXPECT_EQ("", error.str());
61
62 Logger::SetVerbose(1);
63
64 VLOG(0) << "VLOG 0 INFO log message";
65 VLOG(1) << "VLOG 1 INFO log message";
66 VLOG(2) << "VLOG 2 INFO log message, SHOULD NOT PRINT";
67
68 EXPECT_EQ("INFO: VLOG 0 INFO log message\n"
69 "INFO: VLOG 1 INFO log message\n", info.str());
70 EXPECT_EQ("", error.str());
71 Logger::Reset();
72 }
73
74 TEST(Debug, VlogIf) {
75 Logger::Reset();
76 std::ostringstream info;
77 std::ostringstream error;
78 Logger::SetStreams(&info, &error);
79
80 VLOG_IF(0, true) << "VLOG 0 INFO log message, SHOULD NOT PRINT";
81 VLOG_IF(1, true) << "VLOG 1 INFO log message, SHOULD NOT PRINT";
82 VLOG_IF(2, true) << "VLOG 2 INFO log message, SHOULD NOT PRINT";
83
84 EXPECT_EQ("", info.str());
85 EXPECT_EQ("", error.str());
86
87 Logger::SetVerbose(1);
88
89 VLOG_IF(0, true) << "VLOG 0 INFO log message";
90 VLOG_IF(0, false) << "VLOG 0 INFO log message, SHOULD NOT PRINT";
91 VLOG_IF(1, true) << "VLOG 1 INFO log message";
92 VLOG_IF(1, false) << "VLOG 1 INFO log message, SHOULD NOT PRINT";
93 VLOG_IF(2, true) << "VLOG 2 INFO log message, SHOULD NOT PRINT";
94 VLOG_IF(2, false) << "VLOG 2 INFO log message, SHOULD NOT PRINT";
95
96 EXPECT_EQ("INFO: VLOG 0 INFO log message\n"
97 "INFO: VLOG 1 INFO log message\n", info.str());
98 EXPECT_EQ("", error.str());
99 Logger::Reset();
100 }
101
102 TEST(DebugDeathTest, Fatal) {
103 ::testing::FLAGS_gtest_death_test_style = "threadsafe";
104 Logger::Reset();
105 EXPECT_DEATH(LOG(FATAL) << "FATAL log message", "FATAL: FATAL log message");
106 EXPECT_DEATH(
107 LOG_IF(FATAL, true) << "FATAL log message", "FATAL: FATAL log message");
108 }
109
110 TEST(DebugDeathTest, Check) {
111 ::testing::FLAGS_gtest_death_test_style = "threadsafe";
112 Logger::Reset();
113 CHECK(0 == 0);
114 EXPECT_DEATH(CHECK(0 == 1), "FATAL: .*:.*: .*: CHECK '0 == 1' failed");
115 }
116
117 TEST(DebugDeathTest, NotReached) {
118 ::testing::FLAGS_gtest_death_test_style = "threadsafe";
119 Logger::Reset();
120 EXPECT_DEATH(NOTREACHED(), "FATAL: .*:.*: .*: NOTREACHED\\(\\) hit");
121 }
122
123 } // namespace relocation_packer
OLDNEW
« no previous file with comments | « tools/relocation_packer/src/debug.cc ('k') | tools/relocation_packer/src/elf_file.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698