Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: dbus/values_util_unittest.cc

Issue 2058233002: Rewrite simple uses of base::ListValue::Append() taking a raw pointer var. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/common/font_list_pango.cc ('k') | extensions/browser/api/serial/serial_apitest.cc » ('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) 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 <vector> 13 #include <vector>
13 14
14 #include "base/json/json_writer.h" 15 #include "base/json/json_writer.h"
15 #include "base/macros.h" 16 #include "base/macros.h"
16 #include "base/values.h" 17 #include "base/values.h"
17 #include "dbus/message.h" 18 #include "dbus/message.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 20
20 namespace dbus { 21 namespace dbus {
21 22
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 TEST(ValuesUtilTest, AppendList) { 607 TEST(ValuesUtilTest, AppendList) {
607 // Set up the input list. 608 // Set up the input list.
608 const std::string kKey1 = "one"; 609 const std::string kKey1 = "one";
609 const std::string kKey2 = "two"; 610 const std::string kKey2 = "two";
610 611
611 const bool kBoolValue = true; 612 const bool kBoolValue = true;
612 const int32_t kInt32Value = -45; 613 const int32_t kInt32Value = -45;
613 const double kDoubleValue = 4.9; 614 const double kDoubleValue = 4.9;
614 const std::string kStringValue = "fifty"; 615 const std::string kStringValue = "fifty";
615 616
616 base::ListValue* list_value = new base::ListValue(); 617 std::unique_ptr<base::ListValue> list_value(new base::ListValue());
617 list_value->AppendBoolean(kBoolValue); 618 list_value->AppendBoolean(kBoolValue);
618 list_value->AppendInteger(kInt32Value); 619 list_value->AppendInteger(kInt32Value);
619 620
620 base::DictionaryValue* dictionary_value = new base::DictionaryValue(); 621 std::unique_ptr<base::DictionaryValue> dictionary_value(
622 new base::DictionaryValue());
621 dictionary_value->SetBoolean(kKey1, kBoolValue); 623 dictionary_value->SetBoolean(kKey1, kBoolValue);
622 dictionary_value->SetInteger(kKey2, kDoubleValue); 624 dictionary_value->SetInteger(kKey2, kDoubleValue);
623 625
624 base::ListValue test_list; 626 base::ListValue test_list;
625 test_list.AppendBoolean(kBoolValue); 627 test_list.AppendBoolean(kBoolValue);
626 test_list.AppendInteger(kInt32Value); 628 test_list.AppendInteger(kInt32Value);
627 test_list.AppendDouble(kDoubleValue); 629 test_list.AppendDouble(kDoubleValue);
628 test_list.AppendString(kStringValue); 630 test_list.AppendString(kStringValue);
629 test_list.Append(list_value); // takes ownership 631 test_list.Append(std::move(list_value)); // takes ownership
Lei Zhang 2016/06/10 21:20:53 no need for ownership comments
dcheng 2016/06/10 21:30:44 Done. Sadly, the tool's not smart enough to parse
630 test_list.Append(dictionary_value); // takes ownership 632 test_list.Append(std::move(dictionary_value)); // takes ownership
631 633
632 std::unique_ptr<Response> response(Response::CreateEmpty()); 634 std::unique_ptr<Response> response(Response::CreateEmpty());
633 MessageWriter writer(response.get()); 635 MessageWriter writer(response.get());
634 AppendValueData(&writer, test_list); 636 AppendValueData(&writer, test_list);
635 base::FundamentalValue int_value(kInt32Value); 637 base::FundamentalValue int_value(kInt32Value);
636 AppendValueData(&writer, int_value); 638 AppendValueData(&writer, int_value);
637 639
638 // Read the data. 640 // Read the data.
639 MessageReader reader(response.get()); 641 MessageReader reader(response.get());
640 std::unique_ptr<base::Value> value; 642 std::unique_ptr<base::Value> value;
641 value = PopDataAsValue(&reader); 643 value = PopDataAsValue(&reader);
642 ASSERT_TRUE(value.get() != NULL); 644 ASSERT_TRUE(value.get() != NULL);
643 EXPECT_TRUE(value->Equals(&test_list)); 645 EXPECT_TRUE(value->Equals(&test_list));
644 value = PopDataAsValue(&reader); 646 value = PopDataAsValue(&reader);
645 ASSERT_TRUE(value.get() != NULL); 647 ASSERT_TRUE(value.get() != NULL);
646 EXPECT_TRUE(value->Equals(&int_value)); 648 EXPECT_TRUE(value->Equals(&int_value));
647 } 649 }
648 650
649 TEST(ValuesUtilTest, AppendListAsVariant) { 651 TEST(ValuesUtilTest, AppendListAsVariant) {
650 // Set up the input list. 652 // Set up the input list.
651 const std::string kKey1 = "one"; 653 const std::string kKey1 = "one";
652 const std::string kKey2 = "two"; 654 const std::string kKey2 = "two";
653 655
654 const bool kBoolValue = true; 656 const bool kBoolValue = true;
655 const int32_t kInt32Value = -45; 657 const int32_t kInt32Value = -45;
656 const double kDoubleValue = 4.9; 658 const double kDoubleValue = 4.9;
657 const std::string kStringValue = "fifty"; 659 const std::string kStringValue = "fifty";
658 660
659 base::ListValue* list_value = new base::ListValue(); 661 std::unique_ptr<base::ListValue> list_value(new base::ListValue());
660 list_value->AppendBoolean(kBoolValue); 662 list_value->AppendBoolean(kBoolValue);
661 list_value->AppendInteger(kInt32Value); 663 list_value->AppendInteger(kInt32Value);
662 664
663 base::DictionaryValue* dictionary_value = new base::DictionaryValue(); 665 std::unique_ptr<base::DictionaryValue> dictionary_value(
666 new base::DictionaryValue());
664 dictionary_value->SetBoolean(kKey1, kBoolValue); 667 dictionary_value->SetBoolean(kKey1, kBoolValue);
665 dictionary_value->SetInteger(kKey2, kDoubleValue); 668 dictionary_value->SetInteger(kKey2, kDoubleValue);
666 669
667 base::ListValue test_list; 670 base::ListValue test_list;
668 test_list.AppendBoolean(kBoolValue); 671 test_list.AppendBoolean(kBoolValue);
669 test_list.AppendInteger(kInt32Value); 672 test_list.AppendInteger(kInt32Value);
670 test_list.AppendDouble(kDoubleValue); 673 test_list.AppendDouble(kDoubleValue);
671 test_list.AppendString(kStringValue); 674 test_list.AppendString(kStringValue);
672 test_list.Append(list_value); // takes ownership 675 test_list.Append(std::move(list_value)); // takes ownership
673 test_list.Append(dictionary_value); // takes ownership 676 test_list.Append(std::move(dictionary_value)); // takes ownership
674 677
675 std::unique_ptr<Response> response(Response::CreateEmpty()); 678 std::unique_ptr<Response> response(Response::CreateEmpty());
676 MessageWriter writer(response.get()); 679 MessageWriter writer(response.get());
677 AppendValueDataAsVariant(&writer, test_list); 680 AppendValueDataAsVariant(&writer, test_list);
678 base::FundamentalValue int_value(kInt32Value); 681 base::FundamentalValue int_value(kInt32Value);
679 AppendValueData(&writer, int_value); 682 AppendValueData(&writer, int_value);
680 683
681 // Read the data. 684 // Read the data.
682 MessageReader reader(response.get()); 685 MessageReader reader(response.get());
683 std::unique_ptr<base::Value> value; 686 std::unique_ptr<base::Value> value;
684 value = PopDataAsValue(&reader); 687 value = PopDataAsValue(&reader);
685 ASSERT_TRUE(value.get() != NULL); 688 ASSERT_TRUE(value.get() != NULL);
686 EXPECT_TRUE(value->Equals(&test_list)); 689 EXPECT_TRUE(value->Equals(&test_list));
687 value = PopDataAsValue(&reader); 690 value = PopDataAsValue(&reader);
688 ASSERT_TRUE(value.get() != NULL); 691 ASSERT_TRUE(value.get() != NULL);
689 EXPECT_TRUE(value->Equals(&int_value)); 692 EXPECT_TRUE(value->Equals(&int_value));
690 } 693 }
691 694
692 } // namespace dbus 695 } // namespace dbus
OLDNEW
« no previous file with comments | « content/common/font_list_pango.cc ('k') | extensions/browser/api/serial/serial_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698