Browse Source

TgaImporter: test also file opening.

pull/34/head
Vladimír Vondruš 13 years ago
parent
commit
9f2ea8aa15
  1. 5
      src/Plugins/TgaImporter/Test/CMakeLists.txt
  2. 32
      src/Plugins/TgaImporter/Test/TgaImporterTest.cpp
  3. 25
      src/Plugins/TgaImporter/Test/configure.h.cmake
  4. BIN
      src/Plugins/TgaImporter/Test/file.tga

5
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)

32
src/Plugins/TgaImporter/Test/TgaImporterTest.cpp

@ -24,10 +24,14 @@
#include <sstream>
#include <TestSuite/Tester.h>
#include <Math/Vector2.h>
#include <Utility/Directory.h>
#include <Trade/ImageData.h>
#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<const char*>(image->data()), 2*3), std::string(data + 18, 2*3));
}
}}}}
CORRADE_TEST_MAIN(Magnum::Trade::TgaImporter::Test::TgaImporterTest)

25
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š <mosra@centrum.cz>
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}"

BIN
src/Plugins/TgaImporter/Test/file.tga

Binary file not shown.
Loading…
Cancel
Save