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> |
11 #include <memory> | 11 #include <memory> |
12 #include <utility> | 12 #include <utility> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/json/json_writer.h" | 15 #include "base/json/json_writer.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ptr_util.h" |
17 #include "base/values.h" | 18 #include "base/values.h" |
18 #include "dbus/message.h" | 19 #include "dbus/message.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 | 21 |
21 namespace dbus { | 22 namespace dbus { |
22 | 23 |
23 TEST(ValuesUtilTest, PopBasicTypes) { | 24 TEST(ValuesUtilTest, PopBasicTypes) { |
24 std::unique_ptr<Response> response(Response::CreateEmpty()); | 25 std::unique_ptr<Response> response(Response::CreateEmpty()); |
25 // Append basic type values. | 26 // Append basic type values. |
26 MessageWriter writer(response.get()); | 27 MessageWriter writer(response.get()); |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 const std::string kKey3 = "three"; | 510 const std::string kKey3 = "three"; |
510 const std::string kKey4 = "four"; | 511 const std::string kKey4 = "four"; |
511 const std::string kKey5 = "five"; | 512 const std::string kKey5 = "five"; |
512 const std::string kKey6 = "six"; | 513 const std::string kKey6 = "six"; |
513 | 514 |
514 const bool kBoolValue = true; | 515 const bool kBoolValue = true; |
515 const int32_t kInt32Value = -45; | 516 const int32_t kInt32Value = -45; |
516 const double kDoubleValue = 4.9; | 517 const double kDoubleValue = 4.9; |
517 const std::string kStringValue = "fifty"; | 518 const std::string kStringValue = "fifty"; |
518 | 519 |
519 base::ListValue* list_value = new base::ListValue(); | 520 auto list_value = base::MakeUnique<base::ListValue>(); |
520 list_value->AppendBoolean(kBoolValue); | 521 list_value->AppendBoolean(kBoolValue); |
521 list_value->AppendInteger(kInt32Value); | 522 list_value->AppendInteger(kInt32Value); |
522 | 523 |
523 base::DictionaryValue* dictionary_value = new base::DictionaryValue(); | 524 auto dictionary_value = base::MakeUnique<base::DictionaryValue>(); |
524 dictionary_value->SetBoolean(kKey1, kBoolValue); | 525 dictionary_value->SetBoolean(kKey1, kBoolValue); |
525 dictionary_value->SetInteger(kKey2, kDoubleValue); | 526 dictionary_value->SetInteger(kKey2, kDoubleValue); |
526 | 527 |
527 base::DictionaryValue test_dictionary; | 528 base::DictionaryValue test_dictionary; |
528 test_dictionary.SetBoolean(kKey1, kBoolValue); | 529 test_dictionary.SetBoolean(kKey1, kBoolValue); |
529 test_dictionary.SetInteger(kKey2, kInt32Value); | 530 test_dictionary.SetInteger(kKey2, kInt32Value); |
530 test_dictionary.SetDouble(kKey3, kDoubleValue); | 531 test_dictionary.SetDouble(kKey3, kDoubleValue); |
531 test_dictionary.SetString(kKey4, kStringValue); | 532 test_dictionary.SetString(kKey4, kStringValue); |
532 test_dictionary.Set(kKey5, list_value); // takes ownership | 533 test_dictionary.Set(kKey5, std::move(list_value)); |
533 test_dictionary.Set(kKey6, dictionary_value); // takes ownership | 534 test_dictionary.Set(kKey6, std::move(dictionary_value)); |
534 | 535 |
535 std::unique_ptr<Response> response(Response::CreateEmpty()); | 536 std::unique_ptr<Response> response(Response::CreateEmpty()); |
536 MessageWriter writer(response.get()); | 537 MessageWriter writer(response.get()); |
537 AppendValueData(&writer, test_dictionary); | 538 AppendValueData(&writer, test_dictionary); |
538 base::Value int_value(kInt32Value); | 539 base::Value int_value(kInt32Value); |
539 AppendValueData(&writer, int_value); | 540 AppendValueData(&writer, int_value); |
540 | 541 |
541 // Read the data. | 542 // Read the data. |
542 MessageReader reader(response.get()); | 543 MessageReader reader(response.get()); |
543 std::unique_ptr<base::Value> value; | 544 std::unique_ptr<base::Value> value; |
(...skipping 12 matching lines...) Expand all Loading... |
556 const std::string kKey3 = "three"; | 557 const std::string kKey3 = "three"; |
557 const std::string kKey4 = "four"; | 558 const std::string kKey4 = "four"; |
558 const std::string kKey5 = "five"; | 559 const std::string kKey5 = "five"; |
559 const std::string kKey6 = "six"; | 560 const std::string kKey6 = "six"; |
560 | 561 |
561 const bool kBoolValue = true; | 562 const bool kBoolValue = true; |
562 const int32_t kInt32Value = -45; | 563 const int32_t kInt32Value = -45; |
563 const double kDoubleValue = 4.9; | 564 const double kDoubleValue = 4.9; |
564 const std::string kStringValue = "fifty"; | 565 const std::string kStringValue = "fifty"; |
565 | 566 |
566 base::ListValue* list_value = new base::ListValue(); | 567 auto list_value = base::MakeUnique<base::ListValue>(); |
567 list_value->AppendBoolean(kBoolValue); | 568 list_value->AppendBoolean(kBoolValue); |
568 list_value->AppendInteger(kInt32Value); | 569 list_value->AppendInteger(kInt32Value); |
569 | 570 |
570 base::DictionaryValue* dictionary_value = new base::DictionaryValue(); | 571 auto dictionary_value = base::MakeUnique<base::DictionaryValue>(); |
571 dictionary_value->SetBoolean(kKey1, kBoolValue); | 572 dictionary_value->SetBoolean(kKey1, kBoolValue); |
572 dictionary_value->SetInteger(kKey2, kDoubleValue); | 573 dictionary_value->SetInteger(kKey2, kDoubleValue); |
573 | 574 |
574 base::DictionaryValue test_dictionary; | 575 base::DictionaryValue test_dictionary; |
575 test_dictionary.SetBoolean(kKey1, kBoolValue); | 576 test_dictionary.SetBoolean(kKey1, kBoolValue); |
576 test_dictionary.SetInteger(kKey2, kInt32Value); | 577 test_dictionary.SetInteger(kKey2, kInt32Value); |
577 test_dictionary.SetDouble(kKey3, kDoubleValue); | 578 test_dictionary.SetDouble(kKey3, kDoubleValue); |
578 test_dictionary.SetString(kKey4, kStringValue); | 579 test_dictionary.SetString(kKey4, kStringValue); |
579 test_dictionary.Set(kKey5, list_value); // takes ownership | 580 test_dictionary.Set(kKey5, std::move(list_value)); |
580 test_dictionary.Set(kKey6, dictionary_value); // takes ownership | 581 test_dictionary.Set(kKey6, std::move(dictionary_value)); |
581 | 582 |
582 std::unique_ptr<Response> response(Response::CreateEmpty()); | 583 std::unique_ptr<Response> response(Response::CreateEmpty()); |
583 MessageWriter writer(response.get()); | 584 MessageWriter writer(response.get()); |
584 AppendValueDataAsVariant(&writer, test_dictionary); | 585 AppendValueDataAsVariant(&writer, test_dictionary); |
585 base::Value int_value(kInt32Value); | 586 base::Value int_value(kInt32Value); |
586 AppendValueData(&writer, int_value); | 587 AppendValueData(&writer, int_value); |
587 | 588 |
588 // Read the data. | 589 // Read the data. |
589 MessageReader reader(response.get()); | 590 MessageReader reader(response.get()); |
590 std::unique_ptr<base::Value> value; | 591 std::unique_ptr<base::Value> value; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 std::unique_ptr<base::Value> value; | 679 std::unique_ptr<base::Value> value; |
679 value = PopDataAsValue(&reader); | 680 value = PopDataAsValue(&reader); |
680 ASSERT_TRUE(value.get() != NULL); | 681 ASSERT_TRUE(value.get() != NULL); |
681 EXPECT_TRUE(value->Equals(&test_list)); | 682 EXPECT_TRUE(value->Equals(&test_list)); |
682 value = PopDataAsValue(&reader); | 683 value = PopDataAsValue(&reader); |
683 ASSERT_TRUE(value.get() != NULL); | 684 ASSERT_TRUE(value.get() != NULL); |
684 EXPECT_TRUE(value->Equals(&int_value)); | 685 EXPECT_TRUE(value->Equals(&int_value)); |
685 } | 686 } |
686 | 687 |
687 } // namespace dbus | 688 } // namespace dbus |
OLD | NEW |