From db18016ef05383cf451438bf9bf92f0df25f506b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 21 Aug 2016 20:59:19 +0200 Subject: [PATCH] Trade: test construction and assignments of the container classes. --- src/Magnum/Trade/CameraData.h | 12 ++ src/Magnum/Trade/PhongMaterialData.cpp | 47 ++++- src/Magnum/Trade/PhongMaterialData.h | 32 ++-- src/Magnum/Trade/Test/CMakeLists.txt | 4 + src/Magnum/Trade/Test/CameraDataTest.cpp | 121 +++++++++++++ src/Magnum/Trade/Test/MaterialDataTest.cpp | 192 ++++++++++++++++++++- src/Magnum/Trade/Test/MeshData2DTest.cpp | 143 +++++++++++++++ src/Magnum/Trade/Test/MeshData3DTest.cpp | 169 ++++++++++++++++++ src/Magnum/Trade/Test/ObjectData2DTest.cpp | 82 ++++++++- src/Magnum/Trade/Test/ObjectData3DTest.cpp | 94 +++++++++- src/Magnum/Trade/Test/SceneDataTest.cpp | 82 +++++++++ src/Magnum/Trade/Test/TextureDataTest.cpp | 77 ++++++++- 12 files changed, 1030 insertions(+), 25 deletions(-) create mode 100644 src/Magnum/Trade/Test/CameraDataTest.cpp create mode 100644 src/Magnum/Trade/Test/MeshData2DTest.cpp create mode 100644 src/Magnum/Trade/Test/MeshData3DTest.cpp create mode 100644 src/Magnum/Trade/Test/SceneDataTest.cpp diff --git a/src/Magnum/Trade/CameraData.h b/src/Magnum/Trade/CameraData.h index 7daa4acd2..1b7f2d7b8 100644 --- a/src/Magnum/Trade/CameraData.h +++ b/src/Magnum/Trade/CameraData.h @@ -54,6 +54,18 @@ class CameraData { */ explicit CameraData(Rad fov, Float near, Float far, const void* importerState = nullptr) noexcept; + /** @brief Copying is not allowed */ + CameraData(const CameraData&) = delete; + + /** @brief Move constructor */ + CameraData(CameraData&&) noexcept = default; + + /** @brief Copying is not allowed */ + CameraData& operator=(const CameraData&) = delete; + + /** @brief Move assignment */ + CameraData& operator=(CameraData&&) noexcept = default; + /** @brief Field-of-view angle */ Rad fov() const { return _fov; } diff --git a/src/Magnum/Trade/PhongMaterialData.cpp b/src/Magnum/Trade/PhongMaterialData.cpp index ff427d677..2d8423ea2 100644 --- a/src/Magnum/Trade/PhongMaterialData.cpp +++ b/src/Magnum/Trade/PhongMaterialData.cpp @@ -27,7 +27,48 @@ namespace Magnum { namespace Trade { -Vector3& PhongMaterialData::ambientColor() { +PhongMaterialData::PhongMaterialData(PhongMaterialData&& other) noexcept: AbstractMaterialData{std::move(other)}, _flags{std::move(other._flags)}, _shininess{std::move(other._shininess)} { + if(_flags & Flag::AmbientTexture) + _ambient.texture = other._ambient.texture; + else + _ambient.color = other._ambient.color; + + if(_flags & Flag::DiffuseTexture) + _diffuse.texture = other._diffuse.texture; + else + _diffuse.color = other._diffuse.color; + + if(_flags & Flag::SpecularTexture) + _specular.texture = other._specular.texture; + else + _specular.color = other._specular.color; +} + +PhongMaterialData& PhongMaterialData::operator=(PhongMaterialData&& other) noexcept { + AbstractMaterialData::operator=(std::move(other)); + + _flags = other._flags; + _shininess = other._shininess; + + if(_flags & Flag::AmbientTexture) + _ambient.texture = other._ambient.texture; + else + _ambient.color = other._ambient.color; + + if(_flags & Flag::DiffuseTexture) + _diffuse.texture = other._diffuse.texture; + else + _diffuse.color = other._diffuse.color; + + if(_flags & Flag::SpecularTexture) + _specular.texture = other._specular.texture; + else + _specular.color = other._specular.color; + + return *this; +} + +Color3& PhongMaterialData::ambientColor() { CORRADE_ASSERT(!(_flags & Flag::AmbientTexture), "Trade::PhongMaterialData::ambientColor(): the material has ambient texture", _ambient.color); return _ambient.color; } @@ -37,7 +78,7 @@ UnsignedInt& PhongMaterialData::ambientTexture() { return _ambient.texture; } -Vector3& PhongMaterialData::diffuseColor() { +Color3& PhongMaterialData::diffuseColor() { CORRADE_ASSERT(!(_flags & Flag::DiffuseTexture), "Trade::PhongMaterialData::diffuseColor(): the material has diffuse texture", _diffuse.color); return _diffuse.color; } @@ -47,7 +88,7 @@ UnsignedInt& PhongMaterialData::diffuseTexture() { return _diffuse.texture; } -Vector3& PhongMaterialData::specularColor() { +Color3& PhongMaterialData::specularColor() { CORRADE_ASSERT(!(_flags & Flag::SpecularTexture), "Trade::PhongMaterialData::specularColor(): the material has specular texture", _specular.color); return _specular.color; } diff --git a/src/Magnum/Trade/PhongMaterialData.h b/src/Magnum/Trade/PhongMaterialData.h index 2b076b2e4..3bc231175 100644 --- a/src/Magnum/Trade/PhongMaterialData.h +++ b/src/Magnum/Trade/PhongMaterialData.h @@ -30,7 +30,7 @@ */ #include "Magnum/Magnum.h" -#include "Magnum/Math/Vector3.h" +#include "Magnum/Math/Color.h" #include "Magnum/Trade/AbstractMaterialData.h" namespace Magnum { namespace Trade { @@ -75,6 +75,18 @@ class MAGNUM_EXPORT PhongMaterialData: public AbstractMaterialData { */ explicit PhongMaterialData(Flags flags, Float shininess, const void* importerState = nullptr) noexcept: AbstractMaterialData{MaterialType::Phong, importerState}, _flags{flags}, _shininess{shininess} {} + /** @brief Copying is not allowed */ + PhongMaterialData(const PhongMaterialData&) = delete; + + /** @brief Move constructor */ + PhongMaterialData(PhongMaterialData&& other) noexcept; + + /** @brief Copying is not allowed */ + PhongMaterialData& operator=(const PhongMaterialData&) = delete; + + /** @brief Move assignment */ + PhongMaterialData& operator=(PhongMaterialData&& other) noexcept; + /** @brief Material flags */ Flags flags() const { return _flags; } @@ -84,8 +96,8 @@ class MAGNUM_EXPORT PhongMaterialData: public AbstractMaterialData { * Available only if the material doesn't have @ref Flag::AmbientTexture. * @see @ref flags() */ - Vector3& ambientColor(); - Vector3 ambientColor() const; /**< @overload */ + Color3& ambientColor(); + Color3 ambientColor() const; /**< @overload */ /** * @brief Ambient texture ID @@ -102,8 +114,8 @@ class MAGNUM_EXPORT PhongMaterialData: public AbstractMaterialData { * Available only if the material doesn't have @ref Flag::DiffuseTexture. * @see @ref flags() */ - Vector3& diffuseColor(); - Vector3 diffuseColor() const; /**< @overload */ + Color3& diffuseColor(); + Color3 diffuseColor() const; /**< @overload */ /** * @brief Diffuse texture ID @@ -120,8 +132,8 @@ class MAGNUM_EXPORT PhongMaterialData: public AbstractMaterialData { * Available only if the material doesn't have @ref Flag::SpecularTexture. * @see @ref flags() */ - Vector3& specularColor(); - Vector3 specularColor() const; /**< @overload */ + Color3& specularColor(); + Color3 specularColor() const; /**< @overload */ /** * @brief Specular texture ID @@ -154,7 +166,7 @@ CORRADE_ENUMSET_OPERATORS(PhongMaterialData::Flags) /* Ugly as hell. */ -inline Vector3 PhongMaterialData::ambientColor() const { +inline Color3 PhongMaterialData::ambientColor() const { return const_cast(this)->ambientColor(); } @@ -162,7 +174,7 @@ inline UnsignedInt PhongMaterialData::ambientTexture() const { return const_cast(this)->ambientTexture(); } -inline Vector3 PhongMaterialData::diffuseColor() const { +inline Color3 PhongMaterialData::diffuseColor() const { return const_cast(this)->diffuseColor(); } @@ -170,7 +182,7 @@ inline UnsignedInt PhongMaterialData::diffuseTexture() const { return const_cast(this)->diffuseTexture(); } -inline Vector3 PhongMaterialData::specularColor() const { +inline Color3 PhongMaterialData::specularColor() const { return const_cast(this)->specularColor(); } diff --git a/src/Magnum/Trade/Test/CMakeLists.txt b/src/Magnum/Trade/Test/CMakeLists.txt index 17e56b827..7268fef08 100644 --- a/src/Magnum/Trade/Test/CMakeLists.txt +++ b/src/Magnum/Trade/Test/CMakeLists.txt @@ -38,10 +38,14 @@ corrade_add_test(TradeAbstractImageConverterTest AbstractImageConverterTest.cpp target_include_directories(TradeAbstractImageConverterTest PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) corrade_add_test(TradeAbstractImporterTest AbstractImporterTest.cpp LIBRARIES Magnum) target_include_directories(TradeAbstractImporterTest PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) +corrade_add_test(TradeCameraDataTest CameraDataTest.cpp LIBRARIES Magnum) corrade_add_test(TradeImageDataTest ImageDataTest.cpp LIBRARIES Magnum) corrade_add_test(TradeMaterialDataTest MaterialDataTest.cpp LIBRARIES Magnum) +corrade_add_test(TradeMeshData2DTest MeshData2DTest.cpp LIBRARIES Magnum) +corrade_add_test(TradeMeshData3DTest MeshData3DTest.cpp LIBRARIES Magnum) corrade_add_test(TradeObjectData2DTest ObjectData2DTest.cpp LIBRARIES Magnum) corrade_add_test(TradeObjectData3DTest ObjectData3DTest.cpp LIBRARIES Magnum) +corrade_add_test(TradeSceneDataTest SceneDataTest.cpp LIBRARIES Magnum) corrade_add_test(TradeTextureDataTest TextureDataTest.cpp LIBRARIES Magnum) if(CORRADE_TARGET_EMSCRIPTEN) diff --git a/src/Magnum/Trade/Test/CameraDataTest.cpp b/src/Magnum/Trade/Test/CameraDataTest.cpp new file mode 100644 index 000000000..be7ae405b --- /dev/null +++ b/src/Magnum/Trade/Test/CameraDataTest.cpp @@ -0,0 +1,121 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016 + Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include + +#include "Magnum/Trade/CameraData.h" + +namespace Magnum { namespace Trade { namespace Test { + +struct CameraDataTest: TestSuite::Tester { + explicit CameraDataTest(); + + void construct(); + void constructDefaults(); + void constructCopy(); + void constructMove(); +}; + +namespace { + +using namespace Math::Literals; + +enum: std::size_t { ConstructDefaultsDataCount = 3 }; + +struct { + const char* name; + Rad fov, expectedFov; + Float near, expectedNear; + Float far, expectedFar; +} ConstructDefaultsData[ConstructDefaultsDataCount]{ + {"fov", Rad{Constants::nan()}, 35.0_degf, 0.5f, 0.5f, 120.0f, 120.0f}, + {"near", 25.0_degf, 25.0_degf, Constants::nan(), 0.01f, 120.0f, 120.0f}, + {"far", 25.0_degf, 25.0_degf, 0.5f, 0.5f, Constants::nan(), 100.0f} +}; + +} + +CameraDataTest::CameraDataTest() { + addTests({&CameraDataTest::construct}); + + addInstancedTests({&CameraDataTest::constructDefaults}, ConstructDefaultsDataCount); + + addTests({&CameraDataTest::constructCopy, + &CameraDataTest::constructMove}); +} + +void CameraDataTest::construct() { + const int a{}; + CameraData data{25.0_degf, 0.001f, 1000.0f, &a}; + + CORRADE_COMPARE(data.fov(), 25.0_degf); + CORRADE_COMPARE(data.near(), 0.001f); + CORRADE_COMPARE(data.far(), 1000.0f); + CORRADE_COMPARE(data.importerState(), &a); +} + +void CameraDataTest::constructDefaults() { + setTestCaseDescription(ConstructDefaultsData[testCaseInstanceId()].name); + + const int a{}; + CameraData data{ + ConstructDefaultsData[testCaseInstanceId()].fov, + ConstructDefaultsData[testCaseInstanceId()].near, + ConstructDefaultsData[testCaseInstanceId()].far, + &a}; + + CORRADE_COMPARE(data.fov(), ConstructDefaultsData[testCaseInstanceId()].expectedFov); + CORRADE_COMPARE(data.near(), ConstructDefaultsData[testCaseInstanceId()].expectedNear); + CORRADE_COMPARE(data.far(), ConstructDefaultsData[testCaseInstanceId()].expectedFar); + CORRADE_COMPARE(data.importerState(), &a); +} + +void CameraDataTest::constructCopy() { + CORRADE_VERIFY(!(std::is_constructible{})); + CORRADE_VERIFY(!(std::is_assignable{})); +} + +void CameraDataTest::constructMove() { + const int a{}; + CameraData data{25.0_degf, 0.001f, 1000.0f, &a}; + + CameraData b{std::move(data)}; + CORRADE_COMPARE(b.fov(), 25.0_degf); + CORRADE_COMPARE(b.near(), 0.001f); + CORRADE_COMPARE(b.far(), 1000.0f); + CORRADE_COMPARE(b.importerState(), &a); + + const int c{}; + CameraData d{75.0_degf, 0.5f, 10.0f, &c}; + d = std::move(b); + CORRADE_COMPARE(d.fov(), 25.0_degf); + CORRADE_COMPARE(d.near(), 0.001f); + CORRADE_COMPARE(d.far(), 1000.0f); + CORRADE_COMPARE(d.importerState(), &a); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::Trade::Test::CameraDataTest) diff --git a/src/Magnum/Trade/Test/MaterialDataTest.cpp b/src/Magnum/Trade/Test/MaterialDataTest.cpp index e87164b7d..1685bacd9 100644 --- a/src/Magnum/Trade/Test/MaterialDataTest.cpp +++ b/src/Magnum/Trade/Test/MaterialDataTest.cpp @@ -34,11 +34,201 @@ class MaterialDataTest: public TestSuite::Tester { public: explicit MaterialDataTest(); + void constructPhong(); + void constructPhongAmbientTexture(); + void constructPhongDiffuseTexture(); + void constructPhongSpecularTexture(); + void constructCopy(); + void constructMovePhongNoAmbientTexture(); + void constructMovePhongNoDiffuseTexture(); + void constructMovePhongNoSpecularTexture(); + void debugType(); }; MaterialDataTest::MaterialDataTest() { - addTests({&MaterialDataTest::debugType}); + addTests({&MaterialDataTest::constructPhong, + &MaterialDataTest::constructPhongAmbientTexture, + &MaterialDataTest::constructPhongDiffuseTexture, + &MaterialDataTest::constructPhongSpecularTexture, + &MaterialDataTest::constructCopy, + &MaterialDataTest::constructMovePhongNoAmbientTexture, + &MaterialDataTest::constructMovePhongNoDiffuseTexture, + &MaterialDataTest::constructMovePhongNoSpecularTexture, + + &MaterialDataTest::debugType}); +} + +void MaterialDataTest::constructPhong() { + using namespace Math::Literals; + + const int a{}; + PhongMaterialData data{{}, 80.0f, &a}; + data.ambientColor() = 0xccffbb_rgbf; + data.diffuseColor() = 0xeebbff_rgbf; + data.specularColor() = 0xacabad_rgbf; + + const PhongMaterialData& cdata = data; + + CORRADE_VERIFY(cdata.flags() == PhongMaterialData::Flags{}); + CORRADE_COMPARE(cdata.ambientColor(), 0xccffbb_rgbf); + CORRADE_COMPARE(cdata.diffuseColor(), 0xeebbff_rgbf); + CORRADE_COMPARE(cdata.specularColor(), 0xacabad_rgbf); + CORRADE_COMPARE(cdata.shininess(), 80.0f); +} + +void MaterialDataTest::constructPhongAmbientTexture() { + using namespace Math::Literals; + + const int a{}; + PhongMaterialData data{PhongMaterialData::Flag::AmbientTexture, 80.0f, &a}; + data.ambientTexture() = 42; + data.diffuseColor() = 0xeebbff_rgbf; + data.specularColor() = 0xacabad_rgbf; + + const PhongMaterialData& cdata = data; + + CORRADE_VERIFY(cdata.flags() == PhongMaterialData::Flag::AmbientTexture); + CORRADE_COMPARE(cdata.ambientTexture(), 42); + CORRADE_COMPARE(cdata.diffuseColor(), 0xeebbff_rgbf); + CORRADE_COMPARE(cdata.specularColor(), 0xacabad_rgbf); + CORRADE_COMPARE(cdata.shininess(), 80.0f); +} + +void MaterialDataTest::constructPhongDiffuseTexture() { + using namespace Math::Literals; + + const int a{}; + PhongMaterialData data{PhongMaterialData::Flag::DiffuseTexture, 80.0f, &a}; + data.ambientColor() = 0xccffbb_rgbf; + data.diffuseTexture() = 42; + data.specularColor() = 0xacabad_rgbf; + + const PhongMaterialData& cdata = data; + + CORRADE_VERIFY(cdata.flags() == PhongMaterialData::Flag::DiffuseTexture); + CORRADE_COMPARE(cdata.ambientColor(), 0xccffbb_rgbf); + CORRADE_COMPARE(cdata.diffuseTexture(), 42); + CORRADE_COMPARE(cdata.specularColor(), 0xacabad_rgbf); + CORRADE_COMPARE(cdata.shininess(), 80.0f); +} + +void MaterialDataTest::constructPhongSpecularTexture() { + using namespace Math::Literals; + + const int a{}; + PhongMaterialData data{PhongMaterialData::Flag::SpecularTexture, 30.0f, &a}; + data.ambientColor() = 0xccffbb_rgbf; + data.diffuseColor() = 0xeebbff_rgbf; + data.specularTexture() = 42; + + const PhongMaterialData& cdata = data; + + CORRADE_VERIFY(cdata.flags() == PhongMaterialData::Flag::SpecularTexture); + CORRADE_COMPARE(cdata.ambientColor(), 0xccffbb_rgbf); + CORRADE_COMPARE(cdata.diffuseColor(), 0xeebbff_rgbf); + CORRADE_COMPARE(cdata.specularTexture(), 42); + CORRADE_COMPARE(cdata.shininess(), 30.0f); +} + +void MaterialDataTest::constructCopy() { + CORRADE_VERIFY(!(std::is_constructible{})); + CORRADE_VERIFY(!(std::is_constructible{})); + CORRADE_VERIFY(!(std::is_assignable{})); + CORRADE_VERIFY(!(std::is_assignable{})); +} + +void MaterialDataTest::constructMovePhongNoAmbientTexture() { + using namespace Math::Literals; + + const int a{}; + PhongMaterialData data{PhongMaterialData::Flag::DiffuseTexture|PhongMaterialData::Flag::SpecularTexture, 80.0f, &a}; + data.ambientColor() = 0xccffbb_rgbf; + data.diffuseTexture() = 42; + data.specularTexture() = 13; + + PhongMaterialData b{std::move(data)}; + + CORRADE_VERIFY(b.flags() == (PhongMaterialData::Flag::DiffuseTexture|PhongMaterialData::Flag::SpecularTexture)); + CORRADE_COMPARE(b.ambientColor(), 0xccffbb_rgbf); + CORRADE_COMPARE(b.diffuseTexture(), 42); + CORRADE_COMPARE(b.specularTexture(), 13); + CORRADE_COMPARE(b.shininess(), 80.0f); + + const int c{}; + PhongMaterialData d{PhongMaterialData::Flag::AmbientTexture, 100.0f, &c}; + d.ambientTexture() = 42; + d.diffuseColor() = 0xeebbff_rgbf; + d.specularColor() = 0xacabad_rgbf; + d = std::move(b); + + CORRADE_VERIFY(d.flags() == (PhongMaterialData::Flag::DiffuseTexture|PhongMaterialData::Flag::SpecularTexture)); + CORRADE_COMPARE(d.ambientColor(), 0xccffbb_rgbf); + CORRADE_COMPARE(d.diffuseTexture(), 42); + CORRADE_COMPARE(d.specularTexture(), 13); + CORRADE_COMPARE(d.shininess(), 80.0f); +} + +void MaterialDataTest::constructMovePhongNoDiffuseTexture() { + using namespace Math::Literals; + + const int a{}; + PhongMaterialData data{PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::SpecularTexture, 80.0f, &a}; + data.ambientTexture() = 42; + data.diffuseColor() = 0xeebbff_rgbf; + data.specularTexture() = 13; + + PhongMaterialData b{std::move(data)}; + + CORRADE_VERIFY(b.flags() == (PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::SpecularTexture)); + CORRADE_COMPARE(b.ambientTexture(), 42); + CORRADE_COMPARE(b.diffuseColor(), 0xeebbff_rgbf); + CORRADE_COMPARE(b.specularTexture(), 13); + CORRADE_COMPARE(b.shininess(), 80.0f); + + const int c{}; + PhongMaterialData d{PhongMaterialData::Flag::DiffuseTexture, 100.0f, &c}; + d.ambientColor() = 0xccffbb_rgbf; + d.diffuseTexture() = 42; + d.specularColor() = 0xacabad_rgbf; + d = std::move(b); + + CORRADE_VERIFY(d.flags() == (PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::SpecularTexture)); + CORRADE_COMPARE(d.ambientTexture(), 42); + CORRADE_COMPARE(d.diffuseColor(), 0xeebbff_rgbf); + CORRADE_COMPARE(d.specularTexture(), 13); + CORRADE_COMPARE(d.shininess(), 80.0f); +} + +void MaterialDataTest::constructMovePhongNoSpecularTexture() { + using namespace Math::Literals; + + const int a{}; + PhongMaterialData data{PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::DiffuseTexture, 80.0f, &a}; + data.ambientTexture() = 13; + data.diffuseTexture() = 42; + data.specularColor() = 0xacabad_rgbf; + + PhongMaterialData b{std::move(data)}; + + CORRADE_VERIFY(b.flags() == (PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::DiffuseTexture)); + CORRADE_COMPARE(b.ambientTexture(), 13); + CORRADE_COMPARE(b.diffuseTexture(), 42); + CORRADE_COMPARE(b.specularColor(), 0xacabad_rgbf); + CORRADE_COMPARE(b.shininess(), 80.0f); + + const int c{}; + PhongMaterialData d{PhongMaterialData::Flag::SpecularTexture, 30.0f, &c}; + d.ambientColor() = 0xccffbb_rgbf; + d.diffuseColor() = 0xeebbff_rgbf; + d.specularTexture() = 42; + d = std::move(b); + + CORRADE_VERIFY(d.flags() == (PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::DiffuseTexture)); + CORRADE_COMPARE(d.ambientTexture(), 13); + CORRADE_COMPARE(d.diffuseTexture(), 42); + CORRADE_COMPARE(d.specularColor(), 0xacabad_rgbf); + CORRADE_COMPARE(d.shininess(), 80.0f); } void MaterialDataTest::debugType() { diff --git a/src/Magnum/Trade/Test/MeshData2DTest.cpp b/src/Magnum/Trade/Test/MeshData2DTest.cpp new file mode 100644 index 000000000..639891355 --- /dev/null +++ b/src/Magnum/Trade/Test/MeshData2DTest.cpp @@ -0,0 +1,143 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016 + Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include + +#include "Magnum/Mesh.h" +#include "Magnum/Math/Vector2.h" +#include "Magnum/Trade/MeshData2D.h" + +namespace Magnum { namespace Trade { namespace Test { + +struct MeshData2DTest: TestSuite::Tester { + explicit MeshData2DTest(); + + void construct(); + void constructNonIndexed(); + void constructNoTexCoords(); + void constructCopy(); + void constructMove(); +}; + +MeshData2DTest::MeshData2DTest() { + addTests({&MeshData2DTest::construct, + &MeshData2DTest::constructNonIndexed, + &MeshData2DTest::constructNoTexCoords, + &MeshData2DTest::constructCopy, + &MeshData2DTest::constructMove}); +} + +void MeshData2DTest::construct() { + const int a{}; + const MeshData2D data{MeshPrimitive::Lines, {12, 1, 0}, + {{{0.5f, 1.0f}, {-1.0f, 0.3f}}, + {{1.4f, 0.2f}, {1.1f, 0.13f}}}, + {{{0.0f, 0.0f}, {0.3f, 0.7f}}, + {{0.1f, 0.2f}, {0.7f, 1.0f}}, + {{0.0f, 0.0f}, {1.0f, 1.0f}}}, + &a}; + + CORRADE_COMPARE(data.primitive(), MeshPrimitive::Lines); + + CORRADE_VERIFY(data.isIndexed()); + CORRADE_COMPARE(data.indices(), (std::vector{12, 1, 0})); + + CORRADE_COMPARE(data.positionArrayCount(), 2); + CORRADE_COMPARE(data.positions(0), (std::vector{{0.5f, 1.0f}, {-1.0f, 0.3f}})); + CORRADE_COMPARE(data.positions(1), (std::vector{{1.4f, 0.2f}, {1.1f, 0.13f}})); + + CORRADE_VERIFY(data.hasTextureCoords2D()); + CORRADE_COMPARE(data.textureCoords2DArrayCount(), 3); + CORRADE_COMPARE(data.textureCoords2D(0), (std::vector{{0.0f, 0.0f}, {0.3f, 0.7f}})); + CORRADE_COMPARE(data.textureCoords2D(1), (std::vector{{0.1f, 0.2f}, {0.7f, 1.0f}})); + CORRADE_COMPARE(data.textureCoords2D(2), (std::vector{{0.0f, 0.0f}, {1.0f, 1.0f}})); + + CORRADE_COMPARE(data.importerState(), &a); +} + +void MeshData2DTest::constructNonIndexed() { + const int a{}; + const MeshData2D data{MeshPrimitive::Lines, {}, + {{{0.5f, 1.0f}, {-1.0f, 0.3f}}}, + {{{0.0f, 0.0f}, {0.3f, 0.7f}}}, + &a}; + + CORRADE_VERIFY(!data.isIndexed()); +} + +void MeshData2DTest::constructNoTexCoords() { + const int a{}; + const MeshData2D data{MeshPrimitive::Lines, {12, 1, 0}, + {{{0.5f, 1.0f}, {-1.0f, 0.3f}}, + {{1.4f, 0.2f}, {1.1f, 0.13f}}}, + {}, + &a}; + + CORRADE_VERIFY(!data.hasTextureCoords2D()); + CORRADE_COMPARE(data.textureCoords2DArrayCount(), 0); +} + +void MeshData2DTest::constructCopy() { + CORRADE_VERIFY(!(std::is_constructible{})); + CORRADE_VERIFY(!(std::is_assignable{})); +} + +void MeshData2DTest::constructMove() { + const int a{}; + MeshData2D data{MeshPrimitive::LineStrip, {12, 1, 0}, + {{{0.5f, 1.0f}, {-1.0f, 0.3f}}}, + {{{0.0f, 0.0f}, {0.3f, 0.7f}}}, + &a}; + + MeshData2D b{std::move(data)}; + + CORRADE_COMPARE(b.primitive(), MeshPrimitive::LineStrip); + CORRADE_VERIFY(b.isIndexed()); + CORRADE_COMPARE(b.indices(), (std::vector{12, 1, 0})); + CORRADE_COMPARE(b.positionArrayCount(), 1); + CORRADE_COMPARE(b.positions(0), (std::vector{{0.5f, 1.0f}, {-1.0f, 0.3f}})); + CORRADE_COMPARE(b.textureCoords2DArrayCount(), 1); + CORRADE_COMPARE(b.textureCoords2D(0), (std::vector{{0.0f, 0.0f}, {0.3f, 0.7f}})); + CORRADE_COMPARE(b.importerState(), &a); + + const int c{}; + MeshData2D d{MeshPrimitive::TriangleFan, {}, + {{}}, + {}, + &c}; + d = std::move(b); + CORRADE_COMPARE(d.primitive(), MeshPrimitive::LineStrip); + CORRADE_VERIFY(d.isIndexed()); + CORRADE_COMPARE(d.indices(), (std::vector{12, 1, 0})); + CORRADE_COMPARE(d.positionArrayCount(), 1); + CORRADE_COMPARE(d.positions(0), (std::vector{{0.5f, 1.0f}, {-1.0f, 0.3f}})); + CORRADE_COMPARE(d.textureCoords2DArrayCount(), 1); + CORRADE_COMPARE(d.textureCoords2D(0), (std::vector{{0.0f, 0.0f}, {0.3f, 0.7f}})); + CORRADE_COMPARE(d.importerState(), &a); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::Trade::Test::MeshData2DTest) diff --git a/src/Magnum/Trade/Test/MeshData3DTest.cpp b/src/Magnum/Trade/Test/MeshData3DTest.cpp new file mode 100644 index 000000000..2ff7e8dce --- /dev/null +++ b/src/Magnum/Trade/Test/MeshData3DTest.cpp @@ -0,0 +1,169 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016 + Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include + +#include "Magnum/Mesh.h" +#include "Magnum/Math/Vector3.h" +#include "Magnum/Trade/MeshData3D.h" + +namespace Magnum { namespace Trade { namespace Test { + +struct MeshData3DTest: TestSuite::Tester { + explicit MeshData3DTest(); + + void construct(); + void constructNonIndexed(); + void constructNoNormals(); + void constructNoTexCoords(); + void constructCopy(); + void constructMove(); +}; + +MeshData3DTest::MeshData3DTest() { + addTests({&MeshData3DTest::construct, + &MeshData3DTest::constructNonIndexed, + &MeshData3DTest::constructNoNormals, + &MeshData3DTest::constructNoTexCoords, + &MeshData3DTest::constructCopy, + &MeshData3DTest::constructMove}); +} + +void MeshData3DTest::construct() { + const int a{}; + const MeshData3D data{MeshPrimitive::Lines, {12, 1, 0}, + {{{0.5f, 1.0f, 0.1f}, {-1.0f, 0.3f, -1.0f}}, + {{1.4f, 0.2f, 0.5f}, {1.1f, 0.13f, -0.3f}}}, + {{{0.0f, 1.0f, 0.0f}, {-1.0f, 0.0f, 0.0f}}}, + {{{0.0f, 0.0f}, {0.3f, 0.7f}}, + {{0.1f, 0.2f}, {0.7f, 1.0f}}, + {{0.0f, 0.0f}, {1.0f, 1.0f}}}, + &a}; + + CORRADE_COMPARE(data.primitive(), MeshPrimitive::Lines); + + CORRADE_VERIFY(data.isIndexed()); + CORRADE_COMPARE(data.indices(), (std::vector{12, 1, 0})); + + CORRADE_COMPARE(data.positionArrayCount(), 2); + CORRADE_COMPARE(data.positions(0), (std::vector{{0.5f, 1.0f, 0.1f}, {-1.0f, 0.3f, -1.0f}})); + CORRADE_COMPARE(data.positions(1), (std::vector{{1.4f, 0.2f, 0.5f}, {1.1f, 0.13f, -0.3f}})); + + CORRADE_VERIFY(data.hasNormals()); + CORRADE_COMPARE(data.normalArrayCount(), 1); + CORRADE_COMPARE(data.normals(0), (std::vector{{0.0f, 1.0f, 0.0f}, {-1.0f, 0.0f, 0.0f}})); + + CORRADE_VERIFY(data.hasTextureCoords2D()); + CORRADE_COMPARE(data.textureCoords2DArrayCount(), 3); + CORRADE_COMPARE(data.textureCoords2D(0), (std::vector{{0.0f, 0.0f}, {0.3f, 0.7f}})); + CORRADE_COMPARE(data.textureCoords2D(1), (std::vector{{0.1f, 0.2f}, {0.7f, 1.0f}})); + CORRADE_COMPARE(data.textureCoords2D(2), (std::vector{{0.0f, 0.0f}, {1.0f, 1.0f}})); + + CORRADE_COMPARE(data.importerState(), &a); +} + +void MeshData3DTest::constructNonIndexed() { + const int a{}; + const MeshData3D data{MeshPrimitive::Lines, {}, + {{{0.5f, 1.0f, 0.1f}, {-1.0f, 0.3f, -1.0f}}}, + {{{0.0f, 1.0f, 0.0f}, {-1.0f, 0.0f, 0.0f}}}, + {{{0.0f, 0.0f}, {0.3f, 0.7f}}}, + &a}; + + CORRADE_VERIFY(!data.isIndexed()); +} + +void MeshData3DTest::constructNoNormals() { + const int a{}; + const MeshData3D data{MeshPrimitive::Lines, {12, 1, 0}, + {{{0.5f, 1.0f, 0.1f}, {-1.0f, 0.3f, -1.0f}}}, + {}, + {{{0.0f, 0.0f}, {0.3f, 0.7f}}}, + &a}; + + CORRADE_VERIFY(!data.hasNormals()); + CORRADE_COMPARE(data.normalArrayCount(), 0); +} + +void MeshData3DTest::constructNoTexCoords() { + const int a{}; + const MeshData3D data{MeshPrimitive::Lines, {12, 1, 0}, + {{{0.5f, 1.0f, 0.1f}, {-1.0f, 0.3f, -1.0f}}}, + {{{0.0f, 1.0f, 0.0f}, {-1.0f, 0.0f, 0.0f}}}, + {}, + &a}; + + CORRADE_VERIFY(!data.hasTextureCoords2D()); + CORRADE_COMPARE(data.textureCoords2DArrayCount(), 0); +} + +void MeshData3DTest::constructCopy() { + CORRADE_VERIFY(!(std::is_constructible{})); + CORRADE_VERIFY(!(std::is_assignable{})); +} + +void MeshData3DTest::constructMove() { + const int a{}; + MeshData3D data{MeshPrimitive::LineStrip, {12, 1, 0}, + {{{0.5f, 1.0f, 0.1f}, {-1.0f, 0.3f, -1.0f}}}, + {{{0.0f, 1.0f, 0.0f}, {-1.0f, 0.0f, 0.0f}}}, + {{{0.0f, 0.0f}, {0.3f, 0.7f}}}, + &a}; + + MeshData3D b{std::move(data)}; + + CORRADE_COMPARE(b.primitive(), MeshPrimitive::LineStrip); + CORRADE_VERIFY(b.isIndexed()); + CORRADE_COMPARE(b.indices(), (std::vector{12, 1, 0})); + CORRADE_COMPARE(b.positionArrayCount(), 1); + CORRADE_COMPARE(b.positions(0), (std::vector{{0.5f, 1.0f, 0.1f}, {-1.0f, 0.3f, -1.0f}})); + CORRADE_COMPARE(b.normalArrayCount(), 1); + CORRADE_COMPARE(b.normals(0), (std::vector{{0.0f, 1.0f, 0.0f}, {-1.0f, 0.0f, 0.0f}})); + CORRADE_COMPARE(b.textureCoords2DArrayCount(), 1); + CORRADE_COMPARE(b.textureCoords2D(0), (std::vector{{0.0f, 0.0f}, {0.3f, 0.7f}})); + CORRADE_COMPARE(b.importerState(), &a); + + const int c{}; + MeshData3D d{MeshPrimitive::TriangleFan, {}, + {{}}, + {}, + {{}}, + &c}; + d = std::move(b); + CORRADE_COMPARE(d.primitive(), MeshPrimitive::LineStrip); + CORRADE_VERIFY(d.isIndexed()); + CORRADE_COMPARE(d.indices(), (std::vector{12, 1, 0})); + CORRADE_COMPARE(d.positionArrayCount(), 1); + CORRADE_COMPARE(d.positions(0), (std::vector{{0.5f, 1.0f, 0.1f}, {-1.0f, 0.3f, -1.0f}})); + CORRADE_COMPARE(d.normalArrayCount(), 1); + CORRADE_COMPARE(d.normals(0), (std::vector{{0.0f, 1.0f, 0.0f}, {-1.0f, 0.0f, 0.0f}})); + CORRADE_COMPARE(d.textureCoords2DArrayCount(), 1); + CORRADE_COMPARE(d.textureCoords2D(0), (std::vector{{0.0f, 0.0f}, {0.3f, 0.7f}})); + CORRADE_COMPARE(d.importerState(), &a); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::Trade::Test::MeshData3DTest) diff --git a/src/Magnum/Trade/Test/ObjectData2DTest.cpp b/src/Magnum/Trade/Test/ObjectData2DTest.cpp index 8b83003ab..5e65fe5ba 100644 --- a/src/Magnum/Trade/Test/ObjectData2DTest.cpp +++ b/src/Magnum/Trade/Test/ObjectData2DTest.cpp @@ -26,7 +26,7 @@ #include #include -#include "Magnum/Trade/ObjectData2D.h" +#include "Magnum/Trade/MeshObjectData2D.h" namespace Magnum { namespace Trade { namespace Test { @@ -34,14 +34,88 @@ class ObjectData2DTest: public TestSuite::Tester { public: explicit ObjectData2DTest(); - void debug(); + void constructEmpty(); + void constructMesh(); + void constructCamera(); + void constructCopy(); + void constructMoveMesh(); + + void debugType(); }; ObjectData2DTest::ObjectData2DTest() { - addTests({&ObjectData2DTest::debug}); + addTests({&ObjectData2DTest::constructEmpty, + &ObjectData2DTest::constructMesh, + &ObjectData2DTest::constructCamera, + &ObjectData2DTest::constructCopy, + &ObjectData2DTest::constructMoveMesh, + + &ObjectData2DTest::debugType}); +} + +void ObjectData2DTest::constructEmpty() { + const int a{}; + const ObjectData2D data{{0, 2, 3}, Matrix3::translation(Vector2::xAxis(-4.0f)), &a}; + + CORRADE_COMPARE(data.children(), (std::vector{0, 2, 3})); + CORRADE_COMPARE(data.transformation(), Matrix3::translation(Vector2::xAxis(-4.0f))); + CORRADE_COMPARE(data.instanceType(), ObjectInstanceType2D::Empty); + CORRADE_COMPARE(data.instance(), -1); +} + +void ObjectData2DTest::constructMesh() { + const int a{}; + const MeshObjectData2D data{{1, 3}, Matrix3::translation(Vector2::yAxis(5.0f)), 13, 42, &a}; + + CORRADE_COMPARE(data.children(), (std::vector{1, 3})); + CORRADE_COMPARE(data.transformation(), Matrix3::translation(Vector2::yAxis(5.0f))); + CORRADE_COMPARE(data.instanceType(), ObjectInstanceType2D::Mesh); + CORRADE_COMPARE(data.instance(), 13); + CORRADE_COMPARE(data.material(), 42); +} + +void ObjectData2DTest::constructCamera() { + const int a{}; + const ObjectData2D data{{1, 3}, Matrix3::translation(Vector2::yAxis(5.0f)), ObjectInstanceType2D::Camera, 42, &a}; + + CORRADE_COMPARE(data.children(), (std::vector{1, 3})); + CORRADE_COMPARE(data.transformation(), Matrix3::translation(Vector2::yAxis(5.0f))); + CORRADE_COMPARE(data.instanceType(), ObjectInstanceType2D::Camera); + CORRADE_COMPARE(data.instance(), 42); +} + +void ObjectData2DTest::constructCopy() { + CORRADE_VERIFY(!(std::is_constructible{})); + CORRADE_VERIFY(!(std::is_constructible{})); + CORRADE_VERIFY(!(std::is_assignable{})); + CORRADE_VERIFY(!(std::is_assignable{})); +} + +void ObjectData2DTest::constructMoveMesh() { + const int a{}; + MeshObjectData2D data{{1, 3}, Matrix3::translation(Vector2::yAxis(5.0f)), 13, 42, &a}; + + MeshObjectData2D b{std::move(data)}; + + CORRADE_COMPARE(b.children(), (std::vector{1, 3})); + CORRADE_COMPARE(b.transformation(), Matrix3::translation(Vector2::yAxis(5.0f))); + CORRADE_COMPARE(b.instanceType(), ObjectInstanceType2D::Mesh); + CORRADE_COMPARE(b.instance(), 13); + CORRADE_COMPARE(b.material(), 42); + + const int c{}; + MeshObjectData2D d{{0, 1}, {}, 27, -1, &c}; + + d = std::move(b); + + CORRADE_COMPARE(d.children(), (std::vector{1, 3})); + CORRADE_COMPARE(d.transformation(), Matrix3::translation(Vector2::yAxis(5.0f))); + CORRADE_COMPARE(d.instanceType(), ObjectInstanceType2D::Mesh); + CORRADE_COMPARE(d.instance(), 13); + CORRADE_COMPARE(d.material(), 42); } -void ObjectData2DTest::debug() { +void ObjectData2DTest::debugType() { std::ostringstream o; Debug(&o) << ObjectInstanceType2D::Empty << ObjectInstanceType2D(0xbe); CORRADE_COMPARE(o.str(), "Trade::ObjectInstanceType2D::Empty Trade::ObjectInstanceType2D(0xbe)\n"); diff --git a/src/Magnum/Trade/Test/ObjectData3DTest.cpp b/src/Magnum/Trade/Test/ObjectData3DTest.cpp index 54de14693..bc7d32745 100644 --- a/src/Magnum/Trade/Test/ObjectData3DTest.cpp +++ b/src/Magnum/Trade/Test/ObjectData3DTest.cpp @@ -26,7 +26,7 @@ #include #include -#include "Magnum/Trade/ObjectData3D.h" +#include "Magnum/Trade/MeshObjectData3D.h" namespace Magnum { namespace Trade { namespace Test { @@ -34,14 +34,100 @@ class ObjectData3DTest: public TestSuite::Tester { public: explicit ObjectData3DTest(); - void debug(); + void constructEmpty(); + void constructMesh(); + void constructCamera(); + void constructLight(); + void constructCopy(); + void constructMoveMesh(); + + void debugType(); }; ObjectData3DTest::ObjectData3DTest() { - addTests({&ObjectData3DTest::debug}); + addTests({&ObjectData3DTest::constructEmpty, + &ObjectData3DTest::constructMesh, + &ObjectData3DTest::constructCamera, + &ObjectData3DTest::constructLight, + &ObjectData3DTest::constructCopy, + &ObjectData3DTest::constructMoveMesh, + + &ObjectData3DTest::debugType}); +} + +void ObjectData3DTest::constructEmpty() { + const int a{}; + const ObjectData3D data{{0, 2, 3}, Matrix4::translation(Vector3::xAxis(-4.0f)), &a}; + + CORRADE_COMPARE(data.children(), (std::vector{0, 2, 3})); + CORRADE_COMPARE(data.transformation(), Matrix4::translation(Vector3::xAxis(-4.0f))); + CORRADE_COMPARE(data.instanceType(), ObjectInstanceType3D::Empty); + CORRADE_COMPARE(data.instance(), -1); +} + +void ObjectData3DTest::constructMesh() { + const int a{}; + const MeshObjectData3D data{{1, 3}, Matrix4::translation(Vector3::yAxis(5.0f)), 13, 42, &a}; + + CORRADE_COMPARE(data.children(), (std::vector{1, 3})); + CORRADE_COMPARE(data.transformation(), Matrix4::translation(Vector3::yAxis(5.0f))); + CORRADE_COMPARE(data.instanceType(), ObjectInstanceType3D::Mesh); + CORRADE_COMPARE(data.instance(), 13); + CORRADE_COMPARE(data.material(), 42); +} + +void ObjectData3DTest::constructCamera() { + const int a{}; + const ObjectData3D data{{1, 3}, Matrix4::translation(Vector3::yAxis(5.0f)), ObjectInstanceType3D::Camera, 42, &a}; + + CORRADE_COMPARE(data.children(), (std::vector{1, 3})); + CORRADE_COMPARE(data.transformation(), Matrix4::translation(Vector3::yAxis(5.0f))); + CORRADE_COMPARE(data.instanceType(), ObjectInstanceType3D::Camera); + CORRADE_COMPARE(data.instance(), 42); +} + +void ObjectData3DTest::constructLight() { + const int a{}; + const ObjectData3D data{{1, 3}, Matrix4::translation(Vector3::yAxis(5.0f)), ObjectInstanceType3D::Light, 42, &a}; + + CORRADE_COMPARE(data.children(), (std::vector{1, 3})); + CORRADE_COMPARE(data.transformation(), Matrix4::translation(Vector3::yAxis(5.0f))); + CORRADE_COMPARE(data.instanceType(), ObjectInstanceType3D::Light); + CORRADE_COMPARE(data.instance(), 42); +} + +void ObjectData3DTest::constructCopy() { + CORRADE_VERIFY(!(std::is_constructible{})); + CORRADE_VERIFY(!(std::is_constructible{})); + CORRADE_VERIFY(!(std::is_assignable{})); + CORRADE_VERIFY(!(std::is_assignable{})); +} + +void ObjectData3DTest::constructMoveMesh() { + const int a{}; + MeshObjectData3D data{{1, 3}, Matrix4::translation(Vector3::yAxis(5.0f)), 13, 42, &a}; + + MeshObjectData3D b{std::move(data)}; + + CORRADE_COMPARE(b.children(), (std::vector{1, 3})); + CORRADE_COMPARE(b.transformation(), Matrix4::translation(Vector3::yAxis(5.0f))); + CORRADE_COMPARE(b.instanceType(), ObjectInstanceType3D::Mesh); + CORRADE_COMPARE(b.instance(), 13); + CORRADE_COMPARE(b.material(), 42); + + const int c{}; + MeshObjectData3D d{{0, 1}, {}, 27, -1, &c}; + + d = std::move(b); + + CORRADE_COMPARE(d.children(), (std::vector{1, 3})); + CORRADE_COMPARE(d.transformation(), Matrix4::translation(Vector3::yAxis(5.0f))); + CORRADE_COMPARE(d.instanceType(), ObjectInstanceType3D::Mesh); + CORRADE_COMPARE(d.instance(), 13); + CORRADE_COMPARE(d.material(), 42); } -void ObjectData3DTest::debug() { +void ObjectData3DTest::debugType() { std::ostringstream o; Debug(&o) << ObjectInstanceType3D::Light << ObjectInstanceType3D(0xbe); CORRADE_COMPARE(o.str(), "Trade::ObjectInstanceType3D::Light Trade::ObjectInstanceType3D(0xbe)\n"); diff --git a/src/Magnum/Trade/Test/SceneDataTest.cpp b/src/Magnum/Trade/Test/SceneDataTest.cpp new file mode 100644 index 000000000..58dcc34ca --- /dev/null +++ b/src/Magnum/Trade/Test/SceneDataTest.cpp @@ -0,0 +1,82 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016 + Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include + +#include "Magnum/Trade/SceneData.h" +#include "Magnum/Magnum.h" + +namespace Magnum { namespace Trade { namespace Test { + +struct SceneDataTest: TestSuite::Tester { + explicit SceneDataTest(); + + void construct(); + void constructCopy(); + void constructMove(); +}; + +SceneDataTest::SceneDataTest() { + addTests({&SceneDataTest::construct, + &SceneDataTest::constructCopy, + &SceneDataTest::constructMove}); +} + +void SceneDataTest::construct() { + const int a{}; + const SceneData data{{0, 1, 4}, {2, 5}, &a}; + + CORRADE_COMPARE(data.children2D(), (std::vector{0, 1, 4})); + CORRADE_COMPARE(data.children3D(), (std::vector{2, 5})); + CORRADE_COMPARE(data.importerState(), &a); +} + +void SceneDataTest::constructCopy() { + CORRADE_VERIFY(!(std::is_constructible{})); + CORRADE_VERIFY(!(std::is_assignable{})); +} + +void SceneDataTest::constructMove() { + const int a{}; + SceneData data{{0, 1, 4}, {2, 5}, &a}; + + SceneData b{std::move(data)}; + + CORRADE_COMPARE(b.children2D(), (std::vector{0, 1, 4})); + CORRADE_COMPARE(b.children3D(), (std::vector{2, 5})); + CORRADE_COMPARE(b.importerState(), &a); + + const int c{}; + SceneData d{{1, 3}, {1, 4, 5}, &c}; + d = std::move(b); + + CORRADE_COMPARE(d.children2D(), (std::vector{0, 1, 4})); + CORRADE_COMPARE(d.children3D(), (std::vector{2, 5})); + CORRADE_COMPARE(d.importerState(), &a); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::Trade::Test::SceneDataTest) diff --git a/src/Magnum/Trade/Test/TextureDataTest.cpp b/src/Magnum/Trade/Test/TextureDataTest.cpp index f14a0a98a..ed8963ad2 100644 --- a/src/Magnum/Trade/Test/TextureDataTest.cpp +++ b/src/Magnum/Trade/Test/TextureDataTest.cpp @@ -34,14 +34,85 @@ class TextureDataTest: public TestSuite::Tester { public: explicit TextureDataTest(); - void debug(); + void construct(); + void constructCopy(); + void constructMove(); + + void debugType(); }; TextureDataTest::TextureDataTest() { - addTests({&TextureDataTest::debug}); + addTests({&TextureDataTest::construct, + &TextureDataTest::constructCopy, + &TextureDataTest::constructMove, + + &TextureDataTest::debugType}); +} + +void TextureDataTest::construct() { + const int a{}; + const TextureData data{TextureData::Type::Cube, + Sampler::Filter::Linear, + Sampler::Filter::Nearest, + Sampler::Mipmap::Nearest, + {Sampler::Wrapping::Repeat, Sampler::Wrapping::ClampToEdge, Sampler::Wrapping::MirroredRepeat}, + 42, + &a}; + + CORRADE_COMPARE(data.type(), TextureData::Type::Cube); + CORRADE_COMPARE(data.minificationFilter(), Sampler::Filter::Linear); + CORRADE_COMPARE(data.magnificationFilter(), Sampler::Filter::Nearest); + CORRADE_COMPARE(data.mipmapFilter(), Sampler::Mipmap::Nearest); + CORRADE_COMPARE(data.wrapping(), (Array3D{Sampler::Wrapping::Repeat, Sampler::Wrapping::ClampToEdge, Sampler::Wrapping::MirroredRepeat})); + CORRADE_COMPARE(data.image(), 42); + CORRADE_COMPARE(data.importerState(), &a); +} + +void TextureDataTest::constructCopy() { + CORRADE_VERIFY(!(std::is_constructible{})); + CORRADE_VERIFY(!(std::is_assignable{})); +} + +void TextureDataTest::constructMove() { + const int a{}; + TextureData data{TextureData::Type::Cube, + Sampler::Filter::Linear, + Sampler::Filter::Nearest, + Sampler::Mipmap::Nearest, + {Sampler::Wrapping::Repeat, Sampler::Wrapping::ClampToEdge, Sampler::Wrapping::MirroredRepeat}, + 42, + &a}; + + TextureData b{std::move(data)}; + + CORRADE_COMPARE(b.type(), TextureData::Type::Cube); + CORRADE_COMPARE(b.minificationFilter(), Sampler::Filter::Linear); + CORRADE_COMPARE(b.magnificationFilter(), Sampler::Filter::Nearest); + CORRADE_COMPARE(b.mipmapFilter(), Sampler::Mipmap::Nearest); + CORRADE_COMPARE(b.wrapping(), (Array3D{Sampler::Wrapping::Repeat, Sampler::Wrapping::ClampToEdge, Sampler::Wrapping::MirroredRepeat})); + CORRADE_COMPARE(b.image(), 42); + CORRADE_COMPARE(b.importerState(), &a); + + const int c{}; + TextureData d{TextureData::Type::Texture2D, + Sampler::Filter::Nearest, + Sampler::Filter::Linear, + Sampler::Mipmap::Base, + Sampler::Wrapping::ClampToEdge, + 13, + &c}; + d = std::move(b); + + CORRADE_COMPARE(d.type(), TextureData::Type::Cube); + CORRADE_COMPARE(d.minificationFilter(), Sampler::Filter::Linear); + CORRADE_COMPARE(d.magnificationFilter(), Sampler::Filter::Nearest); + CORRADE_COMPARE(d.mipmapFilter(), Sampler::Mipmap::Nearest); + CORRADE_COMPARE(d.wrapping(), (Array3D{Sampler::Wrapping::Repeat, Sampler::Wrapping::ClampToEdge, Sampler::Wrapping::MirroredRepeat})); + CORRADE_COMPARE(d.image(), 42); + CORRADE_COMPARE(d.importerState(), &a); } -void TextureDataTest::debug() { +void TextureDataTest::debugType() { std::ostringstream out; Debug(&out) << TextureData::Type::Texture3D << TextureData::Type(0xbe);