From 49bd0b6ff0140e117275fcfe6cf5ac9bffce5019 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 2 Jan 2014 19:49:52 +0100 Subject: [PATCH] Added version() utility function. Converts Version enum value to and from major/minor version number. --- src/Test/CMakeLists.txt | 1 + src/Test/VersionTest.cpp | 62 ++++++++++++++++++++++++++++++++++++++++ src/Version.h | 20 ++++++++++--- 3 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 src/Test/VersionTest.cpp diff --git a/src/Test/CMakeLists.txt b/src/Test/CMakeLists.txt index 43c63b64b..d747f50b1 100644 --- a/src/Test/CMakeLists.txt +++ b/src/Test/CMakeLists.txt @@ -36,6 +36,7 @@ corrade_add_test(RendererTest RendererTest.cpp LIBRARIES Magnum) corrade_add_test(ResourceManagerTest ResourceManagerTest.cpp LIBRARIES MagnumTestLib) corrade_add_test(SamplerTest SamplerTest.cpp LIBRARIES Magnum) corrade_add_test(ShaderTest ShaderTest.cpp LIBRARIES Magnum) +corrade_add_test(VersionTest VersionTest.cpp LIBRARIES Magnum) if(BUILD_GL_TESTS) corrade_add_test(AbstractObjectGLTest AbstractObjectGLTest.cpp LIBRARIES ${GL_TEST_LIBRARIES}) diff --git a/src/Test/VersionTest.cpp b/src/Test/VersionTest.cpp new file mode 100644 index 000000000..d3d6d9693 --- /dev/null +++ b/src/Test/VersionTest.cpp @@ -0,0 +1,62 @@ +/* + 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 + +#include "Version.h" + +namespace Magnum { namespace Test { + +class VersionTest: public TestSuite::Tester { + public: + explicit VersionTest(); + + void fromNumber(); + void toNumber(); +}; + +VersionTest::VersionTest() { + addTests({&VersionTest::fromNumber, + &VersionTest::toNumber}); +} + +void VersionTest::fromNumber() { + #ifndef MAGNUM_TARGET_GLES + CORRADE_COMPARE(version(4, 3), Version::GL430); + #else + CORRADE_COMPARE(version(3, 0), Version::GLES300); + #endif +} + +void VersionTest::toNumber() { + #ifndef MAGNUM_TARGET_GLES + CORRADE_COMPARE(version(Version::GL430), std::make_pair(4, 3)); + #else + CORRADE_COMPARE(version(Version::GLES300), std::make_pair(3, 0)); + #endif +} + +}} + +CORRADE_TEST_MAIN(Magnum::Test::VersionTest) diff --git a/src/Version.h b/src/Version.h index ba2ed5b7d..279088dc6 100644 --- a/src/Version.h +++ b/src/Version.h @@ -24,13 +24,15 @@ DEALINGS IN THE SOFTWARE. */ -#include "Magnum.h" -#include "magnumVisibility.h" - /** @file Version.h - * Enum @ref Magnum::Version + * Enum @ref Magnum::Version, function @ref version() */ +#include + +#include "Magnum.h" +#include "magnumVisibility.h" + namespace Magnum { /** @@ -80,6 +82,16 @@ enum class Version: Int { #endif }; +/** @brief Enum value from major and minor version number */ +inline Version version(Int major, Int minor) { + return Version(major*100 + minor*10); +} + +/** @brief Major and minor version number from enum value */ +inline std::pair version(Version version) { + return {Int(version)/100, (Int(version)%100)/10}; +} + /** @debugoperator{Magnum::Context} */ Debug MAGNUM_EXPORT operator<<(Debug debug, Version value);