From 0d73256627a6624f173c8b91852a52d89702c6c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 17 Nov 2013 19:12:18 +0100 Subject: [PATCH] Shapes: test also copying and movement of Composition. Now we know where it crashes. --- src/Shapes/Test/CompositionTest.cpp | 43 +++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/Shapes/Test/CompositionTest.cpp b/src/Shapes/Test/CompositionTest.cpp index 381616b5e..da9a4d08e 100644 --- a/src/Shapes/Test/CompositionTest.cpp +++ b/src/Shapes/Test/CompositionTest.cpp @@ -46,6 +46,8 @@ class CompositionTest: public TestSuite::Tester { void hierarchy(); void empty(); + void copy(); + void move(); void transformed(); }; @@ -57,6 +59,8 @@ CompositionTest::CompositionTest() { &CompositionTest::hierarchy, &CompositionTest::empty, + &CompositionTest::copy, + &CompositionTest::move, &CompositionTest::transformed}); } @@ -130,6 +134,45 @@ void CompositionTest::empty() { VERIFY_NOT_COLLIDES(a, Shapes::Sphere2D({}, 1.0f)); } +void CompositionTest::copy() { + const Shapes::Composition3D a = Shapes::Sphere3D({}, 1.0f) && + (Shapes::Point3D(Vector3::xAxis(1.5f)) || !Shapes::AxisAlignedBox3D({}, Vector3(0.5f))); + + /* Copy constructor */ + const Shapes::Composition3D b(a); + CORRADE_COMPARE(b.size(), 3); + CORRADE_COMPARE(b.get(2).max(), Vector3(0.5f)); + + /* Copy assignment */ + Shapes::Composition3D c; + c = a; + CORRADE_COMPARE(c.size(), 3); + CORRADE_COMPARE(c.get(1).position(), Vector3::xAxis(1.5f)); +} + +void CompositionTest::move() { + { + Shapes::Composition3D a = Shapes::Sphere3D({}, 1.0f) && + (Shapes::Point3D(Vector3::xAxis(1.5f)) || !Shapes::AxisAlignedBox3D({}, Vector3(0.5f))); + + /* Move constructor */ + const Shapes::Composition3D b(std::move(a)); + CORRADE_COMPARE(a.size(), 0); + CORRADE_COMPARE(b.size(), 3); + CORRADE_COMPARE(b.get(1).position(), Vector3::xAxis(1.5f)); + } { + Shapes::Composition3D a = Shapes::Sphere3D({}, 1.0f) && + (Shapes::Point3D(Vector3::xAxis(1.5f)) || !Shapes::AxisAlignedBox3D({}, Vector3(0.5f))); + + /* Move assignment */ + Shapes::Composition3D b; + b = std::move(a); + CORRADE_COMPARE(a.size(), 0); + CORRADE_COMPARE(b.size(), 3); + CORRADE_COMPARE(b.get(2).max(), Vector3(0.5f)); + } +} + void CompositionTest::transformed() { const Shapes::Composition2D a = Shapes::Sphere2D({}, 1.0f) && (Shapes::Point2D(Vector2::xAxis(1.5f)) || !Shapes::AxisAlignedBox2D({}, Vector2(0.5f)));