diff --git a/src/Test/CMakeLists.txt b/src/Test/CMakeLists.txt index 16803fc05..8f10d79ab 100644 --- a/src/Test/CMakeLists.txt +++ b/src/Test/CMakeLists.txt @@ -37,6 +37,7 @@ corrade_add_test(SwizzleTest SwizzleTest.cpp LIBRARIES MagnumMathTestLib) if(BUILD_GL_TESTS) corrade_add_test(BufferGLTest BufferGLTest.cpp LIBRARIES ${GL_TEST_LIBRARIES}) + corrade_add_test(ContextTest ContextTest.cpp LIBRARIES ${GL_TEST_LIBRARIES}) endif() set_target_properties(ResourceManagerTest PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) diff --git a/src/Test/ContextTest.cpp b/src/Test/ContextTest.cpp new file mode 100644 index 000000000..69dd9d05a --- /dev/null +++ b/src/Test/ContextTest.cpp @@ -0,0 +1,119 @@ +/* + 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 "Test/AbstractOpenGLTester.h" +#include "Context.h" +#include + +namespace Magnum { namespace Test { + +class ContextTest: public AbstractOpenGLTester { + public: + explicit ContextTest(); + + void version(); + void versionList(); + void supportedExtension(); + void unsupportedExtension(); + void pastExtension(); +}; + +ContextTest::ContextTest() { + addTests({&ContextTest::version, + &ContextTest::versionList, + &ContextTest::supportedExtension, + &ContextTest::unsupportedExtension, + &ContextTest::pastExtension}); +} + +void ContextTest::version() { + const Version v = Context::current()->version(); + CORRADE_VERIFY(Context::current()->isVersionSupported(v)); + CORRADE_VERIFY(Context::current()->isVersionSupported(Version(Int(v)-1))); + CORRADE_VERIFY(!Context::current()->isVersionSupported(Version(Int(v)+1))); + + /* No assertions should be fired */ + MAGNUM_ASSERT_VERSION_SUPPORTED(v); + MAGNUM_ASSERT_VERSION_SUPPORTED(Version(Int(v)-1)); +} + +void ContextTest::versionList() { + const Version v = Context::current()->version(); + + /* Selects first supported version (thus not necessarily the highest) */ + CORRADE_VERIFY(Context::current()->supportedVersion({Version(Int(v)+1), v, Version(Int(v)-1)}) == v); + CORRADE_VERIFY(Context::current()->supportedVersion({Version(Int(v)+1), Version(Int(v)-1), v}) == Version(Int(v)-1)); +} + +void ContextTest::supportedExtension() { + if(!Context::current()->isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::EXT::texture_filter_anisotropic::string() + std::string(" extension should be supported, can't test")); + + std::string extensions(reinterpret_cast(glGetString(GL_EXTENSIONS))); + CORRADE_VERIFY(extensions.find(Extensions::GL::EXT::texture_filter_anisotropic::string()) != std::string::npos); +} + +void ContextTest::unsupportedExtension() { + #ifndef MAGNUM_TARGET_GLES + if(Context::current()->isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::GREMEDY::string_marker::string() + std::string(" extension shouldn't be supported, can't test")); + + std::string extensions(reinterpret_cast(glGetString(GL_EXTENSIONS))); + CORRADE_VERIFY(extensions.find(Extensions::GL::GREMEDY::string_marker::string()) == std::string::npos); + #elif !defined(CORRADE_TARGET_NACL) + if(Context::current()->isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::CHROMIUM::map_sub::string() + std::string(" extension shouldn't be supported, can't test")); + + std::string extensions(reinterpret_cast(glGetString(GL_EXTENSIONS))); + CORRADE_VERIFY(extensions.find(Extensions::GL::CHROMIUM::map_sub::string()) == std::string::npos); + #else + if(Context::current()->isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::NV::read_buffer_front::string() + std::string(" extension shouldn't be supported, can't test")); + + std::string extensions(reinterpret_cast(glGetString(GL_EXTENSIONS))); + CORRADE_VERIFY(extensions.find(Extensions::GL::NV::read_buffer_front::string()) == std::string::npos); + #endif +} + +void ContextTest::pastExtension() { + #ifndef MAGNUM_TARGET_GLES + if(!Context::current()->isVersionSupported(Version::GL300)) + CORRADE_SKIP("No already supported extensions exist in OpenGL 2.1"); + + CORRADE_VERIFY(Context::current()->isExtensionSupported()); + /* No assertion should be fired */ + MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::APPLE::vertex_array_object); + #else + if(!Context::current()->isVersionSupported(Version::GLES300)) + CORRADE_SKIP("No already supported extensions exist in OpenGL ES 2.0"); + + CORRADE_VERIFY(Context::current()->isExtensionSupported()); + /* No assertion should be fired */ + MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::EXT::texture_rg); + #endif +} + +}} + +CORRADE_TEST_MAIN(Magnum::Test::ContextTest)