OLD | NEW |
| (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 "mojo/public/c/environment/logger.h" | |
6 #include "mojo/public/cpp/environment/environment.h" | |
7 #include "testing/gtest/include/gtest/gtest.h" | |
8 | |
9 namespace mojo { | |
10 namespace { | |
11 | |
12 TEST(LoggerTest, Basic) { | |
13 Environment environment; | |
14 const MojoLogger* const logger = Environment::GetDefaultLogger(); | |
15 | |
16 logger->LogMessage(MOJO_LOG_LEVEL_VERBOSE - 1, "Logged at VERBOSE-1 level"); | |
17 logger->LogMessage(MOJO_LOG_LEVEL_VERBOSE, "Logged at VERBOSE level"); | |
18 logger->LogMessage(MOJO_LOG_LEVEL_INFO, "Logged at INFO level"); | |
19 logger->LogMessage(MOJO_LOG_LEVEL_WARNING, "Logged at WARNING level"); | |
20 logger->LogMessage(MOJO_LOG_LEVEL_ERROR, "Logged at ERROR level"); | |
21 | |
22 // This should kill us: | |
23 EXPECT_DEATH_IF_SUPPORTED( | |
24 { logger->LogMessage(MOJO_LOG_LEVEL_FATAL, "Logged at FATAL level"); }, | |
25 ""); | |
26 } | |
27 | |
28 TEST(LoggerTest, LogLevels) { | |
29 Environment environment; | |
30 const MojoLogger* const logger = Environment::GetDefaultLogger(); | |
31 | |
32 for (MojoLogLevel log_level = MOJO_LOG_LEVEL_VERBOSE - 1; | |
33 log_level <= MOJO_LOG_LEVEL_FATAL + 1; | |
34 log_level++) { | |
35 logger->SetMinimumLogLevel(log_level); | |
36 | |
37 if (log_level <= MOJO_LOG_LEVEL_FATAL) | |
38 EXPECT_EQ(log_level, logger->GetMinimumLogLevel()); | |
39 else | |
40 EXPECT_EQ(MOJO_LOG_LEVEL_FATAL, logger->GetMinimumLogLevel()); | |
41 | |
42 logger->LogMessage(MOJO_LOG_LEVEL_VERBOSE - 1, "Logged at VERBOSE-1 level"); | |
43 logger->LogMessage(MOJO_LOG_LEVEL_VERBOSE, "Logged at VERBOSE level"); | |
44 logger->LogMessage(MOJO_LOG_LEVEL_INFO, "Logged at INFO level"); | |
45 logger->LogMessage(MOJO_LOG_LEVEL_WARNING, "Logged at WARNING level"); | |
46 logger->LogMessage(MOJO_LOG_LEVEL_ERROR, "Logged at ERROR level"); | |
47 | |
48 // This should kill us: | |
49 EXPECT_DEATH_IF_SUPPORTED( | |
50 { logger->LogMessage(MOJO_LOG_LEVEL_FATAL, "Logged at FATAL level"); }, | |
51 ""); | |
52 } | |
53 } | |
54 | |
55 } // namespace | |
56 } // namespace mojo | |
OLD | NEW |