Chromium Code Reviews| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "tools/json_schema_compiler/test/objects.h" | 9 #include "tools/json_schema_compiler/test/objects.h" |
| 10 #include "tools/json_schema_compiler/test/objects_movable.h" | 10 #include "tools/json_schema_compiler/test/objects_movable.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 pod.foo = FOO_BAZ; | 89 pod.foo = FOO_BAZ; |
| 90 pod.str = "str2"; | 90 pod.str = "str2"; |
| 91 pod.num = 45; | 91 pod.num = 45; |
| 92 pod.b = false; | 92 pod.b = false; |
| 93 pods.push_back(std::move(pod)); | 93 pods.push_back(std::move(pod)); |
| 94 } | 94 } |
| 95 MovableParent parent; | 95 MovableParent parent; |
| 96 parent.pods = std::move(pods); | 96 parent.pods = std::move(pods); |
| 97 parent.strs.push_back("pstr"); | 97 parent.strs.push_back("pstr"); |
| 98 parent.blob.additional_properties.SetString("key", "val"); | 98 parent.blob.additional_properties.SetString("key", "val"); |
| 99 parent.choice.as_string.reset(new std::string("string")); | |
| 99 | 100 |
| 100 MovableParent parent2(std::move(parent)); | 101 MovableParent parent2(std::move(parent)); |
| 101 ASSERT_EQ(2u, parent2.pods.size()); | 102 ASSERT_EQ(2u, parent2.pods.size()); |
| 102 EXPECT_EQ(FOO_BAR, parent2.pods[0].foo); | 103 EXPECT_EQ(FOO_BAR, parent2.pods[0].foo); |
| 103 EXPECT_EQ("str1", parent2.pods[0].str); | 104 EXPECT_EQ("str1", parent2.pods[0].str); |
| 104 EXPECT_EQ(42, parent2.pods[0].num); | 105 EXPECT_EQ(42, parent2.pods[0].num); |
| 105 EXPECT_TRUE(parent2.pods[0].b); | 106 EXPECT_TRUE(parent2.pods[0].b); |
| 106 EXPECT_EQ(FOO_BAZ, parent2.pods[1].foo); | 107 EXPECT_EQ(FOO_BAZ, parent2.pods[1].foo); |
| 107 EXPECT_EQ("str2", parent2.pods[1].str); | 108 EXPECT_EQ("str2", parent2.pods[1].str); |
| 108 EXPECT_EQ(45, parent2.pods[1].num); | 109 EXPECT_EQ(45, parent2.pods[1].num); |
| 109 EXPECT_FALSE(parent2.pods[1].b); | 110 EXPECT_FALSE(parent2.pods[1].b); |
| 110 ASSERT_EQ(1u, parent2.strs.size()); | 111 ASSERT_EQ(1u, parent2.strs.size()); |
| 111 EXPECT_EQ("pstr", parent2.strs[0]); | 112 EXPECT_EQ("pstr", parent2.strs[0]); |
| 113 ASSERT_TRUE(parent2.choice.as_string.get()); | |
| 114 EXPECT_EQ("string", *parent2.choice.as_string); | |
|
asargent_no_longer_on_chrome
2016/03/31 21:56:34
maybe also add a test of as_movable_pod?
Devlin
2016/04/01 00:09:01
Done.
| |
| 112 std::string blob_string; | 115 std::string blob_string; |
| 113 EXPECT_TRUE( | 116 EXPECT_TRUE( |
| 114 parent2.blob.additional_properties.GetString("key", &blob_string)); | 117 parent2.blob.additional_properties.GetString("key", &blob_string)); |
| 115 EXPECT_EQ("val", blob_string); | 118 EXPECT_EQ("val", blob_string); |
| 116 | 119 |
| 117 MovableWithAdditional with_additional; | 120 MovableWithAdditional with_additional; |
| 118 with_additional.str = "str"; | 121 with_additional.str = "str"; |
| 119 std::vector<std::string> vals1; | 122 std::vector<std::string> vals1; |
| 120 vals1.push_back("vals1a"); | 123 vals1.push_back("vals1a"); |
| 121 vals1.push_back("vals1b"); | 124 vals1.push_back("vals1b"); |
| 122 with_additional.additional_properties["key1"] = vals1; | 125 with_additional.additional_properties["key1"] = vals1; |
| 123 std::vector<std::string> vals2; | 126 std::vector<std::string> vals2; |
| 124 vals2.push_back("vals2a"); | 127 vals2.push_back("vals2a"); |
| 125 vals2.push_back("vals2b"); | 128 vals2.push_back("vals2b"); |
| 126 with_additional.additional_properties["key2"] = vals2; | 129 with_additional.additional_properties["key2"] = vals2; |
| 127 | 130 |
| 128 MovableWithAdditional with_additional2(std::move(with_additional)); | 131 MovableWithAdditional with_additional2(std::move(with_additional)); |
| 129 EXPECT_EQ("str", with_additional2.str); | 132 EXPECT_EQ("str", with_additional2.str); |
| 130 EXPECT_EQ(2u, with_additional2.additional_properties.size()); | 133 EXPECT_EQ(2u, with_additional2.additional_properties.size()); |
| 131 EXPECT_EQ(vals1, with_additional2.additional_properties["key1"]); | 134 EXPECT_EQ(vals1, with_additional2.additional_properties["key1"]); |
| 132 EXPECT_EQ(vals2, with_additional2.additional_properties["key2"]); | 135 EXPECT_EQ(vals2, with_additional2.additional_properties["key2"]); |
| 133 } | 136 } |
| OLD | NEW |