OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include <string> | 5 #include <string> |
6 #include <utility> | 6 #include <utility> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
11 #include "mojo/public/c/environment/logger.h" | 11 #include "mojo/public/c/environment/logger.h" |
12 #include "mojo/public/cpp/application/application_impl.h" | 12 #include "mojo/public/cpp/application/application_impl.h" |
13 #include "mojo/public/cpp/application/application_test_base.h" | 13 #include "mojo/public/cpp/application/application_test_base.h" |
14 #include "mojo/public/cpp/application/connection_context.h" | 14 #include "mojo/public/cpp/application/connection_context.h" |
15 #include "mojo/public/cpp/system/time.h" | 15 #include "mojo/public/cpp/system/time.h" |
16 #include "mojo/services/log/interfaces/entry.mojom.h" | 16 #include "mojo/services/log/interfaces/entry.mojom.h" |
17 #include "mojo/services/log/interfaces/log.mojom.h" | 17 #include "mojo/services/log/interfaces/log.mojom.h" |
18 #include "services/log/log_impl.h" | 18 #include "services/log/log_impl.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 | 20 |
21 namespace mojo { | 21 namespace mojo { |
22 namespace log { | 22 namespace log { |
23 namespace { | 23 namespace { |
24 | 24 |
25 using base::MessageLoop; | 25 using base::MessageLoop; |
26 using LogImplTest = mojo::test::ApplicationTestBase; | 26 using LogImplTest = mojo::test::ApplicationTestBase; |
27 | 27 |
28 // We need to supply a ApplicationConnection to LogImpl::Create(). | |
29 class TestApplicationConnection : public ApplicationConnection { | |
30 public: | |
31 TestApplicationConnection() | |
32 : connection_context_(ConnectionContext::Type::INCOMING, | |
33 "mojo:log_impl_unittest", | |
34 "mojo:log") {} | |
35 | |
36 const ConnectionContext& GetConnectionContext() const override { | |
37 return connection_context_; | |
38 } | |
39 | |
40 const std::string& GetConnectionURL() override { | |
41 return connection_context_.connection_url; | |
42 } | |
43 | |
44 const std::string& GetRemoteApplicationURL() override { | |
45 return connection_context_.remote_url; | |
46 } | |
47 | |
48 void SetServiceConnectorForName(ServiceConnector* service_connector, | |
49 const std::string& name) override {} | |
50 | |
51 private: | |
52 const ConnectionContext connection_context_; | |
53 }; | |
54 | |
55 // Tests the Log service implementation by calling its AddEntry and verifying | 28 // Tests the Log service implementation by calling its AddEntry and verifying |
56 // the log message that it "prints". | 29 // the log message that it "prints". |
57 TEST_F(LogImplTest, AddEntryOutput) { | 30 TEST_F(LogImplTest, AddEntryOutput) { |
58 std::vector<std::string> messages; | 31 std::vector<std::string> messages; |
59 | 32 |
60 LogPtr log; | 33 LogPtr log; |
61 TestApplicationConnection app_connection; | 34 ConnectionContext connection_context(ConnectionContext::Type::INCOMING, |
| 35 "mojo:log_impl_unittest", "mojo:log"); |
62 LogImpl::Create( | 36 LogImpl::Create( |
63 &app_connection, GetProxy(&log), | 37 connection_context, GetProxy(&log), |
64 [&messages](const std::string& message) { messages.push_back(message); }); | 38 [&messages](const std::string& message) { messages.push_back(message); }); |
65 | 39 |
66 Entry entry; | 40 Entry entry; |
67 entry.log_level = MOJO_LOG_LEVEL_INFO; | 41 entry.log_level = MOJO_LOG_LEVEL_INFO; |
68 entry.timestamp = GetTimeTicksNow(); | 42 entry.timestamp = GetTimeTicksNow(); |
69 entry.source_file = "file.ext"; | 43 entry.source_file = "file.ext"; |
70 entry.source_line = 0; | 44 entry.source_line = 0; |
71 entry.message = "1234567890"; | 45 entry.message = "1234567890"; |
72 log->AddEntry(entry.Clone()); | 46 log->AddEntry(entry.Clone()); |
73 | 47 |
(...skipping 19 matching lines...) Expand all Loading... |
93 "<mojo:log_impl_unittest> [INFO] file.ext:1: 1234567890", | 67 "<mojo:log_impl_unittest> [INFO] file.ext:1: 1234567890", |
94 "<mojo:log_impl_unittest> [INFO] 1234567890", | 68 "<mojo:log_impl_unittest> [INFO] 1234567890", |
95 "<mojo:log_impl_unittest> [INFO] <no message>", | 69 "<mojo:log_impl_unittest> [INFO] <no message>", |
96 }; | 70 }; |
97 EXPECT_EQ(kExpectedMessages, messages); | 71 EXPECT_EQ(kExpectedMessages, messages); |
98 } | 72 } |
99 | 73 |
100 } // namespace | 74 } // namespace |
101 } // namespace log | 75 } // namespace log |
102 } // namespace mojo | 76 } // namespace mojo |
OLD | NEW |