Chromium Code Reviews

Side by Side Diff: ceee/ie/broker/broker_rpc_unittest.cc

Issue 5258006: Restart of ceee_broker on crash. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
« no previous file with comments | « ceee/ie/broker/broker_rpc_server.cc ('k') | ceee/ie/broker/broker_rpc_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "ceee/ie/broker/broker_rpc_client.h" 5 #include "ceee/ie/broker/broker_rpc_client.h"
6 #include "ceee/ie/broker/broker_rpc_server.h" 6 #include "ceee/ie/broker/broker_rpc_server.h"
7 7
8 #include <atlbase.h> 8 #include <atlbase.h>
9 #include "broker_rpc_lib.h" // NOLINT 9 #include "broker_rpc_lib.h" // NOLINT
10 #include "ceee/ie/broker/broker_rpc_utils.h" 10 #include "ceee/ie/broker/broker_rpc_utils.h"
11 #include "ceee/ie/common/ceee_module_util.h" 11 #include "ceee/ie/common/ceee_module_util.h"
12 #include "ceee/testing/utils/mock_static.h" 12 #include "ceee/testing/utils/mock_static.h"
13 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 using testing::_;
17 using testing::StrEq;
18 using testing::StrictMock;
19 using testing::Return;
20
21 namespace { 16 namespace {
22 17
23 using testing::_; 18 using testing::_;
19 using testing::DoAll;
20 using testing::Invoke;
21 using testing::InvokeWithoutArgs;
22 using testing::StrEq;
23 using testing::Return;
24 24
25 MOCK_STATIC_CLASS_BEGIN(BrokerRpcMock) 25 MOCK_STATIC_CLASS_BEGIN(BrokerRpcMock)
26 MOCK_STATIC_INIT_BEGIN(BrokerRpcMock) 26 MOCK_STATIC_INIT_BEGIN(BrokerRpcMock)
27 MOCK_STATIC_INIT(GetRpcEndPointAddress); 27 MOCK_STATIC_INIT(GetRpcEndpointAddress);
28 MOCK_STATIC_INIT(BrokerRpcServer_FireEvent); 28 MOCK_STATIC_INIT(BrokerRpcServer_FireEvent);
29 MOCK_STATIC_INIT(BrokerRpcServer_SendUmaHistogramTimes); 29 MOCK_STATIC_INIT(BrokerRpcServer_SendUmaHistogramTimes);
30 MOCK_STATIC_INIT(BrokerRpcServer_SendUmaHistogramData); 30 MOCK_STATIC_INIT(BrokerRpcServer_SendUmaHistogramData);
31 MOCK_STATIC_INIT_END() 31 MOCK_STATIC_INIT_END()
32 MOCK_STATIC0(std::wstring, , GetRpcEndPointAddress); 32 MOCK_STATIC0(std::wstring, , GetRpcEndpointAddress);
33 MOCK_STATIC4(void, , BrokerRpcServer_FireEvent, handle_t, BrokerContextHandle, 33 MOCK_STATIC4(void, , BrokerRpcServer_FireEvent, handle_t, BrokerContextHandle,
34 const char*, const char*); 34 const char*, const char*);
35 MOCK_STATIC3(void, , BrokerRpcServer_SendUmaHistogramTimes, handle_t, 35 MOCK_STATIC3(void, , BrokerRpcServer_SendUmaHistogramTimes, handle_t,
36 const char*, int); 36 const char*, int);
37 MOCK_STATIC6(void, , BrokerRpcServer_SendUmaHistogramData, handle_t, 37 MOCK_STATIC6(void, , BrokerRpcServer_SendUmaHistogramData, handle_t,
38 const char*, int, int, int, int); 38 const char*, int, int, int, int);
39 MOCK_STATIC_CLASS_END(BrokerRpcMock) 39 MOCK_STATIC_CLASS_END(BrokerRpcMock)
40 40
41 class BrokerRpcTest : public testing::Test { 41 class BrokerRpcTest : public testing::Test {
42 protected: 42 protected:
43 virtual void SetUp() { 43 virtual void SetUp() {
44 EXPECT_CALL(broker_rpc_mock_, GetRpcEndPointAddress()) 44 EXPECT_CALL(broker_rpc_mock_, GetRpcEndpointAddress())
45 .WillRepeatedly(Return(L"BrokerRpcTestEP")); 45 .WillRepeatedly(Return(L"BrokerRpcTestEP"));
46 } 46 }
47 47
48 virtual void TearDown() { 48 virtual void TearDown() {
49 } 49 }
50 50
51 BrokerRpcMock broker_rpc_mock_; 51 BrokerRpcMock broker_rpc_mock_;
52 }; 52 };
53 53
54 TEST_F(BrokerRpcTest, ConnectNoServer) { 54 TEST_F(BrokerRpcTest, ConnectNoServer) {
55 BrokerRpcClient client; 55 BrokerRpcClient client(false);
56 ASSERT_FALSE(client.is_connected()); 56 ASSERT_FALSE(client.is_connected());
57 ASSERT_HRESULT_FAILED(client.Connect(false)); 57 ASSERT_HRESULT_FAILED(client.Connect(false));
58 ASSERT_FALSE(client.is_connected()); 58 ASSERT_FALSE(client.is_connected());
59 } 59 }
60 60
61 TEST_F(BrokerRpcTest, Connect) { 61 TEST_F(BrokerRpcTest, Connect) {
62 BrokerRpcServer server; 62 BrokerRpcServer server;
63 ASSERT_FALSE(server.is_started()); 63 ASSERT_FALSE(server.is_started());
64 ASSERT_TRUE(server.Start()); 64 ASSERT_TRUE(server.Start());
65 ASSERT_TRUE(server.is_started()); 65 ASSERT_TRUE(server.is_started());
66 BrokerRpcClient client; 66 BrokerRpcClient client(false);
67 ASSERT_HRESULT_SUCCEEDED(client.Connect(false)); 67 ASSERT_HRESULT_SUCCEEDED(client.Connect(false));
68 ASSERT_TRUE(client.is_connected()); 68 ASSERT_TRUE(client.is_connected());
69 } 69 }
70 70
71 TEST_F(BrokerRpcTest, RpcCalls) { 71 TEST_F(BrokerRpcTest, RpcCalls) {
72 BrokerRpcServer server; 72 BrokerRpcServer server;
73 ASSERT_TRUE(server.Start()); 73 ASSERT_TRUE(server.Start());
74 74
75 BrokerRpcClient client; 75 BrokerRpcClient client(false);
76 ASSERT_HRESULT_SUCCEEDED(client.Connect(false)); 76 ASSERT_HRESULT_SUCCEEDED(client.Connect(false));
77 77
78 const char* name = "name"; 78 const char* name = "name";
79 const char* args = "args"; 79 const char* args = "args";
80 80
81 EXPECT_CALL(broker_rpc_mock_, 81 EXPECT_CALL(broker_rpc_mock_,
82 BrokerRpcServer_FireEvent(_, _, StrEq(name), StrEq(args))) 82 BrokerRpcServer_FireEvent(_, _, StrEq(name), StrEq(args)))
83 .Times(1); 83 .Times(1);
84 84
85 ASSERT_HRESULT_SUCCEEDED(client.FireEvent(name, args)); 85 ASSERT_HRESULT_SUCCEEDED(client.FireEvent(name, args));
86 86
87 EXPECT_CALL(broker_rpc_mock_, 87 EXPECT_CALL(broker_rpc_mock_,
88 BrokerRpcServer_SendUmaHistogramTimes(_, StrEq(name), 321)) 88 BrokerRpcServer_SendUmaHistogramTimes(_, StrEq(name), 321))
89 .Times(1); 89 .Times(1);
90 ASSERT_HRESULT_SUCCEEDED(client.SendUmaHistogramTimes(name, 321)); 90 ASSERT_HRESULT_SUCCEEDED(client.SendUmaHistogramTimes(name, 321));
91 91
92 EXPECT_CALL(broker_rpc_mock_, 92 EXPECT_CALL(broker_rpc_mock_,
93 BrokerRpcServer_SendUmaHistogramData(_, StrEq(name), 1, 2, 3, 4)) 93 BrokerRpcServer_SendUmaHistogramData(_, StrEq(name), 1, 2, 3, 4))
94 .Times(1); 94 .Times(1);
95 ASSERT_HRESULT_SUCCEEDED(client.SendUmaHistogramData(name, 1, 2, 3, 4)); 95 ASSERT_HRESULT_SUCCEEDED(client.SendUmaHistogramData(name, 1, 2, 3, 4));
96 } 96 }
97 97
98 class TestingBrokerRpcClient : public BrokerRpcClient {
99 public:
100 explicit TestingBrokerRpcClient(bool allow_restarts)
101 : BrokerRpcClient(allow_restarts) {}
102 MOCK_METHOD1(StartServer, HRESULT(IUnknown**));
103 };
104
105 TEST_F(BrokerRpcTest, StartServer) {
106 BrokerRpcServer server;
107 TestingBrokerRpcClient client(true);
108 EXPECT_CALL(client, StartServer(_))
109 .Times(0);
110 ASSERT_HRESULT_FAILED(client.Connect(false));
111
112 EXPECT_CALL(client, StartServer(_))
113 .Times(1)
114 .WillOnce(DoAll(IgnoreResult(InvokeWithoutArgs(&server,
115 &BrokerRpcServer::Start)),
116 Return(RPC_E_FAULT)));
117 ASSERT_HRESULT_FAILED(client.Connect(true));
118
119 EXPECT_CALL(client, StartServer(_))
120 .Times(1)
121 .WillOnce(DoAll(IgnoreResult(InvokeWithoutArgs(&server,
122 &BrokerRpcServer::Start)),
123 Return(RPC_S_OK)));
124 ASSERT_HRESULT_SUCCEEDED(client.Connect(true));
125 }
126
127 TEST_F(BrokerRpcTest, NoRestartServer) {
128 BrokerRpcServer server;
129 TestingBrokerRpcClient client(false);
130 EXPECT_CALL(client, StartServer(_))
131 .Times(1)
132 .WillOnce(DoAll(IgnoreResult(InvokeWithoutArgs(&server,
133 &BrokerRpcServer::Start)),
134 Return(RPC_S_OK)));
135 ASSERT_HRESULT_SUCCEEDED(client.Connect(true));
136 server.Stop();
137
138 EXPECT_CALL(client, StartServer(_))
139 .Times(0);
140 EXPECT_CALL(broker_rpc_mock_,
141 BrokerRpcServer_FireEvent(_, _, _, _))
142 .Times(0);
143 ASSERT_HRESULT_FAILED(client.FireEvent("A", "B"));
144 }
145
146 TEST_F(BrokerRpcTest, RestartServer) {
147 BrokerRpcServer server;
148 TestingBrokerRpcClient client(true);
149 EXPECT_CALL(client, StartServer(_))
150 .Times(1)
151 .WillOnce(DoAll(IgnoreResult(InvokeWithoutArgs(&server,
152 &BrokerRpcServer::Start)),
153 Return(RPC_S_OK)));
154 ASSERT_HRESULT_SUCCEEDED(client.Connect(true));
155 server.Stop();
156
157 EXPECT_CALL(client, StartServer(_))
158 .Times(1)
159 .WillOnce(DoAll(IgnoreResult(InvokeWithoutArgs(&server,
160 &BrokerRpcServer::Start)),
161 Return(RPC_S_OK)));
162 EXPECT_CALL(broker_rpc_mock_,
163 BrokerRpcServer_FireEvent(_, _, _, _))
164 .Times(1);
165 ASSERT_HRESULT_SUCCEEDED(client.FireEvent("A", "B"));
166 }
167
98 } // namespace 168 } // namespace
OLDNEW
« no previous file with comments | « ceee/ie/broker/broker_rpc_server.cc ('k') | ceee/ie/broker/broker_rpc_utils.h » ('j') | no next file with comments »

Powered by Google App Engine