From 9f2ea8aa15fe8b852e2856d9e4bd87c5ff315a9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 29 Mar 2013 17:46:30 +0100 Subject: [PATCH] TgaImporter: test also file opening. --- src/Plugins/TgaImporter/Test/CMakeLists.txt | 5 +++ .../TgaImporter/Test/TgaImporterTest.cpp | 32 ++++++++++++++++-- .../TgaImporter/Test/configure.h.cmake | 25 ++++++++++++++ src/Plugins/TgaImporter/Test/file.tga | Bin 0 -> 24 bytes 4 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 src/Plugins/TgaImporter/Test/configure.h.cmake create mode 100644 src/Plugins/TgaImporter/Test/file.tga diff --git a/src/Plugins/TgaImporter/Test/CMakeLists.txt b/src/Plugins/TgaImporter/Test/CMakeLists.txt index 5834c045e..3e825ad47 100644 --- a/src/Plugins/TgaImporter/Test/CMakeLists.txt +++ b/src/Plugins/TgaImporter/Test/CMakeLists.txt @@ -22,4 +22,9 @@ # DEALINGS IN THE SOFTWARE. # +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configure.h.cmake + ${CMAKE_CURRENT_BINARY_DIR}/configure.h) + +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + corrade_add_test(TgaImporterTest TgaImporterTest.cpp LIBRARIES TgaImporterTestLib) diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp index 1305d4cd2..f0ac0d188 100644 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp @@ -24,10 +24,14 @@ #include #include -#include +#include #include -#include "../TgaImporter.h" +#include "TgaImporter/TgaImporter.h" + +#include "configure.h" + +using Corrade::Utility::Directory; namespace Magnum { namespace Trade { namespace TgaImporter { namespace Test { @@ -46,6 +50,8 @@ class TgaImporterTest: public Corrade::TestSuite::Tester { void grayscaleBits8(); void grayscaleBits16(); + + void file(); }; TgaImporterTest::TgaImporterTest() { @@ -59,7 +65,9 @@ TgaImporterTest::TgaImporterTest() { &TgaImporterTest::colorBits32, &TgaImporterTest::grayscaleBits8, - &TgaImporterTest::grayscaleBits16}); + &TgaImporterTest::grayscaleBits16, + + &TgaImporterTest::file}); } void TgaImporterTest::openInexistent() { @@ -210,6 +218,24 @@ void TgaImporterTest::grayscaleBits16() { CORRADE_COMPARE(debug.str(), "Trade::TgaImporter::TgaImporter::image2D(): unsupported grayscale bits-per-pixel: 16\n"); } +void TgaImporterTest::file() { + TgaImporter importer; + const char data[] = { + 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 8, 0, + 1, 2, + 3, 4, + 5, 6 + }; + CORRADE_VERIFY(importer.openFile(Directory::join(TGAIMPORTER_TEST_DIR, "file.tga"))); + + Trade::ImageData2D* image = importer.image2D(0); + CORRADE_VERIFY(image); + CORRADE_COMPARE(image->format(), Trade::ImageData2D::Format::Red); + CORRADE_COMPARE(image->size(), Vector2i(2, 3)); + CORRADE_COMPARE(image->type(), Trade::ImageData2D::Type::UnsignedByte); + CORRADE_COMPARE(std::string(reinterpret_cast(image->data()), 2*3), std::string(data + 18, 2*3)); +} + }}}} CORRADE_TEST_MAIN(Magnum::Trade::TgaImporter::Test::TgaImporterTest) diff --git a/src/Plugins/TgaImporter/Test/configure.h.cmake b/src/Plugins/TgaImporter/Test/configure.h.cmake new file mode 100644 index 000000000..e507e8ed7 --- /dev/null +++ b/src/Plugins/TgaImporter/Test/configure.h.cmake @@ -0,0 +1,25 @@ +/* + 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. +*/ + +#define TGAIMPORTER_TEST_DIR "${CMAKE_CURRENT_SOURCE_DIR}" diff --git a/src/Plugins/TgaImporter/Test/file.tga b/src/Plugins/TgaImporter/Test/file.tga new file mode 100644 index 0000000000000000000000000000000000000000..711486718a0f3ccfad7e39ebfaae81823912afae GIT binary patch literal 24 XcmZQzU}k^;CLo)Gfsu)sg_R8e0SEvl literal 0 HcmV?d00001