| 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/property.h" | 5 #include "dbus/property.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 // the method call is made that identifies it and distinguishes from any | 151 // the method call is made that identifies it and distinguishes from any |
| 152 // other; you can set this to whatever you wish. | 152 // other; you can set this to whatever you wish. |
| 153 void WaitForCallback(const std::string& id) { | 153 void WaitForCallback(const std::string& id) { |
| 154 while (last_callback_ != id) { | 154 while (last_callback_ != id) { |
| 155 run_loop_.reset(new base::RunLoop); | 155 run_loop_.reset(new base::RunLoop); |
| 156 run_loop_->Run(); | 156 run_loop_->Run(); |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 | 159 |
| 160 base::MessageLoop message_loop_; | 160 base::MessageLoop message_loop_; |
| 161 scoped_ptr<base::RunLoop> run_loop_; | 161 std::unique_ptr<base::RunLoop> run_loop_; |
| 162 scoped_ptr<base::Thread> dbus_thread_; | 162 std::unique_ptr<base::Thread> dbus_thread_; |
| 163 scoped_refptr<Bus> bus_; | 163 scoped_refptr<Bus> bus_; |
| 164 ObjectProxy* object_proxy_; | 164 ObjectProxy* object_proxy_; |
| 165 scoped_ptr<Properties> properties_; | 165 std::unique_ptr<Properties> properties_; |
| 166 scoped_ptr<TestService> test_service_; | 166 std::unique_ptr<TestService> test_service_; |
| 167 // Properties updated. | 167 // Properties updated. |
| 168 std::vector<std::string> updated_properties_; | 168 std::vector<std::string> updated_properties_; |
| 169 // Last callback received. | 169 // Last callback received. |
| 170 std::string last_callback_; | 170 std::string last_callback_; |
| 171 }; | 171 }; |
| 172 | 172 |
| 173 TEST_F(PropertyTest, InitialValues) { | 173 TEST_F(PropertyTest, InitialValues) { |
| 174 EXPECT_FALSE(properties_->name.is_valid()); | 174 EXPECT_FALSE(properties_->name.is_valid()); |
| 175 EXPECT_FALSE(properties_->version.is_valid()); | 175 EXPECT_FALSE(properties_->version.is_valid()); |
| 176 | 176 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 base::Unretained(this), "Set")); | 321 base::Unretained(this), "Set")); |
| 322 WaitForCallback("Set"); | 322 WaitForCallback("Set"); |
| 323 | 323 |
| 324 // TestService sends a property update. | 324 // TestService sends a property update. |
| 325 WaitForUpdates(1); | 325 WaitForUpdates(1); |
| 326 | 326 |
| 327 EXPECT_TRUE(properties_->name.is_valid()); | 327 EXPECT_TRUE(properties_->name.is_valid()); |
| 328 } | 328 } |
| 329 | 329 |
| 330 TEST(PropertyTestStatic, ReadWriteStringMap) { | 330 TEST(PropertyTestStatic, ReadWriteStringMap) { |
| 331 scoped_ptr<Response> message(Response::CreateEmpty()); | 331 std::unique_ptr<Response> message(Response::CreateEmpty()); |
| 332 MessageWriter writer(message.get()); | 332 MessageWriter writer(message.get()); |
| 333 MessageWriter variant_writer(NULL); | 333 MessageWriter variant_writer(NULL); |
| 334 MessageWriter variant_array_writer(NULL); | 334 MessageWriter variant_array_writer(NULL); |
| 335 MessageWriter struct_entry_writer(NULL); | 335 MessageWriter struct_entry_writer(NULL); |
| 336 | 336 |
| 337 writer.OpenVariant("a{ss}", &variant_writer); | 337 writer.OpenVariant("a{ss}", &variant_writer); |
| 338 variant_writer.OpenArray("{ss}", &variant_array_writer); | 338 variant_writer.OpenArray("{ss}", &variant_array_writer); |
| 339 const char* items[] = {"One", "Two", "Three", "Four"}; | 339 const char* items[] = {"One", "Two", "Three", "Four"}; |
| 340 for (unsigned i = 0; i < arraysize(items); ++i) { | 340 for (unsigned i = 0; i < arraysize(items); ++i) { |
| 341 variant_array_writer.OpenDictEntry(&struct_entry_writer); | 341 variant_array_writer.OpenDictEntry(&struct_entry_writer); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 355 EXPECT_EQ("3", string_map.value().at("Three")); | 355 EXPECT_EQ("3", string_map.value().at("Three")); |
| 356 EXPECT_EQ("4", string_map.value().at("Four")); | 356 EXPECT_EQ("4", string_map.value().at("Four")); |
| 357 } | 357 } |
| 358 | 358 |
| 359 TEST(PropertyTestStatic, SerializeStringMap) { | 359 TEST(PropertyTestStatic, SerializeStringMap) { |
| 360 std::map<std::string, std::string> test_map; | 360 std::map<std::string, std::string> test_map; |
| 361 test_map["Hi"] = "There"; | 361 test_map["Hi"] = "There"; |
| 362 test_map["Map"] = "Test"; | 362 test_map["Map"] = "Test"; |
| 363 test_map["Random"] = "Text"; | 363 test_map["Random"] = "Text"; |
| 364 | 364 |
| 365 scoped_ptr<Response> message(Response::CreateEmpty()); | 365 std::unique_ptr<Response> message(Response::CreateEmpty()); |
| 366 MessageWriter writer(message.get()); | 366 MessageWriter writer(message.get()); |
| 367 | 367 |
| 368 Property<std::map<std::string, std::string>> string_map; | 368 Property<std::map<std::string, std::string>> string_map; |
| 369 string_map.ReplaceSetValueForTesting(test_map); | 369 string_map.ReplaceSetValueForTesting(test_map); |
| 370 string_map.AppendSetValueToWriter(&writer); | 370 string_map.AppendSetValueToWriter(&writer); |
| 371 | 371 |
| 372 MessageReader reader(message.get()); | 372 MessageReader reader(message.get()); |
| 373 EXPECT_TRUE(string_map.PopValueFromReader(&reader)); | 373 EXPECT_TRUE(string_map.PopValueFromReader(&reader)); |
| 374 EXPECT_EQ(test_map, string_map.value()); | 374 EXPECT_EQ(test_map, string_map.value()); |
| 375 } | 375 } |
| 376 | 376 |
| 377 TEST(PropertyTestStatic, ReadWriteNetAddressArray) { | 377 TEST(PropertyTestStatic, ReadWriteNetAddressArray) { |
| 378 scoped_ptr<Response> message(Response::CreateEmpty()); | 378 std::unique_ptr<Response> message(Response::CreateEmpty()); |
| 379 MessageWriter writer(message.get()); | 379 MessageWriter writer(message.get()); |
| 380 MessageWriter variant_writer(NULL); | 380 MessageWriter variant_writer(NULL); |
| 381 MessageWriter variant_array_writer(NULL); | 381 MessageWriter variant_array_writer(NULL); |
| 382 MessageWriter struct_entry_writer(NULL); | 382 MessageWriter struct_entry_writer(NULL); |
| 383 | 383 |
| 384 writer.OpenVariant("a(ayq)", &variant_writer); | 384 writer.OpenVariant("a(ayq)", &variant_writer); |
| 385 variant_writer.OpenArray("(ayq)", &variant_array_writer); | 385 variant_writer.OpenArray("(ayq)", &variant_array_writer); |
| 386 uint8_t ip_bytes[] = {0x54, 0x65, 0x73, 0x74, 0x30}; | 386 uint8_t ip_bytes[] = {0x54, 0x65, 0x73, 0x74, 0x30}; |
| 387 for (uint16_t i = 0; i < 5; ++i) { | 387 for (uint16_t i = 0; i < 5; ++i) { |
| 388 variant_array_writer.OpenStruct(&struct_entry_writer); | 388 variant_array_writer.OpenStruct(&struct_entry_writer); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 412 TEST(PropertyTestStatic, SerializeNetAddressArray) { | 412 TEST(PropertyTestStatic, SerializeNetAddressArray) { |
| 413 std::vector<std::pair<std::vector<uint8_t>, uint16_t>> test_list; | 413 std::vector<std::pair<std::vector<uint8_t>, uint16_t>> test_list; |
| 414 | 414 |
| 415 uint8_t ip_bytes[] = {0x54, 0x65, 0x73, 0x74, 0x30}; | 415 uint8_t ip_bytes[] = {0x54, 0x65, 0x73, 0x74, 0x30}; |
| 416 for (uint16_t i = 0; i < 5; ++i) { | 416 for (uint16_t i = 0; i < 5; ++i) { |
| 417 ip_bytes[4] = 0x30 + i; | 417 ip_bytes[4] = 0x30 + i; |
| 418 std::vector<uint8_t> bytes(ip_bytes, ip_bytes + arraysize(ip_bytes)); | 418 std::vector<uint8_t> bytes(ip_bytes, ip_bytes + arraysize(ip_bytes)); |
| 419 test_list.push_back(make_pair(bytes, 16)); | 419 test_list.push_back(make_pair(bytes, 16)); |
| 420 } | 420 } |
| 421 | 421 |
| 422 scoped_ptr<Response> message(Response::CreateEmpty()); | 422 std::unique_ptr<Response> message(Response::CreateEmpty()); |
| 423 MessageWriter writer(message.get()); | 423 MessageWriter writer(message.get()); |
| 424 | 424 |
| 425 Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>> ip_list; | 425 Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>> ip_list; |
| 426 ip_list.ReplaceSetValueForTesting(test_list); | 426 ip_list.ReplaceSetValueForTesting(test_list); |
| 427 ip_list.AppendSetValueToWriter(&writer); | 427 ip_list.AppendSetValueToWriter(&writer); |
| 428 | 428 |
| 429 MessageReader reader(message.get()); | 429 MessageReader reader(message.get()); |
| 430 EXPECT_TRUE(ip_list.PopValueFromReader(&reader)); | 430 EXPECT_TRUE(ip_list.PopValueFromReader(&reader)); |
| 431 EXPECT_EQ(test_list, ip_list.value()); | 431 EXPECT_EQ(test_list, ip_list.value()); |
| 432 } | 432 } |
| 433 | 433 |
| 434 } // namespace dbus | 434 } // namespace dbus |
| OLD | NEW |