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

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

Issue 1565343003: Move mojo/application/public -> mojo/shell/public (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fetcher
Patch Set: . Created 4 years, 11 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 | « mojo/application/public/cpp/tests/BUILD.gn ('k') | mojo/application/public/interfaces/BUILD.gn » ('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/application/public/cpp/lib/service_registry.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "mojo/application/public/cpp/service_connector.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace mojo {
12 namespace internal {
13 namespace {
14
15 class TestConnector : public ServiceConnector {
16 public:
17 explicit TestConnector(int* delete_count) : delete_count_(delete_count) {}
18 ~TestConnector() override { (*delete_count_)++; }
19 void ConnectToService(ApplicationConnection* application_connection,
20 const std::string& interface_name,
21 ScopedMessagePipeHandle client_handle) override {}
22
23 private:
24 int* delete_count_;
25 };
26
27 TEST(ServiceRegistryTest, Ownership) {
28 int delete_count = 0;
29
30 // Destruction.
31 {
32 ServiceRegistry registry;
33 registry.SetServiceConnectorForName(new TestConnector(&delete_count),
34 "TC1");
35 }
36 EXPECT_EQ(1, delete_count);
37
38 // Removal.
39 {
40 scoped_ptr<ServiceRegistry> registry(new ServiceRegistry);
41 ServiceConnector* c = new TestConnector(&delete_count);
42 registry->SetServiceConnectorForName(c, "TC1");
43 registry->RemoveServiceConnectorForName("TC1");
44 registry.reset();
45 EXPECT_EQ(2, delete_count);
46 }
47
48 // Multiple.
49 {
50 ServiceRegistry registry;
51 registry.SetServiceConnectorForName(new TestConnector(&delete_count),
52 "TC1");
53 registry.SetServiceConnectorForName(new TestConnector(&delete_count),
54 "TC2");
55 }
56 EXPECT_EQ(4, delete_count);
57
58 // Re-addition.
59 {
60 ServiceRegistry registry;
61 registry.SetServiceConnectorForName(new TestConnector(&delete_count),
62 "TC1");
63 registry.SetServiceConnectorForName(new TestConnector(&delete_count),
64 "TC1");
65 EXPECT_EQ(5, delete_count);
66 }
67 EXPECT_EQ(6, delete_count);
68 }
69
70 } // namespace
71 } // namespace internal
72 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/application/public/cpp/tests/BUILD.gn ('k') | mojo/application/public/interfaces/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698