diff options
Diffstat (limited to 'o3d')
-rw-r--r-- | o3d/core/cross/class_manager.cc | 9 | ||||
-rw-r--r-- | o3d/core/cross/class_manager.h | 2 | ||||
-rw-r--r-- | o3d/core/cross/iclass_manager.h | 40 | ||||
-rw-r--r-- | o3d/import/build.scons | 2 | ||||
-rw-r--r-- | o3d/import/cross/camera_info.cc | 98 | ||||
-rw-r--r-- | o3d/import/cross/camera_info.h | 221 | ||||
-rw-r--r-- | o3d/import/cross/camera_info_test.cc | 223 | ||||
-rw-r--r-- | o3d/import/cross/json_object.cc | 67 | ||||
-rw-r--r-- | o3d/import/cross/json_object.h | 289 | ||||
-rw-r--r-- | o3d/import/cross/json_object_test.cc | 449 | ||||
-rw-r--r-- | o3d/serializer/cross/serializer.cc | 9 | ||||
-rw-r--r-- | o3d/tests/build.scons | 4 | ||||
-rw-r--r-- | o3d/utils/cross/math_gtest.cc | 119 | ||||
-rw-r--r-- | o3d/utils/cross/math_gtest.h | 71 | ||||
-rw-r--r-- | o3d/utils/cross/math_gtest_test.cc | 70 |
15 files changed, 1671 insertions, 2 deletions
diff --git a/o3d/core/cross/class_manager.cc b/o3d/core/cross/class_manager.cc index c037a7b..488f316 100644 --- a/o3d/core/cross/class_manager.cc +++ b/o3d/core/cross/class_manager.cc @@ -194,6 +194,15 @@ void ClassManager::AddClass(const ObjectBase::Class* object_class, function)); } +void ClassManager::RemoveClass(const ObjectBase::Class* object_class) { + ObjectClassInfoNameMap::size_type ii = object_class_info_name_map_.erase( + object_class->name()); + DLOG_ASSERT(ii == 1) << "attempt to unregister non-existant class name"; + ObjectCreatorClassMap::size_type jj = object_creator_class_map_.erase( + object_class); + DLOG_ASSERT(jj == 1) << "attempt to unregister non-existant class"; +} + const ObjectBase::Class* ClassManager::GetClassByClassName( const String& class_name) const { ObjectClassInfoNameMap::const_iterator iter = diff --git a/o3d/core/cross/class_manager.h b/o3d/core/cross/class_manager.h index 051aa56b..0a3f922 100644 --- a/o3d/core/cross/class_manager.h +++ b/o3d/core/cross/class_manager.h @@ -50,6 +50,8 @@ class ClassManager : public IClassManager { virtual void AddClass(const ObjectBase::Class* class_type, ObjectCreateFunc function); + virtual void RemoveClass(const ObjectBase::Class* class_type); + virtual const ObjectBase::Class* GetClassByClassName( const String& class_name) const; diff --git a/o3d/core/cross/iclass_manager.h b/o3d/core/cross/iclass_manager.h index 5e0a55f..e7b7a42 100644 --- a/o3d/core/cross/iclass_manager.h +++ b/o3d/core/cross/iclass_manager.h @@ -70,6 +70,17 @@ class IClassManager { AddClass(T::GetApparentClass(), T::Create); } + // Removes a registered class. + // Paramters: + // class_type: Class of type as provided by ObjectBase::GetClass. + virtual void RemoveClass(const ObjectBase::Class* class_type) = 0; + + // A typesafe version of RemoveClass. + template <typename T> + void RemoveTypedClass() { + RemoveClass(T::GetApparentClass()); + } + // Returns the ObjectBase::Class for a particular class name. It only works // for classes that have been registered through AddClass. // Parameters: @@ -99,6 +110,16 @@ class IClassManager { virtual ObjectBase::Ref CreateObjectByClass( const ObjectBase::Class* object_class) = 0; + // Creates a Object based on the type. This is a type safe version of + // CreateObjectByClass for C++. + // Returns: + // pointer to new object if successful. + template<typename T> + typename T::Ref Create() { + return typename T::Ref(down_cast<T*>( + CreateObjectByClass(T::GetApparentClass()).Get())); + } + // Creates an Object by Class name. This is an internal function. Do not use // directly. // Parameters: @@ -111,9 +132,28 @@ class IClassManager { virtual std::vector<const ObjectBase::Class*> GetAllClasses() const = 0; + // This class registers a class with a class manager and removes it on + // destruction. + template <typename T> + class Register { + public: + explicit Register(ServiceLocator* service_locator) + : class_manager_(service_locator->GetService<IClassManager>()) { + class_manager_->AddTypedClass<T>(); + } + ~Register() { + class_manager_->RemoveTypedClass<T>(); + } + + private: + IClassManager* class_manager_; + DISALLOW_COPY_AND_ASSIGN(Register); + }; + private: DISALLOW_COPY_AND_ASSIGN(IClassManager); }; + } // namespace o3d #endif // O3D_CORE_CROSS_ICLASS_MANAGER_H_ diff --git a/o3d/import/build.scons b/o3d/import/build.scons index a695a0a..e831685 100644 --- a/o3d/import/build.scons +++ b/o3d/import/build.scons @@ -62,9 +62,11 @@ else: env.Append(CCFLAGS = [['-include', 'import/cross/precompile.h']]) collada_inputs = [ + 'cross/camera_info.cc', 'cross/collada.cc', 'cross/collada_zip_archive.cc', 'cross/destination_buffer.cc', + 'cross/json_object.cc', 'cross/zip_archive.cc', 'cross/gz_compressor.cc', 'cross/file_output_stream_processor.cc', diff --git a/o3d/import/cross/camera_info.cc b/o3d/import/cross/camera_info.cc new file mode 100644 index 0000000..905c337 --- /dev/null +++ b/o3d/import/cross/camera_info.cc @@ -0,0 +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
+
+
diff --git a/o3d/import/cross/camera_info.h b/o3d/import/cross/camera_info.h new file mode 100644 index 0000000..a221fbb --- /dev/null +++ b/o3d/import/cross/camera_info.h @@ -0,0 +1,221 @@ +/*
+ * 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 declares the CameraInfo class.
+
+#ifndef O3D_IMPORT_CROSS_CAMERA_INFO_H_
+#define O3D_IMPORT_CROSS_CAMERA_INFO_H_
+
+#include "import/cross/json_object.h"
+
+namespace o3d {
+
+// CameraInfo is a used for serialization only and is not part of the
+// normal O3D plugin. It is used for information about the camera.
+class CameraInfo : public JSONObject {
+ public:
+ typedef SmartPointer<CameraInfo> Ref;
+
+ static const char* kAspectRatioParamName;
+ static const char* kNearZParamName;
+ static const char* kFarZParamName;
+ static const char* kTransformValueName;
+ static const char* kEyeValueName;
+ static const char* kTargetValueName;
+ static const char* kUpValueName;
+
+ // Gets the near_z.
+ float near_z() const {
+ return near_z_param_->value();
+ }
+
+ // Sets the near_z.
+ void set_near_z(float value) {
+ near_z_param_->set_value(value);
+ }
+
+ // Gets the far_z.
+ float far_z() const {
+ return far_z_param_->value();
+ }
+
+ // Sets the far_z.
+ void set_far_z(float value) {
+ far_z_param_->set_value(value);
+ }
+
+ // Gets the aspect_ratio.
+ float aspect_ratio() const {
+ return aspect_ratio_param_->value();
+ }
+
+ // Sets the aspect_ratio.
+ void set_aspect_ratio(float value) {
+ aspect_ratio_param_->set_value(value);
+ }
+
+ // Gets the transform.
+ Transform* transform() const {
+ return transform_value_->value();
+ }
+
+ // Sets the transform.
+ void set_transform(Transform* value) {
+ transform_value_->set_value(value);
+ }
+
+ // Gets the eye.
+ Float3 eye() const {
+ return eye_value_->value();
+ }
+
+ // Sets the eye.
+ void set_eye(const Float3& value) {
+ eye_value_->set_value(value);
+ }
+
+ // Gets the target.
+ Float3 target() const {
+ return target_value_->value();
+ }
+
+ // Sets the target.
+ void set_target(const Float3& value) {
+ target_value_->set_value(value);
+ }
+
+ // Gets the up.
+ Float3 up() const {
+ return up_value_->value();
+ }
+
+ // Sets the up.
+ void set_up(const Float3& value) {
+ up_value_->set_value(value);
+ }
+
+ protected:
+ explicit CameraInfo(ServiceLocator* service_locator);
+
+ private:
+ // We make these params so we can easily attach animation to the camera's
+ // parameters.
+ ParamFloat::Ref aspect_ratio_param_;
+ ParamFloat::Ref near_z_param_;
+ ParamFloat::Ref far_z_param_;
+
+ // These are not params, just JSON values.
+ JSONTransform::Ref transform_value_;
+ JSONOptionalFloat3::Ref eye_value_;
+ JSONOptionalFloat3::Ref target_value_;
+ JSONOptionalFloat3::Ref up_value_;
+
+ O3D_OBJECT_BASE_DECL_CLASS(CameraInfo, JSONObject);
+ DISALLOW_COPY_AND_ASSIGN(CameraInfo);
+};
+
+class OrthographicCameraInfo : public CameraInfo {
+ public:
+ typedef SmartPointer<OrthographicCameraInfo> Ref;
+
+ static const char* kMagXParamName;
+ static const char* kMagYParamName;
+
+ // Gets the mag_x.
+ float mag_x() const {
+ return mag_x_param_->value();
+ }
+
+ // Sets the mag_x.
+ void set_mag_x(float value) {
+ mag_x_param_->set_value(value);
+ }
+
+ // Gets the mag_y.
+ float mag_y() const {
+ return mag_y_param_->value();
+ }
+
+ // Sets the mag_y.
+ void set_mag_y(float value) {
+ mag_y_param_->set_value(value);
+ }
+
+ private:
+ explicit OrthographicCameraInfo(ServiceLocator* service_locator);
+
+ friend class IClassManager;
+ static ObjectBase::Ref Create(ServiceLocator* service_locator);
+
+ // We make these params so we can easily attach animation to the camera's
+ // parameters.
+ ParamFloat::Ref mag_x_param_;
+ ParamFloat::Ref mag_y_param_;
+
+ O3D_OBJECT_BASE_DECL_CLASS(OrthographicCameraInfo, CameraInfo);
+ DISALLOW_COPY_AND_ASSIGN(OrthographicCameraInfo);
+};
+
+class PerspectiveCameraInfo : public CameraInfo {
+ public:
+ typedef SmartPointer<PerspectiveCameraInfo> Ref;
+
+ static const char* kFieldOfViewYParamName;
+
+ // Gets the field_of_view_y.
+ float field_of_view_y() const {
+ return field_of_view_y_param_->value();
+ }
+
+ // Sets the field_of_view_y.
+ void set_field_of_view_y(float value) {
+ field_of_view_y_param_->set_value(value);
+ }
+
+ private:
+ explicit PerspectiveCameraInfo(ServiceLocator* service_locator);
+
+ friend class IClassManager;
+ static ObjectBase::Ref Create(ServiceLocator* service_locator);
+
+ // We make these params so we can easily attach animation to the camera's
+ // parameters.
+ ParamFloat::Ref field_of_view_y_param_;
+
+ O3D_OBJECT_BASE_DECL_CLASS(PerspectiveCameraInfo, CameraInfo);
+ DISALLOW_COPY_AND_ASSIGN(PerspectiveCameraInfo);
+};
+
+} // namespace o3d
+
+#endif // O3D_IMPORT_CROSS_CAMERA_INFO_H_
+
diff --git a/o3d/import/cross/camera_info_test.cc b/o3d/import/cross/camera_info_test.cc new file mode 100644 index 0000000..b21cf4a --- /dev/null +++ b/o3d/import/cross/camera_info_test.cc @@ -0,0 +1,223 @@ +/*
+ * 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;
+
+ private:
+ explicit TestCameraInfo(ServiceLocator* service_locator)
+ : CameraInfo(service_locator) {
+ }
+
+ friend class IClassManager;
+ static ObjectBase::Ref Create(ServiceLocator* 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/json_object.cc b/o3d/import/cross/json_object.cc new file mode 100644 index 0000000..bf3f79e --- /dev/null +++ b/o3d/import/cross/json_object.cc @@ -0,0 +1,67 @@ +/*
+ * 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 "core/cross/precompile.h"
+#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.h b/o3d/import/cross/json_object.h new file mode 100644 index 0000000..3cf2815 --- /dev/null +++ b/o3d/import/cross/json_object.h @@ -0,0 +1,289 @@ +/*
+ * 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 declares the JSONObject class.
+
+#ifndef O3D_IMPORT_CROSS_JSON_OBJECT_H_
+#define O3D_IMPORT_CROSS_JSON_OBJECT_H_
+
+#include <map>
+#include "core/cross/param_object.h"
+#include "core/cross/material.h"
+#include "core/cross/transform.h"
+#include "serializer/cross/serializer.h"
+
+namespace o3d {
+
+class StructuredWriter;
+
+// A JSONValue is a base class for all JSON values stored in a JSONObject.
+class JSONValue : public RefCounted {
+ public:
+ typedef SmartPointer<JSONValue> Ref;
+
+ virtual ~JSONValue() {
+ }
+
+ // Whether or not this value exists.
+ bool exists() const {
+ return exists_;
+ }
+
+ // Sets the existence of this value.
+ void set_exists(bool exists) {
+ exists_ = exists;
+ }
+
+ // Function to serialize the value of this JSON value.
+ virtual void Serialize(StructuredWriter* writer) const = 0;
+
+ protected:
+ // optional means the value is optional. If true the value defaults to
+ // not existing. If false the value defaults to existing.
+ explicit JSONValue(bool optional)
+ : optional_(optional), exists_(!optional) {
+ }
+
+ private:
+ bool optional_;
+ bool exists_; // used for optional values.
+};
+
+// A Template for optional typed non-ref JSON values.
+template<class T, bool optional>
+class TypedJSONValue : public JSONValue {
+ public:
+ typedef T DataType;
+ TypedJSONValue()
+ : JSONValue(optional) {
+ }
+ virtual ~TypedJSONValue() {}
+
+ // Sets the value stored in the JSONValue.
+ void set_value(const DataType& value) {
+ set_exists(true);
+ value_ = value;
+ }
+
+ // Returns the current value stored in the JSONValue.
+ DataType value() const {
+ DCHECK(exists());
+ return value_;
+ }
+
+ // Overridden from JSONValue.
+ virtual void Serialize(StructuredWriter* writer) const {
+ DCHECK(exists());
+ o3d::Serialize(writer, value());
+ }
+
+ private:
+ // The value stored in the JSONValue.
+ DataType value_;
+
+ DISALLOW_COPY_AND_ASSIGN(TypedJSONValue);
+};
+
+// A Template for typed ref JSON values.
+template<typename T>
+class TypedRefJSONValue : public JSONValue {
+ public:
+ typedef T* Pointer;
+ typedef T DataType;
+
+ TypedRefJSONValue()
+ : JSONValue(false) {
+ }
+
+ virtual ~TypedRefJSONValue() {
+ }
+
+ // Set the value stored in the.
+ void set_value(Pointer const value) {
+ value_ = typename T::Ref(value);
+ }
+
+ // Returns the current value stored in the Param.
+ Pointer value() const {
+ return value_.Get();
+ }
+
+ // Overridden from JSONValue.
+ virtual void Serialize(StructuredWriter* writer) const {
+ o3d::Serialize(writer, static_cast<ObjectBase*>(value()));
+ }
+
+ protected:
+ typename T::Ref value_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TypedRefJSONValue);
+};
+
+// Classes for various types of JSON Data.
+class JSONFloat : public TypedJSONValue<float, false> {
+ public:
+ typedef SmartPointer<JSONFloat> Ref;
+ JSONFloat() {
+ set_value(0.0f);
+ }
+};
+class JSONFloat2 : public TypedJSONValue<Float2, false> {
+ public:
+ typedef SmartPointer<JSONFloat2> Ref;
+ JSONFloat2() {
+ set_value(Float2(0.0f, 0.0f));
+ }
+};
+class JSONFloat3 : public TypedJSONValue<Float3, false> {
+ public:
+ typedef SmartPointer<JSONFloat3> Ref;
+ JSONFloat3() {
+ set_value(Float3(0.0f, 0.0f, 0.0f));
+ }
+};
+class JSONFloat4 : public TypedJSONValue<Float4, false> {
+ public:
+ typedef SmartPointer<JSONFloat4> Ref;
+ JSONFloat4() {
+ set_value(Float4(0.0f, 0.0f, 0.0f, 0.0f));
+ }
+};
+class JSONMatrix4 : public TypedJSONValue<Matrix4, false> {
+ public:
+ typedef SmartPointer<JSONMatrix4> Ref;
+ JSONMatrix4() {
+ set_value(Matrix4::identity());
+ }
+};
+class JSONInteger : public TypedJSONValue<int, false> {
+ public:
+ typedef SmartPointer<JSONInteger> Ref;
+ JSONInteger() {
+ set_value(0);
+ }
+};
+class JSONBoolean : public TypedJSONValue<bool, false> {
+ public:
+ typedef SmartPointer<JSONBoolean> Ref;
+ JSONBoolean() {
+ set_value(false);
+ }
+};
+class JSONString : public TypedJSONValue<String, false> {
+ public:
+ typedef SmartPointer<JSONString> Ref;
+};
+class JSONTransform : public TypedRefJSONValue<Transform> {
+ public:
+ typedef SmartPointer<JSONTransform> Ref;
+};
+class JSONMaterial : public TypedRefJSONValue<Material> {
+ public:
+ typedef SmartPointer<JSONMaterial> Ref;
+};
+class JSONOptionalFloat : public TypedJSONValue<float, true> {
+ public:
+ typedef SmartPointer<JSONOptionalFloat> Ref;
+};
+class JSONOptionalFloat2 : public TypedJSONValue<Float2, true> {
+ public:
+ typedef SmartPointer<JSONOptionalFloat2> Ref;
+};
+class JSONOptionalFloat3 : public TypedJSONValue<Float3, true> {
+ public:
+ typedef SmartPointer<JSONOptionalFloat3> Ref;
+};
+class JSONOptionalFloat4 : public TypedJSONValue<Float4, true> {
+ public:
+ typedef SmartPointer<JSONOptionalFloat4> Ref;
+};
+class JSONOptionalMatrix4 : public TypedJSONValue<Matrix4, true> {
+ public:
+ typedef SmartPointer<JSONOptionalMatrix4> Ref;
+};
+class JSONOptionalInteger : public TypedJSONValue<int, true> {
+ public:
+ typedef SmartPointer<JSONOptionalInteger> Ref;
+};
+class JSONOptionalBoolean : public TypedJSONValue<bool, true> {
+ public:
+ typedef SmartPointer<JSONOptionalBoolean> Ref;
+};
+class JSONOptionalString : public TypedJSONValue<String, true> {
+ public:
+ typedef SmartPointer<JSONOptionalString> Ref;
+};
+
+// A JSONObject is a used for serialization only and is not part of the normal
+// O3D plugin. It is used to easily add name/value pairs to be serialized by the
+// serializer as JSON objects. Being that it's ParamObject you have 2 choices
+// for getting data serialized. As O3D Params or as JSONValues. The reason to
+// use one over the other... Params can be animated but are relatively heavy.
+// JSONValues become plane JavaScript when deserialized.
+// To add a Param use RegisterParamRef, to add a JSONValue use
+// RegisterJSONValue.
+class JSONObject : public ParamObject {
+ public:
+ typedef SmartPointer<JSONObject> Ref;
+ typedef std::map<String, JSONValue::Ref> NameValueMap;
+
+ // Seralizes the JSONObject.
+ void Serialize(StructuredWriter* writer) const;
+
+ protected:
+ explicit JSONObject(ServiceLocator* service_locator);
+
+ // Registers a pointer to a reference to a JSONValue.
+ // Parameters:
+ // name: name of JSONValue
+ // ref_pointer: Pointer to typed reference to JSONValue.
+ template<typename T>
+ void RegisterJSONValue(const String& name, T* ref_pointer) {
+ *ref_pointer = T(new typename T::ClassType());
+ AddProperty(name, ref_pointer->Get());
+ }
+
+ private:
+ // Adds a property to this JSON Object.
+ void AddProperty(const String& name, JSONValue* value);
+
+ NameValueMap properties_;
+
+ O3D_OBJECT_BASE_DECL_CLASS(JSONObject, ParamObject);
+ DISALLOW_COPY_AND_ASSIGN(JSONObject);
+};
+
+} // namespace o3d
+
+#endif // O3D_IMPORT_CROSS_JSON_OBJECT_H_
+
+
diff --git a/o3d/import/cross/json_object_test.cc b/o3d/import/cross/json_object_test.cc new file mode 100644 index 0000000..ff745a2 --- /dev/null +++ b/o3d/import/cross/json_object_test.cc @@ -0,0 +1,449 @@ +/*
+ * 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);
+ }
+
+ 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_);
+ }
+
+ friend class IClassManager;
+ static ObjectBase::Ref Create(ServiceLocator* service_locator) {
+ return ObjectBase::Ref(new TestJSONObject(service_locator));
+ }
+
+ // 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
+
diff --git a/o3d/serializer/cross/serializer.cc b/o3d/serializer/cross/serializer.cc index 96dd01b..5e70c67 100644 --- a/o3d/serializer/cross/serializer.cc +++ b/o3d/serializer/cross/serializer.cc @@ -49,6 +49,7 @@ #include "core/cross/transform.h" #include "import/cross/destination_buffer.h" #include "import/cross/iarchive_generator.h" +#include "import/cross/json_object.h" #include "import/cross/memory_buffer.h" #include "import/cross/memory_stream.h" #include "serializer/cross/version.h" @@ -221,6 +222,7 @@ class PropertiesVisitor : public VisitorBase<PropertiesVisitor> { Enable<Curve>(&PropertiesVisitor::Visit); Enable<Element>(&PropertiesVisitor::Visit); Enable<NamedObject>(&PropertiesVisitor::Visit); + Enable<JSONObject>(&PropertiesVisitor::Visit); Enable<Pack>(&PropertiesVisitor::Visit); Enable<Primitive>(&PropertiesVisitor::Visit); Enable<Shape>(&PropertiesVisitor::Visit); @@ -252,6 +254,11 @@ class PropertiesVisitor : public VisitorBase<PropertiesVisitor> { Serialize(writer_, element->owner()); } + void Visit(JSONObject* object) { + Visit(static_cast<ParamObject*>(object)); + object->Serialize(writer_); + } + void Visit(NamedObject* object) { Visit(static_cast<ObjectBase*>(object)); @@ -624,8 +631,6 @@ class BinaryVisitor : public VisitorBase<BinaryVisitor> { void Visit(ObjectBase* object) { } - // TODO: Replace this when we have code to serialize to the - // final binary format. This is just placeholder. void Visit(Curve* curve) { Visit(static_cast<NamedObject*>(curve)); diff --git a/o3d/tests/build.scons b/o3d/tests/build.scons index b622edb..e79d9de 100644 --- a/o3d/tests/build.scons +++ b/o3d/tests/build.scons @@ -217,9 +217,11 @@ tests = [ 'core/cross/vertex_source_test.cc', 'core/cross/visitor_base_test.cc', 'core/cross/weak_ptr_test.cc', + 'import/cross/camera_info_test.cc', 'import/cross/destination_buffer_test.cc', 'import/cross/gz_compressor_test.cc', 'import/cross/gz_decompressor_test.cc', + 'import/cross/json_object_test.cc', 'import/cross/memory_buffer_test.cc', 'import/cross/memory_stream_test.cc', 'import/cross/raw_data_test.cc', @@ -232,6 +234,8 @@ tests = [ 'utils/cross/file_path_utils_test.cc', 'utils/cross/file_text_reader_test.cc', 'utils/cross/json_writer_test.cc', + 'utils/cross/math_gtest.cc', + 'utils/cross/math_gtest_test.cc', 'utils/cross/string_reader_test.cc', 'utils/cross/string_writer_test.cc', 'utils/cross/temporary_file_test.cc', diff --git a/o3d/utils/cross/math_gtest.cc b/o3d/utils/cross/math_gtest.cc new file mode 100644 index 0000000..0f7cc90d --- /dev/null +++ b/o3d/utils/cross/math_gtest.cc @@ -0,0 +1,119 @@ +/*
+ * 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 some helper for gtest for the math library used by O3D.
+
+#include "utils/cross/math_gtest.h"
+#include "core/cross/types.h"
+
+
+namespace Vectormath {
+namespace Aos {
+
+bool operator==(const Vector4& left, const Vector4& right) {
+ return left[0] == right[0] && left[1] == right[1] && left[2] == right[2] &&
+ left[3] == right[3];
+}
+
+bool operator!=(const Vector4& left, const Vector4& right) {
+ return !(left == right);
+}
+
+bool operator==(const Matrix4& left, const Matrix4& right) {
+ return left[0] == right[0] && left[1] == right[1] && left[2] == right[2] &&
+ left[3] == right[3];
+}
+
+bool operator!=(const Matrix4& left, const Matrix4& right) {
+ return !(left == right);
+}
+
+std::ostream& operator<<(std::ostream& stream, const Vector4& value) {
+ stream << "{" << value[0] << ", " << value[1] << ", " << value[2] << ", "
+ << value[3] << "}";
+ return stream;
+}
+
+std::ostream& operator<<(std::ostream& stream, const Matrix4& value) {
+ stream << "{" << value[0] << ", " << value[1] << ", " << value[2] << ", "
+ << value[3] << "}";
+ return stream;
+}
+
+} // namespace Aos
+} // namespace Vectormath
+
+namespace o3d {
+
+bool operator==(const Float2& left, const Float2& right) {
+ return left[0] == right[0] && left[1] == right[1];
+}
+
+bool operator!=(const Float2& left, const Float2& right) {
+ return !(left == right);
+}
+
+bool operator==(const Float3& left, const Float3& right) {
+ return left[0] == right[0] && left[1] == right[1] && left[2] == right[2];
+}
+
+bool operator!=(const Float3& left, const Float3& right) {
+ return !(left == right);
+}
+
+bool operator==(const Float4& left, const Float4& right) {
+ return left[0] == right[0] && left[1] == right[1] && left[2] == right[2] &&
+ left[3] == right[3];
+}
+
+bool operator!=(const Float4& left, const Float4& right) {
+ return !(left == right);
+}
+
+std::ostream& operator<<(std::ostream& stream, const Float2& value) {
+ stream << "{" << value[0] << ", " << value[1] << "}";
+ return stream;
+}
+
+std::ostream& operator<<(std::ostream& stream, const Float3& value) {
+ stream << "{" << value[0] << ", " << value[1] << ", " << value[2] << "}";
+ return stream;
+}
+
+std::ostream& operator<<(std::ostream& stream, const Float4& value) {
+ stream << "{" << value[0] << ", " << value[1] << ", " << value[2] << ", "
+ << value[3] << "}";
+ return stream;
+}
+
+} // namespace o3d
+
+
diff --git a/o3d/utils/cross/math_gtest.h b/o3d/utils/cross/math_gtest.h new file mode 100644 index 0000000..08ce096 --- /dev/null +++ b/o3d/utils/cross/math_gtest.h @@ -0,0 +1,71 @@ +/*
+ * 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 declares the some helper for gtest for the math library used by
+// O3D.
+
+#ifndef O3D_UTILS_CROSS_MATH_GTEST_H_
+#define O3D_UTILS_CROSS_MATH_GTEST_H_
+
+#include <ostream> // NOLINT
+
+namespace Vectormath {
+namespace Aos {
+class Vector4;
+class Matrix4;
+
+bool operator==(const Vector4& left, const Vector4& right);
+bool operator!=(const Vector4& left, const Vector4& right);
+bool operator==(const Matrix4& left, const Matrix4& right);
+bool operator!=(const Matrix4& left, const Matrix4& right);
+std::ostream& operator<<(std::ostream& stream, const Vector4& value);
+std::ostream& operator<<(std::ostream& stream, const Matrix4& value);
+}
+}
+
+namespace o3d {
+class Float2;
+class Float3;
+class Float4;
+
+bool operator==(const Float2& left, const Float2& right);
+bool operator!=(const Float2& left, const Float2& right);
+bool operator==(const Float3& left, const Float3& right);
+bool operator!=(const Float3& left, const Float3& right);
+bool operator==(const Float4& left, const Float4& right);
+bool operator!=(const Float4& left, const Float4& right);
+std::ostream& operator<<(std::ostream& stream, const Float2& value);
+std::ostream& operator<<(std::ostream& stream, const Float3& value);
+std::ostream& operator<<(std::ostream& stream, const Float4& value);
+}
+
+#endif // O3D_UTILS_CROSS_MATH_GTEST_H_
+
diff --git a/o3d/utils/cross/math_gtest_test.cc b/o3d/utils/cross/math_gtest_test.cc new file mode 100644 index 0000000..a0e4f00 --- /dev/null +++ b/o3d/utils/cross/math_gtest_test.cc @@ -0,0 +1,70 @@ +/*
+ * 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 "utils/cross/math_gtest.h"
+
+namespace o3d {
+
+class MathGTestTest : public testing::Test {
+};
+
+// Test the math gtest helper functions.
+TEST_F(MathGTestTest, TestMathGTest) {
+ EXPECT_EQ(Float2(1.2f, 2.3f), Float2(1.2f, 2.3f));
+ EXPECT_NE(Float2(1.2f, 2.3f), Float2(1.3f, 2.3f));
+ EXPECT_NE(Float2(1.2f, 2.3f), Float2(1.2f, 2.4f));
+ EXPECT_EQ(Float3(1.2f, 2.3f, 4.5f), Float3(1.2f, 2.3f, 4.5f));
+ EXPECT_NE(Float3(1.2f, 2.3f, 4.5f), Float3(1.3f, 2.3f, 4.5f));
+ EXPECT_NE(Float3(1.2f, 2.3f, 4.5f), Float3(1.2f, 2.4f, 4.5f));
+ EXPECT_NE(Float3(1.2f, 2.3f, 4.5f), Float3(1.2f, 2.3f, 4.6f));
+ EXPECT_EQ(Float4(1.2f, 2.3f, 4.5f, 6.7f), Float4(1.2f, 2.3f, 4.5f, 6.7f));
+ EXPECT_NE(Float4(1.2f, 2.3f, 4.5f, 6.7f), Float4(1.3f, 2.3f, 4.5f, 6.7f));
+ EXPECT_NE(Float4(1.2f, 2.3f, 4.5f, 6.7f), Float4(1.2f, 2.4f, 4.5f, 6.7f));
+ EXPECT_NE(Float4(1.2f, 2.3f, 4.5f, 6.7f), Float4(1.2f, 2.3f, 4.6f, 6.7f));
+ EXPECT_NE(Float4(1.2f, 2.3f, 4.5f, 6.7f), Float4(1.2f, 2.3f, 4.5f, 6.8f));
+ Matrix4 a(Vector4(1.1f, 2.2f, 3.3f, 4.4f),
+ Vector4(1.2f, 2.3f, 3.4f, 4.5f),
+ Vector4(1.3f, 2.4f, 3.5f, 4.6f),
+ Vector4(1.4f, 2.5f, 3.6f, 4.7f));
+ Matrix4 b(a);
+ EXPECT_EQ(a, b);
+ for (int ii = 0; ii < 4; ++ii) {
+ for (int jj = 0; jj < 4; ++jj) {
+ b = a;
+ b.setElem(ii, jj, b.getElem(ii, jj) * 2);
+ EXPECT_NE(a, b);
+ }
+ }
+}
+
+} // namespace o3d
+
|