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.
5 #include "mojo/application/public/cpp/lib/service_registry.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "mojo/application/public/cpp/service_connector.h"
9 #include "testing/gtest/include/gtest/gtest.h"
15 class TestConnector
: public ServiceConnector
{
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
{}
27 TEST(ServiceRegistryTest
, Ownership
) {
32 ServiceRegistry registry
;
33 registry
.SetServiceConnectorForName(new TestConnector(&delete_count
),
36 EXPECT_EQ(1, delete_count
);
40 scoped_ptr
<ServiceRegistry
> registry(new ServiceRegistry
);
41 ServiceConnector
* c
= new TestConnector(&delete_count
);
42 registry
->SetServiceConnectorForName(c
, "TC1");
43 registry
->RemoveServiceConnectorForName("TC1");
45 EXPECT_EQ(2, delete_count
);
50 ServiceRegistry registry
;
51 registry
.SetServiceConnectorForName(new TestConnector(&delete_count
),
53 registry
.SetServiceConnectorForName(new TestConnector(&delete_count
),
56 EXPECT_EQ(4, delete_count
);
60 ServiceRegistry registry
;
61 registry
.SetServiceConnectorForName(new TestConnector(&delete_count
),
63 registry
.SetServiceConnectorForName(new TestConnector(&delete_count
),
65 EXPECT_EQ(5, delete_count
);
67 EXPECT_EQ(6, delete_count
);
71 } // namespace internal