Browse Source

Make all non-GL tests building and passing on WebGL/Emscripten.

Yay!
pull/158/head
Vladimír Vondruš 10 years ago
parent
commit
5f36f41817
  1. 4
      CMakeLists.txt
  2. 2
      src/Magnum/Math/Test/TypeTraitsTest.cpp
  3. 4
      src/Magnum/Test/CMakeLists.txt
  4. 4
      src/Magnum/Test/ContextTest.cpp
  5. 4
      src/Magnum/Test/DefaultFramebufferTest.cpp
  6. 26
      src/Magnum/Test/ImageTest.cpp
  7. 14
      src/Magnum/Test/ImageViewTest.cpp
  8. 23
      src/Magnum/Test/PixelStorageTest.cpp
  9. 11
      src/Magnum/Test/RendererTest.cpp
  10. 6
      src/Magnum/Test/SamplerTest.cpp
  11. 8
      src/Magnum/Test/VersionTest.cpp
  12. 3
      src/Magnum/Text/Test/AbstractFontConverterTest.cpp
  13. 13
      src/Magnum/Text/Test/CMakeLists.txt
  14. 4
      src/Magnum/Text/Test/configure.h.cmake
  15. 3
      src/Magnum/Trade/Test/AbstractImageConverterTest.cpp
  16. 12
      src/Magnum/Trade/Test/CMakeLists.txt
  17. 26
      src/Magnum/Trade/Test/ImageDataTest.cpp
  18. 4
      src/Magnum/Trade/Test/configure.h.cmake
  19. 10
      src/MagnumPlugins/ObjImporter/Test/CMakeLists.txt
  20. 2
      src/MagnumPlugins/ObjImporter/Test/configure.h.cmake
  21. 20
      src/MagnumPlugins/TgaImageConverter/Test/TgaImageConverterTest.cpp
  22. 10
      src/MagnumPlugins/TgaImporter/Test/CMakeLists.txt
  23. 2
      src/MagnumPlugins/TgaImporter/Test/configure.h.cmake

4
CMakeLists.txt

@ -207,6 +207,10 @@ if(TARGET_HEADLESS)
set(MAGNUM_TARGET_HEADLESS 1)
endif()
if(CORRADE_TARGET_EMSCRIPTEN)
include(UseEmscripten)
endif()
if(BUILD_GL_TESTS)
if(MAGNUM_TARGET_HEADLESS)
set(WITH_WINDOWLESSEGLAPPLICATION ON)

2
src/Magnum/Math/Test/TypeTraitsTest.cpp

@ -48,8 +48,10 @@ TypeTraitsTest::TypeTraitsTest() {
&TypeTraitsTest::equalsIntegral<Short>,
&TypeTraitsTest::equalsIntegral<UnsignedInt>,
&TypeTraitsTest::equalsIntegral<Int>,
#ifndef CORRADE_TARGET_EMSCRIPTEN
&TypeTraitsTest::equalsIntegral<UnsignedLong>,
&TypeTraitsTest::equalsIntegral<Long>,
#endif
&TypeTraitsTest::equalsFloatingPoint0<Float>,
#ifndef MAGNUM_TARGET_GLES
&TypeTraitsTest::equalsFloatingPoint0<Double>,

4
src/Magnum/Test/CMakeLists.txt

@ -27,7 +27,9 @@ corrade_add_test(AbstractShaderProgramTest AbstractShaderProgramTest.cpp LIBRARI
corrade_add_test(ArrayTest ArrayTest.cpp LIBRARIES Magnum)
corrade_add_test(FormatTest FormatTest.cpp LIBRARIES Magnum)
corrade_add_test(ContextTest ContextTest.cpp LIBRARIES Magnum)
corrade_add_test(DebugOutputTest DebugOutputTest.cpp LIBRARIES Magnum)
if(NOT MAGNUM_TARGET_WEBGL)
corrade_add_test(DebugOutputTest DebugOutputTest.cpp LIBRARIES Magnum)
endif()
corrade_add_test(DefaultFramebufferTest DefaultFramebufferTest.cpp LIBRARIES Magnum)
corrade_add_test(FramebufferTest FramebufferTest.cpp LIBRARIES Magnum)
corrade_add_test(ImageTest ImageTest.cpp LIBRARIES Magnum)

4
src/Magnum/Test/ContextTest.cpp

@ -41,9 +41,13 @@ ContextTest::ContextTest() {
}
void ContextTest::debugFlag() {
#ifdef MAGNUM_TARGET_WEBGL
CORRADE_SKIP("No context flags on Emscripten yet.");
#else
std::ostringstream out;
Debug(&out) << Context::Flag::Debug;
CORRADE_COMPARE(out.str(), "Context::Flag::Debug\n");
#endif
}
}}

4
src/Magnum/Test/DefaultFramebufferTest.cpp

@ -43,8 +43,8 @@ DefaultFramebufferTest::DefaultFramebufferTest() {
void DefaultFramebufferTest::debugStatus() {
std::ostringstream out;
Debug(&out) << DefaultFramebuffer::Status::Undefined;
CORRADE_COMPARE(out.str(), "DefaultFramebuffer::Status::Undefined\n");
Debug(&out) << DefaultFramebuffer::Status::Complete;
CORRADE_COMPARE(out.str(), "DefaultFramebuffer::Status::Complete\n");
}
}}

26
src/Magnum/Test/ImageTest.cpp

@ -65,12 +65,12 @@ ImageTest::ImageTest() {
}
void ImageTest::construct() {
auto data = new char[3];
auto data = new char[3*4];
Image2D a{PixelStorage{}.setAlignment(1),
PixelFormat::Red, PixelType::UnsignedByte, {1, 3}, Containers::Array<char>{data, 3}};
PixelFormat::RGBA, PixelType::UnsignedByte, {1, 3}, Containers::Array<char>{data, 3*4}};
CORRADE_COMPARE(a.storage().alignment(), 1);
CORRADE_COMPARE(a.format(), PixelFormat::Red);
CORRADE_COMPARE(a.format(), PixelFormat::RGBA);
CORRADE_COMPARE(a.type(), PixelType::UnsignedByte);
CORRADE_COMPARE(a.size(), Vector2i(1, 3));
CORRADE_COMPARE(a.data(), data);
@ -104,16 +104,16 @@ void ImageTest::constructCopyCompressed() {
}
void ImageTest::constructMove() {
auto data = new char[3];
auto data = new char[3*3];
Image2D a{PixelStorage{}.setAlignment(1),
PixelFormat::Red, PixelType::UnsignedByte, {1, 3}, Containers::Array<char>{data, 3}};
PixelFormat::RGB, PixelType::UnsignedByte, {1, 3}, Containers::Array<char>{data, 3*3}};
Image2D b(std::move(a));
CORRADE_COMPARE(a.data(), nullptr);
CORRADE_COMPARE(a.size(), Vector2i());
CORRADE_COMPARE(b.storage().alignment(), 1);
CORRADE_COMPARE(b.format(), PixelFormat::Red);
CORRADE_COMPARE(b.format(), PixelFormat::RGB);
CORRADE_COMPARE(b.type(), PixelType::UnsignedByte);
CORRADE_COMPARE(b.size(), Vector2i(1, 3));
CORRADE_COMPARE(b.data(), data);
@ -126,7 +126,7 @@ void ImageTest::constructMove() {
CORRADE_COMPARE(b.size(), Vector2i(2, 6));
CORRADE_COMPARE(c.storage().alignment(), 1);
CORRADE_COMPARE(c.format(), PixelFormat::Red);
CORRADE_COMPARE(c.format(), PixelFormat::RGB);
CORRADE_COMPARE(c.type(), PixelType::UnsignedByte);
CORRADE_COMPARE(c.size(), Vector2i(1, 3));
CORRADE_COMPARE(c.data(), data);
@ -170,9 +170,9 @@ void ImageTest::constructMoveCompressed() {
}
void ImageTest::setData() {
auto data = new char[3];
auto data = new char[3*3];
Image2D a{PixelStorage{}.setAlignment(1),
PixelFormat::Red, PixelType::UnsignedByte, {1, 3}, Containers::Array<char>{data, 3}};
PixelFormat::RGB, PixelType::UnsignedByte, {1, 3}, Containers::Array<char>{data, 3*3}};
auto data2 = new char[2*2*4];
a.setData(PixelFormat::RGBA, PixelType::UnsignedShort, {2, 1}, Containers::Array<char>{data2, 2*2*4});
@ -203,13 +203,13 @@ void ImageTest::setDataCompressed() {
}
void ImageTest::toView() {
auto data = new char[3];
auto data = new char[3*3];
const Image2D a{PixelStorage{}.setAlignment(1),
PixelFormat::Red, PixelType::UnsignedByte, {1, 3}, Containers::Array<char>{data, 3}};
PixelFormat::RGB, PixelType::UnsignedByte, {1, 3}, Containers::Array<char>{data, 3*3}};
ImageView2D b = a;
CORRADE_COMPARE(b.storage().alignment(), 1);
CORRADE_COMPARE(b.format(), PixelFormat::Red);
CORRADE_COMPARE(b.format(), PixelFormat::RGB);
CORRADE_COMPARE(b.type(), PixelType::UnsignedByte);
CORRADE_COMPARE(b.size(), Vector2i(1, 3));
CORRADE_COMPARE(b.data(), data);
@ -235,7 +235,7 @@ void ImageTest::toViewCompressed() {
void ImageTest::release() {
char data[] = {'c', 'a', 'f', 'e'};
Image2D a(PixelFormat::Red, PixelType::UnsignedByte, {4, 1}, Containers::Array<char>{data, 4});
Image2D a(PixelFormat::RGBA, PixelType::UnsignedByte, {1, 1}, Containers::Array<char>{data, 4});
const char* const pointer = a.release().release();
CORRADE_COMPARE(pointer, data);

14
src/Magnum/Test/ImageViewTest.cpp

@ -51,12 +51,12 @@ ImageViewTest::ImageViewTest() {
}
void ImageViewTest::construct() {
const char data[3]{};
const char data[3*3]{};
ImageView2D a{PixelStorage{}.setAlignment(1),
PixelFormat::Red, PixelType::UnsignedByte, {1, 3}, data};
PixelFormat::RGB, PixelType::UnsignedByte, {1, 3}, data};
CORRADE_COMPARE(a.storage().alignment(), 1);
CORRADE_COMPARE(a.format(), PixelFormat::Red);
CORRADE_COMPARE(a.format(), PixelFormat::RGB);
CORRADE_COMPARE(a.type(), PixelType::UnsignedByte);
CORRADE_COMPARE(a.size(), Vector2i(1, 3));
CORRADE_COMPARE(a.data(), data);
@ -86,14 +86,14 @@ void ImageViewTest::constructCompressed() {
}
void ImageViewTest::setData() {
const char data[3]{};
const char data[3*3]{};
ImageView2D a{PixelStorage{}.setAlignment(1),
PixelFormat::Red, PixelType::UnsignedByte, {1, 3}, data};
const char data2[3]{};
PixelFormat::RGB, PixelType::UnsignedByte, {1, 3}, data};
const char data2[3*3]{};
a.setData(data2);
CORRADE_COMPARE(a.storage().alignment(), 1);
CORRADE_COMPARE(a.format(), PixelFormat::Red);
CORRADE_COMPARE(a.format(), PixelFormat::RGB);
CORRADE_COMPARE(a.type(), PixelType::UnsignedByte);
CORRADE_COMPARE(a.size(), Vector2i(1, 3));
CORRADE_COMPARE(a.data(), data2);

23
src/Magnum/Test/PixelStorageTest.cpp

@ -38,7 +38,9 @@ struct PixelStorageTest: TestSuite::Tester {
void dataProperties();
void dataPropertiesAlignment();
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
void dataPropertiesRowLength();
#endif
#ifndef MAGNUM_TARGET_GLES2
void dataPropertiesImageHeight();
#endif
@ -61,7 +63,9 @@ PixelStorageTest::PixelStorageTest() {
&PixelStorageTest::dataProperties,
&PixelStorageTest::dataPropertiesAlignment,
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
&PixelStorageTest::dataPropertiesRowLength,
#endif
#ifndef MAGNUM_TARGET_GLES2
&PixelStorageTest::dataPropertiesImageHeight,
#endif
@ -81,7 +85,9 @@ PixelStorageTest::PixelStorageTest() {
void PixelStorageTest::pixelSize() {
CORRADE_COMPARE(PixelStorage::pixelSize(PixelFormat::RGBA, PixelType::UnsignedInt), 4*4);
CORRADE_COMPARE(PixelStorage::pixelSize(PixelFormat::DepthComponent, PixelType::UnsignedShort), 2);
#ifndef MAGNUM_TARGET_WEBGL
CORRADE_COMPARE(PixelStorage::pixelSize(PixelFormat::StencilIndex, PixelType::UnsignedByte), 1);
#endif
CORRADE_COMPARE(PixelStorage::pixelSize(PixelFormat::DepthStencil, PixelType::UnsignedInt248), 4);
}
@ -93,12 +99,14 @@ void PixelStorageTest::dataProperties() {
(std::tuple<std::size_t, Vector3st, std::size_t>{0, {0, 0, 0}, 4}));
CORRADE_COMPARE(storage.dataProperties(PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i{1}),
(std::tuple<std::size_t, Vector3st, std::size_t>{0, {4, 1, 1}, 4}));
#if !defined(MAGNUM_TARGET_WEBGL) && !defined(MAGNUM_TARGET_GLES2)
CORRADE_COMPARE(storage.dataProperties(PixelFormat::Red, PixelType::UnsignedByte, {8, 2, 1}),
(std::tuple<std::size_t, Vector3st, std::size_t>{0, {8, 2, 1}, 1}));
CORRADE_COMPARE(storage.dataProperties(PixelFormat::Red, PixelType::UnsignedByte, {2, 4, 1}),
(std::tuple<std::size_t, Vector3st, std::size_t>{0, {2, 4, 1}, 1}));
CORRADE_COMPARE(storage.dataProperties(PixelFormat::Red, PixelType::UnsignedByte, {2, 4, 6}),
(std::tuple<std::size_t, Vector3st, std::size_t>{0, {2, 4, 6}, 1}));
#endif
}
void PixelStorageTest::dataPropertiesAlignment() {
@ -110,14 +118,17 @@ void PixelStorageTest::dataPropertiesAlignment() {
(std::tuple<std::size_t, Vector3st, std::size_t>{3*4, {0, 0, 0}, 4}));
CORRADE_COMPARE(storage.dataProperties(PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i{1}),
(std::tuple<std::size_t, Vector3st, std::size_t>{8 + 16 + 3*4, {8, 1, 1}, 4}));
#if !defined(MAGNUM_TARGET_WEBGL) && !defined(MAGNUM_TARGET_GLES2)
CORRADE_COMPARE(storage.dataProperties(PixelFormat::Red, PixelType::UnsignedByte, {8, 2, 1}),
(std::tuple<std::size_t, Vector3st, std::size_t>{16 + 16 + 3, {8, 2, 1}, 1}));
CORRADE_COMPARE(storage.dataProperties(PixelFormat::Red, PixelType::UnsignedByte, {2, 4, 1}),
(std::tuple<std::size_t, Vector3st, std::size_t>{32 + 16 + 3, {8, 4, 1}, 1}));
CORRADE_COMPARE(storage.dataProperties(PixelFormat::Red, PixelType::UnsignedByte, {2, 4, 6}),
(std::tuple<std::size_t, Vector3st, std::size_t>{32 + 16 + 3, {8, 4, 6}, 1}));
#endif
}
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
void PixelStorageTest::dataPropertiesRowLength() {
PixelStorage storage;
storage.setAlignment(4)
@ -135,6 +146,7 @@ void PixelStorageTest::dataPropertiesRowLength() {
CORRADE_COMPARE(storage.dataProperties(PixelFormat::Red, PixelType::UnsignedByte, {2, 4, 6}),
(std::tuple<std::size_t, Vector3st, std::size_t>{3 + 7*16, {16, 4, 6}, 1}));
}
#endif
#ifndef MAGNUM_TARGET_GLES2
void PixelStorageTest::dataPropertiesImageHeight() {
@ -159,19 +171,24 @@ void PixelStorageTest::dataPropertiesImageHeight() {
void PixelStorageTest::dataSize() {
/* The same parameters as in PixelStorageGLTest 3D case */
const Image2D image{PixelStorage{}.setAlignment(2)
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
.setRowLength(3)
#endif
#ifndef MAGNUM_TARGET_GLES2
.setImageHeight(5)
#endif
.setSkip({2, 3, 1}),
PixelFormat::RGB, PixelType::UnsignedByte};
#ifndef MAGNUM_TARGET_GLES2
#if defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2)
CORRADE_COMPARE(Implementation::imageDataSizeFor(image, Vector2i{2, 3}),
5*10 + 3*10 + 6 + 3*10);
#else
3*6 + 3*6 + 6 + 3*6);
#elif defined(MAGNUM_TARGET_GLES2)
CORRADE_COMPARE(Implementation::imageDataSizeFor(image, Vector2i{2, 3}),
3*10 + 3*10 + 6 + 3*10);
#else
CORRADE_COMPARE(Implementation::imageDataSizeFor(image, Vector2i{2, 3}),
5*10 + 3*10 + 6 + 3*10);
#endif
}

11
src/Magnum/Test/RendererTest.cpp

@ -34,12 +34,19 @@ struct RendererTest: TestSuite::Tester {
explicit RendererTest();
void debugError();
#ifndef MAGNUM_TARGET_WEBGL
void debugResetNotificationStrategy();
void debugGraphicsResetStatus();
#endif
};
RendererTest::RendererTest() {
addTests({&RendererTest::debugError});
addTests({&RendererTest::debugError,
#ifndef MAGNUM_TARGET_WEBGL
&RendererTest::debugResetNotificationStrategy,
&RendererTest::debugGraphicsResetStatus
#endif
});
}
void RendererTest::debugError() {
@ -49,6 +56,7 @@ void RendererTest::debugError() {
CORRADE_COMPARE(out.str(), "Renderer::Error::InvalidOperation\n");
}
#ifndef MAGNUM_TARGET_WEBGL
void RendererTest::debugResetNotificationStrategy() {
std::ostringstream out;
@ -62,6 +70,7 @@ void RendererTest::debugGraphicsResetStatus() {
Debug(&out) << Renderer::GraphicsResetStatus::GuiltyContextReset;
CORRADE_COMPARE(out.str(), "Renderer::GraphicsResetStatus::GuiltyContextReset\n");
}
#endif
}}

6
src/Magnum/Test/SamplerTest.cpp

@ -36,8 +36,10 @@ struct SamplerTest: TestSuite::Tester {
void debugFilter();
void debugMipmap();
void debugWrapping();
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
void debugCompareMode();
void debugCompareFunction();
#endif
#ifndef MAGNUM_TARGET_GLES
void debugDepthStencilMode();
#endif
@ -47,8 +49,10 @@ SamplerTest::SamplerTest() {
addTests({&SamplerTest::debugFilter,
&SamplerTest::debugMipmap,
&SamplerTest::debugWrapping,
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
&SamplerTest::debugCompareMode,
&SamplerTest::debugCompareFunction,
#endif
#ifndef MAGNUM_TARGET_GLES
&SamplerTest::debugDepthStencilMode
#endif
@ -76,6 +80,7 @@ void SamplerTest::debugWrapping() {
CORRADE_COMPARE(out.str(), "Sampler::Wrapping::ClampToEdge\n");
}
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
void SamplerTest::debugCompareMode() {
std::ostringstream out;
@ -89,6 +94,7 @@ void SamplerTest::debugCompareFunction() {
Debug(&out) << Sampler::CompareFunction::GreaterOrEqual;
CORRADE_COMPARE(out.str(), "Sampler::CompareFunction::GreaterOrEqual\n");
}
#endif
#ifndef MAGNUM_TARGET_GLES
void SamplerTest::debugDepthStencilMode() {

8
src/Magnum/Test/VersionTest.cpp

@ -108,10 +108,12 @@ void VersionTest::debug() {
Debug(&out) << Version::GLES200;
#endif
#ifndef MAGNUM_TARGET_GLES
CORRADE_COMPARE(out.str(), "OpenGL 2.1\n");
#else
#ifdef MAGNUM_TARGET_WEBGL
CORRADE_COMPARE(out.str(), "WebGL 1.0\n");
#elif defined(MAGNUM_TARGET_GLES)
CORRADE_COMPARE(out.str(), "OpenGL ES 2.0\n");
#else
CORRADE_COMPARE(out.str(), "OpenGL 2.1\n");
#endif
}

3
src/Magnum/Text/Test/AbstractFontConverterTest.cpp

@ -62,6 +62,9 @@ AbstractFontConverterTest::AbstractFontConverterTest() {
&AbstractFontConverterTest::importGlyphCacheFromSingleData,
&AbstractFontConverterTest::importGlyphCacheFromFile});
/* Create testing dir */
Utility::Directory::mkpath(TEXT_TEST_OUTPUT_DIR);
}
namespace {

13
src/Magnum/Text/Test/CMakeLists.txt

@ -23,6 +23,14 @@
# DEALINGS IN THE SOFTWARE.
#
if(CORRADE_TARGET_EMSCRIPTEN)
set(TEXT_TEST_DIR "")
set(TEXT_TEST_OUTPUT_DIR "/write")
else()
set(TEXT_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(TEXT_TEST_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configure.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/configure.h)
@ -32,6 +40,11 @@ corrade_add_test(TextAbstractFontConverterTest AbstractFontConverterTest.cpp LIB
target_include_directories(TextAbstractFontConverterTest PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
corrade_add_test(TextAbstractLayouterTest AbstractLayouterTest.cpp LIBRARIES Magnum MagnumText)
if(CORRADE_TARGET_EMSCRIPTEN)
emscripten_embed_file(TextAbstractFontTest data.bin "/data.bin")
emscripten_embed_file(TextAbstractFontConverterTest data.bin "/data.bin")
endif()
if(BUILD_GL_TESTS)
corrade_add_test(TextGlyphCacheGLTest GlyphCacheGLTest.cpp LIBRARIES MagnumText ${GL_TEST_LIBRARIES})
corrade_add_test(TextRendererGLTest RendererGLTest.cpp LIBRARIES MagnumText ${GL_TEST_LIBRARIES})

4
src/Magnum/Text/Test/configure.h.cmake

@ -23,5 +23,5 @@
DEALINGS IN THE SOFTWARE.
*/
#define TEXT_TEST_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
#define TEXT_TEST_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}"
#define TEXT_TEST_DIR "${TEXT_TEST_DIR}"
#define TEXT_TEST_OUTPUT_DIR "${TEXT_TEST_OUTPUT_DIR}"

3
src/Magnum/Trade/Test/AbstractImageConverterTest.cpp

@ -45,6 +45,9 @@ class AbstractImageConverterTest: public TestSuite::Tester {
AbstractImageConverterTest::AbstractImageConverterTest() {
addTests({&AbstractImageConverterTest::exportToFile});
/* Create testing dir */
Utility::Directory::mkpath(TRADE_TEST_OUTPUT_DIR);
}
void AbstractImageConverterTest::exportToFile() {

12
src/Magnum/Trade/Test/CMakeLists.txt

@ -23,6 +23,14 @@
# DEALINGS IN THE SOFTWARE.
#
if(CORRADE_TARGET_EMSCRIPTEN)
set(TRADE_TEST_DIR "")
set(TRADE_TEST_OUTPUT_DIR "/write")
else()
set(TRADE_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(TRADE_TEST_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configure.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/configure.h)
@ -35,3 +43,7 @@ corrade_add_test(TradeImageDataTest ImageDataTest.cpp LIBRARIES Magnum)
corrade_add_test(TradeObjectData2DTest ObjectData2DTest.cpp LIBRARIES Magnum)
corrade_add_test(TradeObjectData3DTest ObjectData3DTest.cpp LIBRARIES Magnum)
corrade_add_test(TradeTextureDataTest TextureDataTest.cpp LIBRARIES Magnum)
if(CORRADE_TARGET_EMSCRIPTEN)
emscripten_embed_file(TradeAbstractImporterTest file.bin "/file.bin")
endif()

26
src/Magnum/Trade/Test/ImageDataTest.cpp

@ -60,13 +60,13 @@ ImageDataTest::ImageDataTest() {
}
void ImageDataTest::construct() {
auto data = new char[3];
auto data = new char[3*3];
Trade::ImageData2D a{PixelStorage{}.setAlignment(1),
PixelFormat::Red, PixelType::UnsignedByte, {1, 3}, Containers::Array<char>{data, 3}};
PixelFormat::RGB, PixelType::UnsignedByte, {1, 3}, Containers::Array<char>{data, 3*3}};
CORRADE_VERIFY(!a.isCompressed());
CORRADE_COMPARE(a.storage().alignment(), 1);
CORRADE_COMPARE(a.format(), PixelFormat::Red);
CORRADE_COMPARE(a.format(), PixelFormat::RGB);
CORRADE_COMPARE(a.type(), PixelType::UnsignedByte);
CORRADE_COMPARE(a.size(), Vector2i(1, 3));
CORRADE_COMPARE(a.data(), data);
@ -96,9 +96,9 @@ void ImageDataTest::constructCopy() {
}
void ImageDataTest::constructMove() {
auto data = new char[3];
auto data = new char[3*3];
Trade::ImageData2D a{PixelStorage{}.setAlignment(1),
PixelFormat::Red, PixelType::UnsignedByte, {1, 3}, Containers::Array<char>{data, 3}};
PixelFormat::RGB, PixelType::UnsignedByte, {1, 3}, Containers::Array<char>{data, 3*3}};
Trade::ImageData2D b(std::move(a));
CORRADE_COMPARE(a.data(), nullptr);
@ -106,7 +106,7 @@ void ImageDataTest::constructMove() {
CORRADE_VERIFY(!b.isCompressed());
CORRADE_COMPARE(b.storage().alignment(), 1);
CORRADE_COMPARE(b.format(), PixelFormat::Red);
CORRADE_COMPARE(b.format(), PixelFormat::RGB);
CORRADE_COMPARE(b.type(), PixelType::UnsignedByte);
CORRADE_COMPARE(b.size(), Vector2i(1, 3));
CORRADE_COMPARE(b.data(), data);
@ -120,7 +120,7 @@ void ImageDataTest::constructMove() {
CORRADE_VERIFY(!c.isCompressed());
CORRADE_COMPARE(c.storage().alignment(), 1);
CORRADE_COMPARE(c.format(), PixelFormat::Red);
CORRADE_COMPARE(c.format(), PixelFormat::RGB);
CORRADE_COMPARE(c.type(), PixelType::UnsignedByte);
CORRADE_COMPARE(c.size(), Vector2i(1, 3));
CORRADE_COMPARE(c.data(), data);
@ -166,13 +166,15 @@ void ImageDataTest::constructMoveCompressed() {
}
void ImageDataTest::toView() {
auto data = new char[4];
const Trade::ImageData2D a{PixelFormat::Red, PixelType::UnsignedByte, {4, 1}, Containers::Array<char>{data, 4}};
auto data = new char[3*3];
const Trade::ImageData2D a{PixelStorage{}.setAlignment(1),
PixelFormat::RGB, PixelType::UnsignedByte, {1, 3}, Containers::Array<char>{data, 3*3}};
ImageView2D b = a;
CORRADE_COMPARE(b.format(), PixelFormat::Red);
CORRADE_COMPARE(b.storage().alignment(), 1);
CORRADE_COMPARE(b.format(), PixelFormat::RGB);
CORRADE_COMPARE(b.type(), PixelType::UnsignedByte);
CORRADE_COMPARE(b.size(), Vector2i(4, 1));
CORRADE_COMPARE(b.size(), Vector2i(1, 3));
CORRADE_COMPARE(b.data(), data);
}
@ -189,7 +191,7 @@ void ImageDataTest::toViewCompressed() {
void ImageDataTest::release() {
char data[] = {'b', 'e', 'e', 'r'};
Trade::ImageData2D a{PixelFormat::Red, PixelType::UnsignedByte, {4, 1}, Containers::Array<char>{data, 4}};
Trade::ImageData2D a{PixelFormat::RGBA, PixelType::UnsignedByte, {1, 1}, Containers::Array<char>{data, 4}};
const char* const pointer = a.release().release();
CORRADE_COMPARE(pointer, data);

4
src/Magnum/Trade/Test/configure.h.cmake

@ -23,5 +23,5 @@
DEALINGS IN THE SOFTWARE.
*/
#define TRADE_TEST_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
#define TRADE_TEST_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}"
#define TRADE_TEST_DIR "${TRADE_TEST_DIR}"
#define TRADE_TEST_OUTPUT_DIR "${TRADE_TEST_OUTPUT_DIR}"

10
src/MagnumPlugins/ObjImporter/Test/CMakeLists.txt

@ -23,8 +23,18 @@
# DEALINGS IN THE SOFTWARE.
#
if(CORRADE_TARGET_EMSCRIPTEN)
set(OBJIMPORTER_TEST_DIR "")
else()
set(OBJIMPORTER_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configure.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/configure.h)
corrade_add_test(ObjImporterTest Test.cpp LIBRARIES MagnumObjImporterTestLib)
target_include_directories(ObjImporterTest PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
if(CORRADE_TARGET_EMSCRIPTEN)
emscripten_embed_file(ObjImporterTest "" "/")
endif()

2
src/MagnumPlugins/ObjImporter/Test/configure.h.cmake

@ -23,4 +23,4 @@
DEALINGS IN THE SOFTWARE.
*/
#define OBJIMPORTER_TEST_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
#define OBJIMPORTER_TEST_DIR "${OBJIMPORTER_TEST_DIR}"

20
src/MagnumPlugins/TgaImageConverter/Test/TgaImageConverterTest.cpp

@ -87,18 +87,34 @@ TgaImageConverterTest::TgaImageConverterTest() {
}
void TgaImageConverterTest::wrongFormat() {
ImageView2D image(PixelFormat::RG, PixelType::UnsignedByte, {}, nullptr);
ImageView2D image{
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
PixelFormat::RG,
#else
PixelFormat::LuminanceAlpha,
#endif
PixelType::UnsignedByte, {}, nullptr};
std::ostringstream out;
Error redirectError{&out};
const auto data = TgaImageConverter().exportToData(image);
CORRADE_VERIFY(!data);
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
CORRADE_COMPARE(out.str(), "Trade::TgaImageConverter::exportToData(): unsupported color format PixelFormat::RG\n");
#else
CORRADE_COMPARE(out.str(), "Trade::TgaImageConverter::exportToData(): unsupported color format PixelFormat::LuminanceAlpha\n");
#endif
}
void TgaImageConverterTest::wrongType() {
ImageView2D image(PixelFormat::Red, PixelType::Float, {}, nullptr);
ImageView2D image{
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
PixelFormat::Red,
#else
PixelFormat::Luminance,
#endif
PixelType::Float, {}, nullptr};
std::ostringstream out;
Error redirectError{&out};

10
src/MagnumPlugins/TgaImporter/Test/CMakeLists.txt

@ -23,6 +23,12 @@
# DEALINGS IN THE SOFTWARE.
#
if(CORRADE_TARGET_EMSCRIPTEN)
set(TGAIMPORTER_TEST_DIR "")
else()
set(TGAIMPORTER_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configure.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/configure.h)
@ -35,3 +41,7 @@ target_include_directories(TgaImporterTest PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
if(WIN32)
target_compile_definitions(TgaImporterTest PRIVATE "MAGNUM_TGAIMPORTER_BUILD_STATIC")
endif()
if(CORRADE_TARGET_EMSCRIPTEN)
emscripten_embed_file(TgaImporterTest file.tga "/file.tga")
endif()

2
src/MagnumPlugins/TgaImporter/Test/configure.h.cmake

@ -23,4 +23,4 @@
DEALINGS IN THE SOFTWARE.
*/
#define TGAIMPORTER_TEST_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
#define TGAIMPORTER_TEST_DIR "${TGAIMPORTER_TEST_DIR}"

Loading…
Cancel
Save