OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "dbus/values_util.h" | 5 #include "dbus/values_util.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 data.push_back(1); | 197 data.push_back(1); |
198 data.push_back(2); | 198 data.push_back(2); |
199 writer.OpenArray("i", &sub_writer); | 199 writer.OpenArray("i", &sub_writer); |
200 for (size_t i = 0; i != data.size(); ++i) | 200 for (size_t i = 0; i != data.size(); ++i) |
201 sub_writer.AppendInt32(data[i]); | 201 sub_writer.AppendInt32(data[i]); |
202 writer.CloseContainer(&sub_writer); | 202 writer.CloseContainer(&sub_writer); |
203 | 203 |
204 // Create the expected value. | 204 // Create the expected value. |
205 std::unique_ptr<base::ListValue> list_value(new base::ListValue); | 205 std::unique_ptr<base::ListValue> list_value(new base::ListValue); |
206 for (size_t i = 0; i != data.size(); ++i) | 206 for (size_t i = 0; i != data.size(); ++i) |
207 list_value->Append(new base::FundamentalValue(data[i])); | 207 list_value->AppendInteger(data[i]); |
208 | 208 |
209 // Pop an int32_t array. | 209 // Pop an int32_t array. |
210 MessageReader reader(response.get()); | 210 MessageReader reader(response.get()); |
211 std::unique_ptr<base::Value> value(PopDataAsValue(&reader)); | 211 std::unique_ptr<base::Value> value(PopDataAsValue(&reader)); |
212 ASSERT_TRUE(value.get() != NULL); | 212 ASSERT_TRUE(value.get() != NULL); |
213 EXPECT_TRUE(value->Equals(list_value.get())); | 213 EXPECT_TRUE(value->Equals(list_value.get())); |
214 } | 214 } |
215 | 215 |
216 TEST(ValuesUtilTest, PopStringArray) { | 216 TEST(ValuesUtilTest, PopStringArray) { |
217 std::unique_ptr<Response> response(Response::CreateEmpty()); | 217 std::unique_ptr<Response> response(Response::CreateEmpty()); |
218 // Append a string array. | 218 // Append a string array. |
219 MessageWriter writer(response.get()); | 219 MessageWriter writer(response.get()); |
220 MessageWriter sub_writer(NULL); | 220 MessageWriter sub_writer(NULL); |
221 std::vector<std::string> data; | 221 std::vector<std::string> data; |
222 data.push_back("Dreamlifter"); | 222 data.push_back("Dreamlifter"); |
223 data.push_back("Beluga"); | 223 data.push_back("Beluga"); |
224 data.push_back("Mriya"); | 224 data.push_back("Mriya"); |
225 writer.AppendArrayOfStrings(data); | 225 writer.AppendArrayOfStrings(data); |
226 | 226 |
227 // Create the expected value. | 227 // Create the expected value. |
228 std::unique_ptr<base::ListValue> list_value(new base::ListValue); | 228 std::unique_ptr<base::ListValue> list_value(new base::ListValue); |
229 for (size_t i = 0; i != data.size(); ++i) | 229 for (size_t i = 0; i != data.size(); ++i) |
230 list_value->Append(new base::StringValue(data[i])); | 230 list_value->AppendString(data[i]); |
231 | 231 |
232 // Pop a string array. | 232 // Pop a string array. |
233 MessageReader reader(response.get()); | 233 MessageReader reader(response.get()); |
234 std::unique_ptr<base::Value> value(PopDataAsValue(&reader)); | 234 std::unique_ptr<base::Value> value(PopDataAsValue(&reader)); |
235 ASSERT_TRUE(value.get() != NULL); | 235 ASSERT_TRUE(value.get() != NULL); |
236 EXPECT_TRUE(value->Equals(list_value.get())); | 236 EXPECT_TRUE(value->Equals(list_value.get())); |
237 } | 237 } |
238 | 238 |
239 TEST(ValuesUtilTest, PopStruct) { | 239 TEST(ValuesUtilTest, PopStruct) { |
240 std::unique_ptr<Response> response(Response::CreateEmpty()); | 240 std::unique_ptr<Response> response(Response::CreateEmpty()); |
241 // Append a struct. | 241 // Append a struct. |
242 MessageWriter writer(response.get()); | 242 MessageWriter writer(response.get()); |
243 MessageWriter sub_writer(NULL); | 243 MessageWriter sub_writer(NULL); |
244 writer.OpenStruct(&sub_writer); | 244 writer.OpenStruct(&sub_writer); |
245 const bool kBoolValue = true; | 245 const bool kBoolValue = true; |
246 sub_writer.AppendBool(kBoolValue); | 246 sub_writer.AppendBool(kBoolValue); |
247 const int32_t kInt32Value = -123; | 247 const int32_t kInt32Value = -123; |
248 sub_writer.AppendInt32(kInt32Value); | 248 sub_writer.AppendInt32(kInt32Value); |
249 const double kDoubleValue = 1.23; | 249 const double kDoubleValue = 1.23; |
250 sub_writer.AppendDouble(kDoubleValue); | 250 sub_writer.AppendDouble(kDoubleValue); |
251 const std::string kStringValue = "one two three"; | 251 const std::string kStringValue = "one two three"; |
252 sub_writer.AppendString(kStringValue); | 252 sub_writer.AppendString(kStringValue); |
253 writer.CloseContainer(&sub_writer); | 253 writer.CloseContainer(&sub_writer); |
254 | 254 |
255 // Create the expected value. | 255 // Create the expected value. |
256 base::ListValue list_value; | 256 base::ListValue list_value; |
257 list_value.Append(new base::FundamentalValue(kBoolValue)); | 257 list_value.AppendBoolean(kBoolValue); |
258 list_value.Append(new base::FundamentalValue(kInt32Value)); | 258 list_value.AppendInteger(kInt32Value); |
259 list_value.Append(new base::FundamentalValue(kDoubleValue)); | 259 list_value.AppendDouble(kDoubleValue); |
260 list_value.Append(new base::StringValue(kStringValue)); | 260 list_value.AppendString(kStringValue); |
261 | 261 |
262 // Pop a struct. | 262 // Pop a struct. |
263 MessageReader reader(response.get()); | 263 MessageReader reader(response.get()); |
264 std::unique_ptr<base::Value> value(PopDataAsValue(&reader)); | 264 std::unique_ptr<base::Value> value(PopDataAsValue(&reader)); |
265 ASSERT_TRUE(value.get() != NULL); | 265 ASSERT_TRUE(value.get() != NULL); |
266 EXPECT_TRUE(value->Equals(&list_value)); | 266 EXPECT_TRUE(value->Equals(&list_value)); |
267 } | 267 } |
268 | 268 |
269 TEST(ValuesUtilTest, PopStringToVariantDictionary) { | 269 TEST(ValuesUtilTest, PopStringToVariantDictionary) { |
270 std::unique_ptr<Response> response(Response::CreateEmpty()); | 270 std::unique_ptr<Response> response(Response::CreateEmpty()); |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 std::unique_ptr<base::Value> value; | 683 std::unique_ptr<base::Value> value; |
684 value = PopDataAsValue(&reader); | 684 value = PopDataAsValue(&reader); |
685 ASSERT_TRUE(value.get() != NULL); | 685 ASSERT_TRUE(value.get() != NULL); |
686 EXPECT_TRUE(value->Equals(&test_list)); | 686 EXPECT_TRUE(value->Equals(&test_list)); |
687 value = PopDataAsValue(&reader); | 687 value = PopDataAsValue(&reader); |
688 ASSERT_TRUE(value.get() != NULL); | 688 ASSERT_TRUE(value.get() != NULL); |
689 EXPECT_TRUE(value->Equals(&int_value)); | 689 EXPECT_TRUE(value->Equals(&int_value)); |
690 } | 690 } |
691 | 691 |
692 } // namespace dbus | 692 } // namespace dbus |
OLD | NEW |