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

Side by Side Diff: tools/json_schema_compiler/test/idl_schemas_unittest.cc

Issue 1982193002: Add enum class support to json_schema_compiler (idl files) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: I accidentally a patchset dependency Created 4 years, 7 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 | « tools/json_schema_compiler/test/idl_basics.idl ('k') | no next file » | 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 "base/values.h" 5 #include "base/values.h"
6 #include "tools/json_schema_compiler/test/idl_basics.h" 6 #include "tools/json_schema_compiler/test/idl_basics.h"
7 #include "tools/json_schema_compiler/test/idl_object_types.h" 7 #include "tools/json_schema_compiler/test/idl_object_types.h"
8 8
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 &icon)); 198 &icon));
199 base::ListValue list; 199 base::ListValue list;
200 list.Append(icon_props.release()); 200 list.Append(icon_props.release());
201 std::unique_ptr<ObjectFunction1::Params> params = 201 std::unique_ptr<ObjectFunction1::Params> params =
202 ObjectFunction1::Params::Create(list); 202 ObjectFunction1::Params::Create(list);
203 ASSERT_TRUE(params.get() != NULL); 203 ASSERT_TRUE(params.get() != NULL);
204 std::string tmp; 204 std::string tmp;
205 EXPECT_TRUE(params->icon.additional_properties.GetString("hello", &tmp)); 205 EXPECT_TRUE(params->icon.additional_properties.GetString("hello", &tmp));
206 EXPECT_EQ("world", tmp); 206 EXPECT_EQ("world", tmp);
207 } 207 }
208
209 TEST(IdlCompiler, Enums) {
210 using test::api::idl_basics::MyType3;
211 using test::api::idl_basics::EnumClass;
212 using test::api::idl_basics::EnumClassWithPrefix;
213
214 MyType3 a;
215 EXPECT_EQ(a.w, test::api::idl_basics::ENUM_TYPE_NONE);
216
217 // The type name is always used as the prefix for NONE/LAST to avoid symbol
218 // conflicts with types that share a prefix.
219 EXPECT_EQ(a.x, test::api::idl_basics::ENUM_WITH_PREFIX_NONE);
220 EXPECT_EQ(a.y, EnumClass::NONE);
221
222 // Symbol conflicts aren't possible with enum classes, so we just use NONE.
223 EXPECT_EQ(a.z, EnumClassWithPrefix::NONE);
224
225 a.w = test::api::idl_basics::ENUM_TYPE_NAME2;
226 a.x = test::api::idl_basics::PREFIX_NAME2;
227 a.y = EnumClass::NAME2;
228 a.z = EnumClassWithPrefix::PREFIX_NAME2;
229
230 std::unique_ptr<base::DictionaryValue> serialized = a.ToValue();
231 MyType3 b;
232 EXPECT_TRUE(MyType3::Populate(*serialized.get(), &b));
233 EXPECT_EQ(a.w, b.w);
234 EXPECT_EQ(a.x, b.x);
235 EXPECT_EQ(a.y, b.y);
236 EXPECT_EQ(a.z, b.z);
237
238 base::Value* v;
239 std::string w, x, y, z;
240 EXPECT_TRUE(serialized->Get("w", &v));
241 EXPECT_TRUE(v->GetAsString(&w));
242 EXPECT_TRUE(serialized->Get("x", &v));
243 EXPECT_TRUE(v->GetAsString(&x));
244 EXPECT_TRUE(serialized->Get("y", &v));
245 EXPECT_TRUE(v->GetAsString(&y));
246 EXPECT_TRUE(serialized->Get("z", &v));
247 EXPECT_TRUE(v->GetAsString(&z));
248
249 // Only the C++ syntax should be affected, so the string representations
250 // should all match.
251 EXPECT_EQ(w, x);
252 EXPECT_EQ(x, y);
253 EXPECT_EQ(y, z);
254 }
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/test/idl_basics.idl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698