diff --git a/CMakeLists.txt b/CMakeLists.txt index 9cd179519..172bf1f48 100644 --- a/CMakeLists.txt +++ b/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) diff --git a/src/Magnum/Math/Test/TypeTraitsTest.cpp b/src/Magnum/Math/Test/TypeTraitsTest.cpp index 7f733e6ed..21b8fa33d 100644 --- a/src/Magnum/Math/Test/TypeTraitsTest.cpp +++ b/src/Magnum/Math/Test/TypeTraitsTest.cpp @@ -48,8 +48,10 @@ TypeTraitsTest::TypeTraitsTest() { &TypeTraitsTest::equalsIntegral, &TypeTraitsTest::equalsIntegral, &TypeTraitsTest::equalsIntegral, + #ifndef CORRADE_TARGET_EMSCRIPTEN &TypeTraitsTest::equalsIntegral, &TypeTraitsTest::equalsIntegral, + #endif &TypeTraitsTest::equalsFloatingPoint0, #ifndef MAGNUM_TARGET_GLES &TypeTraitsTest::equalsFloatingPoint0, diff --git a/src/Magnum/Test/CMakeLists.txt b/src/Magnum/Test/CMakeLists.txt index a2bca782f..8675864a1 100644 --- a/src/Magnum/Test/CMakeLists.txt +++ b/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) diff --git a/src/Magnum/Test/ContextTest.cpp b/src/Magnum/Test/ContextTest.cpp index 67d9346bf..2a0927ca7 100644 --- a/src/Magnum/Test/ContextTest.cpp +++ b/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 } }} diff --git a/src/Magnum/Test/DefaultFramebufferTest.cpp b/src/Magnum/Test/DefaultFramebufferTest.cpp index 254d5b14c..98f64189a 100644 --- a/src/Magnum/Test/DefaultFramebufferTest.cpp +++ b/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"); } }} diff --git a/src/Magnum/Test/ImageTest.cpp b/src/Magnum/Test/ImageTest.cpp index 224855a2f..5f6e9347c 100644 --- a/src/Magnum/Test/ImageTest.cpp +++ b/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{data, 3}}; + PixelFormat::RGBA, PixelType::UnsignedByte, {1, 3}, Containers::Array{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{data, 3}}; + PixelFormat::RGB, PixelType::UnsignedByte, {1, 3}, Containers::Array{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{data, 3}}; + PixelFormat::RGB, PixelType::UnsignedByte, {1, 3}, Containers::Array{data, 3*3}}; auto data2 = new char[2*2*4]; a.setData(PixelFormat::RGBA, PixelType::UnsignedShort, {2, 1}, Containers::Array{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{data, 3}}; + PixelFormat::RGB, PixelType::UnsignedByte, {1, 3}, Containers::Array{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{data, 4}); + Image2D a(PixelFormat::RGBA, PixelType::UnsignedByte, {1, 1}, Containers::Array{data, 4}); const char* const pointer = a.release().release(); CORRADE_COMPARE(pointer, data); diff --git a/src/Magnum/Test/ImageViewTest.cpp b/src/Magnum/Test/ImageViewTest.cpp index 47074ae7f..45c8cf8df 100644 --- a/src/Magnum/Test/ImageViewTest.cpp +++ b/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); diff --git a/src/Magnum/Test/PixelStorageTest.cpp b/src/Magnum/Test/PixelStorageTest.cpp index 41f96a356..af298516e 100644 --- a/src/Magnum/Test/PixelStorageTest.cpp +++ b/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{0, {0, 0, 0}, 4})); CORRADE_COMPARE(storage.dataProperties(PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i{1}), (std::tuple{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{0, {8, 2, 1}, 1})); CORRADE_COMPARE(storage.dataProperties(PixelFormat::Red, PixelType::UnsignedByte, {2, 4, 1}), (std::tuple{0, {2, 4, 1}, 1})); CORRADE_COMPARE(storage.dataProperties(PixelFormat::Red, PixelType::UnsignedByte, {2, 4, 6}), (std::tuple{0, {2, 4, 6}, 1})); + #endif } void PixelStorageTest::dataPropertiesAlignment() { @@ -110,14 +118,17 @@ void PixelStorageTest::dataPropertiesAlignment() { (std::tuple{3*4, {0, 0, 0}, 4})); CORRADE_COMPARE(storage.dataProperties(PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i{1}), (std::tuple{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{16 + 16 + 3, {8, 2, 1}, 1})); CORRADE_COMPARE(storage.dataProperties(PixelFormat::Red, PixelType::UnsignedByte, {2, 4, 1}), (std::tuple{32 + 16 + 3, {8, 4, 1}, 1})); CORRADE_COMPARE(storage.dataProperties(PixelFormat::Red, PixelType::UnsignedByte, {2, 4, 6}), (std::tuple{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{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 } diff --git a/src/Magnum/Test/RendererTest.cpp b/src/Magnum/Test/RendererTest.cpp index 5aaa689c5..5564ccb3b 100644 --- a/src/Magnum/Test/RendererTest.cpp +++ b/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 }} diff --git a/src/Magnum/Test/SamplerTest.cpp b/src/Magnum/Test/SamplerTest.cpp index 621edffde..a7e1a87f6 100644 --- a/src/Magnum/Test/SamplerTest.cpp +++ b/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() { diff --git a/src/Magnum/Test/VersionTest.cpp b/src/Magnum/Test/VersionTest.cpp index d439b7b02..3ce871418 100644 --- a/src/Magnum/Test/VersionTest.cpp +++ b/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 } diff --git a/src/Magnum/Text/Test/AbstractFontConverterTest.cpp b/src/Magnum/Text/Test/AbstractFontConverterTest.cpp index 3cca1727e..28773364c 100644 --- a/src/Magnum/Text/Test/AbstractFontConverterTest.cpp +++ b/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 { diff --git a/src/Magnum/Text/Test/CMakeLists.txt b/src/Magnum/Text/Test/CMakeLists.txt index 1fe654601..13552d5b9 100644 --- a/src/Magnum/Text/Test/CMakeLists.txt +++ b/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}) diff --git a/src/Magnum/Text/Test/configure.h.cmake b/src/Magnum/Text/Test/configure.h.cmake index 96f3e6a59..e3f4cc05d 100644 --- a/src/Magnum/Text/Test/configure.h.cmake +++ b/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}" diff --git a/src/Magnum/Trade/Test/AbstractImageConverterTest.cpp b/src/Magnum/Trade/Test/AbstractImageConverterTest.cpp index fc2b86f2e..d70edd92c 100644 --- a/src/Magnum/Trade/Test/AbstractImageConverterTest.cpp +++ b/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() { diff --git a/src/Magnum/Trade/Test/CMakeLists.txt b/src/Magnum/Trade/Test/CMakeLists.txt index ffe52e9c9..6cbc59e29 100644 --- a/src/Magnum/Trade/Test/CMakeLists.txt +++ b/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() diff --git a/src/Magnum/Trade/Test/ImageDataTest.cpp b/src/Magnum/Trade/Test/ImageDataTest.cpp index f56132e60..ed8674b93 100644 --- a/src/Magnum/Trade/Test/ImageDataTest.cpp +++ b/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{data, 3}}; + PixelFormat::RGB, PixelType::UnsignedByte, {1, 3}, Containers::Array{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{data, 3}}; + PixelFormat::RGB, PixelType::UnsignedByte, {1, 3}, Containers::Array{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{data, 4}}; + auto data = new char[3*3]; + const Trade::ImageData2D a{PixelStorage{}.setAlignment(1), + PixelFormat::RGB, PixelType::UnsignedByte, {1, 3}, Containers::Array{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{data, 4}}; + Trade::ImageData2D a{PixelFormat::RGBA, PixelType::UnsignedByte, {1, 1}, Containers::Array{data, 4}}; const char* const pointer = a.release().release(); CORRADE_COMPARE(pointer, data); diff --git a/src/Magnum/Trade/Test/configure.h.cmake b/src/Magnum/Trade/Test/configure.h.cmake index d39dc3cdf..017811a26 100644 --- a/src/Magnum/Trade/Test/configure.h.cmake +++ b/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}" diff --git a/src/MagnumPlugins/ObjImporter/Test/CMakeLists.txt b/src/MagnumPlugins/ObjImporter/Test/CMakeLists.txt index 134e83d4d..e51873f87 100644 --- a/src/MagnumPlugins/ObjImporter/Test/CMakeLists.txt +++ b/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() diff --git a/src/MagnumPlugins/ObjImporter/Test/configure.h.cmake b/src/MagnumPlugins/ObjImporter/Test/configure.h.cmake index 459564c9c..04d28dd95 100644 --- a/src/MagnumPlugins/ObjImporter/Test/configure.h.cmake +++ b/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}" diff --git a/src/MagnumPlugins/TgaImageConverter/Test/TgaImageConverterTest.cpp b/src/MagnumPlugins/TgaImageConverter/Test/TgaImageConverterTest.cpp index 52b003d27..6b2628058 100644 --- a/src/MagnumPlugins/TgaImageConverter/Test/TgaImageConverterTest.cpp +++ b/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}; diff --git a/src/MagnumPlugins/TgaImporter/Test/CMakeLists.txt b/src/MagnumPlugins/TgaImporter/Test/CMakeLists.txt index e3499dd25..d74826eac 100644 --- a/src/MagnumPlugins/TgaImporter/Test/CMakeLists.txt +++ b/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() diff --git a/src/MagnumPlugins/TgaImporter/Test/configure.h.cmake b/src/MagnumPlugins/TgaImporter/Test/configure.h.cmake index cb625138d..9b4aac529 100644 --- a/src/MagnumPlugins/TgaImporter/Test/configure.h.cmake +++ b/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}"