diff options
author | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-17 13:21:07 +0000 |
---|---|---|
committer | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-17 13:21:07 +0000 |
commit | a0abcf44533e242c524ed2955838880d00feadc9 (patch) | |
tree | a2e15f339acf72930b63122040e6fdaace0f1e70 /o3d/import | |
parent | 1f01d47474d6b06a2d1351416eeed320f892dde2 (diff) | |
download | chromium_src-a0abcf44533e242c524ed2955838880d00feadc9.zip chromium_src-a0abcf44533e242c524ed2955838880d00feadc9.tar.gz chromium_src-a0abcf44533e242c524ed2955838880d00feadc9.tar.bz2 |
Add missing gclient dependencies to .gitignore.
Fix the format of many directories so they don't show up in git status anymore.
Run dos2unix on *.cc, caught many inconsistent and CRLF files.
TBR=evan
TEST=still build, git status shows nothing
BUG=none
Review URL: http://codereview.chromium.org/211010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26441 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/import')
-rw-r--r-- | o3d/import/cross/camera_info.cc | 196 | ||||
-rw-r--r-- | o3d/import/cross/camera_info_test.cc | 444 | ||||
-rw-r--r-- | o3d/import/cross/destination_buffer.cc | 158 | ||||
-rw-r--r-- | o3d/import/cross/destination_buffer_test.cc | 208 | ||||
-rw-r--r-- | o3d/import/cross/json_object.cc | 132 | ||||
-rw-r--r-- | o3d/import/cross/json_object_test.cc | 896 |
6 files changed, 1017 insertions, 1017 deletions
diff --git a/o3d/import/cross/camera_info.cc b/o3d/import/cross/camera_info.cc index 905c337..3f46e4c 100644 --- a/o3d/import/cross/camera_info.cc +++ b/o3d/import/cross/camera_info.cc @@ -1,98 +1,98 @@ -/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "import/cross/camera_info.h"
-
-namespace o3d {
-
-O3D_OBJECT_BASE_DEFN_CLASS(
- "o3djs.CameraInfo", CameraInfo, JSONObject);
-O3D_OBJECT_BASE_DEFN_CLASS(
- "o3djs.PerspectiveCameraInfo", PerspectiveCameraInfo, CameraInfo);
-O3D_OBJECT_BASE_DEFN_CLASS(
- "o3djs.OrthographicCameraInfo", OrthographicCameraInfo, CameraInfo);
-
-const char* CameraInfo::kAspectRatioParamName = "aspectRatio";
-const char* CameraInfo::kNearZParamName = "nearZ";
-const char* CameraInfo::kFarZParamName = "farZ";
-const char* CameraInfo::kTransformValueName = "transform";
-const char* CameraInfo::kEyeValueName = "eye";
-const char* CameraInfo::kTargetValueName = "target";
-const char* CameraInfo::kUpValueName = "up";
-
-CameraInfo::CameraInfo(ServiceLocator* service_locator)
- : JSONObject(service_locator) {
- RegisterParamRef(kAspectRatioParamName, &aspect_ratio_param_);
- RegisterParamRef(kNearZParamName, &near_z_param_);
- RegisterParamRef(kFarZParamName, &far_z_param_);
- RegisterJSONValue(kTransformValueName, &transform_value_);
- RegisterJSONValue(kEyeValueName, &eye_value_);
- RegisterJSONValue(kTargetValueName, &target_value_);
- RegisterJSONValue(kUpValueName, &up_value_);
-
- set_aspect_ratio(1.0f);
- set_near_z(0.01f);
- set_far_z(10000.0f);
-}
-
-const char* OrthographicCameraInfo::kMagXParamName = "magX";
-const char* OrthographicCameraInfo::kMagYParamName = "magY";
-
-OrthographicCameraInfo::OrthographicCameraInfo(ServiceLocator* service_locator)
- : CameraInfo(service_locator) {
- RegisterParamRef(kMagXParamName, &mag_x_param_);
- RegisterParamRef(kMagYParamName, &mag_y_param_);
-
- set_mag_x(1.0f);
- set_mag_y(1.0f);
-}
-
-ObjectBase::Ref OrthographicCameraInfo::Create(
- ServiceLocator* service_locator) {
- return ObjectBase::Ref(new OrthographicCameraInfo(service_locator));
-}
-
-const char* PerspectiveCameraInfo::kFieldOfViewYParamName = "fieldOfViewY";
-
-PerspectiveCameraInfo::PerspectiveCameraInfo(ServiceLocator* service_locator)
- : CameraInfo(service_locator) {
- RegisterParamRef(kFieldOfViewYParamName, &field_of_view_y_param_);
-
- set_field_of_view_y(30.0f * 3.14159f / 180.0f);
-}
-
-ObjectBase::Ref PerspectiveCameraInfo::Create(ServiceLocator* service_locator) {
- return ObjectBase::Ref(new PerspectiveCameraInfo(service_locator));
-}
-
-} // namespace o3d
-
-
+/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "import/cross/camera_info.h" + +namespace o3d { + +O3D_OBJECT_BASE_DEFN_CLASS( + "o3djs.CameraInfo", CameraInfo, JSONObject); +O3D_OBJECT_BASE_DEFN_CLASS( + "o3djs.PerspectiveCameraInfo", PerspectiveCameraInfo, CameraInfo); +O3D_OBJECT_BASE_DEFN_CLASS( + "o3djs.OrthographicCameraInfo", OrthographicCameraInfo, CameraInfo); + +const char* CameraInfo::kAspectRatioParamName = "aspectRatio"; +const char* CameraInfo::kNearZParamName = "nearZ"; +const char* CameraInfo::kFarZParamName = "farZ"; +const char* CameraInfo::kTransformValueName = "transform"; +const char* CameraInfo::kEyeValueName = "eye"; +const char* CameraInfo::kTargetValueName = "target"; +const char* CameraInfo::kUpValueName = "up"; + +CameraInfo::CameraInfo(ServiceLocator* service_locator) + : JSONObject(service_locator) { + RegisterParamRef(kAspectRatioParamName, &aspect_ratio_param_); + RegisterParamRef(kNearZParamName, &near_z_param_); + RegisterParamRef(kFarZParamName, &far_z_param_); + RegisterJSONValue(kTransformValueName, &transform_value_); + RegisterJSONValue(kEyeValueName, &eye_value_); + RegisterJSONValue(kTargetValueName, &target_value_); + RegisterJSONValue(kUpValueName, &up_value_); + + set_aspect_ratio(1.0f); + set_near_z(0.01f); + set_far_z(10000.0f); +} + +const char* OrthographicCameraInfo::kMagXParamName = "magX"; +const char* OrthographicCameraInfo::kMagYParamName = "magY"; + +OrthographicCameraInfo::OrthographicCameraInfo(ServiceLocator* service_locator) + : CameraInfo(service_locator) { + RegisterParamRef(kMagXParamName, &mag_x_param_); + RegisterParamRef(kMagYParamName, &mag_y_param_); + + set_mag_x(1.0f); + set_mag_y(1.0f); +} + +ObjectBase::Ref OrthographicCameraInfo::Create( + ServiceLocator* service_locator) { + return ObjectBase::Ref(new OrthographicCameraInfo(service_locator)); +} + +const char* PerspectiveCameraInfo::kFieldOfViewYParamName = "fieldOfViewY"; + +PerspectiveCameraInfo::PerspectiveCameraInfo(ServiceLocator* service_locator) + : CameraInfo(service_locator) { + RegisterParamRef(kFieldOfViewYParamName, &field_of_view_y_param_); + + set_field_of_view_y(30.0f * 3.14159f / 180.0f); +} + +ObjectBase::Ref PerspectiveCameraInfo::Create(ServiceLocator* service_locator) { + return ObjectBase::Ref(new PerspectiveCameraInfo(service_locator)); +} + +} // namespace o3d + + diff --git a/o3d/import/cross/camera_info_test.cc b/o3d/import/cross/camera_info_test.cc index ce1b105..662b161 100644 --- a/o3d/import/cross/camera_info_test.cc +++ b/o3d/import/cross/camera_info_test.cc @@ -1,222 +1,222 @@ -/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "tests/common/win/testing_common.h"
-#include "import/cross/camera_info.h"
-#include "core/cross/class_manager.h"
-#include "core/cross/object_manager.h"
-#include "core/cross/pack.h"
-#include "core/cross/service_dependency.h"
-#include "utils/cross/math_gtest.h"
-
-namespace o3d {
-
-namespace {
-
-// A class to test CameraInfo.
-class TestCameraInfo : public CameraInfo {
- public:
- typedef SmartPointer<TestCameraInfo> Ref;
-
- static ObjectBase::Ref Create(ServiceLocator* service_locator);
-
- private:
- explicit TestCameraInfo(ServiceLocator* service_locator)
- : CameraInfo(service_locator) {
- }
-
- O3D_OBJECT_BASE_DECL_CLASS(TestCameraInfo, CameraInfo);
- DISALLOW_COPY_AND_ASSIGN(TestCameraInfo);
-};
-
-O3D_OBJECT_BASE_DEFN_CLASS(
- "o3djs.TestCameraInfo", TestCameraInfo, CameraInfo);
-
-ObjectBase::Ref TestCameraInfo::Create(
- ServiceLocator* service_locator) {
- return ObjectBase::Ref(new TestCameraInfo(service_locator));
-}
-
-} // anonymous namespace
-
-class TestCameraInfoTest : public testing::Test {
- protected:
- TestCameraInfoTest()
- : class_manager_(g_service_locator),
- object_manager_(g_service_locator),
- class_register_(g_service_locator) {
- }
-
- virtual void SetUp();
- virtual void TearDown();
-
- Pack* pack() { return pack_; }
-
- private:
- ServiceDependency<ClassManager> class_manager_;
- ServiceDependency<ObjectManager> object_manager_;
- ClassManager::Register<TestCameraInfo> class_register_;
- Pack* pack_;
-};
-
-void TestCameraInfoTest::SetUp() {
- pack_ = object_manager_->CreatePack();
-}
-
-void TestCameraInfoTest::TearDown() {
- object_manager_->DestroyPack(pack_);
-}
-
-// Creates a TestCameraInfo, tests basic properties.
-TEST_F(TestCameraInfoTest, TestTestCameraInfo) {
- TestCameraInfo *camera_info = pack()->Create<TestCameraInfo>();
- EXPECT_TRUE(camera_info->IsA(TestCameraInfo::GetApparentClass()));
- EXPECT_TRUE(camera_info->IsA(CameraInfo::GetApparentClass()));
- EXPECT_TRUE(camera_info->IsA(JSONObject::GetApparentClass()));
- EXPECT_TRUE(camera_info->IsA(ParamObject::GetApparentClass()));
-
- EXPECT_EQ(camera_info->aspect_ratio(), 1.0f);
- EXPECT_EQ(camera_info->near_z(), 0.01f);
- EXPECT_EQ(camera_info->far_z(), 10000.0f);
- EXPECT_TRUE(camera_info->transform() == NULL);
-
- Transform* transform = pack()->Create<Transform>();
- ASSERT_TRUE(transform != NULL);
-
- camera_info->set_aspect_ratio(2.0f);
- camera_info->set_near_z(0.02f);
- camera_info->set_far_z(20000.0f);
- camera_info->set_transform(transform);
- camera_info->set_eye(Float3(10.0f, 20.0f, 30.0f));
- camera_info->set_target(Float3(11.0f, 22.0f, 33.0f));
- camera_info->set_up(Float3(12.0f, 23.0f, 34.0f));
-
- EXPECT_EQ(camera_info->aspect_ratio(), 2.0f);
- EXPECT_EQ(camera_info->near_z(), 0.02f);
- EXPECT_EQ(camera_info->far_z(), 20000.0f);
- EXPECT_TRUE(camera_info->transform() == transform);
- EXPECT_EQ(camera_info->eye(), Float3(10.0f, 20.0f, 30.0f));
- EXPECT_EQ(camera_info->target(), Float3(11.0f, 22.0f, 33.0f));
- EXPECT_EQ(camera_info->up(), Float3(12.0f, 23.0f, 34.0f));
-}
-
-class PerspectiveCameraInfoTest : public testing::Test {
- protected:
- PerspectiveCameraInfoTest()
- : class_manager_(g_service_locator),
- object_manager_(g_service_locator),
- class_register_(g_service_locator) {
- }
-
- virtual void SetUp();
- virtual void TearDown();
-
- Pack* pack() { return pack_; }
-
- private:
- ServiceDependency<ClassManager> class_manager_;
- ServiceDependency<ObjectManager> object_manager_;
- ClassManager::Register<PerspectiveCameraInfo> class_register_;
- Pack* pack_;
-};
-
-void PerspectiveCameraInfoTest::SetUp() {
- pack_ = object_manager_->CreatePack();
-}
-
-void PerspectiveCameraInfoTest::TearDown() {
- object_manager_->DestroyPack(pack_);
-}
-
-// Creates a PerspectiveCameraInfo, tests basic properties.
-TEST_F(PerspectiveCameraInfoTest, TestPerspectiveCameraInfo) {
- PerspectiveCameraInfo *camera_info = pack()->Create<PerspectiveCameraInfo>();
- EXPECT_TRUE(camera_info->IsA(PerspectiveCameraInfo::GetApparentClass()));
- EXPECT_TRUE(camera_info->IsA(CameraInfo::GetApparentClass()));
- EXPECT_TRUE(camera_info->IsA(JSONObject::GetApparentClass()));
- EXPECT_TRUE(camera_info->IsA(ParamObject::GetApparentClass()));
-
- EXPECT_EQ(camera_info->field_of_view_y(), 30.0f * 3.14159f / 180.0f);
-
- camera_info->set_field_of_view_y(60.0f * 3.14159f / 180.0f);
-
- EXPECT_EQ(camera_info->field_of_view_y(), 60.0f * 3.14159f / 180.0f);
-}
-
-class OrthographicCameraInfoTest : public testing::Test {
- protected:
- OrthographicCameraInfoTest()
- : class_manager_(g_service_locator),
- object_manager_(g_service_locator),
- class_register_(g_service_locator) {
- }
-
- virtual void SetUp();
- virtual void TearDown();
-
- Pack* pack() { return pack_; }
-
- private:
- ServiceDependency<ClassManager> class_manager_;
- ServiceDependency<ObjectManager> object_manager_;
- ClassManager::Register<OrthographicCameraInfo> class_register_;
- Pack* pack_;
-};
-
-void OrthographicCameraInfoTest::SetUp() {
- pack_ = object_manager_->CreatePack();
-}
-
-void OrthographicCameraInfoTest::TearDown() {
- object_manager_->DestroyPack(pack_);
-}
-
-// Creates a OrthographicCameraInfo, tests basic properties.
-TEST_F(OrthographicCameraInfoTest, TestOrthographicCameraInfo) {
- OrthographicCameraInfo *camera_info =
- pack()->Create<OrthographicCameraInfo>();
- EXPECT_TRUE(camera_info->IsA(OrthographicCameraInfo::GetApparentClass()));
- EXPECT_TRUE(camera_info->IsA(CameraInfo::GetApparentClass()));
- EXPECT_TRUE(camera_info->IsA(JSONObject::GetApparentClass()));
- EXPECT_TRUE(camera_info->IsA(ParamObject::GetApparentClass()));
-
- EXPECT_EQ(camera_info->mag_x(), 1.0f);
- EXPECT_EQ(camera_info->mag_y(), 1.0f);
-
- camera_info->set_mag_x(2.0f);
- camera_info->set_mag_y(3.0f);
-
- EXPECT_EQ(camera_info->mag_x(), 2.0f);
- EXPECT_EQ(camera_info->mag_y(), 3.0f);
-}
-
-} // namespace o3d
-
+/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "tests/common/win/testing_common.h" +#include "import/cross/camera_info.h" +#include "core/cross/class_manager.h" +#include "core/cross/object_manager.h" +#include "core/cross/pack.h" +#include "core/cross/service_dependency.h" +#include "utils/cross/math_gtest.h" + +namespace o3d { + +namespace { + +// A class to test CameraInfo. +class TestCameraInfo : public CameraInfo { + public: + typedef SmartPointer<TestCameraInfo> Ref; + + static ObjectBase::Ref Create(ServiceLocator* service_locator); + + private: + explicit TestCameraInfo(ServiceLocator* service_locator) + : CameraInfo(service_locator) { + } + + O3D_OBJECT_BASE_DECL_CLASS(TestCameraInfo, CameraInfo); + DISALLOW_COPY_AND_ASSIGN(TestCameraInfo); +}; + +O3D_OBJECT_BASE_DEFN_CLASS( + "o3djs.TestCameraInfo", TestCameraInfo, CameraInfo); + +ObjectBase::Ref TestCameraInfo::Create( + ServiceLocator* service_locator) { + return ObjectBase::Ref(new TestCameraInfo(service_locator)); +} + +} // anonymous namespace + +class TestCameraInfoTest : public testing::Test { + protected: + TestCameraInfoTest() + : class_manager_(g_service_locator), + object_manager_(g_service_locator), + class_register_(g_service_locator) { + } + + virtual void SetUp(); + virtual void TearDown(); + + Pack* pack() { return pack_; } + + private: + ServiceDependency<ClassManager> class_manager_; + ServiceDependency<ObjectManager> object_manager_; + ClassManager::Register<TestCameraInfo> class_register_; + Pack* pack_; +}; + +void TestCameraInfoTest::SetUp() { + pack_ = object_manager_->CreatePack(); +} + +void TestCameraInfoTest::TearDown() { + object_manager_->DestroyPack(pack_); +} + +// Creates a TestCameraInfo, tests basic properties. +TEST_F(TestCameraInfoTest, TestTestCameraInfo) { + TestCameraInfo *camera_info = pack()->Create<TestCameraInfo>(); + EXPECT_TRUE(camera_info->IsA(TestCameraInfo::GetApparentClass())); + EXPECT_TRUE(camera_info->IsA(CameraInfo::GetApparentClass())); + EXPECT_TRUE(camera_info->IsA(JSONObject::GetApparentClass())); + EXPECT_TRUE(camera_info->IsA(ParamObject::GetApparentClass())); + + EXPECT_EQ(camera_info->aspect_ratio(), 1.0f); + EXPECT_EQ(camera_info->near_z(), 0.01f); + EXPECT_EQ(camera_info->far_z(), 10000.0f); + EXPECT_TRUE(camera_info->transform() == NULL); + + Transform* transform = pack()->Create<Transform>(); + ASSERT_TRUE(transform != NULL); + + camera_info->set_aspect_ratio(2.0f); + camera_info->set_near_z(0.02f); + camera_info->set_far_z(20000.0f); + camera_info->set_transform(transform); + camera_info->set_eye(Float3(10.0f, 20.0f, 30.0f)); + camera_info->set_target(Float3(11.0f, 22.0f, 33.0f)); + camera_info->set_up(Float3(12.0f, 23.0f, 34.0f)); + + EXPECT_EQ(camera_info->aspect_ratio(), 2.0f); + EXPECT_EQ(camera_info->near_z(), 0.02f); + EXPECT_EQ(camera_info->far_z(), 20000.0f); + EXPECT_TRUE(camera_info->transform() == transform); + EXPECT_EQ(camera_info->eye(), Float3(10.0f, 20.0f, 30.0f)); + EXPECT_EQ(camera_info->target(), Float3(11.0f, 22.0f, 33.0f)); + EXPECT_EQ(camera_info->up(), Float3(12.0f, 23.0f, 34.0f)); +} + +class PerspectiveCameraInfoTest : public testing::Test { + protected: + PerspectiveCameraInfoTest() + : class_manager_(g_service_locator), + object_manager_(g_service_locator), + class_register_(g_service_locator) { + } + + virtual void SetUp(); + virtual void TearDown(); + + Pack* pack() { return pack_; } + + private: + ServiceDependency<ClassManager> class_manager_; + ServiceDependency<ObjectManager> object_manager_; + ClassManager::Register<PerspectiveCameraInfo> class_register_; + Pack* pack_; +}; + +void PerspectiveCameraInfoTest::SetUp() { + pack_ = object_manager_->CreatePack(); +} + +void PerspectiveCameraInfoTest::TearDown() { + object_manager_->DestroyPack(pack_); +} + +// Creates a PerspectiveCameraInfo, tests basic properties. +TEST_F(PerspectiveCameraInfoTest, TestPerspectiveCameraInfo) { + PerspectiveCameraInfo *camera_info = pack()->Create<PerspectiveCameraInfo>(); + EXPECT_TRUE(camera_info->IsA(PerspectiveCameraInfo::GetApparentClass())); + EXPECT_TRUE(camera_info->IsA(CameraInfo::GetApparentClass())); + EXPECT_TRUE(camera_info->IsA(JSONObject::GetApparentClass())); + EXPECT_TRUE(camera_info->IsA(ParamObject::GetApparentClass())); + + EXPECT_EQ(camera_info->field_of_view_y(), 30.0f * 3.14159f / 180.0f); + + camera_info->set_field_of_view_y(60.0f * 3.14159f / 180.0f); + + EXPECT_EQ(camera_info->field_of_view_y(), 60.0f * 3.14159f / 180.0f); +} + +class OrthographicCameraInfoTest : public testing::Test { + protected: + OrthographicCameraInfoTest() + : class_manager_(g_service_locator), + object_manager_(g_service_locator), + class_register_(g_service_locator) { + } + + virtual void SetUp(); + virtual void TearDown(); + + Pack* pack() { return pack_; } + + private: + ServiceDependency<ClassManager> class_manager_; + ServiceDependency<ObjectManager> object_manager_; + ClassManager::Register<OrthographicCameraInfo> class_register_; + Pack* pack_; +}; + +void OrthographicCameraInfoTest::SetUp() { + pack_ = object_manager_->CreatePack(); +} + +void OrthographicCameraInfoTest::TearDown() { + object_manager_->DestroyPack(pack_); +} + +// Creates a OrthographicCameraInfo, tests basic properties. +TEST_F(OrthographicCameraInfoTest, TestOrthographicCameraInfo) { + OrthographicCameraInfo *camera_info = + pack()->Create<OrthographicCameraInfo>(); + EXPECT_TRUE(camera_info->IsA(OrthographicCameraInfo::GetApparentClass())); + EXPECT_TRUE(camera_info->IsA(CameraInfo::GetApparentClass())); + EXPECT_TRUE(camera_info->IsA(JSONObject::GetApparentClass())); + EXPECT_TRUE(camera_info->IsA(ParamObject::GetApparentClass())); + + EXPECT_EQ(camera_info->mag_x(), 1.0f); + EXPECT_EQ(camera_info->mag_y(), 1.0f); + + camera_info->set_mag_x(2.0f); + camera_info->set_mag_y(3.0f); + + EXPECT_EQ(camera_info->mag_x(), 2.0f); + EXPECT_EQ(camera_info->mag_y(), 3.0f); +} + +} // namespace o3d + diff --git a/o3d/import/cross/destination_buffer.cc b/o3d/import/cross/destination_buffer.cc index 5aa3124..d52bda8 100644 --- a/o3d/import/cross/destination_buffer.cc +++ b/o3d/import/cross/destination_buffer.cc @@ -1,79 +1,79 @@ -/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "import/cross/destination_buffer.h"
-
-namespace o3d {
-
-O3D_OBJECT_BASE_DEFN_CLASS(
- "o3djs.DestinationBuffer", DestinationBuffer, VertexBuffer);
-
-DestinationBuffer::DestinationBuffer(ServiceLocator* service_locator)
- : VertexBuffer(service_locator),
- buffer_() {
-}
-
-DestinationBuffer::~DestinationBuffer() {
- ConcreteFree();
-}
-
-void DestinationBuffer::ConcreteFree() {
- buffer_.reset();
-}
-
-bool DestinationBuffer::ConcreteAllocate(size_t size_in_bytes) {
- ConcreteFree();
-
- buffer_.reset(new char[size_in_bytes]);
-
- return true;
-}
-
-bool DestinationBuffer::ConcreteLock(AccessMode access_mode,
- void **buffer_data) {
- if (!buffer_.get()) {
- return false;
- }
-
- *buffer_data = reinterpret_cast<void*>(buffer_.get());
- return true;
-}
-
-bool DestinationBuffer::ConcreteUnlock() {
- return buffer_.get() != NULL;
-}
-
-ObjectBase::Ref DestinationBuffer::Create(ServiceLocator* service_locator) {
- return ObjectBase::Ref(new DestinationBuffer(service_locator));
-}
-
-} // namespace o3d
-
+/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "import/cross/destination_buffer.h" + +namespace o3d { + +O3D_OBJECT_BASE_DEFN_CLASS( + "o3djs.DestinationBuffer", DestinationBuffer, VertexBuffer); + +DestinationBuffer::DestinationBuffer(ServiceLocator* service_locator) + : VertexBuffer(service_locator), + buffer_() { +} + +DestinationBuffer::~DestinationBuffer() { + ConcreteFree(); +} + +void DestinationBuffer::ConcreteFree() { + buffer_.reset(); +} + +bool DestinationBuffer::ConcreteAllocate(size_t size_in_bytes) { + ConcreteFree(); + + buffer_.reset(new char[size_in_bytes]); + + return true; +} + +bool DestinationBuffer::ConcreteLock(AccessMode access_mode, + void **buffer_data) { + if (!buffer_.get()) { + return false; + } + + *buffer_data = reinterpret_cast<void*>(buffer_.get()); + return true; +} + +bool DestinationBuffer::ConcreteUnlock() { + return buffer_.get() != NULL; +} + +ObjectBase::Ref DestinationBuffer::Create(ServiceLocator* service_locator) { + return ObjectBase::Ref(new DestinationBuffer(service_locator)); +} + +} // namespace o3d + diff --git a/o3d/import/cross/destination_buffer_test.cc b/o3d/import/cross/destination_buffer_test.cc index c7f69d3..2ad2513 100644 --- a/o3d/import/cross/destination_buffer_test.cc +++ b/o3d/import/cross/destination_buffer_test.cc @@ -1,104 +1,104 @@ -/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "tests/common/win/testing_common.h"
-#include "import/cross/destination_buffer.h"
-#include "core/cross/class_manager.h"
-#include "core/cross/object_manager.h"
-#include "core/cross/pack.h"
-#include "core/cross/service_dependency.h"
-
-namespace o3d {
-
-class DestinationBufferTest : public testing::Test {
- protected:
- DestinationBufferTest()
- : class_manager_(g_service_locator),
- object_manager_(g_service_locator) {
- class_manager_->AddTypedClass<DestinationBuffer>();
- }
-
- virtual void SetUp();
- virtual void TearDown();
-
- Pack* pack() { return pack_; }
-
- private:
- ServiceDependency<ClassManager> class_manager_;
- ServiceDependency<ObjectManager> object_manager_;
- Pack* pack_;
-};
-
-void DestinationBufferTest::SetUp() {
- pack_ = object_manager_->CreatePack();
-}
-
-void DestinationBufferTest::TearDown() {
- object_manager_->DestroyPack(pack_);
-}
-
-
-// Creates a Destination buffer, tests basic properties, and checks that writing
-// then reading data works.
-TEST_F(DestinationBufferTest, TestDestinationBuffer) {
- Buffer *buffer = pack()->Create<DestinationBuffer>();
- EXPECT_TRUE(buffer->IsA(DestinationBuffer::GetApparentClass()));
- EXPECT_TRUE(buffer->IsA(VertexBuffer::GetApparentClass()));
- EXPECT_TRUE(buffer->IsA(Buffer::GetApparentClass()));
-
- const size_t kSize = 100;
- Field* field = buffer->CreateField(UInt32Field::GetApparentClass(), 1);
- ASSERT_TRUE(field != NULL);
- ASSERT_TRUE(buffer->AllocateElements(kSize));
- EXPECT_EQ(kSize * sizeof(uint32), buffer->GetSizeInBytes()); // NOLINT
-
- // Put some data into the buffer.
- uint32 *data = NULL;
- ASSERT_TRUE(buffer->LockAs(Buffer::WRITE_ONLY, &data));
- ASSERT_TRUE(data != NULL);
- for (uint32 i = 0; i < kSize; ++i) {
- data[i] = i;
- }
- ASSERT_TRUE(buffer->Unlock());
-
- data = NULL;
- // Read the data from the buffer, checks that it's the expected values.
- ASSERT_TRUE(buffer->LockAs(Buffer::READ_ONLY, &data));
- ASSERT_TRUE(data != NULL);
- for (uint32 i = 0; i < kSize; ++i) {
- EXPECT_EQ(i, data[i]);
- }
- ASSERT_TRUE(buffer->Unlock());
-}
-
-
-} // namespace o3d
-
+/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "tests/common/win/testing_common.h" +#include "import/cross/destination_buffer.h" +#include "core/cross/class_manager.h" +#include "core/cross/object_manager.h" +#include "core/cross/pack.h" +#include "core/cross/service_dependency.h" + +namespace o3d { + +class DestinationBufferTest : public testing::Test { + protected: + DestinationBufferTest() + : class_manager_(g_service_locator), + object_manager_(g_service_locator) { + class_manager_->AddTypedClass<DestinationBuffer>(); + } + + virtual void SetUp(); + virtual void TearDown(); + + Pack* pack() { return pack_; } + + private: + ServiceDependency<ClassManager> class_manager_; + ServiceDependency<ObjectManager> object_manager_; + Pack* pack_; +}; + +void DestinationBufferTest::SetUp() { + pack_ = object_manager_->CreatePack(); +} + +void DestinationBufferTest::TearDown() { + object_manager_->DestroyPack(pack_); +} + + +// Creates a Destination buffer, tests basic properties, and checks that writing +// then reading data works. +TEST_F(DestinationBufferTest, TestDestinationBuffer) { + Buffer *buffer = pack()->Create<DestinationBuffer>(); + EXPECT_TRUE(buffer->IsA(DestinationBuffer::GetApparentClass())); + EXPECT_TRUE(buffer->IsA(VertexBuffer::GetApparentClass())); + EXPECT_TRUE(buffer->IsA(Buffer::GetApparentClass())); + + const size_t kSize = 100; + Field* field = buffer->CreateField(UInt32Field::GetApparentClass(), 1); + ASSERT_TRUE(field != NULL); + ASSERT_TRUE(buffer->AllocateElements(kSize)); + EXPECT_EQ(kSize * sizeof(uint32), buffer->GetSizeInBytes()); // NOLINT + + // Put some data into the buffer. + uint32 *data = NULL; + ASSERT_TRUE(buffer->LockAs(Buffer::WRITE_ONLY, &data)); + ASSERT_TRUE(data != NULL); + for (uint32 i = 0; i < kSize; ++i) { + data[i] = i; + } + ASSERT_TRUE(buffer->Unlock()); + + data = NULL; + // Read the data from the buffer, checks that it's the expected values. + ASSERT_TRUE(buffer->LockAs(Buffer::READ_ONLY, &data)); + ASSERT_TRUE(data != NULL); + for (uint32 i = 0; i < kSize; ++i) { + EXPECT_EQ(i, data[i]); + } + ASSERT_TRUE(buffer->Unlock()); +} + + +} // namespace o3d + diff --git a/o3d/import/cross/json_object.cc b/o3d/import/cross/json_object.cc index a681a3a..906e730 100644 --- a/o3d/import/cross/json_object.cc +++ b/o3d/import/cross/json_object.cc @@ -1,66 +1,66 @@ -/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-// This file defines the JSON Object class.
-
-#include "import/cross/json_object.h"
-
-namespace o3d {
-
-O3D_OBJECT_BASE_DEFN_CLASS("o3djs.JSONObject", JSONObject, ParamObject);
-
-JSONObject::JSONObject(ServiceLocator* service_locator)
- : ParamObject(service_locator) {
-}
-
-void JSONObject::AddProperty(const String& name, JSONValue* value) {
- std::pair<NameValueMap::iterator, bool> result = properties_.insert(
- std::pair<String, JSONValue::Ref>(name, JSONValue::Ref(value)));
- DCHECK(result.second);
-}
-
-void JSONObject::Serialize(StructuredWriter* writer) const {
- writer->WritePropertyName("object");
- writer->OpenObject();
- for (NameValueMap::const_iterator it(properties_.begin());
- it != properties_.end();
- ++it) {
- if (it->second->exists()) {
- writer->WritePropertyName(it->first);
- it->second->Serialize(writer);
- }
- }
- writer->CloseObject();
-}
-
-} // namespace o3d
-
-
+/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +// This file defines the JSON Object class. + +#include "import/cross/json_object.h" + +namespace o3d { + +O3D_OBJECT_BASE_DEFN_CLASS("o3djs.JSONObject", JSONObject, ParamObject); + +JSONObject::JSONObject(ServiceLocator* service_locator) + : ParamObject(service_locator) { +} + +void JSONObject::AddProperty(const String& name, JSONValue* value) { + std::pair<NameValueMap::iterator, bool> result = properties_.insert( + std::pair<String, JSONValue::Ref>(name, JSONValue::Ref(value))); + DCHECK(result.second); +} + +void JSONObject::Serialize(StructuredWriter* writer) const { + writer->WritePropertyName("object"); + writer->OpenObject(); + for (NameValueMap::const_iterator it(properties_.begin()); + it != properties_.end(); + ++it) { + if (it->second->exists()) { + writer->WritePropertyName(it->first); + it->second->Serialize(writer); + } + } + writer->CloseObject(); +} + +} // namespace o3d + + diff --git a/o3d/import/cross/json_object_test.cc b/o3d/import/cross/json_object_test.cc index 8935f8b..137de45 100644 --- a/o3d/import/cross/json_object_test.cc +++ b/o3d/import/cross/json_object_test.cc @@ -1,448 +1,448 @@ -/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "tests/common/win/testing_common.h"
-#include "import/cross/json_object.h"
-#include "core/cross/class_manager.h"
-#include "core/cross/object_manager.h"
-#include "core/cross/pack.h"
-#include "core/cross/service_dependency.h"
-#include "utils/cross/string_writer.h"
-#include "utils/cross/json_writer.h"
-#include "utils/cross/math_gtest.h"
-
-namespace o3d {
-
-namespace {
-
-// A class to test JSONObject
-class TestJSONObject : public JSONObject {
- public:
- typedef SmartPointer<TestJSONObject> Ref;
-
- static const char* kFloatValueName;
- static const char* kFloat2ValueName;
- static const char* kFloat3ValueName;
- static const char* kFloat4ValueName;
- static const char* kMatrix4ValueName;
- static const char* kIntegerValueName;
- static const char* kBooleanValueName;
- static const char* kStringValueName;
- static const char* kTransformValueName;
- static const char* kMaterialValueName;
- static const char* kOptionalFloatValueName;
- static const char* kOptionalFloat2ValueName;
- static const char* kOptionalFloat3ValueName;
- static const char* kOptionalFloat4ValueName;
- static const char* kOptionalMatrix4ValueName;
- static const char* kOptionalIntegerValueName;
- static const char* kOptionalBooleanValueName;
- static const char* kOptionalStringValueName;
-
- float float_value() const {
- return float_value_->value();
- }
-
- void set_float_value(float value) {
- float_value_->set_value(value);
- }
-
- Float2 float2_value() const {
- return float2_value_->value();
- }
-
- void set_float2_value(const Float2& value) {
- float2_value_->set_value(value);
- }
-
- Float3 float3_value() const {
- return float3_value_->value();
- }
-
- void set_float3_value(const Float3& value) {
- float3_value_->set_value(value);
- }
-
- Float4 float4_value() const {
- return float4_value_->value();
- }
-
- void set_float4_value(const Float4& value) {
- float4_value_->set_value(value);
- }
-
- Matrix4 matrix4_value() const {
- return matrix4_value_->value();
- }
-
- void set_matrix4_value(const Matrix4& value) {
- matrix4_value_->set_value(value);
- }
-
- int integer_value() const {
- return integer_value_->value();
- }
-
- void set_integer_value(int value) {
- integer_value_->set_value(value);
- }
-
- bool boolean_value() const {
- return boolean_value_->value();
- }
-
- void set_boolean_value(bool value) {
- boolean_value_->set_value(value);
- }
-
- String string_value() const {
- return string_value_->value();
- }
-
- void set_string_value(const String& value) {
- string_value_->set_value(value);
- }
-
- Transform* transform_value() const {
- return transform_value_->value();
- }
-
- void set_transform_value(Transform* value) {
- transform_value_->set_value(value);
- }
-
- Material* material_value() const {
- return material_value_->value();
- }
-
- void set_material_value(Material* value) {
- material_value_->set_value(value);
- }
-
- float optional_float_value() const {
- return optional_float_value_->value();
- }
-
- void set_optional_float_value(float value) {
- optional_float_value_->set_value(value);
- }
-
- Float2 optional_float2_value() const {
- return optional_float2_value_->value();
- }
-
- void set_optional_float2_value(const Float2& value) {
- optional_float2_value_->set_value(value);
- }
-
- Float3 optional_float3_value() const {
- return optional_float3_value_->value();
- }
-
- void set_optional_float3_value(const Float3& value) {
- optional_float3_value_->set_value(value);
- }
-
- Float4 optional_float4_value() const {
- return optional_float4_value_->value();
- }
-
- void set_optional_float4_value(const Float4& value) {
- optional_float4_value_->set_value(value);
- }
-
- Matrix4 optional_matrix4_value() const {
- return optional_matrix4_value_->value();
- }
-
- void set_optional_matrix4_value(const Matrix4& value) {
- optional_matrix4_value_->set_value(value);
- }
-
- int optional_integer_value() const {
- return optional_integer_value_->value();
- }
-
- void set_optional_integer_value(int value) {
- optional_integer_value_->set_value(value);
- }
-
- bool optional_boolean_value() const {
- return optional_boolean_value_->value();
- }
-
- void set_optional_boolean_value(bool value) {
- optional_boolean_value_->set_value(value);
- }
-
- String optional_string_value() const {
- return optional_string_value_->value();
- }
-
- void set_optional_string_value(const String& value) {
- optional_string_value_->set_value(value);
- }
-
- static ObjectBase::Ref Create(ServiceLocator* service_locator) {
- return ObjectBase::Ref(new TestJSONObject(service_locator));
- }
-
- private:
- explicit TestJSONObject(ServiceLocator* service_locator)
- : JSONObject(service_locator) {
- RegisterJSONValue(kFloatValueName, &float_value_);
- RegisterJSONValue(kFloat2ValueName, &float2_value_);
- RegisterJSONValue(kFloat3ValueName, &float3_value_);
- RegisterJSONValue(kFloat4ValueName, &float4_value_);
- RegisterJSONValue(kMatrix4ValueName, &matrix4_value_);
- RegisterJSONValue(kIntegerValueName, &integer_value_);
- RegisterJSONValue(kBooleanValueName, &boolean_value_);
- RegisterJSONValue(kStringValueName, &string_value_);
- RegisterJSONValue(kTransformValueName, &transform_value_);
- RegisterJSONValue(kMaterialValueName, &material_value_);
- RegisterJSONValue(kOptionalFloatValueName, &optional_float_value_);
- RegisterJSONValue(kOptionalFloat2ValueName, &optional_float2_value_);
- RegisterJSONValue(kOptionalFloat3ValueName, &optional_float3_value_);
- RegisterJSONValue(kOptionalFloat4ValueName, &optional_float4_value_);
- RegisterJSONValue(kOptionalMatrix4ValueName, &optional_matrix4_value_);
- RegisterJSONValue(kOptionalIntegerValueName, &optional_integer_value_);
- RegisterJSONValue(kOptionalBooleanValueName, &optional_boolean_value_);
- RegisterJSONValue(kOptionalStringValueName, &optional_string_value_);
- }
-
- // One of each type of JSONValue
- JSONFloat::Ref float_value_;
- JSONFloat2::Ref float2_value_;
- JSONFloat3::Ref float3_value_;
- JSONFloat4::Ref float4_value_;
- JSONMatrix4::Ref matrix4_value_;
- JSONInteger::Ref integer_value_;
- JSONBoolean::Ref boolean_value_;
- JSONString::Ref string_value_;
- JSONTransform::Ref transform_value_;
- JSONMaterial::Ref material_value_;
- JSONOptionalFloat::Ref optional_float_value_;
- JSONOptionalFloat2::Ref optional_float2_value_;
- JSONOptionalFloat3::Ref optional_float3_value_;
- JSONOptionalFloat4::Ref optional_float4_value_;
- JSONOptionalMatrix4::Ref optional_matrix4_value_;
- JSONOptionalInteger::Ref optional_integer_value_;
- JSONOptionalBoolean::Ref optional_boolean_value_;
- JSONOptionalString::Ref optional_string_value_;
-
- O3D_OBJECT_BASE_DECL_CLASS(TestJSONObject, JSONObject);
- DISALLOW_COPY_AND_ASSIGN(TestJSONObject);
-};
-
-O3D_OBJECT_BASE_DEFN_CLASS("TestJSONObject", TestJSONObject, JSONObject);
-
-const char* TestJSONObject::kFloatValueName = "floatValue";
-const char* TestJSONObject::kFloat2ValueName = "float2Value";
-const char* TestJSONObject::kFloat3ValueName = "float3Value";
-const char* TestJSONObject::kFloat4ValueName = "float4Value";
-const char* TestJSONObject::kMatrix4ValueName = "matrix4Value";
-const char* TestJSONObject::kIntegerValueName = "integerValue";
-const char* TestJSONObject::kBooleanValueName = "booleanValue";
-const char* TestJSONObject::kStringValueName = "stringValue";
-const char* TestJSONObject::kTransformValueName = "transformValue";
-const char* TestJSONObject::kMaterialValueName = "materialValue";
-const char* TestJSONObject::kOptionalFloatValueName = "optionalFloatValue";
-const char* TestJSONObject::kOptionalFloat2ValueName = "optionalFloat2Value";
-const char* TestJSONObject::kOptionalFloat3ValueName = "optionalFloat3Value";
-const char* TestJSONObject::kOptionalFloat4ValueName = "optionalFloat4Value";
-const char* TestJSONObject::kOptionalMatrix4ValueName = "optionalMatrix4Value";
-const char* TestJSONObject::kOptionalIntegerValueName = "optionalIntegerValue";
-const char* TestJSONObject::kOptionalStringValueName = "optionalStringValue";
-const char* TestJSONObject::kOptionalBooleanValueName = "optionalBooleanValue";
-
-} // anonymous namespace
-
-class JSONObjectTest : public testing::Test {
- protected:
- JSONObjectTest()
- : class_manager_(g_service_locator),
- object_manager_(g_service_locator),
- class_register_(g_service_locator) {
- }
-
- virtual void SetUp();
- virtual void TearDown();
-
- Pack* pack() { return pack_; }
-
- private:
- ServiceDependency<ClassManager> class_manager_;
- ServiceDependency<ObjectManager> object_manager_;
- ClassManager::Register<TestJSONObject> class_register_;
- Pack* pack_;
-};
-
-void JSONObjectTest::SetUp() {
- pack_ = object_manager_->CreatePack();
-}
-
-void JSONObjectTest::TearDown() {
- object_manager_->DestroyPack(pack_);
-}
-
-// Creates a JSONObject, tests basic properties.
-TEST_F(JSONObjectTest, BasicTest) {
- TestJSONObject* object = pack()->Create<TestJSONObject>();
- ASSERT_TRUE(object != NULL);
- EXPECT_TRUE(object->IsA(TestJSONObject::GetApparentClass()));
- EXPECT_TRUE(object->IsA(JSONObject::GetApparentClass()));
- EXPECT_TRUE(object->IsA(ParamObject::GetApparentClass()));
-
- // Test everything has its default value.
- EXPECT_EQ(object->float_value(), 0.0f);
- EXPECT_EQ(object->float2_value(), Float2(0.0f, 0.0f));
- EXPECT_EQ(object->float2_value(), Float2(0.0f, 0.0f));
- EXPECT_EQ(object->float3_value(), Float3(0.0f, 0.0f, 0.0f));
- EXPECT_EQ(object->float4_value(), Float4(0.0f, 0.0f, 0.0f, 0.0f));
- EXPECT_EQ(object->matrix4_value(), Matrix4::identity());
- EXPECT_EQ(object->integer_value(), 0);
- EXPECT_FALSE(object->boolean_value());
- EXPECT_EQ(object->string_value(), "");
- EXPECT_TRUE(object->transform_value() == NULL);
- EXPECT_TRUE(object->material_value() == NULL);
-
- // Test that all the values got created by serializing it.
- {
- StringWriter output(StringWriter::LF);
- JsonWriter json_writer(&output, 2);
- object->Serialize(&json_writer);
- json_writer.Close();
- // There is an assumption here that objects will be serialized in this
- // order.
- static const char *kExpected =
- "\"object\": {\n"
- " \"booleanValue\": false,\n"
- " \"float2Value\": [0,0],\n"
- " \"float3Value\": [0,0,0],\n"
- " \"float4Value\": [0,0,0,0],\n"
- " \"floatValue\": 0,\n"
- " \"integerValue\": 0,\n"
- " \"materialValue\": null,\n"
- " \"matrix4Value\": [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],\n"
- " \"stringValue\": \"\",\n"
- " \"transformValue\": null\n"
- "}\n";
- EXPECT_EQ(kExpected, output.ToString());
- }
-}
-
-TEST_F(JSONObjectTest, SetTest) {
- TestJSONObject* object = pack()->Create<TestJSONObject>();
- ASSERT_TRUE(object != NULL);
- // Test setting the values.
- Matrix4 test_matrix(Vector4(1.0f, 2.0f, 3.0f, 4.0f),
- Vector4(2.0f, 2.0f, 8.0f, 9.0f),
- Vector4(3.0f, 5.0f, 3.0f, 10.0f),
- Vector4(4.0f, 6.0f, 7.0f, 4.0f));
- Matrix4 test_matrix2(Vector4(11.0f, 12.0f, 13.0f, 14.0f),
- Vector4(12.0f, 12.0f, 18.0f, 19.0f),
- Vector4(13.0f, 15.0f, 13.0f, 110.0f),
- Vector4(14.0f, 16.0f, 17.0f, 14.0f));
-
- object->set_float_value(1.2f);
- object->set_float2_value(Float2(3.4f, 5.6f));
- object->set_float3_value(Float3(7.8f, 9.0f, 10.0f));
- object->set_float4_value(Float4(11.0f, 12.0f, 13.0f, 14.0f));
- object->set_matrix4_value(test_matrix);
- object->set_integer_value(123);
- object->set_boolean_value(true);
- object->set_string_value("test");
- object->set_optional_float_value(15.0f);
- object->set_optional_float2_value(Float2(14.0f, 15.0f));
- object->set_optional_float3_value(Float3(13.0f, 14.0f, 15.0f));
- object->set_optional_float4_value(Float4(12.0f, 13.0f, 14.0f, 15.0f));
- object->set_optional_matrix4_value(test_matrix2);
- object->set_optional_integer_value(456);
- object->set_optional_string_value("hello");
- object->set_optional_boolean_value(false);
-
- Transform* transform = pack()->Create<Transform>();
- Material* material = pack()->Create<Material>();
- ASSERT_TRUE(transform != NULL);
- ASSERT_TRUE(material != NULL);
-
- object->set_transform_value(transform);
- object->set_material_value(material);
-
- // Check the new values
- EXPECT_EQ(object->float_value(), 1.2f);
- EXPECT_EQ(object->float2_value(), Float2(3.4f, 5.6f));
- EXPECT_EQ(object->float3_value(), Float3(7.8f, 9.0f, 10.0f));
- EXPECT_EQ(object->float4_value(), Float4(11.0f, 12.0f, 13.0f, 14.0f));
- EXPECT_EQ(object->matrix4_value(), test_matrix);
- EXPECT_EQ(object->integer_value(), 123);
- EXPECT_TRUE(object->boolean_value());
- EXPECT_EQ(object->string_value(), "test");
- EXPECT_TRUE(object->transform_value() == transform);
- EXPECT_TRUE(object->material_value() == material);
-
- // See that they got set by serializing them.
- {
- StringWriter output(StringWriter::LF);
- JsonWriter json_writer(&output, 2);
- object->Serialize(&json_writer);
- json_writer.Close();
-
- char buffer[1000];
- static const char* kExpected =
- "\"object\": {\n"
- " \"booleanValue\": true,\n"
- " \"float2Value\": [3.4,5.6],\n"
- " \"float3Value\": [7.8,9,10],\n"
- " \"float4Value\": [11,12,13,14],\n"
- " \"floatValue\": 1.2,\n"
- " \"integerValue\": 123,\n"
- " \"materialValue\": {\"ref\":%d},\n"
- " \"matrix4Value\": [[1,2,3,4],[2,2,8,9],[3,5,3,10],[4,6,7,4]],\n"
- " \"optionalBooleanValue\": false,\n"
- " \"optionalFloat2Value\": [14,15],\n"
- " \"optionalFloat3Value\": [13,14,15],\n"
- " \"optionalFloat4Value\": [12,13,14,15],\n"
- " \"optionalFloatValue\": 15,\n"
- " \"optionalIntegerValue\": 456,\n"
- " \"optionalMatrix4Value\": "
- "[[11,12,13,14],[12,12,18,19],[13,15,13,110],[14,16,17,14]],\n"
- " \"optionalStringValue\": \"hello\",\n"
- " \"stringValue\": \"test\",\n"
- " \"transformValue\": {\"ref\":%d}\n"
- "}\n";
- sprintf(buffer, kExpected, material->id(), transform->id()); // NOLINT
- EXPECT_EQ(static_cast<const char*>(buffer), output.ToString());
- }
-}
-
-} // namespace o3d
-
+/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "tests/common/win/testing_common.h" +#include "import/cross/json_object.h" +#include "core/cross/class_manager.h" +#include "core/cross/object_manager.h" +#include "core/cross/pack.h" +#include "core/cross/service_dependency.h" +#include "utils/cross/string_writer.h" +#include "utils/cross/json_writer.h" +#include "utils/cross/math_gtest.h" + +namespace o3d { + +namespace { + +// A class to test JSONObject +class TestJSONObject : public JSONObject { + public: + typedef SmartPointer<TestJSONObject> Ref; + + static const char* kFloatValueName; + static const char* kFloat2ValueName; + static const char* kFloat3ValueName; + static const char* kFloat4ValueName; + static const char* kMatrix4ValueName; + static const char* kIntegerValueName; + static const char* kBooleanValueName; + static const char* kStringValueName; + static const char* kTransformValueName; + static const char* kMaterialValueName; + static const char* kOptionalFloatValueName; + static const char* kOptionalFloat2ValueName; + static const char* kOptionalFloat3ValueName; + static const char* kOptionalFloat4ValueName; + static const char* kOptionalMatrix4ValueName; + static const char* kOptionalIntegerValueName; + static const char* kOptionalBooleanValueName; + static const char* kOptionalStringValueName; + + float float_value() const { + return float_value_->value(); + } + + void set_float_value(float value) { + float_value_->set_value(value); + } + + Float2 float2_value() const { + return float2_value_->value(); + } + + void set_float2_value(const Float2& value) { + float2_value_->set_value(value); + } + + Float3 float3_value() const { + return float3_value_->value(); + } + + void set_float3_value(const Float3& value) { + float3_value_->set_value(value); + } + + Float4 float4_value() const { + return float4_value_->value(); + } + + void set_float4_value(const Float4& value) { + float4_value_->set_value(value); + } + + Matrix4 matrix4_value() const { + return matrix4_value_->value(); + } + + void set_matrix4_value(const Matrix4& value) { + matrix4_value_->set_value(value); + } + + int integer_value() const { + return integer_value_->value(); + } + + void set_integer_value(int value) { + integer_value_->set_value(value); + } + + bool boolean_value() const { + return boolean_value_->value(); + } + + void set_boolean_value(bool value) { + boolean_value_->set_value(value); + } + + String string_value() const { + return string_value_->value(); + } + + void set_string_value(const String& value) { + string_value_->set_value(value); + } + + Transform* transform_value() const { + return transform_value_->value(); + } + + void set_transform_value(Transform* value) { + transform_value_->set_value(value); + } + + Material* material_value() const { + return material_value_->value(); + } + + void set_material_value(Material* value) { + material_value_->set_value(value); + } + + float optional_float_value() const { + return optional_float_value_->value(); + } + + void set_optional_float_value(float value) { + optional_float_value_->set_value(value); + } + + Float2 optional_float2_value() const { + return optional_float2_value_->value(); + } + + void set_optional_float2_value(const Float2& value) { + optional_float2_value_->set_value(value); + } + + Float3 optional_float3_value() const { + return optional_float3_value_->value(); + } + + void set_optional_float3_value(const Float3& value) { + optional_float3_value_->set_value(value); + } + + Float4 optional_float4_value() const { + return optional_float4_value_->value(); + } + + void set_optional_float4_value(const Float4& value) { + optional_float4_value_->set_value(value); + } + + Matrix4 optional_matrix4_value() const { + return optional_matrix4_value_->value(); + } + + void set_optional_matrix4_value(const Matrix4& value) { + optional_matrix4_value_->set_value(value); + } + + int optional_integer_value() const { + return optional_integer_value_->value(); + } + + void set_optional_integer_value(int value) { + optional_integer_value_->set_value(value); + } + + bool optional_boolean_value() const { + return optional_boolean_value_->value(); + } + + void set_optional_boolean_value(bool value) { + optional_boolean_value_->set_value(value); + } + + String optional_string_value() const { + return optional_string_value_->value(); + } + + void set_optional_string_value(const String& value) { + optional_string_value_->set_value(value); + } + + static ObjectBase::Ref Create(ServiceLocator* service_locator) { + return ObjectBase::Ref(new TestJSONObject(service_locator)); + } + + private: + explicit TestJSONObject(ServiceLocator* service_locator) + : JSONObject(service_locator) { + RegisterJSONValue(kFloatValueName, &float_value_); + RegisterJSONValue(kFloat2ValueName, &float2_value_); + RegisterJSONValue(kFloat3ValueName, &float3_value_); + RegisterJSONValue(kFloat4ValueName, &float4_value_); + RegisterJSONValue(kMatrix4ValueName, &matrix4_value_); + RegisterJSONValue(kIntegerValueName, &integer_value_); + RegisterJSONValue(kBooleanValueName, &boolean_value_); + RegisterJSONValue(kStringValueName, &string_value_); + RegisterJSONValue(kTransformValueName, &transform_value_); + RegisterJSONValue(kMaterialValueName, &material_value_); + RegisterJSONValue(kOptionalFloatValueName, &optional_float_value_); + RegisterJSONValue(kOptionalFloat2ValueName, &optional_float2_value_); + RegisterJSONValue(kOptionalFloat3ValueName, &optional_float3_value_); + RegisterJSONValue(kOptionalFloat4ValueName, &optional_float4_value_); + RegisterJSONValue(kOptionalMatrix4ValueName, &optional_matrix4_value_); + RegisterJSONValue(kOptionalIntegerValueName, &optional_integer_value_); + RegisterJSONValue(kOptionalBooleanValueName, &optional_boolean_value_); + RegisterJSONValue(kOptionalStringValueName, &optional_string_value_); + } + + // One of each type of JSONValue + JSONFloat::Ref float_value_; + JSONFloat2::Ref float2_value_; + JSONFloat3::Ref float3_value_; + JSONFloat4::Ref float4_value_; + JSONMatrix4::Ref matrix4_value_; + JSONInteger::Ref integer_value_; + JSONBoolean::Ref boolean_value_; + JSONString::Ref string_value_; + JSONTransform::Ref transform_value_; + JSONMaterial::Ref material_value_; + JSONOptionalFloat::Ref optional_float_value_; + JSONOptionalFloat2::Ref optional_float2_value_; + JSONOptionalFloat3::Ref optional_float3_value_; + JSONOptionalFloat4::Ref optional_float4_value_; + JSONOptionalMatrix4::Ref optional_matrix4_value_; + JSONOptionalInteger::Ref optional_integer_value_; + JSONOptionalBoolean::Ref optional_boolean_value_; + JSONOptionalString::Ref optional_string_value_; + + O3D_OBJECT_BASE_DECL_CLASS(TestJSONObject, JSONObject); + DISALLOW_COPY_AND_ASSIGN(TestJSONObject); +}; + +O3D_OBJECT_BASE_DEFN_CLASS("TestJSONObject", TestJSONObject, JSONObject); + +const char* TestJSONObject::kFloatValueName = "floatValue"; +const char* TestJSONObject::kFloat2ValueName = "float2Value"; +const char* TestJSONObject::kFloat3ValueName = "float3Value"; +const char* TestJSONObject::kFloat4ValueName = "float4Value"; +const char* TestJSONObject::kMatrix4ValueName = "matrix4Value"; +const char* TestJSONObject::kIntegerValueName = "integerValue"; +const char* TestJSONObject::kBooleanValueName = "booleanValue"; +const char* TestJSONObject::kStringValueName = "stringValue"; +const char* TestJSONObject::kTransformValueName = "transformValue"; +const char* TestJSONObject::kMaterialValueName = "materialValue"; +const char* TestJSONObject::kOptionalFloatValueName = "optionalFloatValue"; +const char* TestJSONObject::kOptionalFloat2ValueName = "optionalFloat2Value"; +const char* TestJSONObject::kOptionalFloat3ValueName = "optionalFloat3Value"; +const char* TestJSONObject::kOptionalFloat4ValueName = "optionalFloat4Value"; +const char* TestJSONObject::kOptionalMatrix4ValueName = "optionalMatrix4Value"; +const char* TestJSONObject::kOptionalIntegerValueName = "optionalIntegerValue"; +const char* TestJSONObject::kOptionalStringValueName = "optionalStringValue"; +const char* TestJSONObject::kOptionalBooleanValueName = "optionalBooleanValue"; + +} // anonymous namespace + +class JSONObjectTest : public testing::Test { + protected: + JSONObjectTest() + : class_manager_(g_service_locator), + object_manager_(g_service_locator), + class_register_(g_service_locator) { + } + + virtual void SetUp(); + virtual void TearDown(); + + Pack* pack() { return pack_; } + + private: + ServiceDependency<ClassManager> class_manager_; + ServiceDependency<ObjectManager> object_manager_; + ClassManager::Register<TestJSONObject> class_register_; + Pack* pack_; +}; + +void JSONObjectTest::SetUp() { + pack_ = object_manager_->CreatePack(); +} + +void JSONObjectTest::TearDown() { + object_manager_->DestroyPack(pack_); +} + +// Creates a JSONObject, tests basic properties. +TEST_F(JSONObjectTest, BasicTest) { + TestJSONObject* object = pack()->Create<TestJSONObject>(); + ASSERT_TRUE(object != NULL); + EXPECT_TRUE(object->IsA(TestJSONObject::GetApparentClass())); + EXPECT_TRUE(object->IsA(JSONObject::GetApparentClass())); + EXPECT_TRUE(object->IsA(ParamObject::GetApparentClass())); + + // Test everything has its default value. + EXPECT_EQ(object->float_value(), 0.0f); + EXPECT_EQ(object->float2_value(), Float2(0.0f, 0.0f)); + EXPECT_EQ(object->float2_value(), Float2(0.0f, 0.0f)); + EXPECT_EQ(object->float3_value(), Float3(0.0f, 0.0f, 0.0f)); + EXPECT_EQ(object->float4_value(), Float4(0.0f, 0.0f, 0.0f, 0.0f)); + EXPECT_EQ(object->matrix4_value(), Matrix4::identity()); + EXPECT_EQ(object->integer_value(), 0); + EXPECT_FALSE(object->boolean_value()); + EXPECT_EQ(object->string_value(), ""); + EXPECT_TRUE(object->transform_value() == NULL); + EXPECT_TRUE(object->material_value() == NULL); + + // Test that all the values got created by serializing it. + { + StringWriter output(StringWriter::LF); + JsonWriter json_writer(&output, 2); + object->Serialize(&json_writer); + json_writer.Close(); + // There is an assumption here that objects will be serialized in this + // order. + static const char *kExpected = + "\"object\": {\n" + " \"booleanValue\": false,\n" + " \"float2Value\": [0,0],\n" + " \"float3Value\": [0,0,0],\n" + " \"float4Value\": [0,0,0,0],\n" + " \"floatValue\": 0,\n" + " \"integerValue\": 0,\n" + " \"materialValue\": null,\n" + " \"matrix4Value\": [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],\n" + " \"stringValue\": \"\",\n" + " \"transformValue\": null\n" + "}\n"; + EXPECT_EQ(kExpected, output.ToString()); + } +} + +TEST_F(JSONObjectTest, SetTest) { + TestJSONObject* object = pack()->Create<TestJSONObject>(); + ASSERT_TRUE(object != NULL); + // Test setting the values. + Matrix4 test_matrix(Vector4(1.0f, 2.0f, 3.0f, 4.0f), + Vector4(2.0f, 2.0f, 8.0f, 9.0f), + Vector4(3.0f, 5.0f, 3.0f, 10.0f), + Vector4(4.0f, 6.0f, 7.0f, 4.0f)); + Matrix4 test_matrix2(Vector4(11.0f, 12.0f, 13.0f, 14.0f), + Vector4(12.0f, 12.0f, 18.0f, 19.0f), + Vector4(13.0f, 15.0f, 13.0f, 110.0f), + Vector4(14.0f, 16.0f, 17.0f, 14.0f)); + + object->set_float_value(1.2f); + object->set_float2_value(Float2(3.4f, 5.6f)); + object->set_float3_value(Float3(7.8f, 9.0f, 10.0f)); + object->set_float4_value(Float4(11.0f, 12.0f, 13.0f, 14.0f)); + object->set_matrix4_value(test_matrix); + object->set_integer_value(123); + object->set_boolean_value(true); + object->set_string_value("test"); + object->set_optional_float_value(15.0f); + object->set_optional_float2_value(Float2(14.0f, 15.0f)); + object->set_optional_float3_value(Float3(13.0f, 14.0f, 15.0f)); + object->set_optional_float4_value(Float4(12.0f, 13.0f, 14.0f, 15.0f)); + object->set_optional_matrix4_value(test_matrix2); + object->set_optional_integer_value(456); + object->set_optional_string_value("hello"); + object->set_optional_boolean_value(false); + + Transform* transform = pack()->Create<Transform>(); + Material* material = pack()->Create<Material>(); + ASSERT_TRUE(transform != NULL); + ASSERT_TRUE(material != NULL); + + object->set_transform_value(transform); + object->set_material_value(material); + + // Check the new values + EXPECT_EQ(object->float_value(), 1.2f); + EXPECT_EQ(object->float2_value(), Float2(3.4f, 5.6f)); + EXPECT_EQ(object->float3_value(), Float3(7.8f, 9.0f, 10.0f)); + EXPECT_EQ(object->float4_value(), Float4(11.0f, 12.0f, 13.0f, 14.0f)); + EXPECT_EQ(object->matrix4_value(), test_matrix); + EXPECT_EQ(object->integer_value(), 123); + EXPECT_TRUE(object->boolean_value()); + EXPECT_EQ(object->string_value(), "test"); + EXPECT_TRUE(object->transform_value() == transform); + EXPECT_TRUE(object->material_value() == material); + + // See that they got set by serializing them. + { + StringWriter output(StringWriter::LF); + JsonWriter json_writer(&output, 2); + object->Serialize(&json_writer); + json_writer.Close(); + + char buffer[1000]; + static const char* kExpected = + "\"object\": {\n" + " \"booleanValue\": true,\n" + " \"float2Value\": [3.4,5.6],\n" + " \"float3Value\": [7.8,9,10],\n" + " \"float4Value\": [11,12,13,14],\n" + " \"floatValue\": 1.2,\n" + " \"integerValue\": 123,\n" + " \"materialValue\": {\"ref\":%d},\n" + " \"matrix4Value\": [[1,2,3,4],[2,2,8,9],[3,5,3,10],[4,6,7,4]],\n" + " \"optionalBooleanValue\": false,\n" + " \"optionalFloat2Value\": [14,15],\n" + " \"optionalFloat3Value\": [13,14,15],\n" + " \"optionalFloat4Value\": [12,13,14,15],\n" + " \"optionalFloatValue\": 15,\n" + " \"optionalIntegerValue\": 456,\n" + " \"optionalMatrix4Value\": " + "[[11,12,13,14],[12,12,18,19],[13,15,13,110],[14,16,17,14]],\n" + " \"optionalStringValue\": \"hello\",\n" + " \"stringValue\": \"test\",\n" + " \"transformValue\": {\"ref\":%d}\n" + "}\n"; + sprintf(buffer, kExpected, material->id(), transform->id()); // NOLINT + EXPECT_EQ(static_cast<const char*>(buffer), output.ToString()); + } +} + +} // namespace o3d + |