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.
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace relocation_packer
{
14 std::ostringstream info
;
15 std::ostringstream error
;
16 Logger::SetStreams(&info
, &error
);
18 LOG(INFO
) << "INFO log message";
19 LOG(WARNING
) << "WARNING log message";
20 LOG(ERROR
) << "ERROR log message";
22 EXPECT_EQ("INFO: INFO log message\n", info
.str());
23 EXPECT_EQ("WARNING: WARNING log message\n"
24 "ERROR: ERROR log message\n", error
.str());
30 std::ostringstream info
;
31 std::ostringstream error
;
32 Logger::SetStreams(&info
, &error
);
34 LOG_IF(INFO
, true) << "INFO log message";
35 LOG_IF(INFO
, false) << "INFO log message, SHOULD NOT PRINT";
36 LOG_IF(WARNING
, true) << "WARNING log message";
37 LOG_IF(WARNING
, false) << "WARNING log message, SHOULD NOT PRINT";
38 LOG_IF(ERROR
, true) << "ERROR log message";
39 LOG_IF(ERROR
, false) << "ERROR log message, SHOULD NOT PRINT";
40 LOG_IF(FATAL
, false) << "FATAL log message, SHOULD NOT PRINT";
42 EXPECT_EQ("INFO: INFO log message\n", info
.str());
43 EXPECT_EQ("WARNING: WARNING log message\n"
44 "ERROR: ERROR log message\n", error
.str());
50 std::ostringstream info
;
51 std::ostringstream error
;
52 Logger::SetStreams(&info
, &error
);
54 VLOG(0) << "VLOG 0 INFO log message, SHOULD NOT PRINT";
55 VLOG(1) << "VLOG 1 INFO log message, SHOULD NOT PRINT";
56 VLOG(2) << "VLOG 2 INFO log message, SHOULD NOT PRINT";
58 EXPECT_EQ("", info
.str());
59 EXPECT_EQ("", error
.str());
61 Logger::SetVerbose(1);
63 VLOG(0) << "VLOG 0 INFO log message";
64 VLOG(1) << "VLOG 1 INFO log message";
65 VLOG(2) << "VLOG 2 INFO log message, SHOULD NOT PRINT";
67 EXPECT_EQ("INFO: VLOG 0 INFO log message\n"
68 "INFO: VLOG 1 INFO log message\n", info
.str());
69 EXPECT_EQ("", error
.str());
75 std::ostringstream info
;
76 std::ostringstream error
;
77 Logger::SetStreams(&info
, &error
);
79 VLOG_IF(0, true) << "VLOG 0 INFO log message, SHOULD NOT PRINT";
80 VLOG_IF(1, true) << "VLOG 1 INFO log message, SHOULD NOT PRINT";
81 VLOG_IF(2, true) << "VLOG 2 INFO log message, SHOULD NOT PRINT";
83 EXPECT_EQ("", info
.str());
84 EXPECT_EQ("", error
.str());
86 Logger::SetVerbose(1);
88 VLOG_IF(0, true) << "VLOG 0 INFO log message";
89 VLOG_IF(0, false) << "VLOG 0 INFO log message, SHOULD NOT PRINT";
90 VLOG_IF(1, true) << "VLOG 1 INFO log message";
91 VLOG_IF(1, false) << "VLOG 1 INFO log message, SHOULD NOT PRINT";
92 VLOG_IF(2, true) << "VLOG 2 INFO log message, SHOULD NOT PRINT";
93 VLOG_IF(2, false) << "VLOG 2 INFO log message, SHOULD NOT PRINT";
95 EXPECT_EQ("INFO: VLOG 0 INFO log message\n"
96 "INFO: VLOG 1 INFO log message\n", info
.str());
97 EXPECT_EQ("", error
.str());
101 TEST(DebugDeathTest
, Fatal
) {
102 ::testing::FLAGS_gtest_death_test_style
= "threadsafe";
104 EXPECT_DEATH(LOG(FATAL
) << "FATAL log message", "FATAL: FATAL log message");
106 LOG_IF(FATAL
, true) << "FATAL log message", "FATAL: FATAL log message");
109 TEST(DebugDeathTest
, Check
) {
110 ::testing::FLAGS_gtest_death_test_style
= "threadsafe";
113 EXPECT_DEATH(CHECK(0 == 1), "FATAL: .*:.*: .*: CHECK '0 == 1' failed");
116 TEST(DebugDeathTest
, NotReached
) {
117 ::testing::FLAGS_gtest_death_test_style
= "threadsafe";
119 EXPECT_DEATH(NOTREACHED(), "FATAL: .*:.*: .*: NOTREACHED\\(\\) hit");
122 } // namespace relocation_packer