diff --git a/src/Test/CMakeLists.txt b/src/Test/CMakeLists.txt index 6eaf09105..d484b063b 100644 --- a/src/Test/CMakeLists.txt +++ b/src/Test/CMakeLists.txt @@ -30,6 +30,7 @@ corrade_add_test(DebugMessageTest DebugMessageTest.cpp LIBRARIES Magnum) corrade_add_test(DefaultFramebufferTest DefaultFramebufferTest.cpp LIBRARIES Magnum) corrade_add_test(FramebufferTest FramebufferTest.cpp LIBRARIES Magnum) corrade_add_test(ImageTest ImageTest.cpp LIBRARIES Magnum) +corrade_add_test(ImageReferenceTest ImageReferenceTest.cpp LIBRARIES Magnum) corrade_add_test(MeshTest MeshTest.cpp LIBRARIES Magnum) corrade_add_test(RendererTest RendererTest.cpp LIBRARIES Magnum) corrade_add_test(ResourceManagerTest ResourceManagerTest.cpp LIBRARIES MagnumTestLib) diff --git a/src/Test/ImageReferenceTest.cpp b/src/Test/ImageReferenceTest.cpp new file mode 100644 index 000000000..eeb80a59f --- /dev/null +++ b/src/Test/ImageReferenceTest.cpp @@ -0,0 +1,69 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 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 "ColorFormat.h" +#include "ImageReference.h" + +namespace Magnum { namespace Test { + +class ImageReferenceTest: public TestSuite::Tester { + public: + explicit ImageReferenceTest(); + + void construct(); + void setData(); +}; + +ImageReferenceTest::ImageReferenceTest() { + addTests({&ImageReferenceTest::construct, + &ImageReferenceTest::setData}); +} + +void ImageReferenceTest::construct() { + const unsigned char data[3] = {}; + ImageReference2D a(ColorFormat::Red, ColorType::UnsignedByte, {1, 3}, data); + + CORRADE_COMPARE(a.format(), ColorFormat::Red); + CORRADE_COMPARE(a.type(), ColorType::UnsignedByte); + CORRADE_COMPARE(a.size(), Vector2i(1, 3)); + CORRADE_COMPARE(a.data(), data); +} + +void ImageReferenceTest::setData() { + const unsigned char data[3] = {}; + ImageReference2D a(ColorFormat::Red, ColorType::UnsignedByte, {1, 3}, data); + const unsigned char data2[8] = {}; + a.setData(data2); + + CORRADE_COMPARE(a.format(), ColorFormat::Red); + CORRADE_COMPARE(a.type(), ColorType::UnsignedByte); + CORRADE_COMPARE(a.size(), Vector2i(1, 3)); + CORRADE_COMPARE(a.data(), reinterpret_cast(data2)); +} + +}} + +CORRADE_TEST_MAIN(Magnum::Test::ImageReferenceTest) diff --git a/src/Test/ImageTest.cpp b/src/Test/ImageTest.cpp index 1f81ace24..7ea196199 100644 --- a/src/Test/ImageTest.cpp +++ b/src/Test/ImageTest.cpp @@ -33,53 +33,87 @@ class ImageTest: public TestSuite::Tester { public: explicit ImageTest(); - void moveConstructor(); - void moveAssignment(); + void construct(); + void constructCopy(); + void constructMove(); + + void setData(); void toReference(); void release(); }; ImageTest::ImageTest() { - addTests({&ImageTest::moveConstructor, - &ImageTest::moveAssignment, + addTests({&ImageTest::construct, + &ImageTest::constructCopy, + &ImageTest::constructMove, + + &ImageTest::setData, &ImageTest::toReference, &ImageTest::release}); } -void ImageTest::moveConstructor() { - unsigned char* data = new unsigned char[3]; +void ImageTest::construct() { + auto data = new unsigned char[3]; Image2D a(ColorFormat::Red, ColorType::UnsignedByte, {1, 3}, data); + CORRADE_COMPARE(a.format(), ColorFormat::Red); + CORRADE_COMPARE(a.type(), ColorType::UnsignedByte); + CORRADE_COMPARE(a.size(), Vector2i(1, 3)); + CORRADE_COMPARE(a.data(), data); +} + +void ImageTest::constructCopy() { + CORRADE_VERIFY(!(std::is_constructible{})); + CORRADE_VERIFY(!(std::is_assignable{})); +} + +void ImageTest::constructMove() { + auto data = new unsigned char[3]; + Image2D a(ColorFormat::Red, ColorType::UnsignedByte, {1, 3}, data); Image2D b(std::move(a)); - CORRADE_VERIFY(!a.data()); + + CORRADE_COMPARE(a.data(), nullptr); + CORRADE_COMPARE(a.size(), Vector2i()); + CORRADE_COMPARE(b.format(), ColorFormat::Red); CORRADE_COMPARE(b.type(), ColorType::UnsignedByte); CORRADE_COMPARE(b.size(), Vector2i(1, 3)); - CORRADE_VERIFY(b.data() == data); + CORRADE_COMPARE(b.data(), data); + + auto data2 = new unsigned char[3]; + Image2D c(ColorFormat::RGBA, ColorType::UnsignedShort, {2, 6}, data2); + c = std::move(b); + + CORRADE_COMPARE(b.data(), data2); + CORRADE_COMPARE(b.size(), Vector2i(2, 6)); + + CORRADE_COMPARE(c.format(), ColorFormat::Red); + CORRADE_COMPARE(c.type(), ColorType::UnsignedByte); + CORRADE_COMPARE(c.size(), Vector2i(1, 3)); + CORRADE_COMPARE(c.data(), data); } -void ImageTest::moveAssignment() { - unsigned char* data = new unsigned char[3]; +void ImageTest::setData() { + auto data = new unsigned char[3]; Image2D a(ColorFormat::Red, ColorType::UnsignedByte, {1, 3}, data); + auto data2 = new unsigned short[2*4]; + a.setData(ColorFormat::RGBA, ColorType::UnsignedShort, {2, 1}, data2); - Image2D b(ColorFormat::Red, ColorType::UnsignedByte); - b = std::move(a); - CORRADE_VERIFY(!a.data()); - CORRADE_COMPARE(b.format(), ColorFormat::Red); - CORRADE_COMPARE(b.type(), ColorType::UnsignedByte); - CORRADE_COMPARE(b.size(), Vector2i(1, 3)); - CORRADE_VERIFY(b.data() == data); + CORRADE_COMPARE(a.format(), ColorFormat::RGBA); + CORRADE_COMPARE(a.type(), ColorType::UnsignedShort); + CORRADE_COMPARE(a.size(), Vector2i(2, 1)); + CORRADE_COMPARE(a.data(), reinterpret_cast(data2)); } void ImageTest::toReference() { - unsigned char* data = new unsigned char[3]; + auto data = new unsigned char[3]; const Image2D a(ColorFormat::Red, ColorType::UnsignedByte, {1, 3}, data); - ImageReference2D b = a; + CORRADE_COMPARE(b.format(), ColorFormat::Red); CORRADE_COMPARE(b.type(), ColorType::UnsignedByte); CORRADE_COMPARE(b.size(), Vector2i(1, 3)); - CORRADE_VERIFY(b.data() == data); + CORRADE_COMPARE(b.data(), data); CORRADE_VERIFY((std::is_convertible::value)); { @@ -95,9 +129,10 @@ void ImageTest::release() { unsigned char data[] = {'c', 'a', 'f', 'e'}; Image2D a(ColorFormat::Red, ColorType::UnsignedByte, {1, 4}, data); const unsigned char* const pointer = a.release(); + CORRADE_COMPARE(pointer, data); - CORRADE_VERIFY(!a.data()); - CORRADE_VERIFY(a.size().isZero()); + CORRADE_COMPARE(a.data(), nullptr); + CORRADE_COMPARE(a.size(), Vector2i()); } }} diff --git a/src/Trade/Test/ImageDataTest.cpp b/src/Trade/Test/ImageDataTest.cpp index b805d2be9..040cccc94 100644 --- a/src/Trade/Test/ImageDataTest.cpp +++ b/src/Trade/Test/ImageDataTest.cpp @@ -33,49 +33,69 @@ class ImageDataTest: public TestSuite::Tester { public: explicit ImageDataTest(); - void moveConstructor(); - void moveAssignment(); + void construct(); + void constructCopy(); + void constructMove(); + void toReference(); void release(); }; ImageDataTest::ImageDataTest() { - addTests({&ImageDataTest::moveConstructor, - &ImageDataTest::moveAssignment, + addTests({&ImageDataTest::construct, + &ImageDataTest::constructCopy, + &ImageDataTest::constructMove, + &ImageDataTest::toReference, &ImageDataTest::release}); } -void ImageDataTest::moveConstructor() { - unsigned char* data = new unsigned char[3]; +void ImageDataTest::construct() { + auto data = new unsigned char[3]; Trade::ImageData2D a(ColorFormat::Red, ColorType::UnsignedByte, {1, 3}, data); - Trade::ImageData2D b(std::move(a)); - CORRADE_VERIFY(!a.data()); - CORRADE_COMPARE(b.format(), ColorFormat::Red); - CORRADE_COMPARE(b.type(), ColorType::UnsignedByte); - CORRADE_COMPARE(b.size(), Vector2i(1, 3)); - CORRADE_VERIFY(b.data() == data); + CORRADE_COMPARE(a.format(), ColorFormat::Red); + CORRADE_COMPARE(a.type(), ColorType::UnsignedByte); + CORRADE_COMPARE(a.size(), Vector2i(1, 3)); + CORRADE_COMPARE(a.data(), data); +} + +void ImageDataTest::constructCopy() { + CORRADE_VERIFY(!(std::is_constructible{})); + CORRADE_VERIFY(!(std::is_assignable{})); } -void ImageDataTest::moveAssignment() { - unsigned char* data = new unsigned char[3]; +void ImageDataTest::constructMove() { + auto data = new unsigned char[3]; Trade::ImageData2D a(ColorFormat::Red, ColorType::UnsignedByte, {1, 3}, data); + Trade::ImageData2D b(std::move(a)); + + CORRADE_COMPARE(a.data(), nullptr); + CORRADE_COMPARE(a.size(), Vector2i()); - Trade::ImageData2D b(ColorFormat::Red, ColorType::UnsignedByte, {}, nullptr); - b = std::move(a); - CORRADE_VERIFY(!a.data()); CORRADE_COMPARE(b.format(), ColorFormat::Red); CORRADE_COMPARE(b.type(), ColorType::UnsignedByte); CORRADE_COMPARE(b.size(), Vector2i(1, 3)); - CORRADE_VERIFY(b.data() == data); + CORRADE_COMPARE(b.data(), data); + + auto data2 = new unsigned char[3]; + Trade::ImageData2D c(ColorFormat::RGBA, ColorType::UnsignedShort, {2, 6}, data2); + c = std::move(b); + + CORRADE_COMPARE(b.data(), data2); + CORRADE_COMPARE(b.size(), Vector2i(2, 6)); + + CORRADE_COMPARE(c.format(), ColorFormat::Red); + CORRADE_COMPARE(c.type(), ColorType::UnsignedByte); + CORRADE_COMPARE(c.size(), Vector2i(1, 3)); + CORRADE_COMPARE(c.data(), data); } void ImageDataTest::toReference() { - unsigned char* data = new unsigned char[3]; + auto data = new unsigned char[3]; const Trade::ImageData2D a(ColorFormat::Red, ColorType::UnsignedByte, {1, 3}, data); - ImageReference2D b = a; + CORRADE_COMPARE(b.format(), ColorFormat::Red); CORRADE_COMPARE(b.type(), ColorType::UnsignedByte); CORRADE_COMPARE(b.size(), Vector2i(1, 3)); @@ -95,9 +115,10 @@ void ImageDataTest::release() { unsigned char data[] = {'b', 'e', 'e', 'r'}; ImageData2D a(ColorFormat::Red, ColorType::UnsignedByte, {1, 4}, data); const unsigned char* const pointer = a.release(); + CORRADE_COMPARE(pointer, data); - CORRADE_VERIFY(!a.data()); - CORRADE_VERIFY(a.size().isZero()); + CORRADE_COMPARE(a.data(), nullptr); + CORRADE_COMPARE(a.size(), Vector2i()); } }}}