15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "tools/json_schema_compiler/test/objects.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/json/json_writer.h"
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using namespace test::api::objects;
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST(JsonSchemaCompilerObjectsTest, ObjectParamParamsCreate) {
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  {
145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    scoped_ptr<base::ListValue> strings(new base::ListValue());
155f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    strings->Append(new base::StringValue("one"));
165f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    strings->Append(new base::StringValue("two"));
175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    scoped_ptr<base::DictionaryValue> info_value(new base::DictionaryValue());
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    info_value->Set("strings", strings.release());
19116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    info_value->Set("integer", new base::FundamentalValue(5));
20116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    info_value->Set("boolean", new base::FundamentalValue(true));
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    scoped_ptr<base::ListValue> params_value(new base::ListValue());
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    params_value->Append(info_value.release());
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    scoped_ptr<ObjectParam::Params> params(
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        ObjectParam::Params::Create(*params_value));
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_TRUE(params.get());
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_EQ((size_t) 2, params->info.strings.size());
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_EQ("one", params->info.strings[0]);
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_EQ("two", params->info.strings[1]);
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_EQ(5, params->info.integer);
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_TRUE(params->info.boolean);
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  {
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    scoped_ptr<base::ListValue> strings(new base::ListValue());
355f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    strings->Append(new base::StringValue("one"));
365f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    strings->Append(new base::StringValue("two"));
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    scoped_ptr<base::DictionaryValue> info_value(new base::DictionaryValue());
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    info_value->Set("strings", strings.release());
39116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    info_value->Set("integer", new base::FundamentalValue(5));
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    scoped_ptr<base::ListValue> params_value(new base::ListValue());
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    params_value->Append(info_value.release());
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    scoped_ptr<ObjectParam::Params> params(
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        ObjectParam::Params::Create(*params_value));
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_FALSE(params.get());
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST(JsonSchemaCompilerObjectsTest, ReturnsObjectResultCreate) {
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ReturnsObject::Results::Info info;
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  info.state = ReturnsObject::Results::Info::STATE_FOO;
525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  scoped_ptr<base::ListValue> results = ReturnsObject::Results::Create(info);
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::DictionaryValue expected;
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  expected.SetString("state", "foo");
565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::DictionaryValue* result = NULL;
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_TRUE(results->GetDictionary(0, &result));
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_TRUE(result->Equals(&expected));
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST(JsonSchemaCompilerObjectsTest, OnObjectFiredCreate) {
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  OnObjectFired::SomeObject object;
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  object.state = OnObjectFired::SomeObject::STATE_BAR;
645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  scoped_ptr<base::ListValue> results(OnObjectFired::Create(object));
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::DictionaryValue expected;
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  expected.SetString("state", "bar");
685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::DictionaryValue* result = NULL;
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_TRUE(results->GetDictionary(0, &result));
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_TRUE(result->Equals(&expected));
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
72