Chromium Code Reviews

Side by Side Diff: mojo/public/cpp/application/tests/service_registry_unittest.cc

Issue 1977043002: ApplicationConnection devolution, part 1. (Closed) Base URL: https://github.com/domokit/mojo.git@work791_service_registry_spimpl
Patch Set: rebased Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « mojo/public/cpp/application/tests/BUILD.gn ('k') | services/dart/content_handler_main.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 "mojo/public/cpp/application/lib/service_registry.h"
6
7 #include "mojo/public/cpp/application/service_connector.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace mojo {
11 namespace internal {
12 namespace {
13
14 class TestConnector : public ServiceConnector {
15 public:
16 explicit TestConnector(int* delete_count) : delete_count_(delete_count) {}
17 ~TestConnector() override { (*delete_count_)++; }
18 void ConnectToService(const ConnectionContext& connection_context,
19 const std::string& interface_name,
20 ScopedMessagePipeHandle client_handle) override {}
21
22 private:
23 int* delete_count_;
24 };
25
26 TEST(ServiceRegistryTest, Ownership) {
27 int delete_count = 0;
28
29 // Destruction.
30 {
31 ServiceRegistry registry;
32 registry.SetServiceConnectorForName(new TestConnector(&delete_count),
33 "TC1");
34 }
35 EXPECT_EQ(1, delete_count);
36
37 // Removal.
38 {
39 ServiceRegistry registry;
40 ServiceConnector* c = new TestConnector(&delete_count);
41 registry.SetServiceConnectorForName(c, "TC1");
42 registry.RemoveServiceConnectorForName("TC1");
43 EXPECT_EQ(2, delete_count);
44 }
45
46 // Multiple.
47 {
48 ServiceRegistry registry;
49 registry.SetServiceConnectorForName(new TestConnector(&delete_count),
50 "TC1");
51 registry.SetServiceConnectorForName(new TestConnector(&delete_count),
52 "TC2");
53 }
54 EXPECT_EQ(4, delete_count);
55
56 // Re-addition.
57 {
58 ServiceRegistry registry;
59 registry.SetServiceConnectorForName(new TestConnector(&delete_count),
60 "TC1");
61 registry.SetServiceConnectorForName(new TestConnector(&delete_count),
62 "TC1");
63 EXPECT_EQ(5, delete_count);
64 }
65 EXPECT_EQ(6, delete_count);
66 }
67
68 } // namespace
69 } // namespace internal
70 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/application/tests/BUILD.gn ('k') | services/dart/content_handler_main.cc » ('j') | no next file with comments »

Powered by Google App Engine