OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 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 "base/bind.h" | |
6 #include "base/values.h" | |
7 #include "chromeos/dbus/flimflam_client_unittest_base.h" | |
8 #include "chromeos/dbus/flimflam_device_client.h" | |
9 #include "dbus/message.h" | |
10 #include "dbus/object_path.h" | |
11 #include "dbus/values_util.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 #include "third_party/cros_system_api/dbus/service_constants.h" | |
14 | |
15 namespace chromeos { | |
16 | |
17 namespace { | |
18 | |
19 const char kExampleDevicePath[] = "/foo/bar"; | |
20 | |
21 // Expects the reader to have a string and a bool. | |
22 void ExpectStringAndBoolArguments(const std::string& expected_string, | |
23 bool expected_bool, | |
24 dbus::MessageReader* reader) { | |
25 std::string arg1; | |
26 ASSERT_TRUE(reader->PopString(&arg1)); | |
27 EXPECT_EQ(expected_string, arg1); | |
28 bool arg2 = false; | |
29 ASSERT_TRUE(reader->PopBool(&arg2)); | |
30 EXPECT_EQ(expected_bool, arg2); | |
31 EXPECT_FALSE(reader->HasMoreData()); | |
32 } | |
33 | |
34 // Expects the reader to have two strings. | |
35 void ExpectTwoStringArguments(const std::string& expected_string1, | |
36 const std::string& expected_string2, | |
37 dbus::MessageReader* reader) { | |
38 std::string arg1; | |
39 ASSERT_TRUE(reader->PopString(&arg1)); | |
40 EXPECT_EQ(expected_string1, arg1); | |
41 std::string arg2; | |
42 ASSERT_TRUE(reader->PopString(&arg2)); | |
43 EXPECT_EQ(expected_string2, arg2); | |
44 EXPECT_FALSE(reader->HasMoreData()); | |
45 } | |
46 | |
47 } // namespace | |
48 | |
49 class FlimflamDeviceClientTest : public FlimflamClientUnittestBase { | |
50 public: | |
51 FlimflamDeviceClientTest() | |
52 : FlimflamClientUnittestBase(flimflam::kFlimflamDeviceInterface, | |
53 dbus::ObjectPath(kExampleDevicePath)) { | |
54 } | |
55 | |
56 virtual void SetUp() { | |
57 FlimflamClientUnittestBase::SetUp(); | |
58 // Create a client with the mock bus. | |
59 client_.reset(FlimflamDeviceClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION, | |
60 mock_bus_)); | |
stevenjb
2012/04/17 00:25:52
nit: alignment
hashimoto
2012/04/17 02:26:06
Done.
| |
61 // Run the message loop to run the signal connection result callback. | |
62 message_loop_.RunAllPending(); | |
63 } | |
64 | |
65 virtual void TearDown() { | |
66 FlimflamClientUnittestBase::TearDown(); | |
67 } | |
68 | |
69 protected: | |
70 scoped_ptr<FlimflamDeviceClient> client_; | |
71 }; | |
72 | |
73 TEST_F(FlimflamDeviceClientTest, PropertyChanged) { | |
74 const bool kValue = true; | |
75 // Create a signal. | |
76 dbus::Signal signal(flimflam::kFlimflamDeviceInterface, | |
77 flimflam::kMonitorPropertyChanged); | |
78 dbus::MessageWriter writer(&signal); | |
79 writer.AppendString(flimflam::kCellularAllowRoamingProperty); | |
80 writer.AppendVariantOfBool(kValue); | |
81 | |
82 // Set expectations. | |
83 const base::FundamentalValue value(kValue); | |
84 client_->SetPropertyChangedHandler( | |
85 dbus::ObjectPath(kExampleDevicePath), | |
86 base::Bind(&ExpectPropertyChanged, | |
87 flimflam::kCellularAllowRoamingProperty, | |
88 &value)); | |
89 // Run the signal callback. | |
90 SendPropertyChangedSignal(&signal); | |
91 | |
92 // Reset the handler. | |
93 client_->ResetPropertyChangedHandler(dbus::ObjectPath(kExampleDevicePath)); | |
94 } | |
95 | |
96 TEST_F(FlimflamDeviceClientTest, GetProperties) { | |
97 const bool kValue = true; | |
98 // Create response. | |
99 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | |
100 dbus::MessageWriter writer(response.get()); | |
101 dbus::MessageWriter array_writer(NULL); | |
102 writer.OpenArray("{sv}", &array_writer); | |
103 dbus::MessageWriter entry_writer(NULL); | |
104 array_writer.OpenDictEntry(&entry_writer); | |
105 entry_writer.AppendString(flimflam::kCellularAllowRoamingProperty); | |
106 entry_writer.AppendVariantOfBool(kValue); | |
107 array_writer.CloseContainer(&entry_writer); | |
108 writer.CloseContainer(&array_writer); | |
109 | |
110 // Set expectations. | |
111 base::DictionaryValue value; | |
112 value.SetWithoutPathExpansion(flimflam::kCellularAllowRoamingProperty, | |
113 base::Value::CreateBooleanValue(kValue)); | |
114 PrepareForMethodCall(flimflam::kGetPropertiesFunction, | |
115 base::Bind(&ExpectNoArgument), | |
116 response.get()); | |
117 // Call method. | |
118 client_->GetProperties(dbus::ObjectPath(kExampleDevicePath), | |
119 base::Bind(&ExpectDictionaryValueResult, &value)); | |
120 // Run the message loop. | |
121 message_loop_.RunAllPending(); | |
122 } | |
123 | |
124 TEST_F(FlimflamDeviceClientTest, ProposeScan) { | |
125 // Create response. | |
126 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | |
127 | |
128 // Set expectations. | |
129 PrepareForMethodCall(flimflam::kProposeScanFunction, | |
130 base::Bind(&ExpectNoArgument), | |
131 response.get()); | |
132 // Call method. | |
133 client_->ProposeScan(dbus::ObjectPath(kExampleDevicePath), | |
134 base::Bind(&ExpectNoResultValue)); | |
135 // Run the message loop. | |
136 message_loop_.RunAllPending(); | |
137 } | |
138 | |
139 TEST_F(FlimflamDeviceClientTest, SetProperty) { | |
140 const bool kValue = true; | |
141 // Create response. | |
142 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | |
143 | |
144 // Set expectations. | |
145 const base::FundamentalValue value(kValue); | |
146 PrepareForMethodCall(flimflam::kSetPropertyFunction, | |
147 base::Bind(&ExpectStringAndValueArguments, | |
148 flimflam::kCellularAllowRoamingProperty, | |
149 &value), | |
150 response.get()); | |
151 // Call method. | |
152 client_->SetProperty(dbus::ObjectPath(kExampleDevicePath), | |
153 flimflam::kCellularAllowRoamingProperty, | |
154 value, | |
155 base::Bind(&ExpectNoResultValue)); | |
156 // Run the message loop. | |
157 message_loop_.RunAllPending(); | |
158 } | |
159 | |
160 TEST_F(FlimflamDeviceClientTest, ClearProperty) { | |
161 // Create response. | |
162 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | |
163 | |
164 // Set expectations. | |
165 PrepareForMethodCall(flimflam::kClearPropertyFunction, | |
166 base::Bind(&ExpectStringArgument, | |
167 flimflam::kCellularAllowRoamingProperty), | |
168 response.get()); | |
169 // Call method. | |
170 client_->ClearProperty(dbus::ObjectPath(kExampleDevicePath), | |
171 flimflam::kCellularAllowRoamingProperty, | |
172 base::Bind(&ExpectNoResultValue)); | |
173 // Run the message loop. | |
174 message_loop_.RunAllPending(); | |
175 } | |
176 | |
177 TEST_F(FlimflamDeviceClientTest, RequirePin) { | |
178 const char kPin[] = "123456"; | |
179 const bool kRequired = true; | |
180 // Create response. | |
181 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | |
182 | |
183 // Set expectations. | |
184 PrepareForMethodCall(flimflam::kRequirePinFunction, | |
185 base::Bind(&ExpectStringAndBoolArguments, | |
186 kPin, | |
187 kRequired), | |
188 response.get()); | |
189 // Call method. | |
190 client_->RequirePin(dbus::ObjectPath(kExampleDevicePath), | |
191 kPin, | |
192 kRequired, | |
193 base::Bind(&ExpectNoResultValue)); | |
194 // Run the message loop. | |
195 message_loop_.RunAllPending(); | |
196 } | |
197 | |
198 TEST_F(FlimflamDeviceClientTest, EnterPin) { | |
199 const char kPin[] = "123456"; | |
200 // Create response. | |
201 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | |
202 | |
203 // Set expectations. | |
204 PrepareForMethodCall(flimflam::kEnterPinFunction, | |
205 base::Bind(&ExpectStringArgument, | |
206 kPin), | |
207 response.get()); | |
208 // Call method. | |
209 client_->EnterPin(dbus::ObjectPath(kExampleDevicePath), | |
210 kPin, | |
211 base::Bind(&ExpectNoResultValue)); | |
212 // Run the message loop. | |
213 message_loop_.RunAllPending(); | |
214 } | |
215 | |
216 TEST_F(FlimflamDeviceClientTest, UnblockPin) { | |
217 const char kPuk[] = "987654"; | |
218 const char kPin[] = "123456"; | |
219 // Create response. | |
220 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | |
221 | |
222 // Set expectations. | |
223 PrepareForMethodCall(flimflam::kUnblockPinFunction, | |
224 base::Bind(&ExpectTwoStringArguments, kPuk, kPin), | |
225 response.get()); | |
226 // Call method. | |
227 client_->UnblockPin(dbus::ObjectPath(kExampleDevicePath), | |
228 kPuk, | |
229 kPin, | |
230 base::Bind(&ExpectNoResultValue)); | |
231 // Run the message loop. | |
232 message_loop_.RunAllPending(); | |
233 } | |
234 | |
235 TEST_F(FlimflamDeviceClientTest, ChangePin) { | |
236 const char kOldPin[] = "123456"; | |
237 const char kNewPin[] = "234567"; | |
238 // Create response. | |
239 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | |
240 | |
241 // Set expectations. | |
242 PrepareForMethodCall(flimflam::kChangePinFunction, | |
243 base::Bind(&ExpectTwoStringArguments, | |
244 kOldPin, | |
245 kNewPin), | |
246 response.get()); | |
247 // Call method. | |
248 client_->ChangePin(dbus::ObjectPath(kExampleDevicePath), | |
249 kOldPin, | |
250 kNewPin, | |
251 base::Bind(&ExpectNoResultValue)); | |
252 // Run the message loop. | |
253 message_loop_.RunAllPending(); | |
254 } | |
255 | |
256 TEST_F(FlimflamDeviceClientTest, Register) { | |
257 const char kNetworkId[] = "networkid"; | |
258 // Create response. | |
259 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | |
260 | |
261 // Set expectations. | |
262 PrepareForMethodCall(flimflam::kRegisterFunction, | |
263 base::Bind(&ExpectStringArgument, kNetworkId), | |
264 response.get()); | |
265 // Call method. | |
266 client_->Register(dbus::ObjectPath(kExampleDevicePath), | |
267 kNetworkId, | |
268 base::Bind(&ExpectNoResultValue)); | |
269 // Run the message loop. | |
270 message_loop_.RunAllPending(); | |
271 } | |
272 | |
273 } // namespace chromeos | |
OLD | NEW |