From 8f81360628fa77b6d4148d673cb89386a55d8846 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 10 Feb 2020 21:10:35 +0100 Subject: [PATCH] Move the OpenSpace unit tests from GTest to Catch2 Fix for default.scene --- CMakeLists.txt | 12 +- data/assets/default.scene | 2 +- .../webbrowser/cmake/webbrowser_helpers.cmake | 1 - .../dependencyfunctionsexist.asset | 6 - tests/CMakeLists.txt | 64 + tests/basicvolume.rawvolume | Bin 0 -> 256 bytes tests/main.cpp | 145 +- tests/regression/{517.inl => 517.cpp} | 12 +- tests/test_angle.inl | 119 - ...t_assetloader.inl => test_assetloader.cpp} | 167 +- tests/test_chunknode.inl | 83 - tests/test_common.inl | 110 - ...ager.inl => test_concurrentjobmanager.cpp} | 138 +- ...rentqueue.inl => test_concurrentqueue.cpp} | 23 +- tests/test_configurationmanager.inl | 1116 ------ tests/test_documentation.cpp | 3079 +++++++++++++++++ tests/test_documentation.inl | 2924 ---------------- tests/test_gdalwms.inl | 58 - ...ltileprovider.inl => test_iswamanager.cpp} | 28 +- tests/test_iswamanager.inl | 87 - tests/test_latlonpatch.cpp | 142 + tests/test_latlonpatch.inl | 167 - .../{test_lrucache.inl => test_lrucache.cpp} | 81 +- tests/test_luaconversions.cpp | 877 +++++ tests/test_luaconversions.inl | 2216 ------------ ...onproperty.inl => test_optionproperty.cpp} | 146 +- tests/test_patchcoverageprovider.inl | 203 -- ...t_rawvolumeio.inl => test_rawvolumeio.cpp} | 30 +- tests/test_screenspaceimage.inl | 69 - ...scheduler.inl => test_scriptscheduler.cpp} | 539 +-- tests/test_spicemanager.cpp | 493 +++ tests/test_spicemanager.inl | 476 --- ...soid.inl => test_temporaltileprovider.cpp} | 22 +- .../{test_timeline.inl => test_timeline.cpp} | 49 +- tests/tinyvolume.rawvolume | Bin 0 -> 4 bytes 35 files changed, 5301 insertions(+), 8383 deletions(-) delete mode 100644 tests/AssetLoaderTest/dependencyfunctionsexist.asset create mode 100644 tests/CMakeLists.txt create mode 100644 tests/basicvolume.rawvolume rename tests/regression/{517.inl => 517.cpp} (94%) delete mode 100644 tests/test_angle.inl rename tests/{test_assetloader.inl => test_assetloader.cpp} (51%) delete mode 100644 tests/test_chunknode.inl delete mode 100644 tests/test_common.inl rename tests/{test_concurrentjobmanager.inl => test_concurrentjobmanager.cpp} (59%) rename tests/{test_concurrentqueue.inl => test_concurrentqueue.cpp} (82%) delete mode 100644 tests/test_configurationmanager.inl create mode 100644 tests/test_documentation.cpp delete mode 100644 tests/test_documentation.inl delete mode 100644 tests/test_gdalwms.inl rename tests/{test_temporaltileprovider.inl => test_iswamanager.cpp} (77%) delete mode 100644 tests/test_iswamanager.inl create mode 100644 tests/test_latlonpatch.cpp delete mode 100644 tests/test_latlonpatch.inl rename tests/{test_lrucache.inl => test_lrucache.cpp} (68%) create mode 100644 tests/test_luaconversions.cpp delete mode 100644 tests/test_luaconversions.inl rename tests/{test_optionproperty.inl => test_optionproperty.cpp} (55%) delete mode 100644 tests/test_patchcoverageprovider.inl rename tests/{test_rawvolumeio.inl => test_rawvolumeio.cpp} (88%) delete mode 100644 tests/test_screenspaceimage.inl rename tests/{test_scriptscheduler.inl => test_scriptscheduler.cpp} (58%) create mode 100644 tests/test_spicemanager.cpp delete mode 100644 tests/test_spicemanager.inl rename tests/{test_ellipsoid.inl => test_temporaltileprovider.cpp} (83%) rename tests/{test_timeline.inl => test_timeline.cpp} (71%) create mode 100644 tests/tinyvolume.rawvolume diff --git a/CMakeLists.txt b/CMakeLists.txt index 10852f0aa9..aaf5f0e21e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -218,6 +218,13 @@ handle_applications() end_header("End: Configuring Applications") message(STATUS "") +option(OPENSPACE_HAVE_TESTS "Activate the OpenSpace unit tests" ON) +if (OPENSPACE_HAVE_TESTS) + begin_header("Generating OpenSpace unit test") + add_subdirectory("${OPENSPACE_BASE_DIR}/tests") + end_header() +endif (OPENSPACE_HAVE_TESTS) + # Web Browser and Web gui # Why not put these in the module's path? Because they do not have access to the @@ -236,11 +243,6 @@ if (OPENSPACE_MODULE_WEBBROWSER AND CEF_ROOT) # find CEF to initialize it properly. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${WEBBROWSER_MODULE_PATH}/cmake") include(webbrowser_helpers) - - if (TARGET OpenSpaceTest) - set_cef_targets("${CEF_ROOT}" OpenSpaceTest) - run_cef_platform_config("${CEF_ROOT}" "${CEF_TARGET}" "${WEBBROWSER_MODULE_PATH}") - endif () elseif (OPENSPACE_MODULE_WEBBROWSER) message(WARNING "Web configured to be included, but no CEF_ROOT was found, please try configuring CMake again.") endif () diff --git a/data/assets/default.scene b/data/assets/default.scene index b98d9adbc1..31a2e83d4f 100644 --- a/data/assets/default.scene +++ b/data/assets/default.scene @@ -1,7 +1,7 @@ asset.require('./base') local earthAsset = asset.require('scene/solarsystem/planets/earth/earth') -asset.request('scene/solarsystem/planets/earth/satellites/satellites.asset') +asset.require('scene/solarsystem/planets/earth/satellites/satellites.asset') asset.onInitialize(function () local now = openspace.time.currentWallTime() diff --git a/modules/webbrowser/cmake/webbrowser_helpers.cmake b/modules/webbrowser/cmake/webbrowser_helpers.cmake index fdf33a6d40..9b121f3a64 100644 --- a/modules/webbrowser/cmake/webbrowser_helpers.cmake +++ b/modules/webbrowser/cmake/webbrowser_helpers.cmake @@ -22,7 +22,6 @@ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # ########################################################################################## - function(set_cef_targets cef_root main_target) # find cef cmake helpers set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${cef_root}/cmake") diff --git a/tests/AssetLoaderTest/dependencyfunctionsexist.asset b/tests/AssetLoaderTest/dependencyfunctionsexist.asset deleted file mode 100644 index 66f96d70c4..0000000000 --- a/tests/AssetLoaderTest/dependencyfunctionsexist.asset +++ /dev/null @@ -1,6 +0,0 @@ -local imports, dep = asset.require('export') - -assert(type(dep.localResource) == "function", "localResource should be function") -assert(type(dep.syncedResource) == "function", "syncedResource should be function") -assert(type(dep.onInitialize) == "function", "onInitialize should be function") -assert(type(dep.onDeinitialize) == "function", "onDeinitialize should be function") \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000000..f00a9bede5 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,64 @@ +########################################################################################## +# # +# OpenSpace # +# # +# Copyright (c) 2014-2019 # +# # +# 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. # +########################################################################################## + +add_executable( + OpenSpaceTest + main.cpp + test_assetloader.cpp + test_concurrentjobmanager.cpp + test_concurrentqueue.cpp + test_documentation.cpp + test_iswamanager.cpp + test_latlonpatch.cpp + test_lrucache.cpp + test_luaconversions.cpp + test_optionproperty.cpp + test_rawvolumeio.cpp + test_scriptscheduler.cpp + test_spicemanager.cpp + test_temporaltileprovider.cpp + test_timeline.cpp + + regression/517.cpp +) + +set_openspace_compile_settings(OpenSpaceTest) + +target_include_directories(OpenSpaceTest PUBLIC +"${GHOUL_BASE_DIR}/ext/catch2/single_include" +) +target_compile_definitions(OpenSpaceTest PUBLIC "GHL_THROW_ON_ASSERT") +target_link_libraries(OpenSpaceTest openspace-core) + +if (OPENSPACE_MODULE_WEBBROWSER AND CEF_ROOT) + # Add the CEF binary distribution's cmake/ directory to the module path and + # find CEF to initialize it properly. + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${WEBBROWSER_MODULE_PATH}/cmake") + include(webbrowser_helpers) + + set_cef_targets("${CEF_ROOT}" OpenSpaceTest) + run_cef_platform_config("${CEF_ROOT}" "${CEF_TARGET}" "${WEBBROWSER_MODULE_PATH}") +endif () + +set_folder_location(OpenSpaceTest "Unit Tests") diff --git a/tests/basicvolume.rawvolume b/tests/basicvolume.rawvolume new file mode 100644 index 0000000000000000000000000000000000000000..2ee491bde02535fa997ba58ce7b8ae298e3bf6d9 GIT binary patch literal 256 zcmWl|L5hI^7y!^uQ50q202D=07WRIOqNq8-D2n0^vXYf%HCZ`|tYkG=$!R>VUc|?? zYZ7rbdJ#nvzm0xG+M*@PR&CpH>(0FgkN*1S$%|KS-u?IC)0Z)bNSQWc)|`0@maSN| cX5EHOTPF7Wa_Gph6Q}+-bMC^WE7xuYZ(D&S1ONa4 literal 0 HcmV?d00001 diff --git a/tests/main.cpp b/tests/main.cpp index 8fa9ef3765..64ac5476f2 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -22,143 +22,50 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#if defined(WIN32) -#pragma warning (push) -#pragma warning (disable : 4619) // #pragma warning: there is no warning number '4800' -#elif defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wundef" -#pragma clang diagnostic ignored "-Wmissing-noreturn" -#pragma clang diagnostic ignored "-Wshift-sign-overflow" -#pragma clang diagnostic ignored "-Wsign-compare" -#pragma clang diagnostic ignored "-Wused-but-marked-unused" -#elif defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wundef" -#pragma GCC diagnostic ignored "-Wmissing-noreturn" -#pragma GCC diagnostic ignored "-Wsign-compare" -#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" -#pragma GCC diagnostic ignored "-Wsuggest-override" -#endif // __GNUC__ - -#include "gtest/gtest.h" - -// When running the unit tests we don't want to be asked what to do in the case of an -// assertion -#ifndef GHL_THROW_ON_ASSERT -#define GHL_THROW_ON_ASSERT -#endif // GHL_THROW_ON_ASSERTGHL_THROW_ON_ASSERT +#define CATCH_CONFIG_RUNNER +#include "catch2/catch.hpp" #include +#include #include #include #include #include #include +#include +#include #include #include #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef OPENSPACE_MODULE_GLOBEBROWSING_ENABLED -#include -#include -#include -#include -#include -#endif - -#ifdef OPENSPACE_MODULE_ISWA_ENABLED -#include -#endif - -#ifdef OPENSPACE_MODULE_VOLUME_ENABLED -#include -#endif - -// Regression tests -#include - - - - -using namespace ghoul::filesystem; -using namespace ghoul::logging; - -//#define PRINT_OUTPUT - -namespace { - std::string _loggerCat = "OpenSpaceTest"; -} - int main(int argc, char** argv) { - std::vector args; + using namespace openspace; + ghoul::initialize(); - // Workaround for Visual Studio Google Test Adapter: - // Do not try to initialize osengine if gtest is just listing tests - std::vector gtestArgs(argv, argv + argc); - if (std::find(gtestArgs.begin(), gtestArgs.end(), "--gtest_list_tests") != gtestArgs.end()) { - using namespace openspace; - ghoul::initialize(); + // Register the path of the executable, + // to make it possible to find other files in the same directory. + FileSys.registerPathToken( + "${BIN}", + ghoul::filesystem::File(absPath(argv[0])).directoryName(), + ghoul::filesystem::FileSystem::Override::Yes + ); - std::string configFile = configuration::findConfiguration(); - global::configuration = configuration::loadConfigurationFromFile(configFile); - global::openSpaceEngine.initialize(); + std::string configFile = configuration::findConfiguration(); + global::configuration = configuration::loadConfigurationFromFile(configFile); + global::openSpaceEngine.registerPathTokens(); + global::openSpaceEngine.initialize(); - FileSys.registerPathToken("${TESTDIR}", "${BASE}/tests"); + FileSys.registerPathToken("${TESTDIR}", "${BASE}/tests"); - // All of the relevant tests initialize the SpiceManager - openspace::SpiceManager::deinitialize(); - } + // All of the relevant tests initialize the SpiceManager + openspace::SpiceManager::deinitialize(); - testing::InitGoogleTest(&argc, argv); + int result = Catch::Session().run(argc, argv); -#ifdef PRINT_OUTPUT - testing::internal::CaptureStdout(); - testing::internal::CaptureStderr(); -#endif - -#ifdef PRINT_OUTPUT - - // Stop capturing std out - std::string output = testing::internal::GetCapturedStdout(); - std::string error = testing::internal::GetCapturedStderr(); - - //std::cout << output; - //std::cerr << error; -#endif - - //openspace::SpiceManager::deinitialize(); - - bool b = RUN_ALL_TESTS(); - -#ifdef PRINT_OUTPUT - std::string output = testing::internal::GetCapturedStdout(); - std::string error = testing::internal::GetCapturedStderr(); - - std::ofstream o("output.txt"); - o << output; - - std::ofstream e("error.txt"); - e << error; -#endif - return b; + // And the deinitialization needs the SpiceManager to be initialized + openspace::SpiceManager::initialize(); + global::openSpaceEngine.deinitialize(); + return result; } - -#ifdef WIN32 -#pragma warning (pop) -#elif defined(__clang__) -#pragma clang diagnostic pop -#elif defined(__GNUC__) -#pragma GCC diagnostic pop -#endif // __GNUC__ diff --git a/tests/regression/517.inl b/tests/regression/517.cpp similarity index 94% rename from tests/regression/517.inl rename to tests/regression/517.cpp index 8ffeea5e4f..3ae7f2b0a7 100644 --- a/tests/regression/517.inl +++ b/tests/regression/517.cpp @@ -22,20 +22,20 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ +#include "catch2/catch.hpp" + #include -class Issue527 : public testing::Test {}; - -TEST_F(Issue527, Regression) { +TEST_CASE("Regression: 527", "[regression]") { // Error in OptionProperty if values not starting at 0 are used - openspace::properties::OptionProperty p({ "id", "gui", "desc"}); + openspace::properties::OptionProperty p({ "id", "gui", "desc" }); p.addOptions({ { -1, "a" }, { -2, "b" } - }); + }); p = -1; - ASSERT_EQ("a", p.option().description); + REQUIRE(p.option().description == "a"); } diff --git a/tests/test_angle.inl b/tests/test_angle.inl deleted file mode 100644 index be4dcf5e1e..0000000000 --- a/tests/test_angle.inl +++ /dev/null @@ -1,119 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2019 * - * * - * 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 -// -//#include -//#include -// -//class AngleTest : public testing::Test {}; -// -//TEST_F(AngleTest, DoubleConversions) { -// using namespace openspace::globebrowsing; -// -// ASSERT_EQ(dAngle::fromRadians(0).asDegrees(), 0) << "from radians to degrees"; -// ASSERT_EQ(dAngle::HALF.asDegrees(), 180) << "from radians to degrees"; -// ASSERT_EQ(dAngle::fromDegrees(180).asRadians(), glm::pi()) << "from degrees to radians"; -// -//} -// -//TEST_F(AngleTest, FloatConversions) { -// using namespace openspace::globebrowsing; -// -// ASSERT_EQ(fAngle::ZERO.asDegrees(), 0.0) << "from radians to degrees"; -// ASSERT_EQ(fAngle::HALF.asDegrees(), 180.0) << "from radians to degrees"; -// ASSERT_EQ(fAngle::fromDegrees(180).asRadians(), glm::pi()) << "from degrees to radians"; -// -//} -// -// -//TEST_F(AngleTest, Normalize) { -// using namespace openspace::globebrowsing; -// -// ASSERT_NEAR( -// dAngle::fromDegrees(390).normalize().asDegrees(), -// 30.0, -// dAngle::EPSILON -// ) << "normalize to [0, 360]"; -// -// -// dAngle a = dAngle::fromDegrees(190); -// a.normalizeAround(dAngle::ZERO); -// ASSERT_NEAR( -// a.asDegrees(), -// -170, -// dAngle::EPSILON -// ) << "normalize to [-180,180]"; -// -// -// dAngle b = dAngle::fromDegrees(190); -// b.normalizeAround(dAngle::fromDegrees(90)); -// ASSERT_NEAR( -// b.asDegrees(), -// 190, -// dAngle::EPSILON -// ) << "normalize to [-90,270]"; -// -// -// dAngle c = dAngle::fromDegrees(360); -// c.normalizeAround(dAngle::fromDegrees(1083.2)); -// ASSERT_NEAR( -// c.asDegrees(), -// 1080, -// dAngle::EPSILON -// ) << "normalize to [903.2, 1263.2]"; -//} -// -// -//TEST_F(AngleTest, Clamp) { -// using namespace openspace::globebrowsing; -// -// ASSERT_EQ( -// dAngle::fromDegrees(390).clamp(dAngle::ZERO, dAngle::HALF).asDegrees(), -// 180 -// ) << "clamp [0, 180]"; -// -// ASSERT_EQ( -// dAngle::fromDegrees(390).clamp(dAngle::ZERO, dAngle::FULL).asDegrees(), -// 360 -// ) << "clamp [0, 360]"; -//} -// -// -//TEST_F(AngleTest, ConstClamp) { -// using namespace openspace::globebrowsing; -// -// const dAngle a = dAngle::fromDegrees(390); -// ASSERT_EQ( -// a.getClamped(dAngle::ZERO, dAngle::HALF).asDegrees(), -// 180 -// ) << "clamp [0, 180]"; -// -// const dAngle b = dAngle::fromDegrees(390); -// ASSERT_EQ( -// b.getClamped(dAngle::ZERO, dAngle::FULL).asDegrees(), -// 360 -// ) << "clamp [0, 360]"; -//} diff --git a/tests/test_assetloader.inl b/tests/test_assetloader.cpp similarity index 51% rename from tests/test_assetloader.inl rename to tests/test_assetloader.cpp index 545c7aae9a..6d3ec8d835 100644 --- a/tests/test_assetloader.inl +++ b/tests/test_assetloader.cpp @@ -22,127 +22,90 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include "gtest/gtest.h" +#include "catch2/catch.hpp" + +#include +#include +#include #include #include - #include #include #include #include #include -#include - -#include - -#include -#include - -#include #include - +#include +#include #include #include -#include -//#include -#include - class AssetLoaderTest; namespace { -int passTest(lua_State* state); + int passTest(lua_State* state) { + bool* test = reinterpret_cast(lua_touserdata(state, lua_upvalueindex(1))); + *test = true; + return 0; + } +} // namespace + +TEST_CASE("AssetLoader: Assertion", "[assetloader]") { + openspace::Scene scene(std::make_unique()); + ghoul::lua::LuaState* state = openspace::global::scriptEngine.luaState(); + openspace::SynchronizationWatcher syncWatcher; + openspace::AssetLoader assetLoader( + *state, + &syncWatcher, + FileSys.absolutePath("${TESTDIR}/AssetLoaderTest/") + ); + + REQUIRE_NOTHROW(assetLoader.add("passassertion")); + REQUIRE_NOTHROW(assetLoader.add("failassertion")); } -class AssetLoaderTest : public ::testing::Test { -public: - void pass() { - _passedTest = true; - } +TEST_CASE("AssetLoader: Basic Export Import", "[assetloader]") { + openspace::Scene scene(std::make_unique()); + ghoul::lua::LuaState* state = openspace::global::scriptEngine.luaState(); + openspace::SynchronizationWatcher syncWatcher; + openspace::AssetLoader assetLoader( + *state, + &syncWatcher, + FileSys.absolutePath("${TESTDIR}/AssetLoaderTest/") + ); - bool passed() { - return _passedTest; - } - -protected: - virtual void SetUp() { - _scene = std::make_unique( - std::make_unique() - ); - ghoul::lua::LuaState* state = openspace::global::scriptEngine.luaState(); - openspace::global::scriptEngine.initialize(); - _syncWatcher = std::make_unique(); - _assetLoader = std::make_unique( - *state, - _syncWatcher.get(), - FileSys.absolutePath("${TESTDIR}/AssetLoaderTest/") - ); - - _passedTest = false; - lua_pushlightuserdata(*state, this); - lua_pushcclosure(*state, &passTest, 1); - lua_setglobal(*state, "passTest"); - } - - virtual void TearDown() { - openspace::global::scriptEngine.deinitialize(); - } - - std::unique_ptr _scene; - std::unique_ptr _assetLoader; - std::unique_ptr _syncWatcher; - bool _passedTest; -}; - -namespace { -int passTest(lua_State* state) { - AssetLoaderTest *test = - reinterpret_cast(lua_touserdata(state, lua_upvalueindex(1))); - test->pass(); - return 0; -} + REQUIRE_NOTHROW(assetLoader.add("require")); } -TEST_F(AssetLoaderTest, Assertions) { - EXPECT_NO_THROW(_assetLoader->add("passassertion")); - EXPECT_NO_THROW(_assetLoader->add("failassertion")); +TEST_CASE("AssetLoader: Asset Functions", "[assetloader]") { + openspace::Scene scene(std::make_unique()); + ghoul::lua::LuaState* state = openspace::global::scriptEngine.luaState(); + openspace::SynchronizationWatcher syncWatcher; + openspace::AssetLoader assetLoader( + *state, + &syncWatcher, + FileSys.absolutePath("${TESTDIR}/AssetLoaderTest/") + ); + + REQUIRE_NOTHROW(assetLoader.add("assetfunctionsexist")); } -TEST_F(AssetLoaderTest, BasicExportImport) { - try { - _assetLoader->add("require"); - } - catch (const std::exception& e) { - EXPECT_TRUE(false) << e.what(); - } +TEST_CASE("AssetLoader: Asset Initialization", "[assetloader]") { + openspace::Scene scene(std::make_unique()); + ghoul::lua::LuaState* state = openspace::global::scriptEngine.luaState(); + openspace::SynchronizationWatcher syncWatcher; + openspace::AssetLoader assetLoader( + *state, + &syncWatcher, + FileSys.absolutePath("${TESTDIR}/AssetLoaderTest/") + ); + + bool passed; + lua_pushlightuserdata(*state, &passed); + lua_pushcclosure(*state, &passTest, 1); + lua_setglobal(*state, "passTest"); + + std::shared_ptr asset = assetLoader.add("initialization"); + REQUIRE_NOTHROW(asset->initialize()); + REQUIRE(passed); } - -TEST_F(AssetLoaderTest, AssetFunctions) { - try { - _assetLoader->add("assetfunctionsexist"); - } catch (const std::exception& e) { - EXPECT_TRUE(false) << e.what(); - } -} - -TEST_F(AssetLoaderTest, DependencyFunctions) { - try { - _assetLoader->add("dependencyfunctionsexist"); - } - catch (const std::exception& e) { - EXPECT_TRUE(false) << e.what(); - } -} - -TEST_F(AssetLoaderTest, AssetInitialization) { - try { - std::shared_ptr asset = _assetLoader->add("initialization"); - asset->initialize(); - EXPECT_TRUE(passed()); - } - catch (const std::exception& e) { - EXPECT_TRUE(false) << e.what(); - } -} - - diff --git a/tests/test_chunknode.inl b/tests/test_chunknode.inl deleted file mode 100644 index 114f256a82..0000000000 --- a/tests/test_chunknode.inl +++ /dev/null @@ -1,83 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2019 * - * * - * 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 -#include - -#include -#include - -using namespace openspace; - -class ChunkNodeTest : public testing::Test {}; - -/* -TEST_F(ChunkNodeTest, Split) { - - ghoul::Dictionary dict; - ChunkLodGlobe chunkLodNode(dict); - chunkLodNode.initialize(); - - BoundingRect bounds(Vec2(2, 2), Vec2(2, 2)); - ChunkNode cn(chunkLodNode,bounds); - ASSERT_TRUE(cn.isRoot()) << "Chunk node is root"; - ASSERT_TRUE(cn.isLeaf()) << "Chunk node is leaf"; - - cn.split(); - ASSERT_TRUE(cn.isRoot()) << "Chunk node is root"; - ASSERT_FALSE(cn.isLeaf()) << "Chunk node is not leaf"; - - ASSERT_EQ(cn.bounds.center.x, cn.child(Quad::NORTH_WEST).bounds.center.x * 2); - ASSERT_EQ(cn.bounds.center.x, cn.child(Quad::NORTH_EAST).bounds.center.x * 2/3); - - ASSERT_EQ(cn.bounds.halfSize.x, cn.child(Quad::NORTH_WEST).bounds.halfSize.x * 2); - ASSERT_EQ(cn.bounds.halfSize.y, cn.child(Quad::NORTH_WEST).bounds.halfSize.y * 2); - - chunkLodNode.deinitialize(); -} - -TEST_F(ChunkNodeTest, Merge) { - ghoul::Dictionary dict; - ChunkLodGlobe chunkLodNode(dict); - chunkLodNode.initialize(); - - - BoundingRect bounds(Vec2(2, 2), Vec2(2, 2)); - ChunkNode cn(chunkLodNode,bounds); - ASSERT_TRUE(cn.isRoot()) << "Chunk node is root"; - ASSERT_TRUE(cn.isLeaf()) << "Chunk node is leaf"; - - cn.split(); - ASSERT_TRUE(cn.isRoot()) << "Chunk node is root"; - ASSERT_FALSE(cn.isLeaf()) << "Chunk node is not leaf"; - - cn.merge(); - ASSERT_TRUE(cn.isRoot()) << "Chunk node is root"; - ASSERT_TRUE(cn.isLeaf()) << "Chunk node is leaf"; - - chunkLodNode.deinitialize(); - -} -*/ \ No newline at end of file diff --git a/tests/test_common.inl b/tests/test_common.inl deleted file mode 100644 index 62dd62ba43..0000000000 --- a/tests/test_common.inl +++ /dev/null @@ -1,110 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2019 * - * * - * 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. * - ****************************************************************************************/ - -#ifdef GHL_TIMING_TESTS - -#ifdef WIN32 -#define START_TIMER(__name__, __stream__, __num__) \ - __stream__ << #__name__; \ - double __name__##Total = 0.0; \ - unsigned int __name__##Num = 0; \ - for (__name__##Num = 0; __name__##Num < __num__; ++__name__##Num) { \ - reset(); \ - LARGE_INTEGER __name__##Start; \ - LARGE_INTEGER __name__##End; \ - QueryPerformanceCounter(&__name__##Start) - -#define START_TIMER_NO_RESET(__name__, __stream__, __num__) \ - __stream__ << #__name__; \ - double __name__##Total = 0.0; \ - unsigned int __name__##Num = 0; \ - for (__name__##Num = 0; __name__##Num < __num__; ++__name__##Num) { \ - LARGE_INTEGER __name__##Start; \ - LARGE_INTEGER __name__##End; \ - QueryPerformanceCounter(&__name__##Start) - -#define START_TIMER_PREPARE(__name__, __stream__, __num__, __prepare__) \ - __stream__ << #__name__; \ - double __name__##Total = 0.0; \ - unsigned int __name__##Num = 0; \ - for (__name__##Num = 0; __name__##Num < __num__; ++__name__##Num) { \ - reset(); \ - __prepare__; \ - LARGE_INTEGER __name__##Start; \ - LARGE_INTEGER __name__##End; \ - QueryPerformanceCounter(&__name__##Start) - -#define FINISH_TIMER(__name__, __stream__) \ - QueryPerformanceCounter(&__name__##End); \ - LARGE_INTEGER freq; \ - QueryPerformanceFrequency(&freq); \ - const double freqD = double(freq.QuadPart) / 1000000.0; \ - const double res = ((__name__##End.QuadPart - __name__##Start.QuadPart) / freqD);\ - __name__##Total += res; \ - } \ - __stream__ << '\t' << __name__##Total / __name__##Num << "us\n"; - -#else - -#include - -#define START_TIMER(__name__, __stream__, __num__) \ - __stream__ << #__name__; \ - std::chrono::nanoseconds __name__##Total = std::chrono::nanoseconds(0); \ - unsigned int __name__##Num = 0; \ - for (__name__##Num = 0; __name__##Num < __num__; ++__name__##Num) { \ - reset(); \ - std::chrono::high_resolution_clock::time_point __name__##End; \ - std::chrono::high_resolution_clock::time_point __name__##Start = \ - std::chrono::high_resolution_clock::now() - -#define START_TIMER_NO_RESET(__name__, __stream__, __num__) \ - __stream__ << #__name__; \ - std::chrono::nanoseconds __name__##Total = std::chrono::nanoseconds(0); \ - unsigned int __name__##Num = 0; \ - for (__name__##Num = 0; __name__##Num < __num__; ++__name__##Num) { \ - std::chrono::high_resolution_clock::time_point __name__##End; \ - std::chrono::high_resolution_clock::time_point __name__##Start = \ - std::chrono::high_resolution_clock::now() - -#define START_TIMER_PREPARE(__name__, __stream__, __num__, __prepare__) \ - __stream__ << #__name__; \ - std::chrono::nanoseconds __name__##Total = std::chrono::nanoseconds(0); \ - unsigned int __name__##Num = 0; \ - for (__name__##Num = 0; __name__##Num < __num__; ++__name__##Num) { \ - reset(); \ - __prepare__; \ - std::chrono::high_resolution_clock::time_point __name__##End; \ - std::chrono::high_resolution_clock::time_point __name__##Start = \ - std::chrono::high_resolution_clock::now() - -#define FINISH_TIMER(__name__, __stream__) \ - __name__##End = std::chrono::high_resolution_clock::now(); \ - const std::chrono::nanoseconds d = __name__##End - __name__##Start; \ - __name__##Total += d; \ - } \ - __stream__ << #__name__ << '\t' << __name__##Total.count() / 1000.0 << "us" << '\n'; -#endif - -#endif // GHL_TIMING_TESTS diff --git a/tests/test_concurrentjobmanager.inl b/tests/test_concurrentjobmanager.cpp similarity index 59% rename from tests/test_concurrentjobmanager.inl rename to tests/test_concurrentjobmanager.cpp index 901e8c7efd..6a4372225c 100644 --- a/tests/test_concurrentjobmanager.inl +++ b/tests/test_concurrentjobmanager.cpp @@ -22,44 +22,64 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ - -#include "gtest/gtest.h" +#include "catch2/catch.hpp" #include - #include - -#define _USE_MATH_DEFINES -#include #include -class ConcurrentJobManagerTest : public testing::Test {}; +namespace { + struct TestJob : public openspace::Job { + TestJob(int jobExecutingTime) + : _jobExecutingTime(jobExecutingTime) + {} -struct TestJob : public openspace::Job { - TestJob(int jobExecutingTime) - : _jobExecutingTime(jobExecutingTime) - {} + virtual void execute() { + std::this_thread::sleep_for(std::chrono::milliseconds(_jobExecutingTime)); + prod = 1337; + } - virtual void execute() { - std::cout << "Executing job ... " << std::endl; - std::this_thread::sleep_for(std::chrono::milliseconds(_jobExecutingTime)); - - prod = 1337; - std::cout << "Finished job" << std::endl; - } + virtual int product() { + return int(prod); + } - virtual int product() { - return int(prod); - } - -private: - int _jobExecutingTime; - int prod; -}; + private: + int _jobExecutingTime; + int prod; + }; + struct VerboseProduct { + VerboseProduct(int v) : val(v) {} -TEST_F(ConcurrentJobManagerTest, Basic) { + ~VerboseProduct() {} + + int val; + }; + + + struct VerboseJob : public openspace::Job { + VerboseJob(int jobExecutingTime) + : _jobExecutingTime(jobExecutingTime) + , _product(-1) + {} + + virtual void execute() { + std::this_thread::sleep_for(std::chrono::milliseconds(_jobExecutingTime)); + _product = VerboseProduct(1337); + } + + virtual VerboseProduct product() { + return _product; + } + + int _jobExecutingTime; + VerboseProduct _product; + }; + +} // namespace + +TEST_CASE("ConcurrentJobmanager: Basic", "[concurrentjobmanager]") { using namespace openspace; ConcurrentJobManager jobManager(ThreadPool(1)); @@ -71,82 +91,36 @@ TEST_F(ConcurrentJobManagerTest, Basic) { jobManager.enqueueJob(testJob2); std::this_thread::sleep_for(std::chrono::milliseconds(10)); - EXPECT_EQ(jobManager.numFinishedJobs(), 0) << "A 20ms job should not be done after 10ms"; + REQUIRE(jobManager.numFinishedJobs() == 0); std::this_thread::sleep_for(std::chrono::milliseconds(20)); - - EXPECT_EQ(jobManager.numFinishedJobs(), 1) << "A 20ms job should be done after 10+20 ms"; + + REQUIRE(jobManager.numFinishedJobs() == 1); std::this_thread::sleep_for(std::chrono::milliseconds(20)); - EXPECT_EQ(jobManager.numFinishedJobs(), 2) << "A 20ms job and a 20ms job should be done after 10+20+20 ms"; - + REQUIRE(jobManager.numFinishedJobs() == 2); auto finishedJob = jobManager.popFinishedJob(); int product = finishedJob->product(); - EXPECT_EQ(product, 1337) << "Expecting product to be 1337"; + REQUIRE(product == 1337); } -struct VerboseProduct { - VerboseProduct(int v) - : val(v) { - std::cout << "VerboseProduct constructor" << std::endl; - } - - ~VerboseProduct() { - std::cout << "VerboseProduct destructor" << std::endl; - } - - int val; -}; - - -struct VerboseJob : public openspace::Job { - VerboseJob(int jobExecutingTime) - : _jobExecutingTime(jobExecutingTime) - , _product(-1) - { - std::cout << "VerboseTestJob constructor" << std::endl; - } - - ~VerboseJob() { - std::cout << "VerboseTestJob destructor" << std::endl; - } - - virtual void execute() { - std::cout << " ** Executing job ... " << std::endl; - std::this_thread::sleep_for(std::chrono::milliseconds(_jobExecutingTime)); - _product = VerboseProduct(1337); - std::cout << " ** Finished job" << std::endl; - } - - virtual VerboseProduct product() { - return _product; - } - - int _jobExecutingTime; - VerboseProduct _product; - -}; - -TEST_F(ConcurrentJobManagerTest, JobCreation) { +TEST_CASE("ConcurrentJobmanager: Job Creation", "[concurrentjobmanager]") { using namespace openspace; - + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); ConcurrentJobManager jobManager(ThreadPool(1)); - auto testJob1 = std::shared_ptr(new VerboseJob(20)); jobManager.enqueueJob(testJob1); std::this_thread::sleep_for(std::chrono::milliseconds(10)); - EXPECT_EQ(jobManager.numFinishedJobs(), 0) << "A 20ms job should not be done after 10ms"; + REQUIRE(jobManager.numFinishedJobs() == 0); std::this_thread::sleep_for(std::chrono::milliseconds(20)); - - EXPECT_EQ(jobManager.numFinishedJobs(), 1) << "A 20ms job should be done after 10+20 ms"; - + REQUIRE(jobManager.numFinishedJobs() == 1); auto finishedJob = jobManager.popFinishedJob(); { diff --git a/tests/test_concurrentqueue.inl b/tests/test_concurrentqueue.cpp similarity index 82% rename from tests/test_concurrentqueue.inl rename to tests/test_concurrentqueue.cpp index cab11de5a2..c32251f357 100644 --- a/tests/test_concurrentqueue.inl +++ b/tests/test_concurrentqueue.cpp @@ -22,32 +22,15 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include "gtest/gtest.h" +#include "catch2/catch.hpp" #include -#define _USE_MATH_DEFINES -#include -#include - -class ConcurrentQueueTest : public testing::Test {}; - -TEST_F(ConcurrentQueueTest, Basic) { +TEST_CASE("ConcurrentQueue: Basic", "[concurrentqueue]") { using namespace openspace; ConcurrentQueue q1; q1.push(4); int val = q1.pop(); - std::cout << val << std::endl; + REQUIRE(val == 4); } - -/* -TEST_F(ConcurrentQueueTest, SharedPtr) { - ConcurrentQueue> q1; - std::shared_ptr i1 = std::shared_ptr(new int(1337)); - - q1.push(i1); - auto val = q1.pop(); - std::cout << *val << std::endl; -} -*/ diff --git a/tests/test_configurationmanager.inl b/tests/test_configurationmanager.inl deleted file mode 100644 index 419296f7e5..0000000000 --- a/tests/test_configurationmanager.inl +++ /dev/null @@ -1,1116 +0,0 @@ -/***************************************************************************************** - * * - * GHOUL * - * General Helpful Open Utility Library * - * * - * Copyright (c) 2012-2018 * - * * - * 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 -#include -#include -#include - -namespace { - // A non-existing configuration file - const std::string _configuration0 = "${TEST_DIR}/configurationmanager/test0.cfg"; - - // The configuration1 test configuration has one key "t" = 1 - const std::string _configuration1 = "${TEST_DIR}/configurationmanager/test1.cfg"; - - // The configuration1 test configuration has two keys "t" and "s" - const std::string _configuration2 = "${TEST_DIR}/configurationmanager/test2.cfg"; - - // More complicated configuration file with nested tables - const std::string _configuration3 = "${TEST_DIR}/configurationmanager/test3.cfg"; - - // Deeply nested configuration file with 12 level - const std::string _configuration4 = "${TEST_DIR}/configurationmanager/test4.cfg"; - - // Testfile with glm::vecX, glm::matX - const std::string _configuration5 = "${TEST_DIR}/configurationmanager/test5.cfg"; -} - -/* -Test checklist: ---- loadConfiguration: existing file ---- loadConfiguration: non-existing file ---- getValue: key does not exist ---- getValue: subtable does not exist ---- getValue: overriding previous configuration ---- getValue: function does not change passed value on error ---- getValue: nested keys ---- getValue: deep nesting of keys ---- getValue: correct values returned for each type ---- getValue: are all basic types implemented ---- getValue: glm::vec2, glm::vec3, glm::vec4 implemented ---- getValue: glm::matXxY implemented ---- getValue: valid conversions ---- setValue: all types implemented ---- setValue: create subtables on the way ---- setValue: value gets set correctly for each type ---- setValue: value overwrites setting in configuration file ---- setValue: deep nesting of keys ---- setValue: nested keys ---- setValue: glm::vec2, glm::vec3, glm::vec4, glm::mat3, glm::mat4 implemented ---- hasKeys: deep nesting of keys ---- hasKeys: subtables on the way do not exist ---- hasKeys: correct values for all types ---- hasKeys: nestedKeys ---- timing -*/ - -class ConfigurationManagerTest : public testing::Test { -protected: - ConfigurationManagerTest() { - _m = new ghoul::ConfigurationManager; - } - - ~ConfigurationManagerTest() { - if (_m) { - delete _m; - _m = nullptr; - } - } - - void reset() { - _m->clear(); - } - - ghoul::ConfigurationManager* _m; -}; - -#ifdef GHL_TIMING_TESTS - -TEST_F(ConfigurationManagerTest, TimingTest) { - std::ofstream logFile("ConfigurationManagerTest.timing"); - - START_TIMER(loadConfiguration1, logFile, 25); - _m->loadConfiguration(_configuration1); - FINISH_TIMER(loadConfiguration1, logFile); - - START_TIMER(loadConfiguration2, logFile, 25); - _m->loadConfiguration(_configuration2); - FINISH_TIMER(loadConfiguration2, logFile); - - START_TIMER(loadConfiguration3, logFile, 25); - _m->loadConfiguration(_configuration3); - FINISH_TIMER(loadConfiguration3, logFile); - - START_TIMER(loadConfiguration4, logFile, 25); - _m->loadConfiguration(_configuration4); - FINISH_TIMER(loadConfiguration4, logFile); - - START_TIMER(loadConfiguration5, logFile, 25); - _m->loadConfiguration(_configuration5); - FINISH_TIMER(loadConfiguration5, logFile); - - START_TIMER(loadConfiguration12, logFile, 25); - _m->loadConfiguration(_configuration1); - _m->loadConfiguration(_configuration2); - FINISH_TIMER(loadConfiguration12, logFile); - - START_TIMER(loadConfiguration123, logFile, 25); - _m->loadConfiguration(_configuration1); - _m->loadConfiguration(_configuration2); - _m->loadConfiguration(_configuration3); - FINISH_TIMER(loadConfiguration123, logFile); - - START_TIMER(loadConfiguration1234, logFile, 25); - _m->loadConfiguration(_configuration1); - _m->loadConfiguration(_configuration2); - _m->loadConfiguration(_configuration3); - _m->loadConfiguration(_configuration4); - FINISH_TIMER(loadConfiguration1234, logFile); - - START_TIMER(loadConfiguration12345, logFile, 25); - _m->loadConfiguration(_configuration1); - _m->loadConfiguration(_configuration2); - _m->loadConfiguration(_configuration3); - _m->loadConfiguration(_configuration4); - _m->loadConfiguration(_configuration5); - FINISH_TIMER(loadConfiguration12345, logFile); - - START_TIMER(setValueLevel0Int, logFile, 25); - _m->setValue("t", 1); - FINISH_TIMER(setValueLevel0Int, logFile); - - START_TIMER(setValueLevel1Int, logFile, 25); - _m->setValue("t.t", 1); - FINISH_TIMER(setValueLevel1Int, logFile); - - START_TIMER(setValueLevel10Int, logFile, 25); - _m->setValue("t.t.t.t.t.t.t.t.t.t", 1); - FINISH_TIMER(setValueLevel10Int, logFile); - - START_TIMER(setValueLevel0dvec4, logFile, 25); - _m->setValue("t", glm::dvec4(1.0)); - FINISH_TIMER(setValueLevel0dvec4, logFile); - - START_TIMER(setValueLevel0dmat4, logFile, 25); - _m->setValue("t", glm::dmat4(1.0)); - FINISH_TIMER(setValueLevel0dmat4, logFile); - - { - int i; - START_TIMER_PREPARE(getValueLevel0Int, logFile, 25, {_m->setValue("t", 1);}); - _m->getValue("t", i); - FINISH_TIMER(getValueLevel0Int, logFile); - - START_TIMER(getValueLevel0IntEmpty, logFile, 25); - _m->getValue("t", i); - FINISH_TIMER(getValueLevel0IntEmpty, logFile); - - START_TIMER_PREPARE(getValueLevel1Int, logFile, 25, {_m->setValue("t.t", 1);}); - _m->getValue("t.t", i); - FINISH_TIMER(getValueLevel1Int, logFile); - - START_TIMER_PREPARE(getValueLevel10Int, logFile, 25, - {_m->setValue("t.t.t.t.t.t.t.t.t.t", 1);}); - _m->getValue("t.t.t.t.t.t.t.t.t.t", i); - FINISH_TIMER(getValueLevel10Int, logFile); - - START_TIMER(getValueLevel10IntEmpty, logFile, 25); - _m->getValue("t.t.t.t.t.t.t.t.t.t", i); - FINISH_TIMER(getValueLevel10IntEmpty, logFile); - } - - { - START_TIMER(setValueLevel1vec2, logFile, 25); - _m->setValue("t", glm::vec2(1.0)); - FINISH_TIMER(setValueLevel1vec2, logFile); - } - { - START_TIMER(setValueLevel1vec3, logFile, 25); - _m->setValue("t", glm::vec3(1.0)); - FINISH_TIMER(setValueLevel1vec3, logFile); - } - { - START_TIMER(setValueLevel1vec4, logFile, 25); - _m->setValue("t", glm::vec4(1.0)); - FINISH_TIMER(setValueLevel1vec4, logFile); - } - { - START_TIMER(setValueLevel1dvec2, logFile, 25); - _m->setValue("t", glm::dvec2(1.0)); - FINISH_TIMER(setValueLevel1dvec2, logFile); - } - { - START_TIMER(setValueLevel1dvec3, logFile, 25); - _m->setValue("t", glm::dvec3(1.0)); - FINISH_TIMER(setValueLevel1dvec3, logFile); - } - { - START_TIMER(setValueLevel1dvec4, logFile, 25); - _m->setValue("t", glm::dvec4(1.0)); - FINISH_TIMER(setValueLevel1dvec4, logFile); - } - { - START_TIMER(setValueLevel1ivec2, logFile, 25); - _m->setValue("t", glm::ivec2(1.0)); - FINISH_TIMER(setValueLevel1ivec2, logFile); - } - { - START_TIMER(setValueLevel1ivec3, logFile, 25); - _m->setValue("t", glm::ivec3(1.0)); - FINISH_TIMER(setValueLevel1ivec3, logFile); - } - { - START_TIMER(setValueLevel1ivec4, logFile, 25); - _m->setValue("t", glm::ivec4(1.0)); - FINISH_TIMER(setValueLevel1ivec4, logFile); - } - { - START_TIMER(setValueLevel1bvec2, logFile, 25); - _m->setValue("t", glm::bvec2(true)); - FINISH_TIMER(setValueLevel1bvec2, logFile); - } - { - START_TIMER(setValueLevel1bvec3, logFile, 25); - _m->setValue("t", glm::bvec3(true)); - FINISH_TIMER(setValueLevel1bvec3, logFile); - } - { - START_TIMER(setValueLevel1bvec4, logFile, 25); - _m->setValue("t", glm::bvec4(true)); - FINISH_TIMER(setValueLevel1bvec4, logFile); - } - { - START_TIMER(setValueLevel1uvec2, logFile, 25); - _m->setValue("t", glm::uvec2(1.0)); - FINISH_TIMER(setValueLevel1uvec2, logFile); - } - { - START_TIMER(setValueLevel1uvec3, logFile, 25); - _m->setValue("t", glm::uvec3(1.0)); - FINISH_TIMER(setValueLevel1uvec3, logFile); - } - { - START_TIMER(setValueLevel1uvec4, logFile, 25); - _m->setValue("t", glm::uvec4(1.0)); - FINISH_TIMER(setValueLevel1uvec4, logFile); - } - { - START_TIMER(setValueLevel1dmat2x4, logFile, 25); - _m->setValue("t", glm::dmat2x4(1.0)); - FINISH_TIMER(setValueLevel1dmat2x4, logFile); - } - { - START_TIMER(setValueLevel1dmat2x3, logFile, 25); - _m->setValue("t", glm::dmat2x3(1.0)); - FINISH_TIMER(setValueLevel1dmat2x3, logFile); - } - { - START_TIMER(setValueLevel1dmat2, logFile, 25); - _m->setValue("t", glm::dmat2(1.0)); - FINISH_TIMER(setValueLevel1dmat2, logFile); - } - { - START_TIMER(setValueLevel1dmat3x2, logFile, 25); - _m->setValue("t", glm::dmat3x2(1.0)); - FINISH_TIMER(setValueLevel1dmat3x2, logFile); - } - { - START_TIMER(setValueLevel1dmat3x4, logFile, 25); - _m->setValue("t", glm::dmat3x4(1.0)); - FINISH_TIMER(setValueLevel1dmat3x4, logFile); - } - { - START_TIMER(setValueLevel1dmat3, logFile, 25); - _m->setValue("t", glm::dmat3(1.0)); - FINISH_TIMER(setValueLevel1dmat3, logFile); - } - { - START_TIMER(setValueLevel1dmat4x2, logFile, 25); - _m->setValue("t", glm::dmat4x3(1.0)); - FINISH_TIMER(setValueLevel1dmat4x2, logFile); - } - { - START_TIMER(setValueLevel1dmat4x3, logFile, 25); - _m->setValue("t", glm::dmat4x3(1.0)); - FINISH_TIMER(setValueLevel1dmat4x3, logFile); - } - { - START_TIMER(setValueLevel1dmat4, logFile, 25); - _m->setValue("t", glm::dmat4(1.0)); - FINISH_TIMER(setValueLevel1dmat4, logFile); - } - - { - glm::vec2 i; - START_TIMER_PREPARE(getValueLevel1vec2, logFile, 25, - {_m->setValue("t", glm::vec2(1.0));}); - _m->getValue("t", i); - FINISH_TIMER(getValueLevel1vec2, logFile); - } - { - glm::vec3 i; - START_TIMER_PREPARE(getValueLevel1vec3, logFile, 25, - {_m->setValue("t", glm::vec3(1.0));}); - _m->getValue("t", i); - FINISH_TIMER(getValueLevel1vec3, logFile); - } - { - glm::vec4 i; - START_TIMER_PREPARE(getValueLevel1vec4, logFile, 25, - {_m->setValue("t", glm::vec4(1.0));}); - _m->getValue("t", i); - FINISH_TIMER(getValueLevel1vec4, logFile); - } - { - glm::dvec2 i; - START_TIMER_PREPARE(getValueLevel1dvec2, logFile, 25, - {_m->setValue("t", glm::dvec2(1.0));}); - _m->getValue("t", i); - FINISH_TIMER(getValueLevel1dvec2, logFile); - } - { - glm::dvec3 i; - START_TIMER_PREPARE(getValueLevel1dvec3, logFile, 25, - {_m->setValue("t", glm::dvec3(1.0));}); - _m->getValue("t", i); - FINISH_TIMER(getValueLevel1dvec3, logFile); - } - { - glm::dvec4 i; - START_TIMER_PREPARE(getValueLevel1dvec4, logFile, 25, - {_m->setValue("t", glm::dvec4(1.0));}); - _m->getValue("t", i); - FINISH_TIMER(getValueLevel1dvec4, logFile); - } - { - glm::ivec2 i; - START_TIMER_PREPARE(getValueLevel1ivec2, logFile, 25, - {_m->setValue("t", glm::ivec2(1.0));}); - _m->getValue("t", i); - FINISH_TIMER(getValueLevel1ivec2, logFile); - } - { - glm::ivec3 i; - START_TIMER_PREPARE(getValueLevel1ivec3, logFile, 25, - {_m->setValue("t", glm::ivec3(1.0));}); - _m->getValue("t", i); - FINISH_TIMER(getValueLevel1ivec3, logFile); - } - { - glm::ivec4 i; - START_TIMER_PREPARE(getValueLevel1ivec4, logFile, 25, - {_m->setValue("t", glm::ivec4(1.0));}); - _m->getValue("t", i); - FINISH_TIMER(getValueLevel1ivec4, logFile); - } - { - glm::bvec2 i; - START_TIMER_PREPARE(getValueLevel1bvec2, logFile, 25, - {_m->setValue("t", glm::bvec2(true));}); - _m->getValue("t", i); - FINISH_TIMER(getValueLevel1bvec2, logFile); - } - { - glm::bvec3 i; - START_TIMER_PREPARE(getValueLevel1bvec3, logFile, 25, - {_m->setValue("t", glm::bvec3(true));}); - _m->getValue("t", i); - FINISH_TIMER(getValueLevel1bvec3, logFile); - } - { - glm::bvec4 i; - START_TIMER_PREPARE(getValueLevel1bvec4, logFile, 25, - {_m->setValue("t", glm::bvec4(true));}); - _m->getValue("t", i); - FINISH_TIMER(getValueLevel1bvec4, logFile); - } - { - glm::uvec2 i; - START_TIMER_PREPARE(getValueLevel1uvec2, logFile, 25, - {_m->setValue("t", glm::uvec2(1.0));}); - _m->getValue("t", i); - FINISH_TIMER(getValueLevel1uvec2, logFile); - } - { - glm::uvec3 i; - START_TIMER_PREPARE(getValueLevel1uvec3, logFile, 25, - {_m->setValue("t", glm::uvec3(1.0));}); - _m->getValue("t", i); - FINISH_TIMER(getValueLevel1uvec3, logFile); - } - { - glm::uvec4 i; - START_TIMER_PREPARE(getValueLevel1uvec4, logFile, 25, - {_m->setValue("t", glm::uvec4(1.0));}); - _m->getValue("t", i); - FINISH_TIMER(getValueLevel1uvec4, logFile); - } - { - glm::dmat2x4 i; - START_TIMER_PREPARE(getValueLevel1dmat2x4, logFile, 25, - {_m->setValue("t", glm::dmat2x4(1.0));}); - _m->getValue("t", i); - FINISH_TIMER(getValueLevel1dmat2x4, logFile); - } - { - glm::dmat2x3 i; - START_TIMER_PREPARE(getValueLevel1dmat2x3, logFile, 25, - {_m->setValue("t", glm::dmat2x3(1.0));}); - _m->getValue("t", i); - FINISH_TIMER(getValueLevel1dmat2x3, logFile); - } - { - glm::dmat2 i; - START_TIMER_PREPARE(getValueLevel1dmat2, logFile, 25, - {_m->setValue("t", glm::dmat2(1.0));}); - _m->getValue("t", i); - FINISH_TIMER(getValueLevel1dmat2, logFile); - } - { - glm::dmat3x2 i; - START_TIMER_PREPARE(getValueLevel1dmat3x2, logFile, 25, - {_m->setValue("t", glm::dmat3x2(1.0));}); - _m->getValue("t", i); - FINISH_TIMER(getValueLevel1dmat3x2, logFile); - } - { - glm::dmat3x4 i; - START_TIMER_PREPARE(getValueLevel1dmat3x4, logFile, 25, - {_m->setValue("t", glm::dmat3x4(1.0));}); - _m->getValue("t", i); - FINISH_TIMER(getValueLevel1dmat3x4, logFile); - } - { - glm::dmat3 i; - START_TIMER_PREPARE(getValueLevel1dmat3, logFile, 25, - {_m->setValue("t", glm::dmat3(1.0));}); - _m->getValue("t", i); - FINISH_TIMER(getValueLevel1dmat3, logFile); - } - { - glm::dmat4x2 i; - START_TIMER_PREPARE(getValueLevel1dmat4x2, logFile, 25, - {_m->setValue("t", glm::dmat4x2(1.0));}); - _m->getValue("t", i); - FINISH_TIMER(getValueLevel1dmat4x2, logFile); - } - { - glm::dmat4x3 i; - START_TIMER_PREPARE(getValueLevel1dmat4x3, logFile, 25, - {_m->setValue("t", glm::dmat4x3(1.0));}); - _m->getValue("t", i); - FINISH_TIMER(getValueLevel1dmat4x3, logFile); - } - { - glm::dmat4 i; - START_TIMER_PREPARE(getValueLevel1dmat4, logFile, 25, - {_m->setValue("t", glm::dmat4(1.0));}); - _m->getValue("t", i); - FINISH_TIMER(getValueLevel1dmat4, logFile); - } - - START_TIMER(hasKeyLevel0Empty, logFile, 25); - _m->hasKey("t"); - FINISH_TIMER(hasKeyLevel0Empty, logFile); - - START_TIMER(hasKeyLevel10Empty, logFile, 25); - _m->hasKey("t.t.t.t.t.t.t.t.t.t"); - FINISH_TIMER(hasKeyLevel10Empty, logFile); - - START_TIMER_PREPARE(hasKeyLevel0, logFile, 25, {_m->setValue("t", 1);}); - _m->hasKey("t"); - FINISH_TIMER(hasKeyLevel0, logFile); - - START_TIMER_PREPARE(hasKeyLevel10, logFile, 25, - {_m->setValue("t.t.t.t.t.t.t.t.t.t", 1);}); - _m->hasKey("t.t.t.t.t.t.t.t.t.t"); - FINISH_TIMER(hasKeyLevel10, logFile); -} - -#endif // GHL_TIMING_TESTS - -TEST_F(ConfigurationManagerTest, ReinitTest) { - _m->setValue("t", int(2)); - _m->clear(); - const bool success = _m->hasKey("t"); - EXPECT_EQ(false, success); -} - -TEST_F(ConfigurationManagerTest, LoadConfigurationTest) { - const bool success0 = _m->loadConfiguration(_configuration0); - ASSERT_EQ(false, success0) << "Loading a non-existing file should fail gracefully"; - const bool success1 = _m->loadConfiguration(_configuration1); - ASSERT_EQ(true, success1) << "Loading of configuration file 'test1.cfg'"; - const bool success2 = _m->loadConfiguration(_configuration2); - ASSERT_EQ(true, success2) << "Loading of configuration file 'test2.cfg'"; - const bool success3 = _m->loadConfiguration(_configuration3); - ASSERT_EQ(true, success3) << "Loading of configuration file 'test3.cfg'"; - const bool success4 = _m->loadConfiguration(_configuration4); - ASSERT_EQ(true, success4) << "Loading of configuration file 'test4.cfg'"; -} - -TEST_F(ConfigurationManagerTest, KeysFunction) { - // The empty configuration should not have any keys - size_t nKeys = _m->keys().size(); - EXPECT_EQ(0, nKeys) << "The empty configuration should not have any keys"; - - _m->loadConfiguration(_configuration1); - nKeys = _m->keys().size(); - EXPECT_EQ(1, nKeys) << "test1"; - - _m->loadConfiguration(_configuration3); - nKeys = _m->keys().size(); - EXPECT_EQ(3, nKeys) << "base: test1 + test3"; - - nKeys = _m->keys("s").size(); - EXPECT_EQ(3, nKeys) << "s: test1 + test3"; - - nKeys = _m->keys("s.3").size(); - EXPECT_EQ(2, nKeys) << "s.3: test1 + test3"; - - _m->loadConfiguration(_configuration4); - - const char* keys[] = { - "a", "a.a", "a.a.a", "a.a.a.a", "a.a.a.a.a", "a.a.a.a.a.a", "a.a.a.a.a.a.a", - "a.a.a.a.a.a.a.a", "a.a.a.a.a.a.a.a.a", "a.a.a.a.a.a.a.a.a.a", - "a.a.a.a.a.a.a.a.a.a.a", "a.a.a.a.a.a.a.a.a.a.a.a" - }; - - for (int i = 0; i < 12; ++i) { - nKeys = _m->keys(keys[i]).size(); - EXPECT_EQ(2, nKeys) << keys[i] <<": test1 + test3"; - } - - for (int i = 0; i < 12; ++i) { - const bool hasKey = _m->hasKey(keys[i]); - EXPECT_EQ(true, hasKey) << keys[i] <<": test1 + test3"; - } - - - const char* keysB[] = { - "b", "b.b", "b.b.b", "b.b.b.b", "b.b.b.b.b", "b.b.b.b.b.b", "b.b.b.b.b.b.b", - "b.b.b.b.b.b.b.b", "b.b.b.b.b.b.b.b.b", "b.b.b.b.b.b.b.b.b.b", - "b.b.b.b.b.b.b.b.b.b.b", "b.b.b.b.b.b.b.b.b.b.b.b" - }; - _m->setValue(keysB[11], int(0), true); - for (int i = 0; i < 12; ++i) - EXPECT_EQ(true, _m->hasKey(keysB[i])) << keysB[i] <<": test1 + test3"; -} - -TEST_F(ConfigurationManagerTest, HasKeySubtable) { - _m->loadConfiguration(_configuration1); - const bool tSuccess = _m->hasKey("t"); - ASSERT_EQ(true, tSuccess) << "t"; - - const bool tsSuccess = _m->hasKey("t.s"); - EXPECT_EQ(false, tsSuccess) << "t.s"; - - const bool sSuccess = _m->hasKey("s"); - EXPECT_EQ(false, sSuccess) << "s"; - - const bool sxSuccess = _m->hasKey("s.x"); - EXPECT_EQ(false, sxSuccess) << "s.x"; -} - -TEST_F(ConfigurationManagerTest, HasKeyTypes) { - _m->setValue("t", ghoul::Dictionary()); - _m->setValue("t.bool", bool(1)); - _m->setValue("t.char", char(1)); - _m->setValue("t.unsignedchar", (unsigned char)(1)); - _m->setValue("t.signedchar", (signed char)(1)); - _m->setValue("t.wchar", wchar_t(1)); - _m->setValue("t.short", short(1)); - _m->setValue("t.unsignedshort", (unsigned short)(1)); - _m->setValue("t.int", int(1)); - _m->setValue("t.unsignedint", (unsigned int)(1)); - _m->setValue("t.long", long(1)); - _m->setValue("t.unsignedlong", (unsigned long)(1)); - _m->setValue("t.longlong", (long long)(1)); - _m->setValue("t.unsignedlonglong", (unsigned long long)(1)); - _m->setValue("t.float", float(1)); - _m->setValue("t.double", double(1)); - _m->setValue("t.longdouble", (long double)(1)); - _m->setValue("t.string", "1"); - - bool success = _m->hasKey("t.bool"); - EXPECT_EQ(true, success) << "t.bool"; - success = _m->hasKey("t.char"); - EXPECT_EQ(true, success) << "t.char"; - success = _m->hasKey("t.unsignedchar"); - EXPECT_EQ(true, success) << "t.unsignedchar"; - success = _m->hasKey("t.signedchar"); - EXPECT_EQ(true, success) << "t.signedchar"; - success = _m->hasKey("t.wchar"); - EXPECT_EQ(true, success) << "t.wchar"; - success = _m->hasKey("t.short"); - EXPECT_EQ(true, success) << "t.short"; - success = _m->hasKey("t.unsignedshort"); - EXPECT_EQ(true, success) << "t.unsignedshort"; - success = _m->hasKey("t.int"); - EXPECT_EQ(true, success) << "t.int"; - success = _m->hasKey("t.unsignedint"); - EXPECT_EQ(true, success) << "t.unsignedint"; - success = _m->hasKey("t.long"); - EXPECT_EQ(true, success) << "t.long"; - success = _m->hasKey("t.unsignedlong"); - EXPECT_EQ(true, success) << "t.unsignedlong"; - success = _m->hasKey("t.longlong"); - EXPECT_EQ(true, success) << "t.longlong"; - success = _m->hasKey("t.unsignedlonglong"); - EXPECT_EQ(true, success) << "t.unsignedlonglong"; - success = _m->hasKey("t.float"); - EXPECT_EQ(true, success) << "t.float"; - success = _m->hasKey("t.double"); - EXPECT_EQ(true, success) << "t.double"; - success = _m->hasKey("t.longdouble"); - EXPECT_EQ(true, success) << "t.longdouble"; - success = _m->hasKey("t.string"); - EXPECT_EQ(true, success) << "t.string"; -} - -TEST_F(ConfigurationManagerTest, GetValueFunction) { - std::string test; - bool success = _m->getValue("key", test); - EXPECT_EQ(false, success) << "Empty configuration"; - - success = _m->getValue("key.key", test); - EXPECT_EQ(false, success) << "Empty configuration recursive"; - - _m->loadConfiguration(_configuration1); - _m->loadConfiguration(_configuration3); - int testInt; - success = _m->getValue("t", testInt); - EXPECT_EQ(true, success) << "test1+test3 (t)"; - EXPECT_EQ(1, testInt) << "test1+test3 (t)"; - - success = _m->getValue("s.a", test); - EXPECT_EQ(false, success) << "test1+test3 (s.a)"; - - success = _m->getValue("s.1", test); - EXPECT_EQ(true, success) << "test1+test3 (s.1)"; - - success = _m->getValue("s.1.a", test); - EXPECT_EQ(false, success) << "test1+test3 (s.1.a)"; - - success = _m->getValue("s.3.a", test); - EXPECT_EQ(true, success) << "test1+test3 (s.3.a)"; - - std::vector testVec; - success = _m->getValue("key", testVec); - EXPECT_EQ(false, success) << "test1+test3: Vector access"; -} - -template -void correctnessHelperGetValue(ghoul::ConfigurationManager* m, const std::string& key) { - T value = T(0); - const bool success = m->getValue(key, value); - EXPECT_EQ(true, success) << "Type: " << typeid(T).name(); - EXPECT_EQ(T(1), value) << "Type: " << typeid(T).name(); -} - -TEST_F(ConfigurationManagerTest, GetValueCorrectness) { - _m->loadConfiguration(_configuration1); - - correctnessHelperGetValue(_m, "t"); - correctnessHelperGetValue(_m, "t"); - correctnessHelperGetValue(_m, "t"); - correctnessHelperGetValue(_m, "t"); - correctnessHelperGetValue(_m, "t"); - correctnessHelperGetValue(_m, "t"); - correctnessHelperGetValue(_m, "t"); - correctnessHelperGetValue(_m, "t"); - correctnessHelperGetValue(_m, "t"); - correctnessHelperGetValue(_m, "t"); - correctnessHelperGetValue(_m, "t"); - correctnessHelperGetValue(_m, "t"); - correctnessHelperGetValue(_m, "t"); - correctnessHelperGetValue(_m, "t"); - correctnessHelperGetValue(_m, "t"); - correctnessHelperGetValue(_m, "t"); - - std::string value; - const bool success = _m->getValue("t", value); - EXPECT_EQ(true, success) << "Type: " << typeid(std::string).name(); - EXPECT_STREQ("1", value.c_str()) << "Type: " << typeid(std::string).name(); -} - -TEST_F(ConfigurationManagerTest, SetValueRecursive) { - _m->setValue("t.a.b.c", 1); - EXPECT_EQ(true, _m->hasKey("t")); - EXPECT_EQ(true, _m->hasKey("t.a")); - EXPECT_EQ(true, _m->hasKey("t.a.b")); - EXPECT_EQ(true, _m->hasKey("t.a.b.c")); -} - -TEST_F(ConfigurationManagerTest, SetValueCorrectness) { - _m->setValue("t.bool", bool(1)); - _m->setValue("t.char", char(1)); - _m->setValue("t.unsignedchar", (unsigned char)(1)); - _m->setValue("t.signedchar", (signed char)(1)); - _m->setValue("t.wchar", wchar_t(1)); - _m->setValue("t.short", short(1)); - _m->setValue("t.unsignedshort", (unsigned short)(1)); - _m->setValue("t.int", int(1)); - _m->setValue("t.unsignedint", (unsigned int)(1)); - _m->setValue("t.long", long(1)); - _m->setValue("t.unsignedlong", (unsigned long)(1)); - _m->setValue("t.longlong", (long long)(1)); - _m->setValue("t.unsignedlonglong", (unsigned long long)(1)); - _m->setValue("t.float", float(1)); - _m->setValue("t.double", double(1)); - _m->setValue("t.longdouble", (long double)(1)); - _m->setValue("t.string", "1"); - - correctnessHelperGetValue(_m, "t.bool"); - correctnessHelperGetValue(_m, "t.char"); - correctnessHelperGetValue(_m, "t.unsignedchar"); - correctnessHelperGetValue(_m, "t.signedchar"); - correctnessHelperGetValue(_m, "t.wchar"); - correctnessHelperGetValue(_m, "t.short"); - correctnessHelperGetValue(_m, "t.unsignedshort"); - correctnessHelperGetValue(_m, "t.int"); - correctnessHelperGetValue(_m, "t.unsignedint"); - correctnessHelperGetValue(_m, "t.long"); - correctnessHelperGetValue(_m, "t.unsignedlong"); - correctnessHelperGetValue(_m, "t.longlong"); - correctnessHelperGetValue(_m, "t.unsignedlonglong"); - correctnessHelperGetValue(_m, "t.float"); - correctnessHelperGetValue(_m, "t.double"); - correctnessHelperGetValue(_m, "t.longdouble"); - - std::string value; - const bool success = _m->getValue("t.string", value); - EXPECT_EQ(true, success) << "Type: " << typeid(std::string).name(); - EXPECT_STREQ("1", value.c_str()) << "Type: " << typeid(std::string).name(); -} - -TEST_F(ConfigurationManagerTest, SetValueOverridesConfiguration) { - _m->loadConfiguration(_configuration1); - int v = 0; - bool success = _m->getValue("t", v); - ASSERT_EQ(true, success) << "t"; - ASSERT_EQ(1, v) << "t"; - - _m->setValue("t", int(2)); - success = _m->getValue("t", v); - ASSERT_EQ(true, success) << "t"; - ASSERT_EQ(2, v) << "t"; -} - -TEST_F(ConfigurationManagerTest, GetValueConversions) { - // converting from 1 -> all types is done in GetValueCorrectness - _m->loadConfiguration(_configuration2); - - correctnessHelperGetValue(_m, "s.a1"); - correctnessHelperGetValue(_m, "s.a1"); - correctnessHelperGetValue(_m, "s.a1"); - correctnessHelperGetValue(_m, "s.a1"); - correctnessHelperGetValue(_m, "s.a1"); - correctnessHelperGetValue(_m, "s.a1"); - correctnessHelperGetValue(_m, "s.a1"); - correctnessHelperGetValue(_m, "s.a1"); - correctnessHelperGetValue(_m, "s.a1"); - correctnessHelperGetValue(_m, "s.a1"); - correctnessHelperGetValue(_m, "s.a1"); - correctnessHelperGetValue(_m, "s.a1"); - correctnessHelperGetValue(_m, "s.a1"); - correctnessHelperGetValue(_m, "s.a1"); - correctnessHelperGetValue(_m, "s.a1"); - correctnessHelperGetValue(_m, "s.a1"); - - std::string value; - const bool success = _m->getValue("s.a1", value); - EXPECT_EQ(true, success) << "Type: " << typeid(std::string).name(); - EXPECT_STREQ("1", value.c_str()) << "Type: " << typeid(std::string).name(); -} - -TEST_F(ConfigurationManagerTest, StringKeyVsIntKey) { - _m->loadConfiguration(_configuration3); - - int v = 0; - bool success = _m->getValue("tt[\"1\"]", v); - ASSERT_EQ(true, success) << "tt.1"; - EXPECT_EQ(2, v) << "tt.1"; - - success = _m->getValue("tt[1]", v); - ASSERT_EQ(true, success) << "tt[1]"; - EXPECT_EQ(1, v) << "tt[1]"; -} - -TEST_F(ConfigurationManagerTest, InvalidKeyAccessInvariant) { - // Accessing an invalid key should not change the tested argument - std::mt19937 rd; - { - std::uniform_int_distribution dist; - for (int i = 0; i < 10; ++i) { - const int testValue = dist(rd); - int test = testValue; - _m->getValue("key", test); - ASSERT_EQ(testValue, test) << "invariant int"; - } - } - - { - std::uniform_real_distribution dist; - for (int i = 0; i < 10; ++i) { - const float testValue = dist(rd); - float test = testValue; - _m->getValue("key", test); - ASSERT_EQ(testValue, test) << "invariant float"; - } - } -} - -TEST_F(ConfigurationManagerTest, HasKeyFunction) { - bool success = _m->hasKey("key"); - EXPECT_EQ(false, success) << "empty configuration"; - - _m->loadConfiguration(_configuration1); - success = _m->hasKey("t"); - EXPECT_EQ(true, success) << "test1 (t)"; - - success = _m->hasKey("s"); - EXPECT_EQ(false, success) << "test1 (s)"; - - _m->loadConfiguration(_configuration2); - success = _m->hasKey("s.a"); - EXPECT_EQ(true, success) << "test1+test2 (s.a)"; - - success = _m->hasKey("s.c"); - EXPECT_EQ(false, success) << "test1+test2 (s.c)"; -} - - -TEST_F(ConfigurationManagerTest, MultipleKeyLoadOverwrite) { - _m->loadConfiguration(_configuration1); - int value; - _m->getValue("t", value); - EXPECT_EQ(1, value); - - _m->loadConfiguration(_configuration2); - - // configuration2 should overwrite the value t in configuration1 - _m->getValue("t", value); - EXPECT_EQ(2, value); -} - -template -void vectorClassHelper(ghoul::ConfigurationManager* m, const std::string& key) { - T value = T(0); - const bool success = m->getValue(key, value); - EXPECT_EQ(true, success) << "Type: " << typeid(T).name() << " | Key: " << key; - EXPECT_EQ(T(glm::vec4(5, 6, 7, 8)), value) << "Type: " << typeid(T).name() << - " | Key: " << key; -} - -template <> -void vectorClassHelper(ghoul::ConfigurationManager* m, const std::string& key) { - glm::bvec2 value = glm::bvec2(false); - const bool success = m->getValue(key, value); - EXPECT_EQ(true, success) << "Type: bvec2 | Key: " << key; - EXPECT_EQ(true, value.x) << "Type: bvec2 | Key: " << key; - EXPECT_EQ(true, value.y) << "Type: bvec2 | Key: " << key; -} - -template <> -void vectorClassHelper(ghoul::ConfigurationManager* m, const std::string& key) { - glm::bvec3 value = glm::bvec3(false); - const bool success = m->getValue(key, value); - EXPECT_EQ(true, success) << "Type: bvec3 | Key: " << key; - EXPECT_EQ(true, value.x) << "Type: bvec3 | Key: " << key; - EXPECT_EQ(true, value.y) << "Type: bvec3 | Key: " << key; - EXPECT_EQ(true, value.z) << "Type: bvec3 | Key: " << key; -} - -template <> -void vectorClassHelper(ghoul::ConfigurationManager* m, const std::string& key) { - glm::bvec4 value = glm::bvec4(false); - const bool success = m->getValue(key, value); - EXPECT_EQ(true, success) << "Type: bvec4 | Key: " << key; - EXPECT_EQ(true, value.x) << "Type: bvec4 | Key: " << key; - EXPECT_EQ(true, value.y) << "Type: bvec4 | Key: " << key; - EXPECT_EQ(true, value.z) << "Type: bvec4 | Key: " << key; - EXPECT_EQ(true, value.w) << "Type: bvec4 | Key: " << key; -} - -TEST_F(ConfigurationManagerTest, VectorClassesGet) { - _m->loadConfiguration(_configuration5); - vectorClassHelper(_m, "n2"); - vectorClassHelper(_m, "num2"); - vectorClassHelper(_m, "xy"); - vectorClassHelper(_m, "rg"); - vectorClassHelper(_m, "st"); - vectorClassHelper(_m, "n2"); - vectorClassHelper(_m, "num2"); - vectorClassHelper(_m, "xy"); - vectorClassHelper(_m, "rg"); - vectorClassHelper(_m, "st"); - vectorClassHelper(_m, "n2"); - vectorClassHelper(_m, "num2"); - vectorClassHelper(_m, "xy"); - vectorClassHelper(_m, "rg"); - vectorClassHelper(_m, "st"); - vectorClassHelper(_m, "n2"); - vectorClassHelper(_m, "num2"); - vectorClassHelper(_m, "xy"); - vectorClassHelper(_m, "rg"); - vectorClassHelper(_m, "st"); - vectorClassHelper(_m, "n2"); - vectorClassHelper(_m, "num2"); - vectorClassHelper(_m, "xy"); - vectorClassHelper(_m, "rg"); - vectorClassHelper(_m, "st"); - - vectorClassHelper(_m, "n3"); - vectorClassHelper(_m, "num3"); - vectorClassHelper(_m, "xyz"); - vectorClassHelper(_m, "rgb"); - vectorClassHelper(_m, "stp"); - vectorClassHelper(_m, "n3"); - vectorClassHelper(_m, "num3"); - vectorClassHelper(_m, "xyz"); - vectorClassHelper(_m, "rgb"); - vectorClassHelper(_m, "stp"); - vectorClassHelper(_m, "n3"); - vectorClassHelper(_m, "num3"); - vectorClassHelper(_m, "xyz"); - vectorClassHelper(_m, "rgb"); - vectorClassHelper(_m, "stp"); - vectorClassHelper(_m, "n3"); - vectorClassHelper(_m, "num3"); - vectorClassHelper(_m, "xyz"); - vectorClassHelper(_m, "rgb"); - vectorClassHelper(_m, "stp"); - vectorClassHelper(_m, "n3"); - vectorClassHelper(_m, "num3"); - vectorClassHelper(_m, "xyz"); - vectorClassHelper(_m, "rgb"); - vectorClassHelper(_m, "stp"); - - vectorClassHelper(_m, "n4"); - vectorClassHelper(_m, "num4"); - vectorClassHelper(_m, "xyzw"); - vectorClassHelper(_m, "rgba"); - vectorClassHelper(_m, "stpq"); - vectorClassHelper(_m, "n4"); - vectorClassHelper(_m, "num4"); - vectorClassHelper(_m, "xyzw"); - vectorClassHelper(_m, "rgba"); - vectorClassHelper(_m, "stpq"); - vectorClassHelper(_m, "num4"); - vectorClassHelper(_m, "n4"); - vectorClassHelper(_m, "xyzw"); - vectorClassHelper(_m, "rgba"); - vectorClassHelper(_m, "stpq"); - vectorClassHelper(_m, "num4"); - vectorClassHelper(_m, "n4"); - vectorClassHelper(_m, "xyzw"); - vectorClassHelper(_m, "rgba"); - vectorClassHelper(_m, "stpq"); - vectorClassHelper(_m, "num4"); - vectorClassHelper(_m, "n4"); - vectorClassHelper(_m, "xyzw"); - vectorClassHelper(_m, "rgba"); - vectorClassHelper(_m, "stpq"); - - glm::vec3 value = glm::vec3(0.f); - const bool success = _m->getValue("mix", value); - EXPECT_EQ(false, success) << "Type: mixed"; - EXPECT_EQ(glm::vec3(0.f), value) << "Type: mixed"; -} - -TEST_F(ConfigurationManagerTest, VectorClassesSet) { - _m->setValue("t.vec2", glm::vec2(5,6)); - _m->setValue("t.vec3", glm::vec3(5,6,7)); - _m->setValue("t.vec4", glm::vec4(5,6,7,8)); - _m->setValue("t.dvec2", glm::dvec2(5,6)); - _m->setValue("t.dvec3", glm::dvec3(5,6,7)); - _m->setValue("t.dvec4", glm::dvec4(5,6,7,8)); - _m->setValue("t.ivec2", glm::ivec2(5,6)); - _m->setValue("t.ivec3", glm::ivec3(5,6,7)); - _m->setValue("t.ivec4", glm::ivec4(5,6,7,8)); - _m->setValue("t.uvec2", glm::uvec2(5,6)); - _m->setValue("t.uvec3", glm::uvec3(5,6,7)); - _m->setValue("t.uvec4", glm::uvec4(5,6,7,8)); - _m->setValue("t.bvec2", glm::bvec2(true)); - _m->setValue("t.bvec3", glm::bvec3(true)); - _m->setValue("t.bvec4", glm::bvec4(true)); - - vectorClassHelper(_m, "t.vec2"); - vectorClassHelper(_m, "t.vec3"); - vectorClassHelper(_m, "t.vec4"); - vectorClassHelper(_m, "t.dvec2"); - vectorClassHelper(_m, "t.dvec3"); - vectorClassHelper(_m, "t.dvec4"); - vectorClassHelper(_m, "t.ivec2"); - vectorClassHelper(_m, "t.ivec3"); - vectorClassHelper(_m, "t.ivec4"); - vectorClassHelper(_m, "t.uvec2"); - vectorClassHelper(_m, "t.uvec3"); - vectorClassHelper(_m, "t.uvec4"); - vectorClassHelper(_m, "t.bvec2"); - vectorClassHelper(_m, "t.bvec3"); - vectorClassHelper(_m, "t.bvec4"); -} - -template -void matrixClassHelper(ghoul::ConfigurationManager* m, const std::string& key) { - T value = T(0); - const bool success = m->getValue(key, value); - EXPECT_EQ(success, true) << "Type: " << typeid(T).name(); - - const glm::detail::tmat4x4 res4 = glm::detail::tmat4x4( - 5.0, 6.0, 7.0, 8.0, - 9.0, 10.0,11.0,12.0, - 13.0,14.0,15.0,16.0, - 17.0,18.0,19.0,20.0 - ); - - const T res = T(res4); - - EXPECT_EQ(res, value) << "Type: " << typeid(T).name(); -} - -TEST_F(ConfigurationManagerTest, MatrixClassesGet) { - _m->loadConfiguration(_configuration5); - matrixClassHelper(_m, "m2x2"); - matrixClassHelper(_m, "m2x3"); - matrixClassHelper(_m, "m2x4"); - matrixClassHelper(_m, "m3x2"); - matrixClassHelper(_m, "m3x3"); - matrixClassHelper(_m, "m3x4"); - matrixClassHelper(_m, "m4x2"); - matrixClassHelper(_m, "m4x3"); - matrixClassHelper(_m, "m4x4"); - - matrixClassHelper(_m, "m2x2"); - matrixClassHelper(_m, "m2x3"); - matrixClassHelper(_m, "m2x4"); - matrixClassHelper(_m, "m3x2"); - matrixClassHelper(_m, "m3x3"); - matrixClassHelper(_m, "m3x4"); - matrixClassHelper(_m, "m4x2"); - matrixClassHelper(_m, "m4x3"); - matrixClassHelper(_m, "m4x4"); -} - -TEST_F(ConfigurationManagerTest, MatrixClassSet) { - _m->setValue("f.m2x2", glm::mat2x2(5, 6, 9, 10)); - _m->setValue("f.m2x3", glm::mat2x3(5, 6, 7, 9, 10, 11)); - _m->setValue("f.m2x4", glm::mat2x4(5, 6, 7, 8, 9, 10, 11, 12)); - _m->setValue("f.m3x2", glm::mat3x2(5, 6, 9, 10, 13, 14)); - _m->setValue("f.m3x3", glm::mat3x3(5, 6, 7, 9, 10, 11, 13, 14, 15)); - _m->setValue("f.m3x4", glm::mat3x4(5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)); - _m->setValue("f.m4x2", glm::mat4x2(5, 6, 9, 10, 13, 14, 17, 18)); - _m->setValue("f.m4x3", glm::mat4x3(5, 6, 7, 9, 10, 11, 13, 14, 15, 17, 18, 19)); - _m->setValue("f.m4x4", glm::mat4x4(5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)); - - matrixClassHelper(_m, "f.m2x2"); - matrixClassHelper(_m, "f.m2x3"); - matrixClassHelper(_m, "f.m2x4"); - matrixClassHelper(_m, "f.m3x2"); - matrixClassHelper(_m, "f.m3x3"); - matrixClassHelper(_m, "f.m3x4"); - matrixClassHelper(_m, "f.m4x2"); - matrixClassHelper(_m, "f.m4x3"); - matrixClassHelper(_m, "f.m4x4"); - - _m->setValue("d.m2x2", glm::dmat2x2(5, 6, 9, 10)); - _m->setValue("d.m2x3", glm::dmat2x3(5, 6, 7, 9, 10, 11)); - _m->setValue("d.m2x4", glm::dmat2x4(5, 6, 7, 8, 9, 10, 11, 12)); - _m->setValue("d.m3x2", glm::dmat3x2(5, 6, 9, 10, 13, 14)); - _m->setValue("d.m3x3", glm::dmat3x3(5, 6, 7, 9, 10, 11, 13, 14, 15)); - _m->setValue("d.m3x4", glm::dmat3x4(5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)); - _m->setValue("d.m4x2", glm::dmat4x2(5, 6, 9, 10, 13, 14, 17, 18)); - _m->setValue("d.m4x3", glm::dmat4x3(5, 6, 7, 9, 10, 11, 13, 14, 15, 17, 18, 19)); - _m->setValue("d.m4x4", glm::dmat4x4( - 5, 6, 7, 8, - 9, 10, 11, 12, - 13, 14, 15, 16, - 17, 18, 19, 20)); - - - matrixClassHelper(_m, "d.m2x2"); - matrixClassHelper(_m, "d.m2x3"); - matrixClassHelper(_m, "d.m2x4"); - matrixClassHelper(_m, "d.m3x2"); - matrixClassHelper(_m, "d.m3x3"); - matrixClassHelper(_m, "d.m3x4"); - matrixClassHelper(_m, "d.m4x2"); - matrixClassHelper(_m, "d.m4x3"); - matrixClassHelper(_m, "d.m4x4"); -} diff --git a/tests/test_documentation.cpp b/tests/test_documentation.cpp new file mode 100644 index 0000000000..6111446b4d --- /dev/null +++ b/tests/test_documentation.cpp @@ -0,0 +1,3079 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2019 * + * * + * 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 "catch2/catch.hpp" + +#include +#include +#include +#include +#include + +TEST_CASE("Documentation: Constructor", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc; + + // Basic Verifiers + doc.entries.emplace_back( + "BoolVerifier", + new BoolVerifier, + Optional::No + ); + doc.entries.emplace_back( + "DoubleVerifier", + new DoubleVerifier, + Optional::No + ); + doc.entries.emplace_back( + "IntVerifier", + new IntVerifier, + Optional::No + ); + doc.entries.emplace_back( + "StringVerifier", + new StringVerifier, + Optional::No + ); + doc.entries.emplace_back( + "TableVerifier", + new TableVerifier, + Optional::No + ); + + // Operator Verifiers + doc.entries.emplace_back( + "LessDouble", + new DoubleLessVerifier(0.0), + Optional::No + ); + doc.entries.emplace_back( + "LessInt", + new IntLessVerifier(0), + Optional::No + ); + doc.entries.emplace_back( + "LessEqualDouble", + new DoubleLessEqualVerifier(0.0), + Optional::No + ); + doc.entries.emplace_back( + "LessEqualInt", + new IntLessEqualVerifier(0), + Optional::No + ); + + doc.entries.emplace_back( + "GreaterDouble", + new DoubleGreaterVerifier(0.0), + Optional::No + ); + doc.entries.emplace_back( + "GreaterInt", + new IntGreaterVerifier(0), + Optional::No + ); + + doc.entries.emplace_back( + "GreaterEqualDouble", + new DoubleGreaterEqualVerifier(0.0), + Optional::No + ); + doc.entries.emplace_back( + "GreaterEqualInt", + new IntGreaterEqualVerifier(0), + Optional::No + ); + + doc.entries.emplace_back( + "EqualBool", + new BoolEqualVerifier(false), + Optional::No + ); + doc.entries.emplace_back( + "EqualDouble", + new DoubleEqualVerifier(0.0), + Optional::No + ); + doc.entries.emplace_back( + "EqualInt", + new IntEqualVerifier(0), + Optional::No + ); + doc.entries.emplace_back( + "EqualString", + new StringEqualVerifier(""), + Optional::No + ); + + doc.entries.emplace_back( + "UnequalBool", + new BoolUnequalVerifier(false), + Optional::No + ); + doc.entries.emplace_back( + "UnequalDouble", + new DoubleUnequalVerifier(0.0), + Optional::No + ); + doc.entries.emplace_back( + "UnequalInt", + new IntUnequalVerifier(0), + Optional::No + ); + doc.entries.emplace_back( + "UnequalString", + new StringUnequalVerifier(""), + Optional::No + ); + + // List Verifiers + doc.entries.emplace_back( + "InListBool", + new BoolInListVerifier({ true, false }), + Optional::No + ); + doc.entries.emplace_back( + "InListDouble", + new DoubleInListVerifier({ 0.0, 1.0}), + Optional::No + ); + doc.entries.emplace_back( + "InListInt", + new IntInListVerifier({ 0, 1 }), + Optional::No + ); + doc.entries.emplace_back( + "InListString", + new StringInListVerifier({ "", "a" }), + Optional::No + ); + + doc.entries.emplace_back( + "NotInListBool", + new BoolNotInListVerifier({ true, false }), + Optional::No + ); + doc.entries.emplace_back( + "NotInListDouble", + new DoubleNotInListVerifier({ 0.0, 1.0 }), + Optional::No + ); + doc.entries.emplace_back( + "NotInListInt", + new IntNotInListVerifier({ 0, 1 }), + Optional::No + ); + doc.entries.emplace_back( + "NotInListString", + new StringNotInListVerifier({ "", "a" }), + Optional::No + ); + + doc.entries.emplace_back( + "StringListVerifier", + new StringListVerifier, + Optional::No + ); + doc.entries.emplace_back( + "IntListVerifier", + new IntListVerifier, + Optional::No + ); + + // Range Verifiers + doc.entries.emplace_back( + "InListDouble", + new DoubleInRangeVerifier({ 0.0, 1.0 }), + Optional::No + ); + doc.entries.emplace_back( + "InListInt", + new IntInRangeVerifier({ 0, 1 }), + Optional::No + ); + + doc.entries.emplace_back( + "NotInListDouble", + new DoubleNotInRangeVerifier({ 0.0, 1.0 }), + Optional::No + ); + doc.entries.emplace_back( + "NotInListInt", + new IntNotInRangeVerifier({ 0, 1 }), + Optional::No + ); + + // Misc Verifiers + doc.entries.emplace_back( + "AnnotationBool", + new BoolAnnotationVerifier("Bool"), + Optional::No + ); + doc.entries.emplace_back( + "AnnotationDouble", + new DoubleAnnotationVerifier("Double"), + Optional::No + ); + doc.entries.emplace_back( + "AnnotationInt", + new IntAnnotationVerifier("Int"), + Optional::No + ); + doc.entries.emplace_back( + "AnnotationString", + new StringAnnotationVerifier("String"), + Optional::No + ); + doc.entries.emplace_back( + "AnnotationTable", + new TableAnnotationVerifier("Table"), + Optional::No + ); +} + +TEST_CASE("Documentation: Initializer Constructor", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + { + // Basic Verifiers + {"BoolVerifier", new BoolVerifier, Optional::No }, + {"DoubleVerifier", new DoubleVerifier, Optional::No }, + {"IntVerifier", new IntVerifier, Optional::No }, + {"StringVerifier", new StringVerifier, Optional::No }, + {"TableVerifier", new TableVerifier, Optional::No }, + + // Operator Verifiers + { "LessDouble", new DoubleLessVerifier(0.0), Optional::No }, + { "LessInt", new IntLessVerifier(0), Optional::No }, + + {"LessEqualDouble", new DoubleLessEqualVerifier(0.0), Optional::No }, + {"LessEqualInt", new IntLessEqualVerifier(0), Optional::No }, + + {"GreaterDouble", new DoubleGreaterVerifier(0.0), Optional::No }, + {"GreaterInt", new IntGreaterVerifier(0), Optional::No }, + + {"GreaterEqualDouble", new DoubleGreaterEqualVerifier(0.0), Optional::No }, + {"GreaterEqualInt", new IntGreaterEqualVerifier(0), Optional::No }, + + {"EqualBool", new BoolEqualVerifier(false), Optional::No }, + {"EqualDouble", new DoubleEqualVerifier(0.0), Optional::No }, + {"EqualInt", new IntEqualVerifier(0), Optional::No }, + {"EqualString", new StringEqualVerifier(""), Optional::No }, + + {"UnequalBool", new BoolUnequalVerifier(false), Optional::No }, + {"UnequalDouble", new DoubleUnequalVerifier(0.0), Optional::No }, + {"UnequalInt", new IntUnequalVerifier(0), Optional::No }, + {"UnequalString", new StringUnequalVerifier(""), Optional::No }, + + // List Verifiers + {"InListBool", new BoolInListVerifier({ true, false }), Optional::No }, + {"InListDouble", new DoubleInListVerifier({ 0.0, 1.0 }), Optional::No }, + {"InListInt", new IntInListVerifier({ 0, 1 }), Optional::No }, + {"InListString", new StringInListVerifier({ "", "a" }), Optional::No }, + + {"NotInListBool", new BoolNotInListVerifier({ true, false }), Optional::No }, + {"NotInListDouble", new DoubleNotInListVerifier({ 0.0, 1.0 }), Optional::No }, + {"NotInListInt", new IntNotInListVerifier({ 0, 1 }), Optional::No }, + {"NotInListString", new StringNotInListVerifier({ "", "a" }), Optional::No }, + + // Range Verifiers + {"InRangeDouble", new DoubleInRangeVerifier(0.0, 1.0), Optional::No }, + {"InRangeInt", new IntInRangeVerifier(0, 1), Optional::No }, + + {"InRangeDouble", new DoubleNotInRangeVerifier(0.0, 1.0), Optional::No }, + {"InRangeInt", new IntNotInRangeVerifier(0, 1), Optional::No }, + + // Misc Verifiers + {"AnnotationBool", new BoolAnnotationVerifier("Bool"), Optional::No }, + {"AnnotationDouble", new DoubleAnnotationVerifier("Double"), Optional::No }, + {"AnnotationInt", new IntAnnotationVerifier("Int"), Optional::No }, + {"AnnotationString", new StringAnnotationVerifier("String"), Optional::No }, + {"AnnotationTable", new TableAnnotationVerifier("Table"), Optional::No } + } + }; +} + +TEST_CASE("Documentation: BoolVerifier", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Bool", new BoolVerifier, Optional::No }} + }; + + ghoul::Dictionary positive { + { "Bool", true } + }; + + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Bool", 0 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Bool"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negativeExist { + { "Bool2", 0 } + }; + negativeRes = testSpecification(doc, negativeExist); + + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Bool"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::MissingKey); +} + +TEST_CASE("Documentation: DoubleVerifier", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Double", new DoubleVerifier, Optional::No }} + }; + + ghoul::Dictionary positive { + { "Double", 0.0 } + }; + + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Double", 0 } + }; + + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Double"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negativeExist{ + { "Double2" , 0.0 } + }; + negativeRes = testSpecification(doc, negativeExist); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Double"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::MissingKey); +} + +TEST_CASE("Documentation: IntVerifier", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Int", new IntVerifier, Optional::No }} + }; + + ghoul::Dictionary positive { + { "Int", 0 } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary positive2 { + { "Int", 0.0 } + }; + positiveRes = testSpecification(doc, positive2); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Int", 0.1 } + }; + + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Int"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negativeExist { + { "Int2", 0 } + }; + negativeRes = testSpecification(doc, negativeExist); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Int"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::MissingKey); +} + +TEST_CASE("Documentation: StringVerifier", "[documentation]") { + using namespace openspace::documentation; + using namespace std::string_literals; + + Documentation doc { + {{ "String", new StringVerifier, Optional::No }} + }; + + ghoul::Dictionary positive { + { "String", ""s } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "String", 0 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "String"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negativeExist { + { "String2", ""s } + }; + negativeRes = testSpecification(doc, negativeExist); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "String"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::MissingKey); +} + +TEST_CASE("Documentation: TableVerifierType", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Table", new TableVerifier, Optional::No }} + }; + + ghoul::Dictionary positive { + { "Table", ghoul::Dictionary{} } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Table", 0 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Table"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negativeExist { + { "Table2", ghoul::Dictionary{} } + }; + negativeRes = testSpecification(doc, negativeExist); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Table"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::MissingKey); +} + +TEST_CASE("Documentation: StringListVerifierType", "[documentation]") { + using namespace openspace::documentation; + using namespace std::string_literals; + + Documentation doc { + { { "StringList", new StringListVerifier, Optional::No } } + }; + + ghoul::Dictionary positive { + { + "StringList", + ghoul::Dictionary { + { "1", "a"s }, + { "2", "b"s }, + { "3", "c"s } + } + } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "StringList", 0 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "StringList"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negative2 { + { + "StringList", + ghoul::Dictionary { + { "1", "a"s }, + { "2", "b"s }, + { "3", 2.0 } + } + } + }; + negativeRes = testSpecification(doc, negative2); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "StringList.3"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negativeExist { + { "StringList2", ghoul::Dictionary{} } + }; + negativeRes = testSpecification(doc, negativeExist); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "StringList"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::MissingKey); +} + +TEST_CASE("Documentation: IntListVerifierType", "[documentation]") { + using namespace openspace::documentation; + using namespace std::string_literals; + + Documentation doc { + { { "IntList", new IntListVerifier, Optional::No } } + }; + + ghoul::Dictionary positive { + { + "IntList", + ghoul::Dictionary{ + { "1", 1 }, + { "2", 2 }, + { "3", 3 } + } + } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative{ + { "IntList", 0 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "IntList"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negative2 { + { + "IntList", + ghoul::Dictionary{ + { "1", "a"s }, + { "2", 1 }, + { "3", 2 } + } + } + }; + negativeRes = testSpecification(doc, negative2); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "IntList.1"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negativeExist { + { "IntList2", ghoul::Dictionary{} } + }; + negativeRes = testSpecification(doc, negativeExist); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "IntList"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::MissingKey); +} + +TEST_CASE("Documentation: MixedVerifiers", "[documentation]") { + using namespace openspace::documentation; + using namespace std::string_literals; + + Documentation doc { + { + { "Bool", new BoolVerifier, Optional::No }, + { "Double", new DoubleVerifier, Optional::No }, + { "Int", new IntVerifier, Optional::No }, + { "String", new StringVerifier, Optional::No }, + { "Table", new TableVerifier, Optional::No } + } + }; + + ghoul::Dictionary positive { + { "Bool", true }, + { "Double", 0.0 }, + { "Int", 0 }, + { "String", ""s }, + { "Table", ghoul::Dictionary{} } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative1 { + { "Bool", true }, + { "Double", 1 }, + { "Int", 0 }, + { "String", ""s }, + { "Table", ghoul::Dictionary{} } + }; + TestResult negativeRes = testSpecification(doc, negative1); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Double"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negative2 { + { "Bool", true }, + { "Double", 0.0 }, + { "Int", ""s }, + { "String", 1 }, + { "Table", ghoul::Dictionary{} } + }; + negativeRes = testSpecification(doc, negative2); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 2); + REQUIRE(negativeRes.offenses[0].offender == "Int"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + REQUIRE(negativeRes.offenses[1].offender == "String"); + REQUIRE(negativeRes.offenses[1].reason == TestResult::Offense::Reason::WrongType); +} + +TEST_CASE("Documentation: NestedTables", "[documentation]") { + using namespace openspace::documentation; + using namespace std::string_literals; + + Documentation doc { + { + { "Outer_Int", new IntVerifier, Optional::No }, + { "Outer_Table", new TableVerifier({ + { "Inner_Double", new DoubleVerifier, Optional::No }, + { "Inner_String", new StringVerifier, Optional::No } + }), Optional::No }, + { "Outer_Double", new DoubleVerifier, Optional::No }, + { "Outer_Table2" , new TableVerifier({ + { "Inner_Double2", new DoubleVerifier, Optional::No }, + { "Inner_String2", new StringVerifier, Optional::No }, + { "Inner_Table" , new TableVerifier({ + { "Inner_Inner_Int", new IntVerifier, Optional::No } + }), Optional::No } + }), Optional::No} + } + }; + + ghoul::Dictionary positive { + { "Outer_Int", 1 }, + { "Outer_Table", ghoul::Dictionary { + { "Inner_Double", 0.0 }, + { "Inner_String", ""s } + }}, + { "Outer_Double", 0.0 }, + { "Outer_Table2", ghoul::Dictionary { + { "Inner_Double2", 0.0 }, + { "Inner_String2", ""s }, + { "Inner_Table", ghoul::Dictionary { + { "Inner_Inner_Int", 0 } + }} + }} + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negativeSimple { + { "Outer_Int", 1 }, + { "Outer_Table", 0}, + { "Outer_Double", 0.0 }, + { "Outer_Table2", ghoul::Dictionary { + { "Inner_Double2", 0.0 }, + { "Inner_String2", ""s }, + { "Inner_Table", ghoul::Dictionary { + { "Inner_Inner_Int", 0 } + }} + }} + }; + TestResult negativeRes = testSpecification(doc, negativeSimple); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Outer_Table"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negativeInner { + { "Outer_Int", 1 }, + { "Outer_Table", ghoul::Dictionary { + { "Inner_Double", ""s }, + { "Inner_String", ""s } + }}, + { "Outer_Double", 0.0 }, + { "Outer_Table2", ghoul::Dictionary { + { "Inner_Double2", 0.0 }, + { "Inner_String2", ""s }, + { "Inner_Table", ghoul::Dictionary { + { "Inner_Inner_Int", 0 } + }} + }} + }; + negativeRes = testSpecification(doc, negativeInner); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Outer_Table.Inner_Double"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negativeInner2 { + { "Outer_Int", 1 }, + { "Outer_Table", ghoul::Dictionary { + { "Inner_Double", ""s }, + { "Inner_String", 0.0 } + }}, + { "Outer_Double", 0.0 }, + { "Outer_Table2", ghoul::Dictionary { + { "Inner_Double2", 0.0 }, + { "Inner_String2", ""s }, + { "Inner_Table", ghoul::Dictionary { + { "Inner_Inner_Int", 0 } + }} + }} + }; + negativeRes = testSpecification(doc, negativeInner2); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 2); + REQUIRE(negativeRes.offenses[0].offender == "Outer_Table.Inner_Double"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + REQUIRE(negativeRes.offenses[1].offender == "Outer_Table.Inner_String"); + REQUIRE(negativeRes.offenses[1].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negativeInnerSeparate { + { "Outer_Int", 1 }, + { "Outer_Table", ghoul::Dictionary { + { "Inner_Double", ""s }, + { "Inner_String", ""s } + } }, + { "Outer_Double", 0.0 }, + { "Outer_Table2", ghoul::Dictionary { + { "Inner_Double2", ""s }, + { "Inner_String2", ""s }, + { "Inner_Table", ghoul::Dictionary { + { "Inner_Inner_Int", 0 } + }} + }} + }; + negativeRes = testSpecification(doc, negativeInnerSeparate); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 2); + REQUIRE(negativeRes.offenses[0].offender == "Outer_Table.Inner_Double"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + REQUIRE(negativeRes.offenses[1].offender == "Outer_Table2.Inner_Double2"); + REQUIRE(negativeRes.offenses[1].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negativeInnerFull { + { "Outer_Int", 1 }, + { "Outer_Table", ghoul::Dictionary { + { "Inner_Double", ""s }, + { "Inner_String", ""s } + } }, + { "Outer_Double", 0.0 }, + { "Outer_Table2", ghoul::Dictionary { + { "Inner_Double2", ""s }, + { "Inner_String2", ""s }, + { "Inner_Table", ghoul::Dictionary { + { "Inner_Inner_Int", ""s } + }} + }} + }; + negativeRes = testSpecification(doc, negativeInnerFull); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 3); + REQUIRE(negativeRes.offenses[0].offender == "Outer_Table.Inner_Double"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + REQUIRE(negativeRes.offenses[1].offender == "Outer_Table2.Inner_Double2"); + REQUIRE(negativeRes.offenses[1].reason == TestResult::Offense::Reason::WrongType); + REQUIRE( + negativeRes.offenses[2].offender == "Outer_Table2.Inner_Table.Inner_Inner_Int" + ); + REQUIRE(negativeRes.offenses[2].reason == TestResult::Offense::Reason::WrongType); +} + +TEST_CASE("Documentation: Optional", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + { + { "Bool_Force", new BoolVerifier, Optional::No }, + { "Bool_Optional", new BoolVerifier, Optional::Yes } + } + }; + + ghoul::Dictionary positive { + { "Bool_Force", true } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary positive2 { + { "Bool_Force", true }, + { "Bool_Optional", true } + }; + positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Bool_Force"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::MissingKey); + + ghoul::Dictionary negative2 { + { "Bool_Optional", true } + }; + negativeRes = testSpecification(doc, negative2); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Bool_Force"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::MissingKey); + + ghoul::Dictionary negative3 { + { "Bool_Force", true }, + { "Bool_Optional", 1 } + }; + negativeRes = testSpecification(doc, negative3); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Bool_Optional"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); +} + +TEST_CASE("Documentation: Required In Optional", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ + "a", + new TableVerifier({ + { + "b", + new IntVerifier, + Optional::No + }, + { + "c", + new IntVerifier, + Optional::Yes + } + }), + Optional::Yes + }} + }; + + ghoul::Dictionary positive { + { + "a", ghoul::Dictionary{ + { "b", 1 } + } + } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary positive2 { + { + "a", ghoul::Dictionary{ + { "b", 1 }, + { "c", 2 } + } + } + }; + positiveRes = testSpecification(doc, positive2); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary positive3 {}; + positiveRes = testSpecification(doc, positive3); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "a", ghoul::Dictionary{ { "c", 2 }}} + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a.b"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::MissingKey); +} + +TEST_CASE("Documentation: Exhaustive", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Int", new IntVerifier, Optional::No }} + }; + + ghoul::Dictionary positive { + { "Int" , 1 } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "False_Int", 1 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Int"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::MissingKey); + + ghoul::Dictionary negative2 { + { "Double", 2.0 } + }; + negativeRes = testSpecification(doc, negative2); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Int"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::MissingKey); +} + +TEST_CASE("Documentation: Nested Exhaustive", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Table", new TableVerifier( + { { "a", new IntVerifier, Optional::No } } + ), Optional::No + }} + }; + + ghoul::Dictionary positive { + { "Table", ghoul::Dictionary{{ "a", 1 }}} + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Table", ghoul::Dictionary{{ "b", 2.0 }}} + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Table.a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::MissingKey); +} + +TEST_CASE("Documentation: Empty Entries Non Exhaustive", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc; + + ghoul::Dictionary positive {}; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary positive2 { + { "a", 1 } + }; + positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); +} + +TEST_CASE("Documentation: Empty Nested Exhaustive", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ + "Table", + new TableVerifier(), + Optional::No, + }} + }; + + ghoul::Dictionary positive { + { "Table", ghoul::Dictionary() } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Table", ghoul::Dictionary{ { "a", 1 }}} + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE(negativeRes.success); + REQUIRE(negativeRes.offenses.empty()); +} + +TEST_CASE("Documentation: Less Int", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Int", new IntLessVerifier(5), Optional::No }} + }; + + ghoul::Dictionary positive { + { "Int", 0 } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Int", 10 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Int"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); +} + +TEST_CASE("Documentation: Less Double", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Double", new DoubleLessVerifier(5.0), Optional::No }} + }; + + ghoul::Dictionary positive { + { "Double", 0.0 } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Double", 10.0 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Double"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); +} + +TEST_CASE("Documentation: LessEqual Int", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Int", new IntLessEqualVerifier(5), Optional::No }} + }; + + ghoul::Dictionary positive { + { "Int", 0 } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary positiveEqual { + { "Int", 5 } + }; + positiveRes = testSpecification(doc, positiveEqual); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Int", 10 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Int"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); +} + +TEST_CASE("Documentation: LessEqual Double", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Double", new DoubleLessEqualVerifier(5.0), Optional::No }} + }; + + ghoul::Dictionary positive { + { "Double", 0.0 } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary positiveEqual { + { "Double", 5.0 } + }; + positiveRes = testSpecification(doc, positiveEqual); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Double", 10.0 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Double"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); +} + +TEST_CASE("Documentation: Greater Int", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Int", new IntGreaterVerifier(5), Optional::No }} + }; + + ghoul::Dictionary positive { + { "Int", 10 } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Int", 0 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Int"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); +} + +TEST_CASE("Documentation: Greater Double", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Double", new DoubleGreaterVerifier(5.0), Optional::No }} + }; + + ghoul::Dictionary positive { + { "Double", 10.0 } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Double", 0.0 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Double"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); +} + +TEST_CASE("Documentation: GreaterEqual Int", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Int", new IntGreaterEqualVerifier(5), Optional::No }} + }; + + ghoul::Dictionary positive { + { "Int", 10 } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary positiveEqual { + { "Int", 5 } + }; + positiveRes = testSpecification(doc, positiveEqual); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Int", 0 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Int"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); +} + +TEST_CASE("Documentation: GreaterEqual Double", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Double", new DoubleGreaterEqualVerifier(5.0), Optional::No }} + }; + + ghoul::Dictionary positive { + { "Double", 10.0 } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary positiveEqual { + { "Double", 5.0 } + }; + positiveRes = testSpecification(doc, positiveEqual); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Double", 0.0 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Double"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); +} + +TEST_CASE("Documentation: Equal Bool", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Bool", new BoolEqualVerifier(true), Optional::No }} + }; + + ghoul::Dictionary positive { + { "Bool", true} + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Bool", false } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Bool"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); +} + +TEST_CASE("Documentation: Equal Int", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Int", new IntEqualVerifier(1), Optional::No }} + }; + + ghoul::Dictionary positive { + { "Int", 1} + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Int", 0 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Int"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); +} + +TEST_CASE("Documentation: Equal Double", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Double", new DoubleEqualVerifier(1.0), Optional::No }} + }; + + ghoul::Dictionary positive { + { "Double", 1.0 } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Double", 0.0 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Double"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); +} + +TEST_CASE("Documentation: Equal String", "[documentation]") { + using namespace openspace::documentation; + using namespace std::string_literals; + + Documentation doc { + {{ "String", new StringEqualVerifier("string"s), Optional::No }} + }; + + ghoul::Dictionary positive { + { "String", "string"s } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "String", "no_string"s } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "String"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); +} + +TEST_CASE("Documentation: Unequal Bool", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Bool", new BoolUnequalVerifier(true), Optional::No }} + }; + + ghoul::Dictionary positive { + { "Bool", false } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Bool", true } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Bool"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); +} + +TEST_CASE("Documentation: Unequal Int", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Int", new IntUnequalVerifier(1), Optional::No }} + }; + + ghoul::Dictionary positive { + { "Int", 0 } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Int", 1 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Int"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); +} + +TEST_CASE("Documentation: Unequal Double", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Double", new DoubleUnequalVerifier(1.0), Optional::No }} + }; + + ghoul::Dictionary positive { + { "Double", 0.0 } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Double", 1.0 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Double"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); +} + +TEST_CASE("Documentation: Unequal String", "[documentation]") { + using namespace openspace::documentation; + using namespace std::string_literals; + + Documentation doc { + {{ "String", new StringUnequalVerifier("string"s), Optional::No }} + }; + + ghoul::Dictionary positive { + { "String", "no_string"s } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "String", "string"s } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "String"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); +} + +TEST_CASE("Documentation: List Bool", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Bool" , new BoolInListVerifier({ true }), Optional::No }} + }; + + ghoul::Dictionary positive { + { "Bool", true } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Bool", false } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Bool"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); +} + +TEST_CASE("Documentation: List Int", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Int" , new IntInListVerifier({ 0, 1, 2 }), Optional::No }} + }; + + ghoul::Dictionary positive { + { "Int", 1 } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary positive2 { + { "Int", 2 } + }; + positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Int", 5 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Int"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); +} + +TEST_CASE("Documentation: List Double", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Double" , new DoubleInListVerifier({ 0.0, 1.0, 2.0 }), Optional::No }} + }; + + ghoul::Dictionary positive { + { "Double", 1.0 } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary positive2 { + { "Double", 2.0 } + }; + positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Double", 5.0 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Double"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); +} + +TEST_CASE("Documentation: List String", "[documentation]") { + using namespace openspace::documentation; + using namespace std::string_literals; + + Documentation doc { + {{ "String" , new StringInListVerifier({ "0"s, "1"s, "2"s }), Optional::No }} + }; + + ghoul::Dictionary positive { + { "String", "1"s } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary positive2 { + { "String", "2"s } + }; + positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "String", "5"s } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "String"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); +} + +TEST_CASE("Documentation: NotList Bool", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Bool" , new BoolNotInListVerifier({ true }), Optional::No }} + }; + + ghoul::Dictionary positive { + { "Bool", false } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Bool", true } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Bool"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); +} + +TEST_CASE("Documentation: NotList Int", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Int" , new IntNotInListVerifier({ 0, 1, 2 }), Optional::No }} + }; + + ghoul::Dictionary positive { + { "Int", -1 } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary positive2 { + { "Int", 3 } + }; + positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Int", 2 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Int"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); +} + +TEST_CASE("Documentation: NotList Double", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Double" , new DoubleNotInListVerifier({ 0.0, 1.0, 2.0 }), Optional::No }} + }; + + ghoul::Dictionary positive { + { "Double", -1.0 } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary positive2 { + { "Double", 3.0 } + }; + positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Double", 1.0 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Double"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); +} + +TEST_CASE("Documentation: NotList String", "[documentation]") { + using namespace openspace::documentation; + using namespace std::string_literals; + + Documentation doc { + {{ "String" , new StringNotInListVerifier({ "0"s, "1"s, "2"s }), Optional::No }} + }; + + ghoul::Dictionary positive { + { "String", "string"s } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary positive2 { + { "String", "foo_string"s } + }; + positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "String", "1"s } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "String"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); +} + +TEST_CASE("Documentation: Annotation Bool", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Bool", new BoolAnnotationVerifier("Bool"), Optional::No }} + }; + + ghoul::Dictionary positive { + { "Bool", true } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Bool", 0 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Bool"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); +} + +TEST_CASE("Documentation: Annotation Int", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Int", new IntAnnotationVerifier("Int"), Optional::No }} + }; + + ghoul::Dictionary positive { + { "Int", 1 } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Int", 1.1 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Int"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); +} + +TEST_CASE("Documentation: Annotation Double", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Double", new DoubleAnnotationVerifier("Double"), Optional::No }} + }; + + ghoul::Dictionary positive { + { "Double", 0.0 } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Double", true } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Double"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); +} + +TEST_CASE("Documentation: Annotation String", "[documentation]") { + using namespace openspace::documentation; + using namespace std::string_literals; + + Documentation doc { + {{ "String", new StringAnnotationVerifier("String"), Optional::No }} + }; + + ghoul::Dictionary positive { + { "String", ""s } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "String", 1 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "String"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); +} + +TEST_CASE("Documentation: Annotation Table", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Table", new TableAnnotationVerifier("Table"), Optional::No }} + }; + + ghoul::Dictionary positive { + { "Table", ghoul::Dictionary{} } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Table", 1 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Table"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); +} + +TEST_CASE("Documentation: InRange Int", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Int", new InRangeVerifier(0, 5), Optional::No }} + }; + + ghoul::Dictionary positive { + { "Int", 2 } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary positive2 { + { "Int", 0 } + }; + positiveRes = testSpecification(doc, positive2); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary positive3 { + { "Int", 5 } + }; + positiveRes = testSpecification(doc, positive3); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Int", 10 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Int"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); +} + +TEST_CASE("Documentation: InRange Double", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Double", new InRangeVerifier(0.0, 5.0), Optional::No }} + }; + + ghoul::Dictionary positive { + { "Double", 2.0 } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary positive2 { + { "Double", 0.0 } + }; + positiveRes = testSpecification(doc, positive2); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary positive3 { + { "Double", 5.0 } + }; + positiveRes = testSpecification(doc, positive3); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary positive4 { + { "Double", 1.5 } + }; + positiveRes = testSpecification(doc, positive4); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Double", 10.0 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Double"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); +} + +TEST_CASE("Documentation: NotInRange Int", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Int", new NotInRangeVerifier(0, 5), Optional::No }} + }; + + ghoul::Dictionary positive { + { "Int", -1 } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary positive2 { + { "Int", 6 } + }; + positiveRes = testSpecification(doc, positive2); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Int", 2 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Int"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); + + ghoul::Dictionary negative2 { + { "Int", 0 } + }; + negativeRes = testSpecification(doc, negative2); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Int"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); + + ghoul::Dictionary negative3 { + { "Int", 5 } + }; + negativeRes = testSpecification(doc, negative3); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Int"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); +} + +TEST_CASE("Documentation: NotInRange Double", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "Double", new NotInRangeVerifier(0.0, 5.0), Optional::No }} + }; + + ghoul::Dictionary positive { + { "Double", -1.0 } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary positive2 { + { "Double", 6.0 } + }; + positiveRes = testSpecification(doc, positive2); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Double", 0.0 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Double"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); + + ghoul::Dictionary negative2 { + { "Double", 5.0 } + }; + negativeRes = testSpecification(doc, negative2); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Double"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); + + ghoul::Dictionary negative3 { + { "Double", 2.5 } + }; + negativeRes = testSpecification(doc, negative3); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Double"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); +} + +TEST_CASE("Documentation: Wildcard", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ DocumentationEntry::Wildcard, new IntVerifier, Optional::No }} + }; + + ghoul::Dictionary positive { + { "a", 1 }, + { "b", 2 }, + { "c", 3 } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "a", false }, + { "b", 2 }, + { "c", 3 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negative2 { + { "a", false }, + { "b", false }, + { "c", 3 } + }; + negativeRes = testSpecification(doc, negative2); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 2); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + REQUIRE(negativeRes.offenses[1].offender == "b"); + REQUIRE(negativeRes.offenses[1].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negative3 { + { "a", false }, + { "b", false }, + { "c", false } + }; + negativeRes = testSpecification(doc, negative3); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 3); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + REQUIRE(negativeRes.offenses[1].offender == "b"); + REQUIRE(negativeRes.offenses[1].reason == TestResult::Offense::Reason::WrongType); + REQUIRE(negativeRes.offenses[2].offender == "c"); + REQUIRE(negativeRes.offenses[2].reason == TestResult::Offense::Reason::WrongType); +} + +TEST_CASE("Documentation: Wildcard Mixed", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + { + { DocumentationEntry::Wildcard, new IntVerifier , Optional::No}, + { "b", new IntGreaterVerifier(5), Optional::No } + } + }; + + ghoul::Dictionary positive { + { "a", 1 }, + { "b", 8 }, + { "c", 3 } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "a", false }, + { "b", 2 }, + { "c", 3 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 2); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + REQUIRE(negativeRes.offenses[1].offender == "b"); + REQUIRE(negativeRes.offenses[1].reason == TestResult::Offense::Reason::Verification); + + ghoul::Dictionary negative2 { + { "a", false }, + { "b", false }, + { "c", 3 } + }; + negativeRes = testSpecification(doc, negative2); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 2); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + REQUIRE(negativeRes.offenses[1].offender == "b"); + REQUIRE(negativeRes.offenses[1].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negative3 { + { "a", false }, + { "b", 1 }, + { "c", false } + }; + negativeRes = testSpecification(doc, negative3); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 3); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + REQUIRE(negativeRes.offenses[1].offender == "b"); + REQUIRE(negativeRes.offenses[1].reason == TestResult::Offense::Reason::Verification); + REQUIRE(negativeRes.offenses[2].offender == "c"); + REQUIRE(negativeRes.offenses[2].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negative4 { + { "a", false }, + { "b", 10 }, + { "c", false } + }; + negativeRes = testSpecification(doc, negative4); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 2); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + REQUIRE(negativeRes.offenses[1].offender == "c"); + REQUIRE(negativeRes.offenses[1].reason == TestResult::Offense::Reason::WrongType); +} + +TEST_CASE("Documentation: Referencing", "[documentation]") { + using namespace openspace::documentation; + + Documentation referenced { + "Referenced Name", + "referenced_id", + { + { "a", new IntVerifier, Optional::No }, + { "b", new DoubleVerifier, Optional::No } + }, + }; + DocEng.addDocumentation(referenced); + + Documentation doc {{ + { "Table", new ReferencingVerifier("referenced_id"), Optional::No } + }}; + + ghoul::Dictionary positive { + { "Table", ghoul::Dictionary{ { "a", 1 }, { "b", 2.0 } }} + }; + + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "Table", 1 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Table"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negative2 { + { "Table", ghoul::Dictionary{ { "a", 1 }, { "b", true }}} + }; + negativeRes = testSpecification(doc, negative2); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Table.b"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + + + Documentation wrongDoc {{ + { "Table", new ReferencingVerifier("WRONG"), Optional::No } + } }; + ghoul::Dictionary wrongNegative { + { "Table", ghoul::Dictionary{ { "a", 1 },{ "b", 2.0 } } } + }; + negativeRes = testSpecification(wrongDoc, wrongNegative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "Table"); + REQUIRE( + negativeRes.offenses[0].reason == TestResult::Offense::Reason::UnknownIdentifier + ); +} + +TEST_CASE("Documentation: AndOperator", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + { + { + "a", + new AndVerifier({ + new IntGreaterEqualVerifier(2), new IntLessEqualVerifier(5) + }), + Optional::No + } + } + }; + + ghoul::Dictionary positive { + { "a", 4 } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "a", 0 } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); + + ghoul::Dictionary negative2 { + { "a", 8 } + }; + negativeRes = testSpecification(doc, negative2); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); +} + +TEST_CASE("Documentation: OrOperator", "[documentation]") { + using namespace openspace::documentation; + using namespace std::string_literals; + + Documentation doc { + {{ "a", new OrVerifier({ new StringVerifier, new IntVerifier }), Optional::No }} + }; + + ghoul::Dictionary positive { + { "a", ""s } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary positive2 { + { "a", 1 } + }; + positiveRes = testSpecification(doc, positive2); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "a", false } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::Verification); +} + +TEST_CASE("Documentation: BoolVector2Verifier", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + {{ "a", new BoolVector2Verifier, Optional::No }} + }; + + ghoul::Dictionary positive { + { "a", glm::bvec2(true) } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "a", ghoul::Dictionary{ { "1", true }, { "2", 1.0 } } } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negative2 { + { "a", true } + }; + negativeRes = testSpecification(doc, negative2); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); +} + +TEST_CASE("Documentation: IntVector2Verifier", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + { { "a", new IntVector2Verifier, Optional::No } } + }; + + ghoul::Dictionary positive { + { "a", glm::ivec2(2) } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "a", ghoul::Dictionary{ { "1", true },{ "2", 1 } } } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negative2 { + { "a", true } + }; + negativeRes = testSpecification(doc, negative2); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); +} + +TEST_CASE("Documentation: DoubleVector2Verifier", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + { { "a", new DoubleVector2Verifier, Optional::No } } + }; + + ghoul::Dictionary positive { + { "a", glm::dvec2(2.0) } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "a", ghoul::Dictionary{ { "1", true }, { "2", 1.0 } } } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negative2 { + { "a", true } + }; + negativeRes = testSpecification(doc, negative2); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); +} + +TEST_CASE("Documentation: BoolVector3Verifier", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + { { "a", new BoolVector3Verifier, Optional::No } } + }; + + ghoul::Dictionary positive { + { "a", glm::bvec3(true) } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "a", ghoul::Dictionary{ { "1", true },{ "2", 1.0 }, { "3", "s" } } } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negative2 { + { "a", true } + }; + negativeRes = testSpecification(doc, negative2); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); +} + +TEST_CASE("Documentation: IntVector3Verifier", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + { { "a", new IntVector3Verifier, Optional::No } } + }; + + ghoul::Dictionary positive { + { "a", glm::ivec3(2) } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "a", ghoul::Dictionary{ { "1", true },{ "2", 1 }, { "3", "s" } } } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negative2 { + { "a", true } + }; + negativeRes = testSpecification(doc, negative2); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); +} + +TEST_CASE("Documentation: DoubleVector3Verifier", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + { { "a", new DoubleVector3Verifier, Optional::No } } + }; + + ghoul::Dictionary positive { + { "a", glm::dvec3(2.0) } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "a", ghoul::Dictionary{ { "1", true },{ "2", 1.0 }, { "3", "s"} } } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negative2 { + { "a", true } + }; + negativeRes = testSpecification(doc, negative2); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); +} + +TEST_CASE("Documentation: BoolVector4Verifier", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + { { "a", new BoolVector4Verifier, Optional::No } } + }; + + ghoul::Dictionary positive { + { "a", glm::bvec4(true) } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "a", ghoul::Dictionary{ { "1", true },{ "2", 1.0 }, { "3", "s" }, { "4", 1 }}} + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negative2 { + { "a", true } + }; + negativeRes = testSpecification(doc, negative2); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); +} + +TEST_CASE("Documentation: IntVector4Verifier", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + { { "a", new IntVector4Verifier, Optional::No } } + }; + + ghoul::Dictionary positive { + { "a", glm::ivec4(2) } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "a", ghoul::Dictionary{ { "1", true },{ "2", 1 },{ "3", "s" }, { "4", 1 } } } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negative2{ + { "a", true } + }; + negativeRes = testSpecification(doc, negative2); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); +} + +TEST_CASE("Documentation: DoubleVector4Verifier", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + { { "a", new DoubleVector4Verifier, Optional::No } } + }; + + ghoul::Dictionary positive { + { "a", glm::dvec4(2.0) } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "a", ghoul::Dictionary{ { "1", true },{ "2", 1.0 },{ "3", "s" }, { "4", 1 } } } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negative2 { + { "a", true } + }; + negativeRes = testSpecification(doc, negative2); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); +} + +TEST_CASE("Documentation: DoubleMatrix2x2Verifier", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + { { "a", new DoubleMatrix2x2Verifier, Optional::No } } + }; + + ghoul::Dictionary positive { + { "a", glm::dmat2x2(1.0) } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "a", ghoul::Dictionary { { "1", true },{ "2", 1.0 },{ "3", "s" } } } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negative2 { + { "a", true } + }; + negativeRes = testSpecification(doc, negative2); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); +} + +TEST_CASE("Documentation: DoubleMatrix2x3Verifier", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + { { "a", new DoubleMatrix2x3Verifier, Optional::No } } + }; + + ghoul::Dictionary positive { + { "a", glm::dmat2x3(1.0) } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "a", ghoul::Dictionary{ { "1", true },{ "2", 1.0 },{ "3", "s" } } } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negative2 { + { "a", true } + }; + negativeRes = testSpecification(doc, negative2); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); +} + +TEST_CASE("Documentation: DoubleMatrix2x4Verifier", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + { { "a", new DoubleMatrix2x4Verifier, Optional::No } } + }; + + ghoul::Dictionary positive { + { "a", glm::dmat2x4(1.0) } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "a", ghoul::Dictionary{ { "1", true },{ "2", 1.0 },{ "3", "s" } } } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negative2 { + { "a", true } + }; + negativeRes = testSpecification(doc, negative2); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); +} + +TEST_CASE("Documentation: DoubleMatrix3x2Verifier", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + { { "a", new DoubleMatrix3x2Verifier, Optional::No } } + }; + + ghoul::Dictionary positive { + { "a", glm::dmat3x2(1.0) } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "a", ghoul::Dictionary{ { "1", true },{ "2", 1.0 },{ "3", "s" } } } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negative2 { + { "a", true } + }; + negativeRes = testSpecification(doc, negative2); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); +} + +TEST_CASE("Documentation: DoubleMatrix3x3Verifier", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + { { "a", new DoubleMatrix3x3Verifier, Optional::No } } + }; + + ghoul::Dictionary positive { + { "a", glm::dmat3x3(1.0) } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "a", ghoul::Dictionary{ { "1", true },{ "2", 1.0 },{ "3", "s" } } } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negative2 { + { "a", true } + }; + negativeRes = testSpecification(doc, negative2); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); +} + +TEST_CASE("Documentation: DoubleMatrix3x4Verifier", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + { { "a", new DoubleMatrix3x4Verifier, Optional::No } } + }; + + ghoul::Dictionary positive { + { "a", glm::dmat3x4(1.0) } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "a", ghoul::Dictionary{ { "1", true },{ "2", 1.0 },{ "3", "s" } } } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negative2 { + { "a", true } + }; + negativeRes = testSpecification(doc, negative2); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); +} + +TEST_CASE("Documentation: DoubleMatrix4x2Verifier", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + { { "a", new DoubleMatrix4x2Verifier, Optional::No } } + }; + + ghoul::Dictionary positive { + { "a", glm::dmat4x2(1.0) } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "a", ghoul::Dictionary{ { "1", true },{ "2", 1.0 },{ "3", "s" } } } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negative2 { + { "a", true } + }; + negativeRes = testSpecification(doc, negative2); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); +} + +TEST_CASE("Documentation: DoubleMatrix4x3Verifier", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + { { "a", new DoubleMatrix4x3Verifier, Optional::No } } + }; + + ghoul::Dictionary positive { + { "a", glm::dmat4x3(1.0) } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "a", ghoul::Dictionary{ { "1", true },{ "2", 1.0 },{ "3", "s" } } } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negative2 { + { "a", true } + }; + negativeRes = testSpecification(doc, negative2); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); +} + +TEST_CASE("Documentation: DoubleMatrix4x4Verifier", "[documentation]") { + using namespace openspace::documentation; + + Documentation doc { + { { "a", new DoubleMatrix4x4Verifier, Optional::No } } + }; + + ghoul::Dictionary positive { + { "a", glm::dmat4x4(1.0) } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + + ghoul::Dictionary negative { + { "a", ghoul::Dictionary{ { "1", true },{ "2", 1.0 },{ "3", "s" } } } + }; + TestResult negativeRes = testSpecification(doc, negative); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); + + ghoul::Dictionary negative2 { + { "a", true } + }; + negativeRes = testSpecification(doc, negative2); + REQUIRE_FALSE(negativeRes.success); + REQUIRE(negativeRes.offenses.size() == 1); + REQUIRE(negativeRes.offenses[0].offender == "a"); + REQUIRE(negativeRes.offenses[0].reason == TestResult::Offense::Reason::WrongType); +} + +TEST_CASE("Documentation: DeprecatedVerifier", "[documentation]") { + using namespace openspace::documentation; + using namespace std::string_literals; + + Documentation doc { { + { "bool", new BoolDeprecatedVerifier, Optional::No }, + { "int" , new IntDeprecatedVerifier, Optional::No }, + { "double", new DoubleDeprecatedVerifier, Optional::No }, + { "string" , new StringDeprecatedVerifier, Optional::No }, + { "boolvec2", new DeprecatedVerifier, Optional::No }, + { "intvec2", new DeprecatedVerifier, Optional::No }, + { "doublevec2", new DeprecatedVerifier, Optional::No }, + { "boolvec3", new DeprecatedVerifier, Optional::No }, + { "intvec3", new DeprecatedVerifier, Optional::No }, + { "doublevec3", new DeprecatedVerifier, Optional::No }, + { "boolvec4", new DeprecatedVerifier, Optional::No }, + { "intvec4", new DeprecatedVerifier, Optional::No }, + { "doublevec4", new DeprecatedVerifier, Optional::No } + }}; + + ghoul::Dictionary positive { + { "bool", true }, + { "int", 1 }, + { "double", 2.0 }, + { "string" , ""s }, + { "boolvec2", glm::bvec2(false) }, + { "intvec2", glm::ivec2(0) }, + { "doublevec2", glm::dvec2(0.0) }, + { "boolvec3", glm::bvec3(false) }, + { "intvec3", glm::ivec3(0) }, + { "doublevec3", glm::dvec3(0.0) }, + { "boolvec4", glm::bvec4(false) }, + { "intvec4", glm::ivec4(0) }, + { "doublevec4", glm::dvec4(0.0) } + }; + TestResult positiveRes = testSpecification(doc, positive); + REQUIRE(positiveRes.success); + REQUIRE(positiveRes.offenses.empty()); + REQUIRE(positiveRes.warnings.size() == 13); + REQUIRE(positiveRes.warnings[0].offender == "bool"); + REQUIRE(positiveRes.warnings[0].reason == TestResult::Warning::Reason::Deprecated); + REQUIRE(positiveRes.warnings[1].offender == "boolvec2"); + REQUIRE(positiveRes.warnings[1].reason == TestResult::Warning::Reason::Deprecated); + REQUIRE(positiveRes.warnings[2].offender == "boolvec3"); + REQUIRE(positiveRes.warnings[2].reason == TestResult::Warning::Reason::Deprecated); + REQUIRE(positiveRes.warnings[3].offender == "boolvec4"); + REQUIRE(positiveRes.warnings[3].reason == TestResult::Warning::Reason::Deprecated); + REQUIRE(positiveRes.warnings[4].offender == "double"); + REQUIRE(positiveRes.warnings[4].reason == TestResult::Warning::Reason::Deprecated); + REQUIRE(positiveRes.warnings[5].offender == "doublevec2"); + REQUIRE(positiveRes.warnings[5].reason == TestResult::Warning::Reason::Deprecated); + REQUIRE(positiveRes.warnings[6].offender == "doublevec3"); + REQUIRE(positiveRes.warnings[6].reason == TestResult::Warning::Reason::Deprecated); + REQUIRE(positiveRes.warnings[7].offender == "doublevec4"); + REQUIRE(positiveRes.warnings[7].reason == TestResult::Warning::Reason::Deprecated); + REQUIRE(positiveRes.warnings[8].offender == "int"); + REQUIRE(positiveRes.warnings[8].reason == TestResult::Warning::Reason::Deprecated); + REQUIRE(positiveRes.warnings[9].offender == "intvec2"); + REQUIRE(positiveRes.warnings[9].reason == TestResult::Warning::Reason::Deprecated); + REQUIRE(positiveRes.warnings[10].offender == "intvec3"); + REQUIRE(positiveRes.warnings[10].reason == TestResult::Warning::Reason::Deprecated); + REQUIRE(positiveRes.warnings[11].offender == "intvec4"); + REQUIRE(positiveRes.warnings[11].reason == TestResult::Warning::Reason::Deprecated); + REQUIRE(positiveRes.warnings[12].offender == "string"); + REQUIRE(positiveRes.warnings[12].reason == TestResult::Warning::Reason::Deprecated); +} + +TEST_CASE("Documentation: Verifier Type Post Conditions", "[documentation]") { + using namespace openspace::documentation; + using namespace std::string_literals; + + REQUIRE(BoolVerifier().type() != ""); + REQUIRE(DoubleVerifier().type() != ""); + REQUIRE(IntVerifier().type() != ""); + REQUIRE(StringVerifier().type() != ""); + REQUIRE(TableVerifier().type() != ""); + + REQUIRE(BoolVector2Verifier().type() != ""); + REQUIRE(IntVector2Verifier().type() != ""); + REQUIRE(DoubleVector2Verifier().type() != ""); + REQUIRE(BoolVector3Verifier().type() != ""); + REQUIRE(IntVector3Verifier().type() != ""); + REQUIRE(DoubleVector3Verifier().type() != ""); + REQUIRE(BoolVector4Verifier().type() != ""); + REQUIRE(IntVector4Verifier().type() != ""); + REQUIRE(DoubleVector4Verifier().type() != ""); + + REQUIRE(IntLessVerifier(0).type() != ""); + REQUIRE(DoubleLessVerifier(0.0).type() != ""); + REQUIRE(IntLessEqualVerifier(0).type() != ""); + REQUIRE(DoubleLessEqualVerifier(0.0).type() != ""); + REQUIRE(IntGreaterVerifier(0).type() != ""); + REQUIRE(DoubleGreaterVerifier(0.0).type() != ""); + REQUIRE(IntGreaterEqualVerifier(0).type() != ""); + REQUIRE(DoubleGreaterEqualVerifier(0.0).type() != ""); + + REQUIRE(BoolEqualVerifier(true).type() != ""); + REQUIRE(IntEqualVerifier(0).type() != ""); + REQUIRE(DoubleEqualVerifier(0.0).type() != ""); + REQUIRE(StringEqualVerifier(""s).type() != ""); + REQUIRE(BoolUnequalVerifier(true).type() != ""); + REQUIRE(IntUnequalVerifier(0).type() != ""); + REQUIRE(DoubleUnequalVerifier(0.0).type() != ""); + REQUIRE(StringUnequalVerifier(""s).type() != ""); + + REQUIRE(BoolInListVerifier({ true }).type() != ""); + REQUIRE(IntInListVerifier({ 0 }).type() != ""); + REQUIRE(DoubleInListVerifier({ 0.0 }).type() != ""); + REQUIRE(StringInListVerifier({ ""s }).type() != ""); + REQUIRE(BoolNotInListVerifier({ true }).type() != ""); + REQUIRE(IntNotInListVerifier({ 0 }).type() != ""); + REQUIRE(DoubleNotInListVerifier({ 0.0 }).type() != ""); + REQUIRE(StringNotInListVerifier({ ""s }).type() != ""); + + REQUIRE(IntInRangeVerifier({ 0, 1 }).type() != ""); + REQUIRE(DoubleInRangeVerifier({ 0.0, 1.0 }).type() != ""); + REQUIRE(IntNotInRangeVerifier({ 0, 1 }).type() != ""); + REQUIRE(DoubleNotInRangeVerifier({ 0.0, 1.0 }).type() != ""); + + REQUIRE(BoolAnnotationVerifier("A"s).type() != ""); + REQUIRE(IntAnnotationVerifier("A"s).type() != ""); + REQUIRE(DoubleAnnotationVerifier("A"s).type() != ""); + REQUIRE(StringAnnotationVerifier("A"s).type() != ""); + REQUIRE(TableAnnotationVerifier("A"s).type() != ""); + REQUIRE(AnnotationVerifier("A"s).type() != ""); + REQUIRE(AnnotationVerifier("A"s).type() != ""); + REQUIRE(AnnotationVerifier("A"s).type() != ""); + REQUIRE(AnnotationVerifier("A"s).type() != ""); + REQUIRE(AnnotationVerifier("A"s).type() != ""); + REQUIRE(AnnotationVerifier("A"s).type() != ""); + REQUIRE(AnnotationVerifier("A"s).type() != ""); + REQUIRE(AnnotationVerifier("A"s).type() != ""); + REQUIRE(AnnotationVerifier("A"s).type() != ""); + + REQUIRE(BoolDeprecatedVerifier().type() != ""); + REQUIRE(IntDeprecatedVerifier().type() != ""); + REQUIRE(DoubleDeprecatedVerifier().type() != ""); + REQUIRE(StringDeprecatedVerifier().type() != ""); + REQUIRE(TableDeprecatedVerifier().type() != ""); + REQUIRE(DeprecatedVerifier().type() != ""); + REQUIRE(DeprecatedVerifier().type() != ""); + REQUIRE(DeprecatedVerifier().type() != ""); + REQUIRE(DeprecatedVerifier().type() != ""); + REQUIRE(DeprecatedVerifier().type() != ""); + REQUIRE(DeprecatedVerifier().type() != ""); + REQUIRE(DeprecatedVerifier().type() != ""); + REQUIRE(DeprecatedVerifier().type() != ""); + REQUIRE(DeprecatedVerifier().type() != ""); + + REQUIRE(ReferencingVerifier("identifier"s).type() != ""); +} + +TEST_CASE("Documentation: Verifier Documentation Post Conditions", "[documentation]") { + using namespace openspace::documentation; + using namespace std::string_literals; + + REQUIRE(BoolVerifier().documentation() != ""); + REQUIRE(DoubleVerifier().documentation() != ""); + REQUIRE(IntVerifier().documentation() != ""); + REQUIRE(StringVerifier().documentation() != ""); + REQUIRE(TableVerifier().documentation() != ""); + + REQUIRE(BoolVector2Verifier().documentation() != ""); + REQUIRE(IntVector2Verifier().documentation() != ""); + REQUIRE(DoubleVector2Verifier().documentation() != ""); + REQUIRE(BoolVector3Verifier().documentation() != ""); + REQUIRE(IntVector3Verifier().documentation() != ""); + REQUIRE(DoubleVector3Verifier().documentation() != ""); + REQUIRE(BoolVector4Verifier().documentation() != ""); + REQUIRE(IntVector4Verifier().documentation() != ""); + REQUIRE(DoubleVector4Verifier().documentation() != ""); + + REQUIRE(IntLessVerifier(0).documentation() != ""); + REQUIRE(DoubleLessVerifier(0.0).documentation() != ""); + REQUIRE(IntLessEqualVerifier(0).documentation() != ""); + REQUIRE(DoubleLessEqualVerifier(0.0).documentation() != ""); + REQUIRE(IntGreaterVerifier(0).documentation() != ""); + REQUIRE(DoubleGreaterVerifier(0.0).documentation() != ""); + REQUIRE(IntGreaterEqualVerifier(0).documentation() != ""); + REQUIRE(DoubleGreaterEqualVerifier(0.0).documentation() != ""); + + REQUIRE(BoolEqualVerifier(true).documentation() != ""); + REQUIRE(IntEqualVerifier(0).documentation() != ""); + REQUIRE(DoubleEqualVerifier(0.0).documentation() != ""); + REQUIRE(StringEqualVerifier(""s).documentation() != ""); + REQUIRE(BoolUnequalVerifier(true).documentation() != ""); + REQUIRE(IntUnequalVerifier(0).documentation() != ""); + REQUIRE(DoubleUnequalVerifier(0.0).documentation() != ""); + REQUIRE(StringUnequalVerifier(""s).documentation() != ""); + + REQUIRE(BoolInListVerifier({ true }).documentation() != ""); + REQUIRE(IntInListVerifier({ 0 }).documentation() != ""); + REQUIRE(DoubleInListVerifier({ 0.0 }).documentation() != ""); + REQUIRE(StringInListVerifier({ ""s }).documentation() != ""); + REQUIRE(BoolNotInListVerifier({ true }).documentation() != ""); + REQUIRE(IntNotInListVerifier({ 0 }).documentation() != ""); + REQUIRE(DoubleNotInListVerifier({ 0.0 }).documentation() != ""); + REQUIRE(StringNotInListVerifier({ ""s }).documentation() != ""); + + REQUIRE(IntInRangeVerifier({ 0, 1 }).documentation() != ""); + REQUIRE(DoubleInRangeVerifier({ 0.0, 1.0 }).documentation() != ""); + REQUIRE(IntNotInRangeVerifier({ 0, 1 }).documentation() != ""); + REQUIRE(DoubleNotInRangeVerifier({ 0.0, 1.0 }).documentation() != ""); + + REQUIRE(BoolAnnotationVerifier("A"s).documentation() != ""); + REQUIRE(IntAnnotationVerifier("A"s).documentation() != ""); + REQUIRE(DoubleAnnotationVerifier("A"s).documentation() != ""); + REQUIRE(StringAnnotationVerifier("A"s).documentation() != ""); + REQUIRE(TableAnnotationVerifier("A"s).documentation() != ""); + REQUIRE(AnnotationVerifier("A"s).documentation() != ""); + REQUIRE(AnnotationVerifier("A"s).documentation() != ""); + REQUIRE(AnnotationVerifier("A"s).documentation() != ""); + REQUIRE(AnnotationVerifier("A"s).documentation() != ""); + REQUIRE(AnnotationVerifier("A"s).documentation() != ""); + REQUIRE(AnnotationVerifier("A"s).documentation() != ""); + REQUIRE(AnnotationVerifier("A"s).documentation() != ""); + REQUIRE(AnnotationVerifier("A"s).documentation() != ""); + REQUIRE(AnnotationVerifier("A"s).documentation() != ""); + + REQUIRE(BoolDeprecatedVerifier().documentation() != ""); + REQUIRE(IntDeprecatedVerifier().documentation() != ""); + REQUIRE(DoubleDeprecatedVerifier().documentation() != ""); + REQUIRE(StringDeprecatedVerifier().documentation() != ""); + REQUIRE(TableDeprecatedVerifier().documentation() != ""); + REQUIRE(DeprecatedVerifier().documentation() != ""); + REQUIRE(DeprecatedVerifier().documentation() != ""); + REQUIRE(DeprecatedVerifier().documentation() != ""); + REQUIRE(DeprecatedVerifier().documentation() != ""); + REQUIRE(DeprecatedVerifier().documentation() != ""); + REQUIRE(DeprecatedVerifier().documentation() != ""); + REQUIRE(DeprecatedVerifier().documentation() != ""); + REQUIRE(DeprecatedVerifier().documentation() != ""); + REQUIRE(DeprecatedVerifier().documentation() != ""); + + REQUIRE(ReferencingVerifier("identifier"s).documentation() != ""); +} diff --git a/tests/test_documentation.inl b/tests/test_documentation.inl deleted file mode 100644 index 10c6b3b0ee..0000000000 --- a/tests/test_documentation.inl +++ /dev/null @@ -1,2924 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2019 * - * * - * 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 -#include - -#include - -#include - -class DocumentationTest : public testing::Test {}; - -TEST_F(DocumentationTest, Constructor) { - using namespace openspace::documentation; - - Documentation doc; - - // Basic Verifiers - doc.entries.emplace_back("BoolVerifier", new BoolVerifier, Optional::No); - doc.entries.emplace_back("DoubleVerifier", new DoubleVerifier, Optional::No); - doc.entries.emplace_back("IntVerifier", new IntVerifier, Optional::No); - doc.entries.emplace_back("StringVerifier", new StringVerifier, Optional::No); - doc.entries.emplace_back("TableVerifier", new TableVerifier, Optional::No); - - // Operator Verifiers - doc.entries.emplace_back("LessDouble", new DoubleLessVerifier(0.0), Optional::No); - doc.entries.emplace_back("LessInt", new IntLessVerifier(0), Optional::No); - - doc.entries.emplace_back("LessEqualDouble", new DoubleLessEqualVerifier(0.0), Optional::No); - doc.entries.emplace_back("LessEqualInt", new IntLessEqualVerifier(0), Optional::No); - - doc.entries.emplace_back("GreaterDouble", new DoubleGreaterVerifier(0.0), Optional::No); - doc.entries.emplace_back("GreaterInt", new IntGreaterVerifier(0), Optional::No); - - doc.entries.emplace_back("GreaterEqualDouble", new DoubleGreaterEqualVerifier(0.0), Optional::No); - doc.entries.emplace_back("GreaterEqualInt", new IntGreaterEqualVerifier(0), Optional::No); - - doc.entries.emplace_back("EqualBool", new BoolEqualVerifier(false), Optional::No); - doc.entries.emplace_back("EqualDouble", new DoubleEqualVerifier(0.0), Optional::No); - doc.entries.emplace_back("EqualInt", new IntEqualVerifier(0), Optional::No); - doc.entries.emplace_back("EqualString", new StringEqualVerifier(""), Optional::No); - - doc.entries.emplace_back("UnequalBool", new BoolUnequalVerifier(false), Optional::No); - doc.entries.emplace_back("UnequalDouble", new DoubleUnequalVerifier(0.0), Optional::No); - doc.entries.emplace_back("UnequalInt", new IntUnequalVerifier(0), Optional::No); - doc.entries.emplace_back("UnequalString", new StringUnequalVerifier(""), Optional::No); - - // List Verifiers - doc.entries.emplace_back("InListBool", new BoolInListVerifier({ true, false }), Optional::No); - doc.entries.emplace_back("InListDouble", new DoubleInListVerifier({ 0.0, 1.0}), Optional::No); - doc.entries.emplace_back("InListInt", new IntInListVerifier({ 0, 1 }), Optional::No); - doc.entries.emplace_back("InListString", new StringInListVerifier({ "", "a" }), Optional::No); - - doc.entries.emplace_back("NotInListBool", new BoolNotInListVerifier({ true, false }), Optional::No); - doc.entries.emplace_back("NotInListDouble", new DoubleNotInListVerifier({ 0.0, 1.0 }), Optional::No); - doc.entries.emplace_back("NotInListInt", new IntNotInListVerifier({ 0, 1 }), Optional::No); - doc.entries.emplace_back("NotInListString", new StringNotInListVerifier({ "", "a" }), Optional::No); - - doc.entries.emplace_back("StringListVerifier", new StringListVerifier, Optional::No); - doc.entries.emplace_back("IntListVerifier", new IntListVerifier, Optional::No); - - // Range Verifiers - doc.entries.emplace_back("InListDouble", new DoubleInRangeVerifier({ 0.0, 1.0 }), Optional::No); - doc.entries.emplace_back("InListInt", new IntInRangeVerifier({ 0, 1 }), Optional::No); - - doc.entries.emplace_back("NotInListDouble", new DoubleNotInRangeVerifier({ 0.0, 1.0 }), Optional::No); - doc.entries.emplace_back("NotInListInt", new IntNotInRangeVerifier({ 0, 1 }), Optional::No); - - // Misc Verifiers - doc.entries.emplace_back("AnnotationBool", new BoolAnnotationVerifier("Bool"), Optional::No); - doc.entries.emplace_back("AnnotationDouble", new DoubleAnnotationVerifier("Double"), Optional::No); - doc.entries.emplace_back("AnnotationInt", new IntAnnotationVerifier("Int"), Optional::No); - doc.entries.emplace_back("AnnotationString", new StringAnnotationVerifier("String"), Optional::No); - doc.entries.emplace_back("AnnotationTable", new TableAnnotationVerifier("Table"), Optional::No); -} - -TEST_F(DocumentationTest, InitializerConstructor) { - using namespace openspace::documentation; - - Documentation doc { - { - // Basic Verifiers - {"BoolVerifier", new BoolVerifier, Optional::No }, - {"DoubleVerifier", new DoubleVerifier, Optional::No }, - {"IntVerifier", new IntVerifier, Optional::No }, - {"StringVerifier", new StringVerifier, Optional::No }, - {"TableVerifier", new TableVerifier, Optional::No }, - - // Operator Verifiers - { "LessDouble", new DoubleLessVerifier(0.0), Optional::No }, - { "LessInt", new IntLessVerifier(0), Optional::No }, - - {"LessEqualDouble", new DoubleLessEqualVerifier(0.0), Optional::No }, - {"LessEqualInt", new IntLessEqualVerifier(0), Optional::No }, - - {"GreaterDouble", new DoubleGreaterVerifier(0.0), Optional::No }, - {"GreaterInt", new IntGreaterVerifier(0), Optional::No }, - - {"GreaterEqualDouble", new DoubleGreaterEqualVerifier(0.0), Optional::No }, - {"GreaterEqualInt", new IntGreaterEqualVerifier(0), Optional::No }, - - {"EqualBool", new BoolEqualVerifier(false), Optional::No }, - {"EqualDouble", new DoubleEqualVerifier(0.0), Optional::No }, - {"EqualInt", new IntEqualVerifier(0), Optional::No }, - {"EqualString", new StringEqualVerifier(""), Optional::No }, - - {"UnequalBool", new BoolUnequalVerifier(false), Optional::No }, - {"UnequalDouble", new DoubleUnequalVerifier(0.0), Optional::No }, - {"UnequalInt", new IntUnequalVerifier(0), Optional::No }, - {"UnequalString", new StringUnequalVerifier(""), Optional::No }, - - // List Verifiers - {"InListBool", new BoolInListVerifier({ true, false }), Optional::No }, - {"InListDouble", new DoubleInListVerifier({ 0.0, 1.0 }), Optional::No }, - {"InListInt", new IntInListVerifier({ 0, 1 }), Optional::No }, - {"InListString", new StringInListVerifier({ "", "a" }), Optional::No }, - - {"NotInListBool", new BoolNotInListVerifier({ true, false }), Optional::No }, - {"NotInListDouble", new DoubleNotInListVerifier({ 0.0, 1.0 }), Optional::No }, - {"NotInListInt", new IntNotInListVerifier({ 0, 1 }), Optional::No }, - {"NotInListString", new StringNotInListVerifier({ "", "a" }), Optional::No }, - - // Range Verifiers - {"InRangeDouble", new DoubleInRangeVerifier(0.0, 1.0), Optional::No }, - {"InRangeInt", new IntInRangeVerifier(0, 1), Optional::No }, - - {"InRangeDouble", new DoubleNotInRangeVerifier(0.0, 1.0), Optional::No }, - {"InRangeInt", new IntNotInRangeVerifier(0, 1), Optional::No }, - - // Misc Verifiers - {"AnnotationBool", new BoolAnnotationVerifier("Bool"), Optional::No }, - {"AnnotationDouble", new DoubleAnnotationVerifier("Double"), Optional::No }, - {"AnnotationInt", new IntAnnotationVerifier("Int"), Optional::No }, - {"AnnotationString", new StringAnnotationVerifier("String"), Optional::No }, - {"AnnotationTable", new TableAnnotationVerifier("Table"), Optional::No } - } - }; -} - -TEST_F(DocumentationTest, BoolVerifier) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Bool", new BoolVerifier, Optional::No }} - }; - - ghoul::Dictionary positive { - { "Bool", true } - }; - - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Bool", 0 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Bool", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - - ghoul::Dictionary negativeExist { - { "Bool2", 0} - }; - negativeRes = testSpecification(doc, negativeExist); - - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Bool", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::MissingKey, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, DoubleVerifier) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Double", new DoubleVerifier, Optional::No }} - }; - - ghoul::Dictionary positive { - { "Double", 0.0 } - }; - - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Double", 0 } - }; - - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Double", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - - ghoul::Dictionary negativeExist{ - { "Double2" , 0.0 } - }; - negativeRes = testSpecification(doc, negativeExist); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Double", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::MissingKey, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, IntVerifier) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Int", new IntVerifier, Optional::No }} - }; - - ghoul::Dictionary positive { - { "Int", 0 } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary positive2 { - { "Int", 0.0 } - }; - positiveRes = testSpecification(doc, positive2); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Int", 0.1 } - }; - - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Int", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - - ghoul::Dictionary negativeExist { - { "Int2", 0 } - }; - negativeRes = testSpecification(doc, negativeExist); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Int", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::MissingKey, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, StringVerifier) { - using namespace openspace::documentation; - using namespace std::string_literals; - - Documentation doc { - {{ "String", new StringVerifier, Optional::No }} - }; - - ghoul::Dictionary positive { - { "String", ""s } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "String", 0 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("String", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - - ghoul::Dictionary negativeExist { - { "String2", ""s } - }; - negativeRes = testSpecification(doc, negativeExist); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("String", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::MissingKey, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, TableVerifierType) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Table", new TableVerifier, Optional::No }} - }; - - ghoul::Dictionary positive { - { "Table", ghoul::Dictionary{} } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Table", 0 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Table", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - - ghoul::Dictionary negativeExist { - { "Table2", ghoul::Dictionary{} } - }; - negativeRes = testSpecification(doc, negativeExist); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Table", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::MissingKey, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, StringListVerifierType) { - using namespace openspace::documentation; - using namespace std::string_literals; - - Documentation doc { - { { "StringList", new StringListVerifier, Optional::No } } - }; - - ghoul::Dictionary positive { - { - "StringList", - ghoul::Dictionary { - { "1", "a"s }, - { "2", "b"s }, - { "3", "c"s } - } - } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "StringList", 0 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("StringList", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - - ghoul::Dictionary negative2 { - { - "StringList", - ghoul::Dictionary { - { "1", "a"s }, - { "2", "b"s }, - { "3", 2.0 } - } - } - }; - negativeRes = testSpecification(doc, negative2); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("StringList.3", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - - ghoul::Dictionary negativeExist { - { "StringList2", ghoul::Dictionary{} } - }; - negativeRes = testSpecification(doc, negativeExist); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("StringList", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::MissingKey, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, IntListVerifierType) { - using namespace openspace::documentation; - using namespace std::string_literals; - - Documentation doc { - { { "IntList", new IntListVerifier, Optional::No } } - }; - - ghoul::Dictionary positive { - { - "IntList", - ghoul::Dictionary{ - { "1", 1 }, - { "2", 2 }, - { "3", 3 } - } - } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative{ - { "IntList", 0 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("IntList", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - - ghoul::Dictionary negative2 { - { - "IntList", - ghoul::Dictionary{ - { "1", "a"s }, - { "2", 1 }, - { "3", 2 } - } - } - }; - negativeRes = testSpecification(doc, negative2); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("IntList.1", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - - ghoul::Dictionary negativeExist { - { "IntList2", ghoul::Dictionary{} } - }; - negativeRes = testSpecification(doc, negativeExist); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("IntList", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::MissingKey, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, MixedVerifiers) { - using namespace openspace::documentation; - using namespace std::string_literals; - - Documentation doc { - { - { "Bool", new BoolVerifier, Optional::No }, - { "Double", new DoubleVerifier, Optional::No }, - { "Int", new IntVerifier, Optional::No }, - { "String", new StringVerifier, Optional::No }, - { "Table", new TableVerifier, Optional::No } - } - }; - - ghoul::Dictionary positive { - { "Bool", true }, - { "Double", 0.0 }, - { "Int", 0 }, - { "String", ""s }, - { "Table", ghoul::Dictionary{} } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative1 { - { "Bool", true }, - { "Double", 1 }, - { "Int", 0 }, - { "String", ""s }, - { "Table", ghoul::Dictionary{} } - }; - TestResult negativeRes = testSpecification(doc, negative1); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Double", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - - ghoul::Dictionary negative2 { - { "Bool", true }, - { "Double", 0.0 }, - { "Int", ""s }, - { "String", 1 }, - { "Table", ghoul::Dictionary{} } - }; - negativeRes = testSpecification(doc, negative2); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(2, negativeRes.offenses.size()); - EXPECT_EQ("Int", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - EXPECT_EQ("String", negativeRes.offenses[1].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[1].reason); -} - -TEST_F(DocumentationTest, NestedTables) { - using namespace openspace::documentation; - using namespace std::string_literals; - - Documentation doc { - { - { "Outer_Int", new IntVerifier, Optional::No }, - { "Outer_Table", new TableVerifier({ - { "Inner_Double", new DoubleVerifier, Optional::No }, - { "Inner_String", new StringVerifier, Optional::No } - }), Optional::No }, - { "Outer_Double", new DoubleVerifier, Optional::No }, - { "Outer_Table2" , new TableVerifier({ - { "Inner_Double2", new DoubleVerifier, Optional::No }, - { "Inner_String2", new StringVerifier, Optional::No }, - { "Inner_Table" , new TableVerifier({ - { "Inner_Inner_Int", new IntVerifier, Optional::No } - }), Optional::No } - }), Optional::No} - } - }; - - ghoul::Dictionary positive { - { "Outer_Int", 1 }, - { "Outer_Table", ghoul::Dictionary { - { "Inner_Double", 0.0 }, - { "Inner_String", ""s } - }}, - { "Outer_Double", 0.0 }, - { "Outer_Table2", ghoul::Dictionary { - { "Inner_Double2", 0.0 }, - { "Inner_String2", ""s }, - { "Inner_Table", ghoul::Dictionary { - { "Inner_Inner_Int", 0 } - }} - }} - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negativeSimple { - { "Outer_Int", 1 }, - { "Outer_Table", 0}, - { "Outer_Double", 0.0 }, - { "Outer_Table2", ghoul::Dictionary { - { "Inner_Double2", 0.0 }, - { "Inner_String2", ""s }, - { "Inner_Table", ghoul::Dictionary { - { "Inner_Inner_Int", 0 } - }} - }} - }; - TestResult negativeRes = testSpecification(doc, negativeSimple); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Outer_Table", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - - ghoul::Dictionary negativeInner { - { "Outer_Int", 1 }, - { "Outer_Table", ghoul::Dictionary { - { "Inner_Double", ""s }, - { "Inner_String", ""s } - }}, - { "Outer_Double", 0.0 }, - { "Outer_Table2", ghoul::Dictionary { - { "Inner_Double2", 0.0 }, - { "Inner_String2", ""s }, - { "Inner_Table", ghoul::Dictionary { - { "Inner_Inner_Int", 0 } - }} - }} - }; - negativeRes = testSpecification(doc, negativeInner); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Outer_Table.Inner_Double", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - - ghoul::Dictionary negativeInner2 { - { "Outer_Int", 1 }, - { "Outer_Table", ghoul::Dictionary { - { "Inner_Double", ""s }, - { "Inner_String", 0.0 } - }}, - { "Outer_Double", 0.0 }, - { "Outer_Table2", ghoul::Dictionary { - { "Inner_Double2", 0.0 }, - { "Inner_String2", ""s }, - { "Inner_Table", ghoul::Dictionary { - { "Inner_Inner_Int", 0 } - }} - }} - }; - negativeRes = testSpecification(doc, negativeInner2); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(2, negativeRes.offenses.size()); - EXPECT_EQ("Outer_Table.Inner_Double", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - EXPECT_EQ("Outer_Table.Inner_String", negativeRes.offenses[1].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[1].reason); - - ghoul::Dictionary negativeInnerSeparate { - { "Outer_Int", 1 }, - { "Outer_Table", ghoul::Dictionary { - { "Inner_Double", ""s }, - { "Inner_String", ""s } - } }, - { "Outer_Double", 0.0 }, - { "Outer_Table2", ghoul::Dictionary { - { "Inner_Double2", ""s }, - { "Inner_String2", ""s }, - { "Inner_Table", ghoul::Dictionary { - { "Inner_Inner_Int", 0 } - }} - }} - }; - negativeRes = testSpecification(doc, negativeInnerSeparate); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(2, negativeRes.offenses.size()); - EXPECT_EQ("Outer_Table.Inner_Double", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - EXPECT_EQ("Outer_Table2.Inner_Double2", negativeRes.offenses[1].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[1].reason); - - ghoul::Dictionary negativeInnerFull { - { "Outer_Int", 1 }, - { "Outer_Table", ghoul::Dictionary { - { "Inner_Double", ""s }, - { "Inner_String", ""s } - } }, - { "Outer_Double", 0.0 }, - { "Outer_Table2", ghoul::Dictionary { - { "Inner_Double2", ""s }, - { "Inner_String2", ""s }, - { "Inner_Table", ghoul::Dictionary { - { "Inner_Inner_Int", ""s } - }} - }} - }; - negativeRes = testSpecification(doc, negativeInnerFull); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(3, negativeRes.offenses.size()); - EXPECT_EQ("Outer_Table.Inner_Double", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - EXPECT_EQ("Outer_Table2.Inner_Double2", negativeRes.offenses[1].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[1].reason); - EXPECT_EQ("Outer_Table2.Inner_Table.Inner_Inner_Int", negativeRes.offenses[2].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[2].reason); -} - -TEST_F(DocumentationTest, Optional) { - using namespace openspace::documentation; - - Documentation doc { - { - { "Bool_Force", new BoolVerifier, Optional::No }, - { "Bool_Optional", new BoolVerifier, Optional::Yes } - } - }; - - ghoul::Dictionary positive { - { "Bool_Force", true }, - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary positive2 { - { "Bool_Force", true }, - { "Bool_Optional", true } - }; - positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Bool_Force", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::MissingKey, negativeRes.offenses[0].reason); - - ghoul::Dictionary negative2 { - { "Bool_Optional", true } - }; - negativeRes = testSpecification(doc, negative2); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Bool_Force", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::MissingKey, negativeRes.offenses[0].reason); - - ghoul::Dictionary negative3 { - { "Bool_Force", true }, - { "Bool_Optional", 1 } - }; - negativeRes = testSpecification(doc, negative3); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Bool_Optional", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, RequiredInOptional) { - using namespace openspace::documentation; - - Documentation doc { - {{ - "a", - new TableVerifier({ - { - "b", - new IntVerifier, - Optional::No - }, - { - "c", - new IntVerifier, - Optional::Yes - } - }), - Optional::Yes - }} - }; - - ghoul::Dictionary positive { - { - "a", ghoul::Dictionary{ - { "b", 1 } - } - } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary positive2 { - { - "a", ghoul::Dictionary{ - { "b", 1 }, - { "c", 2 } - } - } - }; - positiveRes = testSpecification(doc, positive2); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary positive3 {}; - positiveRes = testSpecification(doc, positive3); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "a", ghoul::Dictionary{ { "c", 2 }}} - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a.b", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::MissingKey, negativeRes.offenses[0].reason); -} - -// Exhaustive documentations went away, but we are keeping this test just for funsies -TEST_F(DocumentationTest, Exhaustive) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Int", new IntVerifier, Optional::No }} - }; - - ghoul::Dictionary positive { - { "Int" , 1 } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "False_Int", 1 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Int", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::MissingKey, negativeRes.offenses[0].reason); - - ghoul::Dictionary negative2 { - { "Double", 2.0 } - }; - negativeRes = testSpecification(doc, negative2); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Int", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::MissingKey, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, NestedExhaustive) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Table", new TableVerifier( - { { "a", new IntVerifier, Optional::No } } - ), Optional::No - }} - }; - - ghoul::Dictionary positive { - { "Table", ghoul::Dictionary{{ "a", 1 }}} - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Table", ghoul::Dictionary{{ "b", 2.0 }}} - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Table.a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::MissingKey, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, EmptyEntriesNonExhaustive) { - using namespace openspace::documentation; - - Documentation doc; - - ghoul::Dictionary positive {}; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary positive2 { - { "a", 1 } - }; - positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); -} - -TEST_F(DocumentationTest, EmptyNestedExhaustive) { - using namespace openspace::documentation; - - Documentation doc { - {{ - "Table", - new TableVerifier(), - Optional::No, - }} - }; - - ghoul::Dictionary positive { - { "Table", ghoul::Dictionary() } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Table", ghoul::Dictionary{ { "a", 1 }}} - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_TRUE(negativeRes.success); - ASSERT_EQ(0, negativeRes.offenses.size()); -} - -TEST_F(DocumentationTest, LessInt) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Int", new IntLessVerifier(5), Optional::No }} - }; - - ghoul::Dictionary positive { - { "Int", 0 } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Int", 10 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Int", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, LessDouble) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Double", new DoubleLessVerifier(5.0), Optional::No }} - }; - - ghoul::Dictionary positive { - { "Double", 0.0 } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Double", 10.0 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Double", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, LessEqualInt) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Int", new IntLessEqualVerifier(5), Optional::No }} - }; - - ghoul::Dictionary positive { - { "Int", 0 } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary positiveEqual { - { "Int", 5 } - }; - positiveRes = testSpecification(doc, positiveEqual); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Int", 10 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Int", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, LessEqualDouble) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Double", new DoubleLessEqualVerifier(5.0), Optional::No }} - }; - - ghoul::Dictionary positive { - { "Double", 0.0 } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary positiveEqual { - { "Double", 5.0 } - }; - positiveRes = testSpecification(doc, positiveEqual); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Double", 10.0 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Double", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, GreaterInt) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Int", new IntGreaterVerifier(5), Optional::No }} - }; - - ghoul::Dictionary positive { - { "Int", 10 } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Int", 0 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Int", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, GreaterDouble) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Double", new DoubleGreaterVerifier(5.0), Optional::No }} - }; - - ghoul::Dictionary positive { - { "Double", 10.0 } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Double", 0.0 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Double", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, GreaterEqualInt) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Int", new IntGreaterEqualVerifier(5), Optional::No }} - }; - - ghoul::Dictionary positive { - { "Int", 10 } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary positiveEqual { - { "Int", 5 } - }; - positiveRes = testSpecification(doc, positiveEqual); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Int", 0 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Int", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, GreaterEqualDouble) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Double", new DoubleGreaterEqualVerifier(5.0), Optional::No }} - }; - - ghoul::Dictionary positive { - { "Double", 10.0 } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary positiveEqual { - { "Double", 5.0 } - }; - positiveRes = testSpecification(doc, positiveEqual); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Double", 0.0 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Double", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, EqualBool) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Bool", new BoolEqualVerifier(true), Optional::No }} - }; - - ghoul::Dictionary positive { - { "Bool", true} - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Bool", false } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Bool", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, EqualInt) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Int", new IntEqualVerifier(1), Optional::No }} - }; - - ghoul::Dictionary positive { - { "Int", 1} - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Int", 0 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Int", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, EqualDouble) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Double", new DoubleEqualVerifier(1.0), Optional::No }} - }; - - ghoul::Dictionary positive { - { "Double", 1.0 } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Double", 0.0 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Double", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, EqualString) { - using namespace openspace::documentation; - using namespace std::string_literals; - - Documentation doc { - {{ "String", new StringEqualVerifier("string"s), Optional::No }} - }; - - ghoul::Dictionary positive { - { "String", "string"s } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "String", "no_string"s } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("String", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, UnequalBool) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Bool", new BoolUnequalVerifier(true), Optional::No }} - }; - - ghoul::Dictionary positive { - { "Bool", false } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Bool", true } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Bool", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, UnequalInt) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Int", new IntUnequalVerifier(1), Optional::No }} - }; - - ghoul::Dictionary positive { - { "Int", 0 } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Int", 1 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Int", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, UnequalDouble) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Double", new DoubleUnequalVerifier(1.0), Optional::No }} - }; - - ghoul::Dictionary positive { - { "Double", 0.0 } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Double", 1.0 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Double", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, UnequalString) { - using namespace openspace::documentation; - using namespace std::string_literals; - - Documentation doc { - {{ "String", new StringUnequalVerifier("string"s), Optional::No }} - }; - - ghoul::Dictionary positive { - { "String", "no_string"s } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "String", "string"s } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("String", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, ListBool) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Bool" , new BoolInListVerifier({ true }), Optional::No }} - }; - - ghoul::Dictionary positive { - { "Bool", true } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Bool", false } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Bool", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, ListInt) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Int" , new IntInListVerifier({ 0, 1, 2 }), Optional::No }} - }; - - ghoul::Dictionary positive { - { "Int", 1 } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary positive2 { - { "Int", 2 } - }; - positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Int", 5 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Int", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, ListDouble) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Double" , new DoubleInListVerifier({ 0.0, 1.0, 2.0 }), Optional::No }} - }; - - ghoul::Dictionary positive { - { "Double", 1.0 } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary positive2 { - { "Double", 2.0 } - }; - positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Double", 5.0 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Double", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, ListString) { - using namespace openspace::documentation; - using namespace std::string_literals; - - Documentation doc { - {{ "String" , new StringInListVerifier({ "0"s, "1"s, "2"s }), Optional::No }} - }; - - ghoul::Dictionary positive { - { "String", "1"s } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary positive2 { - { "String", "2"s } - }; - positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "String", "5"s } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("String", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, NotListBool) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Bool" , new BoolNotInListVerifier({ true }), Optional::No }} - }; - - ghoul::Dictionary positive { - { "Bool", false } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Bool", true } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Bool", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, NotListInt) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Int" , new IntNotInListVerifier({ 0, 1, 2 }), Optional::No }} - }; - - ghoul::Dictionary positive { - { "Int", -1 } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary positive2 { - { "Int", 3 } - }; - positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Int", 2 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Int", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, NotListDouble) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Double" , new DoubleNotInListVerifier({ 0.0, 1.0, 2.0 }), Optional::No }} - }; - - ghoul::Dictionary positive { - { "Double", -1.0 } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary positive2 { - { "Double", 3.0 } - }; - positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Double", 1.0 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Double", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, NotListString) { - using namespace openspace::documentation; - using namespace std::string_literals; - - Documentation doc { - {{ "String" , new StringNotInListVerifier({ "0"s, "1"s, "2"s }), Optional::No }} - }; - - ghoul::Dictionary positive { - { "String", "string"s } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary positive2 { - { "String", "foo_string"s } - }; - positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "String", "1"s } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("String", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, AnnotationBool) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Bool", new BoolAnnotationVerifier("Bool"), Optional::No }} - }; - - ghoul::Dictionary positive { - { "Bool", true } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Bool", 0 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Bool", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, AnnotationInt) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Int", new IntAnnotationVerifier("Int"), Optional::No }} - }; - - ghoul::Dictionary positive { - { "Int", 1 } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Int", 1.1 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Int", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, AnnotationDouble) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Double", new DoubleAnnotationVerifier("Double"), Optional::No }} - }; - - ghoul::Dictionary positive { - { "Double", 0.0 } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Double", true } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Double", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, AnnotationString) { - using namespace openspace::documentation; - using namespace std::string_literals; - - Documentation doc { - {{ "String", new StringAnnotationVerifier("String"), Optional::No }} - }; - - ghoul::Dictionary positive { - { "String", ""s } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "String", 1 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("String", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, AnnotationTable) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Table", new TableAnnotationVerifier("Table"), Optional::No }} - }; - - ghoul::Dictionary positive { - { "Table", ghoul::Dictionary{} } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Table", 1 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Table", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, InRangeInt) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Int", new InRangeVerifier(0, 5), Optional::No }} - }; - - ghoul::Dictionary positive { - { "Int", 2 } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary positive2 { - { "Int", 0 } - }; - positiveRes = testSpecification(doc, positive2); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary positive3 { - { "Int", 5 } - }; - positiveRes = testSpecification(doc, positive3); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Int", 10 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Int", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, InRangeDouble) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Double", new InRangeVerifier(0.0, 5.0), Optional::No }} - }; - - ghoul::Dictionary positive { - { "Double", 2.0 } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary positive2 { - { "Double", 0.0 } - }; - positiveRes = testSpecification(doc, positive2); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary positive3 { - { "Double", 5.0 } - }; - positiveRes = testSpecification(doc, positive3); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary positive4 { - { "Double", 1.5 } - }; - positiveRes = testSpecification(doc, positive4); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Double", 10.0 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Double", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, NotInRangeInt) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Int", new NotInRangeVerifier(0, 5), Optional::No }} - }; - - ghoul::Dictionary positive { - { "Int", -1 } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary positive2 { - { "Int", 6 } - }; - positiveRes = testSpecification(doc, positive2); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Int", 2 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Int", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); - - ghoul::Dictionary negative2 { - { "Int", 0 } - }; - negativeRes = testSpecification(doc, negative2); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Int", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); - - ghoul::Dictionary negative3 { - { "Int", 5 } - }; - negativeRes = testSpecification(doc, negative3); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Int", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, NotInRangeDouble) { - using namespace openspace::documentation; - - Documentation doc { - {{ "Double", new NotInRangeVerifier(0.0, 5.0), Optional::No }} - }; - - ghoul::Dictionary positive { - { "Double", -1.0 } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary positive2 { - { "Double", 6.0 } - }; - positiveRes = testSpecification(doc, positive2); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Double", 0.0 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Double", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); - - ghoul::Dictionary negative2 { - { "Double", 5.0 } - }; - negativeRes = testSpecification(doc, negative2); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Double", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); - - ghoul::Dictionary negative3 { - { "Double", 2.5 } - }; - negativeRes = testSpecification(doc, negative3); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Double", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, Wildcard) { - using namespace openspace::documentation; - - Documentation doc { - {{ DocumentationEntry::Wildcard, new IntVerifier, Optional::No }} - }; - - ghoul::Dictionary positive { - { "a", 1 }, - { "b", 2 }, - { "c", 3 } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "a", false }, - { "b", 2 }, - { "c", 3 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - - ghoul::Dictionary negative2 { - { "a", false }, - { "b", false }, - { "c", 3 } - }; - negativeRes = testSpecification(doc, negative2); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(2, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - EXPECT_EQ("b", negativeRes.offenses[1].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[1].reason); - - ghoul::Dictionary negative3 { - { "a", false }, - { "b", false }, - { "c", false } - }; - negativeRes = testSpecification(doc, negative3); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(3, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - EXPECT_EQ("b", negativeRes.offenses[1].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[1].reason); - EXPECT_EQ("c", negativeRes.offenses[2].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[2].reason); -} - -TEST_F(DocumentationTest, WildcardMixed) { - using namespace openspace::documentation; - - Documentation doc { - { - { DocumentationEntry::Wildcard, new IntVerifier , Optional::No}, - { "b", new IntGreaterVerifier(5), Optional::No } - } - }; - - ghoul::Dictionary positive { - { "a", 1 }, - { "b", 8 }, - { "c", 3 } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "a", false }, - { "b", 2 }, - { "c", 3 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(2, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - EXPECT_EQ("b", negativeRes.offenses[1].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[1].reason); - - ghoul::Dictionary negative2 { - { "a", false }, - { "b", false }, - { "c", 3 } - }; - negativeRes = testSpecification(doc, negative2); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(2, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - EXPECT_EQ("b", negativeRes.offenses[1].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[1].reason); - - ghoul::Dictionary negative3 { - { "a", false }, - { "b", 1 }, - { "c", false } - }; - negativeRes = testSpecification(doc, negative3); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(3, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - EXPECT_EQ("b", negativeRes.offenses[1].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[1].reason); - EXPECT_EQ("c", negativeRes.offenses[2].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[2].reason); - - ghoul::Dictionary negative4 { - { "a", false }, - { "b", 10 }, - { "c", false } - }; - negativeRes = testSpecification(doc, negative4); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(2, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - EXPECT_EQ("c", negativeRes.offenses[1].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[1].reason); -} - -TEST_F(DocumentationTest, Referencing) { - using namespace openspace::documentation; - - Documentation referenced { - "Referenced Name", - "referenced_id", - { - { "a", new IntVerifier, Optional::No }, - { "b", new DoubleVerifier, Optional::No } - }, - }; - DocEng.addDocumentation(referenced); - - Documentation doc {{ - { "Table", new ReferencingVerifier("referenced_id"), Optional::No } - }}; - - ghoul::Dictionary positive { - { "Table", ghoul::Dictionary{ { "a", 1 }, { "b", 2.0 } }} - }; - - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "Table", 1 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Table", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - - ghoul::Dictionary negative2 { - { "Table", ghoul::Dictionary{ { "a", 1 }, { "b", true }}} - }; - negativeRes = testSpecification(doc, negative2); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Table.b", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - - - Documentation wrongDoc {{ - { "Table", new ReferencingVerifier("WRONG"), Optional::No } - } }; - ghoul::Dictionary wrongNegative { - { "Table", ghoul::Dictionary{ { "a", 1 },{ "b", 2.0 } } } - }; - negativeRes = testSpecification(wrongDoc, wrongNegative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("Table", negativeRes.offenses[0].offender); - EXPECT_EQ( - TestResult::Offense::Reason::UnknownIdentifier, - negativeRes.offenses[0].reason - ); -} - - -TEST_F(DocumentationTest, AndOperator) { - using namespace openspace::documentation; - - Documentation doc { - { - { - "a", - new AndVerifier({ - new IntGreaterEqualVerifier(2), new IntLessEqualVerifier(5) - }), - Optional::No - } - } - }; - - ghoul::Dictionary positive { - { "a", 4 } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "a", 0 } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); - - ghoul::Dictionary negative2 { - { "a", 8 } - }; - negativeRes = testSpecification(doc, negative2); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, OrOperator) { - using namespace openspace::documentation; - using namespace std::string_literals; - - Documentation doc { - {{ "a", new OrVerifier({ new StringVerifier, new IntVerifier }), Optional::No }} - }; - - ghoul::Dictionary positive { - { "a", ""s } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary positive2 { - { "a", 1 } - }; - positiveRes = testSpecification(doc, positive2); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "a", false } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::Verification, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, BoolVector2Verifier) { - using namespace openspace::documentation; - - Documentation doc { - {{ "a", new BoolVector2Verifier, Optional::No }} - }; - - ghoul::Dictionary positive { - { "a", glm::bvec2(true) } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "a", ghoul::Dictionary{ { "1", true }, { "2", 1.0 } } } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - - ghoul::Dictionary negative2 { - { "a", true } - }; - negativeRes = testSpecification(doc, negative2); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, IntVector2Verifier) { - using namespace openspace::documentation; - - Documentation doc { - { { "a", new IntVector2Verifier, Optional::No } } - }; - - ghoul::Dictionary positive { - { "a", glm::ivec2(2) } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "a", ghoul::Dictionary{ { "1", true },{ "2", 1 } } } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - - ghoul::Dictionary negative2 { - { "a", true } - }; - negativeRes = testSpecification(doc, negative2); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, DoubleVector2Verifier) { - using namespace openspace::documentation; - - Documentation doc { - { { "a", new DoubleVector2Verifier, Optional::No } } - }; - - ghoul::Dictionary positive { - { "a", glm::dvec2(2.0) } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "a", ghoul::Dictionary{ { "1", true }, { "2", 1.0 } } } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - - ghoul::Dictionary negative2 { - { "a", true } - }; - negativeRes = testSpecification(doc, negative2); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, BoolVector3Verifier) { - using namespace openspace::documentation; - - Documentation doc { - { { "a", new BoolVector3Verifier, Optional::No } } - }; - - ghoul::Dictionary positive { - { "a", glm::bvec3(true) } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "a", ghoul::Dictionary{ { "1", true },{ "2", 1.0 }, { "3", "s" } } } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - - ghoul::Dictionary negative2 { - { "a", true } - }; - negativeRes = testSpecification(doc, negative2); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, IntVector3Verifier) { - using namespace openspace::documentation; - - Documentation doc { - { { "a", new IntVector3Verifier, Optional::No } } - }; - - ghoul::Dictionary positive { - { "a", glm::ivec3(2) } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "a", ghoul::Dictionary{ { "1", true },{ "2", 1 }, { "3", "s" } } } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - - ghoul::Dictionary negative2 { - { "a", true } - }; - negativeRes = testSpecification(doc, negative2); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, DoubleVector3Verifier) { - using namespace openspace::documentation; - - Documentation doc { - { { "a", new DoubleVector3Verifier, Optional::No } } - }; - - ghoul::Dictionary positive { - { "a", glm::dvec3(2.0) } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "a", ghoul::Dictionary{ { "1", true },{ "2", 1.0 }, { "3", "s"} } } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - - ghoul::Dictionary negative2 { - { "a", true } - }; - negativeRes = testSpecification(doc, negative2); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, BoolVector4Verifier) { - using namespace openspace::documentation; - - Documentation doc { - { { "a", new BoolVector4Verifier, Optional::No } } - }; - - ghoul::Dictionary positive { - { "a", glm::bvec4(true) } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "a", ghoul::Dictionary{ { "1", true },{ "2", 1.0 }, { "3", "s" }, { "4", 1 }}} - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - - ghoul::Dictionary negative2 { - { "a", true } - }; - negativeRes = testSpecification(doc, negative2); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, IntVector4Verifier) { - using namespace openspace::documentation; - - Documentation doc { - { { "a", new IntVector4Verifier, Optional::No } } - }; - - ghoul::Dictionary positive { - { "a", glm::ivec4(2) } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "a", ghoul::Dictionary{ { "1", true },{ "2", 1 },{ "3", "s" }, { "4", 1 } } } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - - ghoul::Dictionary negative2{ - { "a", true } - }; - negativeRes = testSpecification(doc, negative2); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, DoubleVector4Verifier) { - using namespace openspace::documentation; - - Documentation doc { - { { "a", new DoubleVector4Verifier, Optional::No } } - }; - - ghoul::Dictionary positive { - { "a", glm::dvec4(2.0) } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "a", ghoul::Dictionary{ { "1", true },{ "2", 1.0 },{ "3", "s" }, { "4", 1 } } } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - - ghoul::Dictionary negative2 { - { "a", true } - }; - negativeRes = testSpecification(doc, negative2); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, DoubleMatrix2x2Verifier) { - using namespace openspace::documentation; - - Documentation doc { - { { "a", new DoubleMatrix2x2Verifier, Optional::No } } - }; - - ghoul::Dictionary positive { - { "a", glm::dmat2x2(1.0) } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "a", ghoul::Dictionary { { "1", true },{ "2", 1.0 },{ "3", "s" } } } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - - ghoul::Dictionary negative2 { - { "a", true } - }; - negativeRes = testSpecification(doc, negative2); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, DoubleMatrix2x3Verifier) { - using namespace openspace::documentation; - - Documentation doc { - { { "a", new DoubleMatrix2x3Verifier, Optional::No } } - }; - - ghoul::Dictionary positive { - { "a", glm::dmat2x3(1.0) } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "a", ghoul::Dictionary{ { "1", true },{ "2", 1.0 },{ "3", "s" } } } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - - ghoul::Dictionary negative2 { - { "a", true } - }; - negativeRes = testSpecification(doc, negative2); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, DoubleMatrix2x4Verifier) { - using namespace openspace::documentation; - - Documentation doc { - { { "a", new DoubleMatrix2x4Verifier, Optional::No } } - }; - - ghoul::Dictionary positive { - { "a", glm::dmat2x4(1.0) } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "a", ghoul::Dictionary{ { "1", true },{ "2", 1.0 },{ "3", "s" } } } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - - ghoul::Dictionary negative2 { - { "a", true } - }; - negativeRes = testSpecification(doc, negative2); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, DoubleMatrix3x2Verifier) { - using namespace openspace::documentation; - - Documentation doc { - { { "a", new DoubleMatrix3x2Verifier, Optional::No } } - }; - - ghoul::Dictionary positive { - { "a", glm::dmat3x2(1.0) } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "a", ghoul::Dictionary{ { "1", true },{ "2", 1.0 },{ "3", "s" } } } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - - ghoul::Dictionary negative2 { - { "a", true } - }; - negativeRes = testSpecification(doc, negative2); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, DoubleMatrix3x3Verifier) { - using namespace openspace::documentation; - - Documentation doc { - { { "a", new DoubleMatrix3x3Verifier, Optional::No } } - }; - - ghoul::Dictionary positive { - { "a", glm::dmat3x3(1.0) } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "a", ghoul::Dictionary{ { "1", true },{ "2", 1.0 },{ "3", "s" } } } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - - ghoul::Dictionary negative2 { - { "a", true } - }; - negativeRes = testSpecification(doc, negative2); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, DoubleMatrix3x4Verifier) { - using namespace openspace::documentation; - - Documentation doc { - { { "a", new DoubleMatrix3x4Verifier, Optional::No } } - }; - - ghoul::Dictionary positive { - { "a", glm::dmat3x4(1.0) } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "a", ghoul::Dictionary{ { "1", true },{ "2", 1.0 },{ "3", "s" } } } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - - ghoul::Dictionary negative2 { - { "a", true } - }; - negativeRes = testSpecification(doc, negative2); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, DoubleMatrix4x2Verifier) { - using namespace openspace::documentation; - - Documentation doc { - { { "a", new DoubleMatrix4x2Verifier, Optional::No } } - }; - - ghoul::Dictionary positive { - { "a", glm::dmat4x2(1.0) } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "a", ghoul::Dictionary{ { "1", true },{ "2", 1.0 },{ "3", "s" } } } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - - ghoul::Dictionary negative2 { - { "a", true } - }; - negativeRes = testSpecification(doc, negative2); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, DoubleMatrix4x3Verifier) { - using namespace openspace::documentation; - - Documentation doc { - { { "a", new DoubleMatrix4x3Verifier, Optional::No } } - }; - - ghoul::Dictionary positive { - { "a", glm::dmat4x3(1.0) } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "a", ghoul::Dictionary{ { "1", true },{ "2", 1.0 },{ "3", "s" } } } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - - ghoul::Dictionary negative2 { - { "a", true } - }; - negativeRes = testSpecification(doc, negative2); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, DoubleMatrix4x4Verifier) { - using namespace openspace::documentation; - - Documentation doc { - { { "a", new DoubleMatrix4x4Verifier, Optional::No } } - }; - - ghoul::Dictionary positive { - { "a", glm::dmat4x4(1.0) } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - - ghoul::Dictionary negative { - { "a", ghoul::Dictionary{ { "1", true },{ "2", 1.0 },{ "3", "s" } } } - }; - TestResult negativeRes = testSpecification(doc, negative); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); - - ghoul::Dictionary negative2 { - { "a", true } - }; - negativeRes = testSpecification(doc, negative2); - EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(1, negativeRes.offenses.size()); - EXPECT_EQ("a", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::WrongType, negativeRes.offenses[0].reason); -} - -TEST_F(DocumentationTest, DeprecatedVerifier) { - using namespace openspace::documentation; - using namespace std::string_literals; - - Documentation doc { { - { "bool", new BoolDeprecatedVerifier, Optional::No }, - { "int" , new IntDeprecatedVerifier, Optional::No }, - { "double", new DoubleDeprecatedVerifier, Optional::No }, - { "string" , new StringDeprecatedVerifier, Optional::No }, - { "boolvec2", new DeprecatedVerifier, Optional::No }, - { "intvec2", new DeprecatedVerifier, Optional::No }, - { "doublevec2", new DeprecatedVerifier, Optional::No }, - { "boolvec3", new DeprecatedVerifier, Optional::No }, - { "intvec3", new DeprecatedVerifier, Optional::No }, - { "doublevec3", new DeprecatedVerifier, Optional::No }, - { "boolvec4", new DeprecatedVerifier, Optional::No }, - { "intvec4", new DeprecatedVerifier, Optional::No }, - { "doublevec4", new DeprecatedVerifier, Optional::No } - }}; - - ghoul::Dictionary positive { - { "bool", true }, - { "int", 1 }, - { "double", 2.0 }, - { "string" , ""s }, - { "boolvec2", glm::bvec2() }, - { "intvec2", glm::ivec2() }, - { "doublevec2", glm::dvec2() }, - { "boolvec3", glm::bvec3() }, - { "intvec3", glm::ivec3() }, - { "doublevec3", glm::dvec3() }, - { "boolvec4", glm::bvec4() }, - { "intvec4", glm::ivec4() }, - { "doublevec4", glm::dvec4() } - }; - TestResult positiveRes = testSpecification(doc, positive); - EXPECT_TRUE(positiveRes.success); - EXPECT_EQ(0, positiveRes.offenses.size()); - ASSERT_EQ(13, positiveRes.warnings.size()); - EXPECT_EQ("bool", positiveRes.warnings[0].offender); - EXPECT_EQ(TestResult::Warning::Reason::Deprecated, positiveRes.warnings[0].reason); - EXPECT_EQ("boolvec2", positiveRes.warnings[1].offender); - EXPECT_EQ(TestResult::Warning::Reason::Deprecated, positiveRes.warnings[1].reason); - EXPECT_EQ("boolvec3", positiveRes.warnings[2].offender); - EXPECT_EQ(TestResult::Warning::Reason::Deprecated, positiveRes.warnings[2].reason); - EXPECT_EQ("boolvec4", positiveRes.warnings[3].offender); - EXPECT_EQ(TestResult::Warning::Reason::Deprecated, positiveRes.warnings[3].reason); - EXPECT_EQ("double", positiveRes.warnings[4].offender); - EXPECT_EQ(TestResult::Warning::Reason::Deprecated, positiveRes.warnings[4].reason); - EXPECT_EQ("doublevec2", positiveRes.warnings[5].offender); - EXPECT_EQ(TestResult::Warning::Reason::Deprecated, positiveRes.warnings[5].reason); - EXPECT_EQ("doublevec3", positiveRes.warnings[6].offender); - EXPECT_EQ(TestResult::Warning::Reason::Deprecated, positiveRes.warnings[6].reason); - EXPECT_EQ("doublevec4", positiveRes.warnings[7].offender); - EXPECT_EQ(TestResult::Warning::Reason::Deprecated, positiveRes.warnings[7].reason); - EXPECT_EQ("int", positiveRes.warnings[8].offender); - EXPECT_EQ(TestResult::Warning::Reason::Deprecated, positiveRes.warnings[8].reason); - EXPECT_EQ("intvec2", positiveRes.warnings[9].offender); - EXPECT_EQ(TestResult::Warning::Reason::Deprecated, positiveRes.warnings[9].reason); - EXPECT_EQ("intvec3", positiveRes.warnings[10].offender); - EXPECT_EQ(TestResult::Warning::Reason::Deprecated, positiveRes.warnings[10].reason); - EXPECT_EQ("intvec4", positiveRes.warnings[11].offender); - EXPECT_EQ(TestResult::Warning::Reason::Deprecated, positiveRes.warnings[11].reason); - EXPECT_EQ("string", positiveRes.warnings[12].offender); - EXPECT_EQ(TestResult::Warning::Reason::Deprecated, positiveRes.warnings[12].reason); -} - -TEST_F(DocumentationTest, VerifierTypePostConditions) { - using namespace openspace::documentation; - using namespace std::string_literals; - - EXPECT_NE("", BoolVerifier().type()); - EXPECT_NE("", DoubleVerifier().type()); - EXPECT_NE("", IntVerifier().type()); - EXPECT_NE("", StringVerifier().type()); - EXPECT_NE("", TableVerifier().type()); - - EXPECT_NE("", BoolVector2Verifier().type()); - EXPECT_NE("", IntVector2Verifier().type()); - EXPECT_NE("", DoubleVector2Verifier().type()); - EXPECT_NE("", BoolVector3Verifier().type()); - EXPECT_NE("", IntVector3Verifier().type()); - EXPECT_NE("", DoubleVector3Verifier().type()); - EXPECT_NE("", BoolVector4Verifier().type()); - EXPECT_NE("", IntVector4Verifier().type()); - EXPECT_NE("", DoubleVector4Verifier().type()); - - EXPECT_NE("", IntLessVerifier(0).type()); - EXPECT_NE("", DoubleLessVerifier(0.0).type()); - EXPECT_NE("", IntLessEqualVerifier(0).type()); - EXPECT_NE("", DoubleLessEqualVerifier(0.0).type()); - EXPECT_NE("", IntGreaterVerifier(0).type()); - EXPECT_NE("", DoubleGreaterVerifier(0.0).type()); - EXPECT_NE("", IntGreaterEqualVerifier(0).type()); - EXPECT_NE("", DoubleGreaterEqualVerifier(0.0).type()); - - EXPECT_NE("", BoolEqualVerifier(true).type()); - EXPECT_NE("", IntEqualVerifier(0).type()); - EXPECT_NE("", DoubleEqualVerifier(0.0).type()); - EXPECT_NE("", StringEqualVerifier(""s).type()); - EXPECT_NE("", BoolUnequalVerifier(true).type()); - EXPECT_NE("", IntUnequalVerifier(0).type()); - EXPECT_NE("", DoubleUnequalVerifier(0.0).type()); - EXPECT_NE("", StringUnequalVerifier(""s).type()); - - EXPECT_NE("", BoolInListVerifier({ true }).type()); - EXPECT_NE("", IntInListVerifier({ 0 }).type()); - EXPECT_NE("", DoubleInListVerifier({ 0.0 }).type()); - EXPECT_NE("", StringInListVerifier({ ""s }).type()); - EXPECT_NE("", BoolNotInListVerifier({ true }).type()); - EXPECT_NE("", IntNotInListVerifier({ 0 }).type()); - EXPECT_NE("", DoubleNotInListVerifier({ 0.0 }).type()); - EXPECT_NE("", StringNotInListVerifier({ ""s }).type()); - - EXPECT_NE("", IntInRangeVerifier({ 0, 1 }).type()); - EXPECT_NE("", DoubleInRangeVerifier({ 0.0, 1.0 }).type()); - EXPECT_NE("", IntNotInRangeVerifier({ 0, 1 }).type()); - EXPECT_NE("", DoubleNotInRangeVerifier({ 0.0, 1.0 }).type()); - - EXPECT_NE("", BoolAnnotationVerifier("A"s).type()); - EXPECT_NE("", IntAnnotationVerifier("A"s).type()); - EXPECT_NE("", DoubleAnnotationVerifier("A"s).type()); - EXPECT_NE("", StringAnnotationVerifier("A"s).type()); - EXPECT_NE("", TableAnnotationVerifier("A"s).type()); - EXPECT_NE("", AnnotationVerifier("A"s).type()); - EXPECT_NE("", AnnotationVerifier("A"s).type()); - EXPECT_NE("", AnnotationVerifier("A"s).type()); - EXPECT_NE("", AnnotationVerifier("A"s).type()); - EXPECT_NE("", AnnotationVerifier("A"s).type()); - EXPECT_NE("", AnnotationVerifier("A"s).type()); - EXPECT_NE("", AnnotationVerifier("A"s).type()); - EXPECT_NE("", AnnotationVerifier("A"s).type()); - EXPECT_NE("", AnnotationVerifier("A"s).type()); - - EXPECT_NE("", BoolDeprecatedVerifier().type()); - EXPECT_NE("", IntDeprecatedVerifier().type()); - EXPECT_NE("", DoubleDeprecatedVerifier().type()); - EXPECT_NE("", StringDeprecatedVerifier().type()); - EXPECT_NE("", TableDeprecatedVerifier().type()); - EXPECT_NE("", DeprecatedVerifier().type()); - EXPECT_NE("", DeprecatedVerifier().type()); - EXPECT_NE("", DeprecatedVerifier().type()); - EXPECT_NE("", DeprecatedVerifier().type()); - EXPECT_NE("", DeprecatedVerifier().type()); - EXPECT_NE("", DeprecatedVerifier().type()); - EXPECT_NE("", DeprecatedVerifier().type()); - EXPECT_NE("", DeprecatedVerifier().type()); - EXPECT_NE("", DeprecatedVerifier().type()); - - EXPECT_NE("", ReferencingVerifier("identifier"s).type()); -} - -TEST_F(DocumentationTest, VerifierDocumentationPostConditions) { - using namespace openspace::documentation; - using namespace std::string_literals; - - EXPECT_NE("", BoolVerifier().documentation()); - EXPECT_NE("", DoubleVerifier().documentation()); - EXPECT_NE("", IntVerifier().documentation()); - EXPECT_NE("", StringVerifier().documentation()); - EXPECT_NE("", TableVerifier().documentation()); - - EXPECT_NE("", BoolVector2Verifier().documentation()); - EXPECT_NE("", IntVector2Verifier().documentation()); - EXPECT_NE("", DoubleVector2Verifier().documentation()); - EXPECT_NE("", BoolVector3Verifier().documentation()); - EXPECT_NE("", IntVector3Verifier().documentation()); - EXPECT_NE("", DoubleVector3Verifier().documentation()); - EXPECT_NE("", BoolVector4Verifier().documentation()); - EXPECT_NE("", IntVector4Verifier().documentation()); - EXPECT_NE("", DoubleVector4Verifier().documentation()); - - EXPECT_NE("", IntLessVerifier(0).documentation()); - EXPECT_NE("", DoubleLessVerifier(0.0).documentation()); - EXPECT_NE("", IntLessEqualVerifier(0).documentation()); - EXPECT_NE("", DoubleLessEqualVerifier(0.0).documentation()); - EXPECT_NE("", IntGreaterVerifier(0).documentation()); - EXPECT_NE("", DoubleGreaterVerifier(0.0).documentation()); - EXPECT_NE("", IntGreaterEqualVerifier(0).documentation()); - EXPECT_NE("", DoubleGreaterEqualVerifier(0.0).documentation()); - - EXPECT_NE("", BoolEqualVerifier(true).documentation()); - EXPECT_NE("", IntEqualVerifier(0).documentation()); - EXPECT_NE("", DoubleEqualVerifier(0.0).documentation()); - EXPECT_NE("", StringEqualVerifier(""s).documentation()); - EXPECT_NE("", BoolUnequalVerifier(true).documentation()); - EXPECT_NE("", IntUnequalVerifier(0).documentation()); - EXPECT_NE("", DoubleUnequalVerifier(0.0).documentation()); - EXPECT_NE("", StringUnequalVerifier(""s).documentation()); - - EXPECT_NE("", BoolInListVerifier({ true }).documentation()); - EXPECT_NE("", IntInListVerifier({ 0 }).documentation()); - EXPECT_NE("", DoubleInListVerifier({ 0.0 }).documentation()); - EXPECT_NE("", StringInListVerifier({ ""s }).documentation()); - EXPECT_NE("", BoolNotInListVerifier({ true }).documentation()); - EXPECT_NE("", IntNotInListVerifier({ 0 }).documentation()); - EXPECT_NE("", DoubleNotInListVerifier({ 0.0 }).documentation()); - EXPECT_NE("", StringNotInListVerifier({ ""s }).documentation()); - - EXPECT_NE("", IntInRangeVerifier({ 0, 1 }).documentation()); - EXPECT_NE("", DoubleInRangeVerifier({ 0.0, 1.0 }).documentation()); - EXPECT_NE("", IntNotInRangeVerifier({ 0, 1 }).documentation()); - EXPECT_NE("", DoubleNotInRangeVerifier({ 0.0, 1.0 }).documentation()); - - EXPECT_NE("", BoolAnnotationVerifier("A"s).documentation()); - EXPECT_NE("", IntAnnotationVerifier("A"s).documentation()); - EXPECT_NE("", DoubleAnnotationVerifier("A"s).documentation()); - EXPECT_NE("", StringAnnotationVerifier("A"s).documentation()); - EXPECT_NE("", TableAnnotationVerifier("A"s).documentation()); - EXPECT_NE("", AnnotationVerifier("A"s).documentation()); - EXPECT_NE("", AnnotationVerifier("A"s).documentation()); - EXPECT_NE("", AnnotationVerifier("A"s).documentation()); - EXPECT_NE("", AnnotationVerifier("A"s).documentation()); - EXPECT_NE("", AnnotationVerifier("A"s).documentation()); - EXPECT_NE("", AnnotationVerifier("A"s).documentation()); - EXPECT_NE("", AnnotationVerifier("A"s).documentation()); - EXPECT_NE("", AnnotationVerifier("A"s).documentation()); - EXPECT_NE("", AnnotationVerifier("A"s).documentation()); - - EXPECT_NE("", BoolDeprecatedVerifier().documentation()); - EXPECT_NE("", IntDeprecatedVerifier().documentation()); - EXPECT_NE("", DoubleDeprecatedVerifier().documentation()); - EXPECT_NE("", StringDeprecatedVerifier().documentation()); - EXPECT_NE("", TableDeprecatedVerifier().documentation()); - EXPECT_NE("", DeprecatedVerifier().documentation()); - EXPECT_NE("", DeprecatedVerifier().documentation()); - EXPECT_NE("", DeprecatedVerifier().documentation()); - EXPECT_NE("", DeprecatedVerifier().documentation()); - EXPECT_NE("", DeprecatedVerifier().documentation()); - EXPECT_NE("", DeprecatedVerifier().documentation()); - EXPECT_NE("", DeprecatedVerifier().documentation()); - EXPECT_NE("", DeprecatedVerifier().documentation()); - EXPECT_NE("", DeprecatedVerifier().documentation()); - - EXPECT_NE("", ReferencingVerifier("identifier"s).documentation()); - -} diff --git a/tests/test_gdalwms.inl b/tests/test_gdalwms.inl deleted file mode 100644 index 50b7dec7ec..0000000000 --- a/tests/test_gdalwms.inl +++ /dev/null @@ -1,58 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2019 * - * * - * 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 "gdal.h" -#include "gdal_priv.h" - -#include - - -#include "cpl_conv.h" -#include "cpl_string.h" - -// Error: cannot open source file "wms/wmsdriver.h" -//#include "wms/wmsdriver.h" - -// Error: cannot open source file "wms/wmsmetadataset.h" -//#include "wms/wmsmetadataset.h" - - -class GdalWmsTest : public testing::Test {}; - -TEST_F(GdalWmsTest, Simple) { - //GDALDatasetH poDataset; - //GDALAllRegister(); - - // - //std::string res = GDALVersionInfo("format"); - // - //std::cout << res << std::endl; - - //std::string testFile = absPath("${TESTDIR}/gdal/TERRA_CR_B143_2016-04-12.wms"); - - //poDataset = GDALOpen(testFile.c_str(), GA_ReadOnly); - - // This assertion fails - //ASSERT_NE(poDataset, nullptr) << "Failed to load testFile"; -} diff --git a/tests/test_temporaltileprovider.inl b/tests/test_iswamanager.cpp similarity index 77% rename from tests/test_temporaltileprovider.inl rename to tests/test_iswamanager.cpp index d58f2ce6a8..044cab3b7f 100644 --- a/tests/test_temporaltileprovider.inl +++ b/tests/test_iswamanager.cpp @@ -22,25 +22,21 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include +#ifdef OPENSPACE_MODULE_ISWA_ENABLED +#include "catch2/catch.hpp" + +#include +#include #include -#define _USE_MATH_DEFINES -#include -#include -#include +TEST_CASE("ISWAManager: Initialize", "[iswamanager]") { + openspace::IswaManager::deinitialize(); + REQUIRE_FALSE(openspace::IswaManager::isInitialized()); - -class TemporalTileProviderTest : public testing::Test {}; - -std::string fileName = "data/scene/debugglobe/map_service_configs/VIIRS_SNPP_CorrectedReflectance_TrueColor_temporal.xml"; - -TEST_F(TemporalTileProviderTest, Basic) { - double t = 2016.01; - openspace::Time::ref().setTime(t); - openspace::Time::ref().preSynchronization(); - openspace::Time::ref().postSynchronizationPreDraw(); - openspace::TemporalTileProvider provider(absPath(fileName)); + openspace::IswaManager::initialize(); + REQUIRE(openspace::IswaManager::isInitialized()); + REQUIRE(&openspace::IswaManager::ref() == &openspace::IswaManager::ref()); } +#endif // OPENSPACE_MODULE_ISWA_ENABLED diff --git a/tests/test_iswamanager.inl b/tests/test_iswamanager.inl deleted file mode 100644 index 8275b485d3..0000000000 --- a/tests/test_iswamanager.inl +++ /dev/null @@ -1,87 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2019 * - * * - * 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. * - ****************************************************************************************/ - -#ifdef OPENSPACE_MODULE_ISWA_ENABLED - -#define private public -#include -#define private private - -#include -#include - - -/* - * For each test the following is run: - * Constructor() -> setUp() -> test -> tearDown() -> Deconstructor() - */ - -namespace openspace { - -class IswaManagerTest : public testing::Test { -protected: - - IswaManagerTest() - : _downloadManager("", 0) - { - IswaManager::initialize(); - } - - ~IswaManagerTest() { - IswaManager::deinitialize(); - } - - void reset() {} - - DownloadManager _downloadManager; -}; - -TEST_F(IswaManagerTest, initialize){ - IswaManager::deinitialize(); - - ASSERT_FALSE(IswaManager::isInitialized()) << "IswaManager is initialized before initialize call"; - - IswaManager::initialize(); - - ASSERT_TRUE(IswaManager::isInitialized()) << "IswaManager is not initialized after initialize call"; - - ASSERT_NE(&IswaManager::ref(), nullptr) << "IswaManager ref() is not a nullptr"; - - EXPECT_EQ(&IswaManager::ref(), &IswaManager::ref()) << "IswaManager ref() returns the same object twice"; -} - -TEST_F(IswaManagerTest, iswaUrl){ - - //OsEng.loadSpiceKernels(); - //Time::ref().setTime(double(100000.0)); - //Time::ref().preSynchronization(); - //Time::ref().postSynchronizationPreDraw(); - //std::string url = ISWAManager::ref().iSWAurl(7); - //std::string expectedUrl = "http://iswa2.ccmc.gsfc.nasa.gov/IswaSystemWebApp/iSWACygnetStreamer?timestamp=2000-01-02%2015:45:35&window=-1&cygnetId=7"; - - //EXPECT_EQ(expectedUrl, url); -} - -}//namespace openspace -#endif diff --git a/tests/test_latlonpatch.cpp b/tests/test_latlonpatch.cpp new file mode 100644 index 0000000000..c061746fd5 --- /dev/null +++ b/tests/test_latlonpatch.cpp @@ -0,0 +1,142 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2019 * + * * + * 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 "catch2/catch.hpp" + +#include +#include +#include + +TEST_CASE("LatLonPatch: findCenterControlPoint", "[latlonpatch]") { + using namespace openspace::globebrowsing; + + GeodeticPatch patch(0, 0, glm::pi() / 4.f, glm::pi() / 4.f); +} + +TEST_CASE("LatLonPatch: Find Closest Corner", "[latlonpatch]") { + using namespace openspace::globebrowsing; + + constexpr float piOver4 = glm::pi() / 4.f; + Geodetic2 halfSize { piOver4, piOver4 }; + Geodetic2 center { 0, 0 }; + GeodeticPatch patch(center, halfSize); + + constexpr float piOver3 = glm::pi() / 3.f; + Geodetic2 point { piOver3, piOver3 }; + + Geodetic2 closestCorner = patch.closestCorner(point); + Geodetic2 northEastCorner = patch.corner(NORTH_EAST); + + REQUIRE(closestCorner.lat == northEastCorner.lat); + REQUIRE(closestCorner.lon == northEastCorner.lon); +} + +TEST_CASE("LatLonPatch: Find Closest Corner 2", "[latlonpatch]") { + using namespace openspace::globebrowsing; + + constexpr float piOver6 = glm::pi() / 4.f; + + Geodetic2 halfSize { 1.1 * piOver6, 1.1 * piOver6 }; + Geodetic2 center { piOver6, piOver6 }; + GeodeticPatch patch(center, halfSize); + + Geodetic2 point { 0, 0 }; + + Geodetic2 closestCorner = patch.closestCorner(point); + Geodetic2 expectedCorner = patch.corner(SOUTH_WEST); + + REQUIRE(closestCorner.lat == expectedCorner.lat); + REQUIRE(closestCorner.lon == expectedCorner.lon); +} + +TEST_CASE("LatLonPatch: Spherical Clamp 1", "[latlonpatch]") { + using namespace openspace::globebrowsing; + + GeodeticPatch patch(0, 0, glm::pi() / 4.f, glm::pi() / 4.f); + + // inside patch latitude-wise, east of patch longitude-wise + Geodetic2 point { glm::pi() / 6.0, glm::pi() / 4.0 - 0.01 }; + + + Geodetic2 clampedPoint = patch.closestPoint(point); + Geodetic2 neCorner = patch.corner(NORTH_EAST); + //REQUIRE(clampedPoint.lat == neCorner.lat); + //REQUIRE(clampedPoint.lon == neCorner.lon); +} + +TEST_CASE("LatLonPatch: Spherical Clamp 2", "[latlonpatch]") { + using namespace openspace::globebrowsing; + + GeodeticPatch patch(0, 0, glm::pi() / 4.f, glm::pi() / 4.f); + + // inside patch latitude-wise, west of patch longitude-wise + Geodetic2 point { glm::pi() / 6.0, glm::pi() / 4.0 + 0.01 }; + + Geodetic2 clampedPoint = patch.closestPoint(point); + Geodetic2 nwCorner = patch.corner(NORTH_WEST); + //REQUIRE(clampedPoint.lat == nwCorner.lat); + //REQUIRE(clampedPoint.lon == nwCorner.lon); +} + +TEST_CASE("LatLonPatch: Spherical Clamp 3", "[latlonpatch]") { + using namespace openspace::globebrowsing; + + GeodeticPatch patch(0, 0, glm::pi() / 4.f, glm::pi() / 4.f); + + // North east of patch + Geodetic2 point { glm::pi() / 3.0, glm::pi() / 4.0 - 0.01 }; + + Geodetic2 clampedPoint = patch.closestPoint(point); + Geodetic2 neCorner = patch.corner(NORTH_EAST); + //REQUIRE(clampedPoint.lat == neCorner.lat); + //REQUIRE(clampedPoint.lon == neCorner.lon); +} + +TEST_CASE("LatLonPatch: Spherical Clamp 4", "[latlonpatch]") { + using namespace openspace::globebrowsing; + + GeodeticPatch patch(0, 0, glm::pi() / 4.f, glm::pi() / 4.f); + + // South east of patch + Geodetic2 point { -glm::pi() / 3.0, glm::pi() / 4.0 - 0.01 }; + + Geodetic2 clampedPoint = patch.closestPoint(point); + Geodetic2 seCorner = patch.corner(SOUTH_EAST); + //REQUIRE(clampedPoint.lat == seCorner.lat); + //REQUIRE(clampedPoint.lon == seCorner.lon); +} + +TEST_CASE("LatLonPatch: Spherical Clamp 5", "[latlonpatch]") { + using namespace openspace::globebrowsing; + + GeodeticPatch patch(0, 0, glm::pi() / 4.f, glm::pi() / 4.f); + + // South west of patch + Geodetic2 point { -glm::pi() / 3.0, 3 * glm::pi() / 4.0 + 0.01 }; + + Geodetic2 clampedPoint = patch.closestPoint(point); + Geodetic2 swCorner = patch.corner(SOUTH_WEST); + //REQUIRE(clampedPoint.lat == swCorner.lat); + //REQUIRE(clampedPoint.lon == swCorner.lon); +} diff --git a/tests/test_latlonpatch.inl b/tests/test_latlonpatch.inl deleted file mode 100644 index 73156dafeb..0000000000 --- a/tests/test_latlonpatch.inl +++ /dev/null @@ -1,167 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2019 * - * * - * 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 - -#define _USE_MATH_DEFINES -#include -#include - -class LatLonPatchTest : public testing::Test {}; - -using namespace openspace; - -TEST_F(LatLonPatchTest, findCenterControlPoint) { - - GeodeticPatch patch(0, 0, M_PI / 4, M_PI / 4); - -} - - - -TEST_F(LatLonPatchTest, TestFindClosestCorner) { - - Scalar piOver4 = M_PI / 4; - Geodetic2 halfSize(piOver4, piOver4); - Geodetic2 center(0, 0); - GeodeticPatch patch(center, halfSize); - - Scalar piOver3 = M_PI / 3; - Geodetic2 point(piOver3, piOver3); - - Geodetic2 closestCorner = patch.closestCorner(point); - Geodetic2 northEastCorner = patch.northEastCorner(); - - ASSERT_EQ(closestCorner.lat, northEastCorner.lat); - ASSERT_EQ(closestCorner.lon, northEastCorner.lon); - -} - -TEST_F(LatLonPatchTest, TestFindClosestCorner2) { - - Scalar piOver6 = M_PI / 4; - Scalar piOver3 = M_PI / 3; - - Geodetic2 halfSize(1.1*piOver6, 1.1*piOver6); - Geodetic2 center(piOver6, piOver6); - GeodeticPatch patch(center, halfSize); - - Geodetic2 point(0, 0); - - Geodetic2 closestCorner = patch.closestCorner(point); - Geodetic2 expectedCorner = patch.southWestCorner(); - - ASSERT_EQ(closestCorner.lat, expectedCorner.lat); - ASSERT_EQ(closestCorner.lon, expectedCorner.lon); - -} - - -TEST_F(LatLonPatchTest, TestSphericalClamp1) { - GeodeticPatch patch(0, 0, M_PI / 4, M_PI / 4); - - // inside patch latitude-wise, east of patch longitude-wise - Geodetic2 point(M_PI / 6, M_PI - 0.01); - - - Geodetic2 clampedPoint = patch.closestPoint(point); - Geodetic2 neCorner = patch.northEastCorner(); - ASSERT_EQ(clampedPoint.lat, neCorner.lat); - ASSERT_EQ(clampedPoint.lon, neCorner.lon); -} - - -TEST_F(LatLonPatchTest, TestSphericalClamp2) { - GeodeticPatch patch(0, 0, M_PI / 4, M_PI / 4); - - // inside patch latitude-wise, west of patch longitude-wise - Geodetic2 point(M_PI / 6, M_PI + 0.01); - - Geodetic2 clampedPoint = patch.closestPoint(point); - Geodetic2 nwCorner = patch.northWestCorner(); - ASSERT_EQ(clampedPoint.lat, nwCorner.lat); - ASSERT_EQ(clampedPoint.lon, nwCorner.lon); -} - -TEST_F(LatLonPatchTest, TestSphericalClamp3) { - GeodeticPatch patch(0, 0, M_PI / 4, M_PI / 4); - - // North east of patch - Geodetic2 point(M_PI / 3, M_PI - 0.01); - - Geodetic2 clampedPoint = patch.closestPoint(point); - Geodetic2 neCorner = patch.northEastCorner(); - ASSERT_EQ(clampedPoint.lat, neCorner.lat); - ASSERT_EQ(clampedPoint.lon, neCorner.lon); -} - -TEST_F(LatLonPatchTest, TestSphericalClamp4) { - GeodeticPatch patch(0, 0, M_PI / 4, M_PI / 4); - - // South east of patch - Geodetic2 point(-M_PI / 3, M_PI - 0.01); - - Geodetic2 clampedPoint = patch.closestPoint(point); - Geodetic2 seCorner = patch.southEastCorner(); - ASSERT_EQ(clampedPoint.lat, seCorner.lat); - ASSERT_EQ(clampedPoint.lon, seCorner.lon); -} - - -TEST_F(LatLonPatchTest, TestSphericalClamp5) { - GeodeticPatch patch(0, 0, M_PI / 4, M_PI / 4); - - // South west of patch - Geodetic2 point(-M_PI / 3, 3*M_PI + 0.01); - - Geodetic2 clampedPoint = patch.closestPoint(point); - Geodetic2 swCorner = patch.southWestCorner(); - ASSERT_EQ(clampedPoint.lat, swCorner.lat); - ASSERT_EQ(clampedPoint.lon, swCorner.lon); -} - -int radAsDeg(double rads) { - return floorf(Angle::fromRadians(rads).asDegrees()); -} - -TEST_F(LatLonPatchTest, PrintingSphericalClamp) { - GeodeticPatch patch(0, 0, M_PI / 4, M_PI / 4); - - using Ang = Angle; - Ang delta = Ang::fromDegrees(30); - std::cout << "point lat, lon --> clamped lat, lon" << std::endl; - for (Ang lat = Ang::fromDegrees(90); lat > -Ang::QUARTER; lat -= delta) { - for (Ang lon = Ang::fromDegrees(180); lon > -Ang::HALF; lon -= delta) { - - Geodetic2 point(lat.asRadians(), lon.asRadians()); - Geodetic2 clamped = patch.closestPoint(point); - std::cout - << radAsDeg(point.lat) << ", " - << radAsDeg(point.lon) << " --> " - << radAsDeg(clamped.lat) << ", " - << radAsDeg(clamped.lon) << std::endl; - } - std::cout << std::endl; - } -} diff --git a/tests/test_lrucache.inl b/tests/test_lrucache.cpp similarity index 68% rename from tests/test_lrucache.inl rename to tests/test_lrucache.cpp index 457217234e..8029108ce9 100644 --- a/tests/test_lrucache.inl +++ b/tests/test_lrucache.cpp @@ -22,59 +22,60 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include +#include "catch2/catch.hpp" -#define _USE_MATH_DEFINES -#include +#include #include -class LRUCacheTest : public testing::Test {}; +namespace { + struct DefaultHasher { + unsigned long long operator()(int var) const { + return static_cast(var); + } + }; -struct DefaultHasher { - unsigned long long operator()(const int& var) const { - return static_cast(var); + struct MyKey { + int x, y; + }; + + bool operator==(const MyKey& a, const MyKey& b) { + return a.x == b.x && a.y == b.y; } -}; -TEST_F(LRUCacheTest, Get) { + std::ostream& operator<<(std::ostream& o, const MyKey& key) { + return o << key.x << ", " << key.y; + } + + // custom specialization + struct DefaultHasherMyKey { + unsigned long long operator()(const MyKey& s) const { + return s.x ^ (s.y << 1); + } + }; +} // namespace + +TEST_CASE("LRUCache: Get", "[lrucache]") { openspace::globebrowsing::cache::LRUCache lru(4); lru.put(1, "hej"); lru.put(12, "san"); - ASSERT_STREQ(lru.get(1).c_str(), "hej") << "testing get"; + REQUIRE(lru.get(1) == "hej"); } -TEST_F(LRUCacheTest, CleaningCache) { +TEST_CASE("LRUCache: CleaningCache", "[lrucache]") { openspace::globebrowsing::cache::LRUCache lru(4); lru.put(1, 1.2); lru.put(12, 2.3); lru.put(123, 33.4); lru.put(1234, 4.5); lru.put(12345, 6.7); - ASSERT_FALSE(lru.exist(1)) << "Element should have been cleaned out of cache"; - ASSERT_TRUE(lru.exist(12)) << "Element should remain in cache"; + REQUIRE_FALSE(lru.exist(1)); + REQUIRE(lru.exist(12)); } -struct MyKey { - int x, y; -}; - -bool operator==(const MyKey& a, const MyKey& b) { - return a.x == b.x && a.y == b.y; -} - -std::ostream& operator<<(std::ostream& o, const MyKey& key) { - return o << key.x << ", " << key.y; -} - -// custom specialization -struct DefaultHasherMyKey { - unsigned long long operator()(const MyKey& s) const { - return s.x ^ (s.y << 1); - } -}; - -TEST_F(LRUCacheTest, StructKey) { - openspace::globebrowsing::cache::LRUCache lru(4); +TEST_CASE("LRUCache: StructKey", "[lrucache]") { + openspace::globebrowsing::cache::LRUCache< + MyKey, std::string, DefaultHasherMyKey + > lru(4); // These two custom keys should be treated as equal MyKey key1 = { 2, 3 }; @@ -85,13 +86,13 @@ TEST_F(LRUCacheTest, StructKey) { lru.put(key1, val1); - ASSERT_TRUE(lru.exist(key1)); - ASSERT_EQ(lru.get(key1), val1); + REQUIRE(lru.exist(key1)); + REQUIRE(lru.get(key1) == val1); // Putting key2 should replace key1 lru.put(key2, val2); - ASSERT_EQ(key1, key2) << "key 1 and key2 should be considered equal"; - ASSERT_TRUE(lru.exist(key2)); - ASSERT_EQ(lru.get(key1), val2); - ASSERT_EQ(lru.get(key2), val2); + REQUIRE(key1 == key2); + REQUIRE(lru.exist(key2)); + REQUIRE(lru.get(key1) == val2); + REQUIRE(lru.get(key2) == val2); } diff --git a/tests/test_luaconversions.cpp b/tests/test_luaconversions.cpp new file mode 100644 index 0000000000..c53dcacb4c --- /dev/null +++ b/tests/test_luaconversions.cpp @@ -0,0 +1,877 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2019 * + * * + * 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 "catch2/catch.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace { + constexpr const int NumberFuzzTests = 10000; +} // namespace + +TEST_CASE("LuaConversion: LuaExecution", "[luaconversion]") { + lua_State* state = luaL_newstate(); + luaL_openlibs(state); + + const int status = luaL_loadstring(state, ""); + REQUIRE(status == LUA_OK); + + lua_close(state); +} + +TEMPLATE_TEST_CASE("LuaConversion", "[luaconversion]", bool, char, signed char, + unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, + long long, unsigned long long, float, double, long double, glm::vec2, glm::vec3, + glm::vec4, glm::dvec2, glm::dvec3, glm::dvec4, glm::ivec2, glm::ivec3, glm::ivec4, + glm::uvec2, glm::uvec3, glm::uvec4, glm::mat2x2, glm::mat2x3, glm::mat2x4, + glm::mat3x2, glm::mat3x3, glm::mat3x4, glm::mat4x2, glm::mat4x3, glm::mat4x4, + glm::dmat2x2, glm::dmat2x3, glm::dmat2x4, glm::dmat3x2, glm::dmat3x3, glm::dmat3x4, + glm::dmat4x2, glm::dmat4x3, glm::dmat4x4) +{ + using T = TestType; + + lua_State* state = luaL_newstate(); + luaL_openlibs(state); + + const T val(1); + + using namespace openspace::properties; + const bool success = PropertyDelegate>::template toLuaValue( + state, + val + ); + REQUIRE(success); + bool success2; + const T value = PropertyDelegate>::template fromLuaValue( + state, + success2 + ); + REQUIRE(success2); + REQUIRE(value == val); + + lua_close(state); +} + +TEMPLATE_TEST_CASE("LuaConversion Fuzz dis( + std::numeric_limits::lowest(), + std::numeric_limits::max() + ); + + for (int i = 0; i < NumberFuzzTests; ++i) { + + const T val = T(dis(gen)); + + const bool success = PropertyDelegate>::template toLuaValue( + state, + val + ); + REQUIRE(success); + bool success2; + const T value = PropertyDelegate>::template fromLuaValue( + state, + success2 + ); + REQUIRE(success2); + REQUIRE(value == val); + + lua_pop(state, 1); + } + + lua_close(state); +} + +TEMPLATE_TEST_CASE("LuaConversion Fuzz >short", "[luaconversion]", short, unsigned short, + int, unsigned int) +{ + using T = TestType; + using namespace openspace::properties; + + lua_State* state = luaL_newstate(); + + std::mt19937 gen(1337); + std::uniform_int_distribution dis( + std::numeric_limits::lowest(), + std::numeric_limits::max() + ); + + for (int i = 0; i < NumberFuzzTests; ++i) { + + const T val = T(dis(gen)); + + const bool success = PropertyDelegate>::template toLuaValue( + state, + val + ); + REQUIRE(success); + bool success2; + const T value = PropertyDelegate>::template fromLuaValue( + state, + success2 + ); + REQUIRE(success2); + REQUIRE(value == val); + + lua_pop(state, 1); + } + + lua_close(state); +} + + +TEMPLATE_TEST_CASE("LuaConversion Fuzz Limited Signed", "[luaconversion]", long, + long long) +{ + using T = TestType; + lua_State* state = luaL_newstate(); + + using namespace openspace::properties; + + std::mt19937 gen(1337); + std::uniform_int_distribution<> dis( + // We need to limit the range of values as Lua uses 'doubles' to store, and some + // values will not be representable + std::numeric_limits::lowest(), + std::numeric_limits::max() + ); + + for (int i = 0; i < NumberFuzzTests; ++i) { + const T val = T(dis(gen)); + + const bool success = PropertyDelegate>::template toLuaValue( + state, + val + ); + REQUIRE(success); + bool success2; + const T value = PropertyDelegate>::template fromLuaValue( + state, + success2 + ); + REQUIRE(success2); + REQUIRE(value == val); + + lua_pop(state, 1); + } + + lua_close(state); +} + +TEMPLATE_TEST_CASE("LuaConversion Fuzz Limited Unsigned", "[luaconversion]", + unsigned long, unsigned long long) +{ + using T = TestType; + lua_State* state = luaL_newstate(); + + using namespace openspace::properties; + + std::mt19937 gen(1337); + std::uniform_int_distribution dis( + // We need to limit the range of values as Lua uses 'doubles' to store, and some + // values will not be representable + std::numeric_limits::lowest(), + std::numeric_limits::max() + ); + + for (int i = 0; i < NumberFuzzTests; ++i) { + const T val = T(dis(gen)); + + const bool success = PropertyDelegate>::template toLuaValue( + state, + val + ); + REQUIRE(success); + bool success2; + const T value = PropertyDelegate>::template fromLuaValue( + state, + success2 + ); + REQUIRE(success2); + REQUIRE(value == val); + + lua_pop(state, 1); + } + + lua_close(state); +} + +TEMPLATE_TEST_CASE("LuaConversion Float Fuzz", "[luaconversion]", float, double, + long double) +{ + lua_State* state = luaL_newstate(); + + using namespace openspace::properties; + using T = TestType; + + std::mt19937 gen(1337); + std::uniform_real_distribution dis( + 0.f, + std::numeric_limits::max() + ); + + for (int i = 0; i < NumberFuzzTests; ++i) { + const T val = T(dis(gen)); + + const bool success = PropertyDelegate>::template toLuaValue( + state, + val + ); + REQUIRE(success); + bool success2; + const T value = PropertyDelegate>::template fromLuaValue( + state, + success2 + ); + REQUIRE(success2); + REQUIRE(value == val); + + lua_pop(state, 1); + } + + lua_close(state); +} + +TEMPLATE_TEST_CASE("LuaConversion: Vec2 Float Fuzz", "[luaconversion]", glm::vec2, + glm::dvec2) +{ + lua_State* state = luaL_newstate(); + + using namespace openspace::properties; + using T = TestType; + + std::mt19937 gen(1337); + std::uniform_real_distribution dis( + std::numeric_limits::min(), + std::numeric_limits::max() + ); + + for (int i = 0; i < NumberFuzzTests; ++i) { + const T val = T(dis(gen), dis(gen)); + + const bool success = PropertyDelegate>::template toLuaValue( + state, + val + ); + REQUIRE(success); + bool success2; + const T value = PropertyDelegate>::template fromLuaValue( + state, + success2 + ); + REQUIRE(success2); + REQUIRE(value == val); + + lua_pop(state, 1); + } + + lua_close(state); +} +TEMPLATE_TEST_CASE("LuaConversion: Vec2 Fuzz", "[luaconversion]", glm::ivec2, glm::uvec2) +{ + lua_State* state = luaL_newstate(); + + using namespace openspace::properties; + using T = TestType; + + std::mt19937 gen(1337); + std::uniform_int_distribution dis( + std::numeric_limits::min(), + std::numeric_limits::max() + ); + + for (int i = 0; i < NumberFuzzTests; ++i) { + const T val = T(dis(gen), dis(gen)); + + const bool success = PropertyDelegate>::template toLuaValue( + state, + val + ); + REQUIRE(success); + bool success2; + const T value = PropertyDelegate>::template fromLuaValue( + state, + success2 + ); + REQUIRE(success2); + REQUIRE(value == val); + + lua_pop(state, 1); + } + + lua_close(state); +} + +TEMPLATE_TEST_CASE("LuaConversion: Vec3 Float Fuzz", "[luaconversion]", glm::vec3, + glm::dvec3) +{ + lua_State* state = luaL_newstate(); + + using namespace openspace::properties; + using T = TestType; + + std::mt19937 gen(1337); + std::uniform_real_distribution dis( + std::numeric_limits::min(), + std::numeric_limits::max() + ); + + for (int i = 0; i < NumberFuzzTests; ++i) { + const T val = T(dis(gen), dis(gen), dis(gen)); + + const bool success = PropertyDelegate>::template toLuaValue( + state, + val + ); + REQUIRE(success); + bool success2; + const T value = PropertyDelegate>::template fromLuaValue( + state, + success2 + ); + REQUIRE(success2); + REQUIRE(value == val); + + lua_pop(state, 1); + } + + lua_close(state); +} + +TEMPLATE_TEST_CASE("LuaConversion: Vec3 Fuzz", "[luaconversion]", glm::ivec3, glm::uvec3) +{ + lua_State* state = luaL_newstate(); + + using namespace openspace::properties; + using T = TestType; + + std::mt19937 gen(1337); + std::uniform_int_distribution dis( + std::numeric_limits::min(), + std::numeric_limits::max() + ); + + for (int i = 0; i < NumberFuzzTests; ++i) { + const T val = T(dis(gen), dis(gen), dis(gen)); + + const bool success = PropertyDelegate>::template toLuaValue( + state, + val + ); + REQUIRE(success); + bool success2; + const T value = PropertyDelegate>::template fromLuaValue( + state, + success2 + ); + REQUIRE(success2); + REQUIRE(value == val); + + lua_pop(state, 1); + } + + lua_close(state); +} + +TEMPLATE_TEST_CASE("LuaConversion: Vec4 Float Fuzz", "[luaconversion]", glm::vec4, + glm::dvec4) +{ + lua_State* state = luaL_newstate(); + + using namespace openspace::properties; + using T = TestType; + + std::mt19937 gen(1337); + std::uniform_real_distribution dis( + std::numeric_limits::min(), + std::numeric_limits::max() + ); + + for (int i = 0; i < NumberFuzzTests; ++i) { + const T val = T(dis(gen), dis(gen), dis(gen), dis(gen)); + + const bool success = PropertyDelegate>::template toLuaValue( + state, + val + ); + REQUIRE(success); + bool success2; + const T value = PropertyDelegate>::template fromLuaValue( + state, + success2 + ); + REQUIRE(success2); + REQUIRE(value == val); + + lua_pop(state, 1); + } + + lua_close(state); +} + +TEMPLATE_TEST_CASE("LuaConversion: Vec4 Fuzz", "[luaconversion]", glm::ivec4, glm::uvec4) +{ + lua_State* state = luaL_newstate(); + + using namespace openspace::properties; + using T = TestType; + + std::mt19937 gen(1337); + std::uniform_int_distribution dis( + std::numeric_limits::min(), + std::numeric_limits::max() + ); + + for (int i = 0; i < NumberFuzzTests; ++i) { + const T val = T(dis(gen), dis(gen), dis(gen), dis(gen)); + + const bool success = PropertyDelegate>::template toLuaValue( + state, + val + ); + REQUIRE(success); + bool success2; + const T value = PropertyDelegate>::template fromLuaValue( + state, + success2 + ); + REQUIRE(success2); + REQUIRE(value == val); + + lua_pop(state, 1); + } + + lua_close(state); +} + +TEMPLATE_TEST_CASE("LuaConversion: Mat2x2 Fuzz", "[luaconversion]", glm::mat2x2, + glm::dmat2x2) +{ + lua_State* state = luaL_newstate(); + + using namespace openspace::properties; + using T = TestType; + + std::mt19937 gen(1337); + std::uniform_real_distribution dis( + std::numeric_limits::min(), + std::numeric_limits::max() + ); + + for (int i = 0; i < NumberFuzzTests; ++i) { + const T val = T(dis(gen), dis(gen), dis(gen), dis(gen)); + + const bool success = PropertyDelegate>::template toLuaValue( + state, + val + ); + REQUIRE(success); + bool success2; + const T value = PropertyDelegate>::template fromLuaValue( + state, + success2 + ); + REQUIRE(success2); + REQUIRE(value == val); + + lua_pop(state, 1); + } + + lua_close(state); +} + +TEMPLATE_TEST_CASE("LuaConversion: Mat2x3 Fuzz", "[luaconversion]", glm::mat2x3, + glm::dmat2x3) +{ + lua_State* state = luaL_newstate(); + + using namespace openspace::properties; + using T = TestType; + + std::mt19937 gen(1337); + std::uniform_real_distribution dis( + std::numeric_limits::min(), + std::numeric_limits::max() + ); + + for (int i = 0; i < NumberFuzzTests; ++i) { + const T val = T(dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), dis(gen)); + + const bool success = PropertyDelegate>::template toLuaValue( + state, + val + ); + REQUIRE(success); + bool success2; + const T value = PropertyDelegate>::template fromLuaValue( + state, + success2 + ); + REQUIRE(success2); + REQUIRE(value == val); + + lua_pop(state, 1); + } + + lua_close(state); +} + +TEMPLATE_TEST_CASE("LuaConversion: Mat2x4 Fuzz", "[luaconversion]", glm::mat2x4, + glm::dmat2x4) +{ + lua_State* state = luaL_newstate(); + + using namespace openspace::properties; + using T = TestType; + + std::mt19937 gen(1337); + std::uniform_real_distribution dis( + std::numeric_limits::min(), + std::numeric_limits::max() + ); + + for (int i = 0; i < NumberFuzzTests; ++i) { + const T val = T(dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), + dis(gen)); + + const bool success = PropertyDelegate>::template toLuaValue( + state, + val + ); + REQUIRE(success); + bool success2; + const T value = PropertyDelegate>::template fromLuaValue( + state, + success2 + ); + REQUIRE(success2); + REQUIRE(value == val); + + lua_pop(state, 1); + } + + lua_close(state); +} + +TEMPLATE_TEST_CASE("LuaConversion: Mat3x2 Fuzz", "[luaconversion]", glm::mat3x2, + glm::dmat3x2) +{ + lua_State* state = luaL_newstate(); + + using namespace openspace::properties; + using T = TestType; + + std::mt19937 gen(1337); + std::uniform_real_distribution dis( + std::numeric_limits::min(), + std::numeric_limits::max() + ); + + for (int i = 0; i < NumberFuzzTests; ++i) { + const T val = T(dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), dis(gen)); + + const bool success = PropertyDelegate>::template toLuaValue( + state, + val + ); + REQUIRE(success); + bool success2; + const T value = PropertyDelegate>::template fromLuaValue( + state, + success2 + ); + REQUIRE(success2); + REQUIRE(value == val); + + lua_pop(state, 1); + } + + lua_close(state); +} + +TEMPLATE_TEST_CASE("LuaConversion: Mat3x3 Fuzz", "[luaconversion]", glm::mat3x3, + glm::dmat3x3) +{ + lua_State* state = luaL_newstate(); + + using namespace openspace::properties; + using T = TestType; + + std::mt19937 gen(1337); + std::uniform_real_distribution dis( + std::numeric_limits::min(), + std::numeric_limits::max() + ); + + for (int i = 0; i < NumberFuzzTests; ++i) { + const T val = T(dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), + dis(gen), dis(gen), dis(gen)); + + const bool success = PropertyDelegate>::template toLuaValue( + state, + val + ); + REQUIRE(success); + bool success2; + const T value = PropertyDelegate>::template fromLuaValue( + state, + success2 + ); + REQUIRE(success2); + REQUIRE(value == val); + + lua_pop(state, 1); + } + + lua_close(state); +} + +TEMPLATE_TEST_CASE("LuaConversion: Mat3x4 Fuzz", "[luaconversion]", glm::mat3x4, + glm::dmat3x4) +{ + lua_State* state = luaL_newstate(); + + using namespace openspace::properties; + using T = TestType; + + std::mt19937 gen(1337); + std::uniform_real_distribution dis( + std::numeric_limits::min(), + std::numeric_limits::max() + ); + + for (int i = 0; i < NumberFuzzTests; ++i) { + const T val = T(dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), + dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), dis(gen)); + + const bool success = PropertyDelegate>::template toLuaValue( + state, + val + ); + REQUIRE(success); + bool success2; + const T value = PropertyDelegate>::template fromLuaValue( + state, + success2 + ); + REQUIRE(success2); + REQUIRE(value == val); + + lua_pop(state, 1); + } + + lua_close(state); +} + +TEMPLATE_TEST_CASE("LuaConversion: Mat4x2 Fuzz", "[luaconversion]", glm::mat4x2, + glm::dmat4x2) +{ + lua_State* state = luaL_newstate(); + + using namespace openspace::properties; + using T = TestType; + + std::mt19937 gen(1337); + std::uniform_real_distribution dis( + std::numeric_limits::min(), + std::numeric_limits::max() + ); + + for (int i = 0; i < NumberFuzzTests; ++i) { + const T val = T(dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), + dis(gen), dis(gen)); + + const bool success = PropertyDelegate>::template toLuaValue( + state, + val + ); + REQUIRE(success); + bool success2; + const T value = PropertyDelegate>::template fromLuaValue( + state, + success2 + ); + REQUIRE(success2); + REQUIRE(value == val); + + lua_pop(state, 1); + } + + lua_close(state); +} + +TEMPLATE_TEST_CASE("LuaConversion: Mat4x3 Fuzz", "[luaconversion]", glm::mat4x3, + glm::dmat4x3) +{ + lua_State* state = luaL_newstate(); + + using namespace openspace::properties; + using T = TestType; + + std::mt19937 gen(1337); + std::uniform_real_distribution dis( + std::numeric_limits::min(), + std::numeric_limits::max() + ); + + for (int i = 0; i < NumberFuzzTests; ++i) { + const T val = T(dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), + dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), dis(gen)); + + const bool success = PropertyDelegate>::template toLuaValue( + state, + val + ); + REQUIRE(success); + bool success2; + const T value = PropertyDelegate>::template fromLuaValue( + state, + success2 + ); + REQUIRE(success2); + REQUIRE(value == val); + + lua_pop(state, 1); + } + + lua_close(state); +} + +TEMPLATE_TEST_CASE("LuaConversion: Mat4x4 Fuzz", "[luaconversion]", glm::mat4x4, + glm::dmat4x4) +{ + lua_State* state = luaL_newstate(); + + using namespace openspace::properties; + using T = TestType; + + std::mt19937 gen(1337); + std::uniform_real_distribution dis( + std::numeric_limits::min(), + std::numeric_limits::max() + ); + + for (int i = 0; i < NumberFuzzTests; ++i) { + const T val = T(dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), + dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), + dis(gen), dis(gen), dis(gen)); + + const bool success = PropertyDelegate>::template toLuaValue( + state, + val + ); + REQUIRE(success); + bool success2; + const T value = PropertyDelegate>::template fromLuaValue( + state, + success2 + ); + REQUIRE(success2); + REQUIRE(value == val); + + lua_pop(state, 1); + } + + lua_close(state); +} + + +TEST_CASE("LuaConversion: String", "[luaconversion]") { + lua_State* state = luaL_newstate(); + + using namespace openspace::properties; + bool success + = PropertyDelegate>::template toLuaValue( + state, "value"); + REQUIRE(success); + std::string value; + bool success2; + value = PropertyDelegate>::template fromLuaValue( + state, + success2 + ); + REQUIRE(success2); + REQUIRE(value == "value"); + + lua_close(state); +} diff --git a/tests/test_luaconversions.inl b/tests/test_luaconversions.inl deleted file mode 100644 index ca5fef1627..0000000000 --- a/tests/test_luaconversions.inl +++ /dev/null @@ -1,2216 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2019 * - * * - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -namespace { - constexpr int NumberFuzzTests = 100000; -} // namespace - -class LuaConversionTest : public testing::Test { -protected: - lua_State* state; - - LuaConversionTest() { - state = luaL_newstate(); - luaL_openlibs(state); - } - - ~LuaConversionTest() { - lua_close(state); - } - - void reset() { - lua_close(state); - state = luaL_newstate(); - luaL_openlibs(state); - } -}; - -TEST_F(LuaConversionTest, LuaExecution) { - int status = luaL_loadstring(state, ""); - EXPECT_EQ(status, LUA_OK); -} - -TEST_F(LuaConversionTest, Bool) { - using namespace openspace::properties; - bool success = PropertyDelegate>::toLuaValue( - state, - true - ); - EXPECT_TRUE(success) << "toLuaValue"; - bool value = static_cast(0); - value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, true) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, Char) { - using namespace openspace::properties; - using T = char; - T val = T(1); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, CharFuzz) { - using namespace openspace::properties; - using T = char; - - std::mt19937 gen(1337); - std::uniform_int_distribution<> dis( - std::numeric_limits::lowest(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen)); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -//TEST_F(LuaConversionTest, WChar) { -// using namespace openspace::properties; -// using T = wchar_t; -// -// T val = T(1); -// -// bool success = PropertyDelegate>::toLuaValue( -// state, -// val -// ); -// EXPECT_TRUE(success) << "toLuaValue"; -// T value = PropertyDelegate>::fromLuaValue( -// state, -// success -// ); -// EXPECT_TRUE(success) << "fromLuaValue"; -// EXPECT_EQ(value, val) << "fromLuaValue"; -//} - -//TEST_F(LuaConversionTest, WCharFuzz) { -// using namespace openspace::properties; -// using T = wchar_t; -// -// std::mt19937 gen(1337); -// std::uniform_int_distribution<> dis( -// std::numeric_limits::lowest(), -// std::numeric_limits::max() -// ); -// -// constexpr int NumberFuzzTests = 10000; -// for (int i = 0; i < NumberFuzzTests; ++i) { -// T val = T(dis(gen)); -// -// bool success = PropertyDelegate>::toLuaValue( -// state, -// val -// ); -// EXPECT_TRUE(success) << "toLuaValue"; -// T value = PropertyDelegate>::fromLuaValue( -// state, -// success -// ); -// EXPECT_TRUE(success) << "fromLuaValue"; -// EXPECT_EQ(value, val) << "fromLuaValue"; -// } -//} - -TEST_F(LuaConversionTest, SignedChar) { - using namespace openspace::properties; - using T = signed char; - T val = T(1); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, SignedCharFuzz) { - using namespace openspace::properties; - using T = signed char; - - std::mt19937 gen(1337); - std::uniform_int_distribution<> dis( - std::numeric_limits::lowest(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen)); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, UnsignedChar) { - using namespace openspace::properties; - using T = unsigned char; - T val = T(1); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, UnsignedCharFuzz) { - using namespace openspace::properties; - using T = unsigned char; - - std::mt19937 gen(1337); - std::uniform_int_distribution<> dis( - std::numeric_limits::lowest(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen)); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, Short) { - using namespace openspace::properties; - using T = short; - T val = T(1); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, ShortFuzz) { - using namespace openspace::properties; - using T = short; - - std::mt19937 gen(1337); - std::uniform_int_distribution dis( - std::numeric_limits::lowest(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen)); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, UnsignedShort) { - using namespace openspace::properties; - using T = unsigned short; - T val = T(1); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, UnsignedShortFuzz) { - using namespace openspace::properties; - using T = unsigned short; - - std::mt19937 gen(1337); - std::uniform_int_distribution dis( - std::numeric_limits::lowest(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen)); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, Int) { - using namespace openspace::properties; - using T = int; - T val = T(1); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, IntFuzz) { - using namespace openspace::properties; - using T = int; - - std::mt19937 gen(1337); - std::uniform_int_distribution dis( - std::numeric_limits::lowest(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen)); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, UnsignedInt) { - using namespace openspace::properties; - using T = unsigned int; - T val = T(1); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, UnsignedIntFuzz) { - using namespace openspace::properties; - using T = unsigned int; - - std::mt19937 gen(1337); - std::uniform_int_distribution dis( - std::numeric_limits::lowest(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen)); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, Long) { - using namespace openspace::properties; - using T = long; - T val = T(1); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, LongFuzz) { - using namespace openspace::properties; - using T = long; - - std::mt19937 gen(1337); - // We need to limit the range of values as Lua uses 'doubles' to store, and some - // values will not be representable - std::uniform_int_distribution dis( - std::numeric_limits::lowest(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen)); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, UnsignedLong) { - using namespace openspace::properties; - using T = unsigned long; - T val = T(1); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, UnsignedLongFuzz) { - using namespace openspace::properties; - using T = unsigned long; - - std::mt19937 gen(1337); - // We need to limit the range of values as Lua uses 'doubles' to store, and some - // values will not be representable - std::uniform_int_distribution dis( - std::numeric_limits::lowest(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen)); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, LongLong) { - using namespace openspace::properties; - using T = long long; - T val = T(1); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, LongLongFuzz) { - using namespace openspace::properties; - using T = long long; - - std::mt19937 gen(1337); - // We need to limit the range of values as Lua uses 'doubles' to store, and some - // values will not be representable - std::uniform_int_distribution dis( - std::numeric_limits::lowest(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen)); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, UnsignedLongLong) { - using namespace openspace::properties; - using T = unsigned long long; - T val = T(1); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, UnsignedLongLongFuzz) { - using namespace openspace::properties; - using T = unsigned long long; - - std::mt19937 gen(1337); - // We need to limit the range of values as Lua uses 'doubles' to store, and some - // values will not be representable - std::uniform_int_distribution dis( - std::numeric_limits::lowest(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen)); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, Float) { - using namespace openspace::properties; - using T = float; - T val = T(1.f); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, FloatFuzz) { - using namespace openspace::properties; - using T = float; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - 0.f, - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen)); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, Double) { - using namespace openspace::properties; - using T = double; - T val = T(1.0); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, DoubleFuzz) { - using namespace openspace::properties; - using T = double; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - 0.0, - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen)); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, LongDouble) { - using namespace openspace::properties; - using T = long double; - T val = T(1.0); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, LongDoubleFuzz) { - using namespace openspace::properties; - using T = long double; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - 0l, - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen)); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, Vec2) { - using namespace openspace::properties; - using T = glm::vec2; - T val = T(1.f); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, Vec2Fuzz) { - using namespace openspace::properties; - using T = glm::vec2; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - T::value_type(0), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen), dis(gen)); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, Vec3) { - using namespace openspace::properties; - using T = glm::vec3; - T val = T(1.f); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, Vec3Fuzz) { - using namespace openspace::properties; - using T = glm::vec3; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - T::value_type(0), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen), dis(gen), dis(gen)); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, Vec4) { - using namespace openspace::properties; - using T = glm::vec4; - T val = T(1.f); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, Vec4Fuzz) { - using namespace openspace::properties; - using T = glm::vec4; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - T::value_type(0), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen), dis(gen), dis(gen), dis(gen)); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, DVec2) { - using namespace openspace::properties; - using T = glm::dvec2; - T val = T(1.0); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, DVec2Fuzz) { - using namespace openspace::properties; - using T = glm::dvec2; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - T::value_type(0), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen), dis(gen)); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, DVec3) { - using namespace openspace::properties; - using T = glm::dvec3; - T val = T(1.0); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, DVec3Fuzz) { - using namespace openspace::properties; - using T = glm::dvec3; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - T::value_type(0), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen), dis(gen), dis(gen)); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, DVec4) { - using namespace openspace::properties; - using T = glm::dvec4; - T val = T(1.0); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, DVec4Fuzz) { - using namespace openspace::properties; - using T = glm::dvec4; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - T::value_type(0), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen), dis(gen), dis(gen), dis(gen)); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, IVec2) { - using namespace openspace::properties; - using T = glm::ivec2; - T val = T(1); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, IVec2Fuzz) { - using namespace openspace::properties; - using T = glm::ivec2; - - std::mt19937 gen(1337); - std::uniform_int_distribution dis( - std::numeric_limits::lowest(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen), dis(gen)); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, IVec3) { - using namespace openspace::properties; - using T = glm::ivec3; - T val = T(1); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, IVec3Fuzz) { - using namespace openspace::properties; - using T = glm::ivec3; - - std::mt19937 gen(1337); - std::uniform_int_distribution dis( - std::numeric_limits::lowest(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen), dis(gen), dis(gen)); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, IVec4) { - using namespace openspace::properties; - using T = glm::ivec4; - T val = T(1); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, IVec4Fuzz) { - using namespace openspace::properties; - using T = glm::ivec4; - - std::mt19937 gen(1337); - std::uniform_int_distribution dis( - std::numeric_limits::lowest(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen), dis(gen), dis(gen), dis(gen)); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, UVec2) { - using namespace openspace::properties; - using T = glm::uvec2; - T val = T(1); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, UVec2Fuzz) { - using namespace openspace::properties; - using T = glm::uvec2; - - std::mt19937 gen(1337); - std::uniform_int_distribution dis( - std::numeric_limits::lowest(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen), dis(gen)); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, UVec3) { - using namespace openspace::properties; - using T = glm::uvec3; - T val = T(1); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, UVec3Fuzz) { - using namespace openspace::properties; - using T = glm::uvec3; - - std::mt19937 gen(1337); - std::uniform_int_distribution dis( - std::numeric_limits::lowest(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen), dis(gen), dis(gen)); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, UVec4) { - using namespace openspace::properties; - using T = glm::uvec4; - T val = T(1); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, UVec4Fuzz) { - using namespace openspace::properties; - using T = glm::uvec4; - - std::mt19937 gen(1337); - std::uniform_int_distribution dis( - std::numeric_limits::lowest(), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen), dis(gen), dis(gen), dis(gen)); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, Mat2x2) { - using namespace openspace::properties; - using T = glm::mat2x2; - T val = T(1.f); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, Mat2x2Fuzz) { - using namespace openspace::properties; - using T = glm::mat2x2; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - T::value_type(0), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen), dis(gen), dis(gen), dis(gen)); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, Mat2x3) { - using namespace openspace::properties; - using T = glm::mat2x3; - T val = T(1.f); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, Mat2x3Fuzz) { - using namespace openspace::properties; - using T = glm::mat2x3; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - T::value_type(0), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), dis(gen)); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, Mat2x4) { - using namespace openspace::properties; - using T = glm::mat2x4; - T val = T(1.f); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, Mat2x4Fuzz) { - using namespace openspace::properties; - using T = glm::mat2x4; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - T::value_type(0), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen), dis(gen), dis(gen), dis(gen), - dis(gen), dis(gen), dis(gen), dis(gen) - ); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, Mat3x2) { - using namespace openspace::properties; - using T = glm::mat3x2; - T val = T(1.f); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, Mat3x2Fuzz) { - using namespace openspace::properties; - using T = glm::mat3x2; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - T::value_type(0), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), dis(gen)); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, Mat3x3) { - using namespace openspace::properties; - using T = glm::mat3x3; - T val = T(1.f); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, Mat3x3Fuzz) { - using namespace openspace::properties; - using T = glm::mat3x3; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - T::value_type(0), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen), dis(gen), dis(gen), - dis(gen), dis(gen), dis(gen), - dis(gen), dis(gen), dis(gen) - ); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, Mat3x4) { - using namespace openspace::properties; - using T = glm::mat3x4; - T val = T(1.f); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, Mat3x4Fuzz) { - using namespace openspace::properties; - using T = glm::mat3x4; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - T::value_type(0), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen), dis(gen), dis(gen), dis(gen), - dis(gen), dis(gen), dis(gen), dis(gen), - dis(gen), dis(gen), dis(gen), dis(gen) - ); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, Mat4x2) { - using namespace openspace::properties; - using T = glm::mat4x2; - T val = T(1.f); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, Mat4x2Fuzz) { - using namespace openspace::properties; - using T = glm::mat4x2; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - T::value_type(0), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen), dis(gen), - dis(gen), dis(gen), - dis(gen), dis(gen), - dis(gen), dis(gen) - ); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, Mat4x3) { - using namespace openspace::properties; - using T = glm::mat4x3; - T val = T(1.f); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, Mat4x3Fuzz) { - using namespace openspace::properties; - using T = glm::mat4x3; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - T::value_type(0), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen), dis(gen), dis(gen), - dis(gen), dis(gen), dis(gen), - dis(gen), dis(gen), dis(gen), - dis(gen), dis(gen), dis(gen) - ); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, Mat4x4) { - using namespace openspace::properties; - using T = glm::mat4x4; - T val = T(1.f); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, Mat4x4Fuzz) { - using namespace openspace::properties; - using T = glm::mat4x4; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - T::value_type(0), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen), dis(gen), dis(gen), dis(gen), - dis(gen), dis(gen), dis(gen), dis(gen), - dis(gen), dis(gen), dis(gen), dis(gen), - dis(gen), dis(gen), dis(gen), dis(gen) - ); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, DMat2x2) { - using namespace openspace::properties; - using T = glm::dmat2x2; - T val = T(1.f); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, DMat2x2Fuzz) { - using namespace openspace::properties; - using T = glm::dmat2x2; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - T::value_type(0), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen), dis(gen), dis(gen), dis(gen)); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, DMat2x3) { - using namespace openspace::properties; - using T = glm::dmat2x3; - T val = T(1.f); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, DMat2x3Fuzz) { - using namespace openspace::properties; - using T = glm::dmat2x3; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - T::value_type(0), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), dis(gen)); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, DMat2x4) { - using namespace openspace::properties; - using T = glm::dmat2x4; - T val = T(1.f); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, DMat2x4Fuzz) { - using namespace openspace::properties; - using T = glm::dmat2x4; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - T::value_type(0), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen), dis(gen), dis(gen), dis(gen), - dis(gen), dis(gen), dis(gen), dis(gen) - ); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, DMat3x2) { - using namespace openspace::properties; - using T = glm::dmat3x2; - T val = T(1.f); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, DMat3x2Fuzz) { - using namespace openspace::properties; - using T = glm::dmat3x2; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - T::value_type(0), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen), dis(gen), dis(gen), dis(gen), dis(gen), dis(gen)); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, DMat3x3) { - using namespace openspace::properties; - using T = glm::dmat3x3; - T val = T(1.f); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, DMat3x3Fuzz) { - using namespace openspace::properties; - using T = glm::dmat3x3; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - T::value_type(0), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen), dis(gen), dis(gen), - dis(gen), dis(gen), dis(gen), - dis(gen), dis(gen), dis(gen) - ); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, DMat3x4) { - using namespace openspace::properties; - using T = glm::dmat3x4; - T val = T(1.f); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, DMat3x4Fuzz) { - using namespace openspace::properties; - using T = glm::dmat3x4; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - T::value_type(0), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen), dis(gen), dis(gen), dis(gen), - dis(gen), dis(gen), dis(gen), dis(gen), - dis(gen), dis(gen), dis(gen), dis(gen) - ); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, DMat4x2) { - using namespace openspace::properties; - using T = glm::dmat4x2; - T val = T(1.f); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, DMat4x2Fuzz) { - using namespace openspace::properties; - using T = glm::dmat4x2; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - T::value_type(0), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen), dis(gen), - dis(gen), dis(gen), - dis(gen), dis(gen), - dis(gen), dis(gen) - ); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, DMat4x3) { - using namespace openspace::properties; - using T = glm::dmat4x3; - T val = T(1.f); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, DMat4x3Fuzz) { - using namespace openspace::properties; - using T = glm::dmat4x3; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - T::value_type(0), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen), dis(gen), dis(gen), - dis(gen), dis(gen), dis(gen), - dis(gen), dis(gen), dis(gen), - dis(gen), dis(gen), dis(gen) - ); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, DMat4x4) { - using namespace openspace::properties; - using T = glm::dmat4x4; - T val = T(1.f); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; -} - -TEST_F(LuaConversionTest, DMat4x4Fuzz) { - using namespace openspace::properties; - using T = glm::dmat4x4; - - std::mt19937 gen(1337); - std::uniform_real_distribution dis( - T::value_type(0), - std::numeric_limits::max() - ); - - for (int i = 0; i < NumberFuzzTests; ++i) { - T val = T(dis(gen), dis(gen), dis(gen), dis(gen), - dis(gen), dis(gen), dis(gen), dis(gen), - dis(gen), dis(gen), dis(gen), dis(gen), - dis(gen), dis(gen), dis(gen), dis(gen) - ); - - bool success = PropertyDelegate>::toLuaValue( - state, - val - ); - EXPECT_TRUE(success) << "toLuaValue"; - T value = PropertyDelegate>::fromLuaValue( - state, - success - ); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, val) << "fromLuaValue"; - } -} - -TEST_F(LuaConversionTest, String) { - using namespace openspace::properties; - bool success - = PropertyDelegate>::toLuaValue( - state, "value"); - EXPECT_TRUE(success) << "toLuaValue"; - std::string value = ""; - value = PropertyDelegate>::fromLuaValue( - state, success); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, "value") << "fromLuaValue"; -} diff --git a/tests/test_optionproperty.inl b/tests/test_optionproperty.cpp similarity index 55% rename from tests/test_optionproperty.inl rename to tests/test_optionproperty.cpp index 8fd3a913ca..954bd669ad 100644 --- a/tests/test_optionproperty.inl +++ b/tests/test_optionproperty.cpp @@ -22,84 +22,78 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ +#include "catch2/catch.hpp" + #include -class OptionPropertyTest : public testing::Test {}; - -TEST_F(OptionPropertyTest, NoOption) { +TEST_CASE("OptionProperty: No Option", "[optionproperty]") { openspace::properties::OptionProperty p({ "id", "gui", "desc" }); - ASSERT_EQ(false, p.hasOption()); + REQUIRE_FALSE(p.hasOption()); } -TEST_F(OptionPropertyTest, SingleOptionSingleZero) { +TEST_CASE("OptionProperty: Single Option Single Zero", "[optionproperty]") { openspace::properties::OptionProperty p({ "id", "gui", "desc"}); p.addOption(0, "a"); p = 0; - ASSERT_EQ(0, p.option().value); - ASSERT_EQ("a", p.option().description); + REQUIRE(p.option().value == 0); + REQUIRE(p.option().description == "a"); } -TEST_F(OptionPropertyTest, SingleOptionSingleNegative) { +TEST_CASE("OptionProperty: Single Option Single Negative", "[optionproperty]") { openspace::properties::OptionProperty p({ "id", "gui", "desc" }); p.addOption(-1, "a"); p = -1; - ASSERT_EQ(-1, p.option().value); - ASSERT_EQ("a", p.option().description); + REQUIRE(p.option().value == -1); + REQUIRE(p.option().description == "a"); } -TEST_F(OptionPropertyTest, SingleOptionSinglePositive) { +TEST_CASE("OptionProperty: Single Option Single Positive", "[optionproperty]") { openspace::properties::OptionProperty p({ "id", "gui", "desc" }); - p.addOptions({ - { 1, "a" } - }); + p.addOptions({ { 1, "a" } }); p = 1; - ASSERT_EQ(1, p.option().value); - ASSERT_EQ("a", p.option().description); + REQUIRE(p.option().value == 1); + REQUIRE(p.option().description == "a"); } -TEST_F(OptionPropertyTest, SingleOptionMultipleZero) { +TEST_CASE("OptionProperty: Single Option Multiple Zero", "[optionproperty]") { openspace::properties::OptionProperty p({ "id", "gui", "desc" }); p.addOptions({ "a" }); p = 0; - ASSERT_EQ(0, p.option().value); - ASSERT_EQ("a", p.option().description); + REQUIRE(p.option().value == 0); + REQUIRE(p.option().description == "a"); } -TEST_F(OptionPropertyTest, SingleOptionMultipleNegative) { +TEST_CASE("OptionProperty: Single Option Multiple Negative", "[optionproperty]") { openspace::properties::OptionProperty p({ "id", "gui", "desc" }); - p.addOptions({ - { -1, "a" } - }); + p.addOptions({ { -1, "a" } }); p = -1; - ASSERT_EQ(-1, p.option().value); - ASSERT_EQ("a", p.option().description); + REQUIRE(p.option().value == -1); + REQUIRE(p.option().description == "a"); } -TEST_F(OptionPropertyTest, SingleOptionMultiplePositive) { +TEST_CASE("OptionProperty: Single Option Multiple Positive", "[optionproperty]") { openspace::properties::OptionProperty p({ "id", "gui", "desc" }); - p.addOptions({ - { 1, "a" } - }); + p.addOptions({ { 1, "a" } }); p = 1; - ASSERT_EQ(1, p.option().value); - ASSERT_EQ("a", p.option().description); + REQUIRE(p.option().value == 1); + REQUIRE(p.option().description == "a"); } -TEST_F(OptionPropertyTest, SingleOptionsZeroBasedConsecutive) { +TEST_CASE("OptionProperty: Single Options Zero Based Consecutive", "[optionproperty]") { openspace::properties::OptionProperty p({ "id", "gui", "desc" }); p.addOption(0, "a"); @@ -107,19 +101,20 @@ TEST_F(OptionPropertyTest, SingleOptionsZeroBasedConsecutive) { p.addOption(2, "c"); p = 0; - ASSERT_EQ(0, p.option().value); - ASSERT_EQ("a", p.option().description); + REQUIRE(p.option().value == 0); + REQUIRE(p.option().description == "a"); p = 1; - ASSERT_EQ(1, p.option().value); - ASSERT_EQ("b", p.option().description); + REQUIRE(p.option().value == 1); + REQUIRE(p.option().description == "b"); p = 2; - ASSERT_EQ(2, p.option().value); - ASSERT_EQ("c", p.option().description); + REQUIRE(p.option().value == 2); + REQUIRE(p.option().description == "c"); } -TEST_F(OptionPropertyTest, SingleOptionsZeroBasedNonConsecutive) { +TEST_CASE("OptionProperty: Single Options Zero Based Non Consecutive", "[optionproperty]") +{ openspace::properties::OptionProperty p({ "id", "gui", "desc" }); p.addOption(0, "a"); @@ -127,19 +122,20 @@ TEST_F(OptionPropertyTest, SingleOptionsZeroBasedNonConsecutive) { p.addOption(4, "c"); p = 0; - ASSERT_EQ(0, p.option().value); - ASSERT_EQ("a", p.option().description); + REQUIRE(p.option().value == 0); + REQUIRE(p.option().description == "a"); p = 2; - ASSERT_EQ(2, p.option().value); - ASSERT_EQ("b", p.option().description); + REQUIRE(p.option().value == 2); + REQUIRE(p.option().description == "b"); p = 4; - ASSERT_EQ(4, p.option().value); - ASSERT_EQ("c", p.option().description); + REQUIRE(p.option().value == 4); + REQUIRE(p.option().description == "c"); } -TEST_F(OptionPropertyTest, SingleOptionsNegativeBasedConsecutive) { +TEST_CASE("OptionProperty: Single Options Negative Based Consecutive", "[optionproperty]") +{ openspace::properties::OptionProperty p({ "id", "gui", "desc" }); p.addOption(-1, "a"); @@ -147,19 +143,22 @@ TEST_F(OptionPropertyTest, SingleOptionsNegativeBasedConsecutive) { p.addOption(-3, "c"); p = -1; - ASSERT_EQ(-1, p.option().value); - ASSERT_EQ("a", p.option().description); + REQUIRE(p.option().value == -1); + REQUIRE(p.option().description == "a"); p = -2; - ASSERT_EQ(-2, p.option().value); - ASSERT_EQ("b", p.option().description); + REQUIRE(p.option().value == -2); + REQUIRE(p.option().description == "b"); p = -3; - ASSERT_EQ(-3, p.option().value); - ASSERT_EQ("c", p.option().description); + REQUIRE(p.option().value == -3); + REQUIRE(p.option().description == "c"); } -TEST_F(OptionPropertyTest, SingleOptionsNonZeroBasedNonConsecutive) { +TEST_CASE( + "OptionProperty: Single Options Non Zero Based Non Consecutive", + "[optionproperty]") +{ openspace::properties::OptionProperty p({ "id", "gui", "desc" }); p.addOption(-1, "a"); @@ -167,19 +166,19 @@ TEST_F(OptionPropertyTest, SingleOptionsNonZeroBasedNonConsecutive) { p.addOption(-5, "c"); p = -1; - ASSERT_EQ(-1, p.option().value); - ASSERT_EQ("a", p.option().description); + REQUIRE(p.option().value == -1); + REQUIRE(p.option().description == "a"); p = -3; - ASSERT_EQ(-3, p.option().value); - ASSERT_EQ("b", p.option().description); + REQUIRE(p.option().value == -3); + REQUIRE(p.option().description == "b"); p = -5; - ASSERT_EQ(-5, p.option().value); - ASSERT_EQ("c", p.option().description); + REQUIRE(p.option().value == -5); + REQUIRE(p.option().description == "c"); } -TEST_F(OptionPropertyTest, SingleOptionsZeroBasedAlternating) { +TEST_CASE("OptionProperty: Single Options Zero Based Alternating", "[optionproperty]") { openspace::properties::OptionProperty p({ "id", "gui", "desc" }); p.addOption(0, "a"); @@ -187,19 +186,20 @@ TEST_F(OptionPropertyTest, SingleOptionsZeroBasedAlternating) { p.addOption(-4, "c"); p = 0; - ASSERT_EQ(0, p.option().value); - ASSERT_EQ("a", p.option().description); + REQUIRE(p.option().value == 0); + REQUIRE(p.option().description == "a"); p = 2; - ASSERT_EQ(2, p.option().value); - ASSERT_EQ("b", p.option().description); + REQUIRE(p.option().value == 2); + REQUIRE(p.option().description == "b"); p = -4; - ASSERT_EQ(-4, p.option().value); - ASSERT_EQ("c", p.option().description); + REQUIRE(p.option().value == -4); + REQUIRE(p.option().description == "c"); } -TEST_F(OptionPropertyTest, SingleOptionsNonZeroBasedAlternating) { +TEST_CASE("OptionProperty: Single Options Non Zero Based Alternating", "[optionproperty]") +{ openspace::properties::OptionProperty p({ "id", "gui", "desc" }); p.addOption(-20, "a"); @@ -207,14 +207,14 @@ TEST_F(OptionPropertyTest, SingleOptionsNonZeroBasedAlternating) { p.addOption(-10, "c"); p = -20; - ASSERT_EQ(-20, p.option().value); - ASSERT_EQ("a", p.option().description); + REQUIRE(p.option().value == -20); + REQUIRE(p.option().description == "a"); p = 2; - ASSERT_EQ(2, p.option().value); - ASSERT_EQ("b", p.option().description); + REQUIRE(p.option().value == 2); + REQUIRE(p.option().description == "b"); p = -10; - ASSERT_EQ(-10, p.option().value); - ASSERT_EQ("c", p.option().description); + REQUIRE(p.option().value == -10); + REQUIRE(p.option().description == "c"); } diff --git a/tests/test_patchcoverageprovider.inl b/tests/test_patchcoverageprovider.inl deleted file mode 100644 index 54b68fb3a1..0000000000 --- a/tests/test_patchcoverageprovider.inl +++ /dev/null @@ -1,203 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2019 * - * * - * 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 - -#define _USE_MATH_DEFINES -#include -#include - -class PatchCoverageProviderTest : public testing::Test {}; - -using namespace openspace; - -TEST_F(PatchCoverageProviderTest, getTileIndexWithBigPatch) { - - // Allocate data - GeodeticPatch patch(0,0,0,0); - ChunkIndex ci; - ChunkIndex ciExpected; - - // Create a provider with 1 in depth - PatchCoverageProvider provider( - Geodetic2(M_PI * 2, M_PI * 2), // size at level 0 - Geodetic2(- M_PI, - M_PI), // offset at level 0 - 1); // depth - - // A big patch - patch = GeodeticPatch( - Geodetic2(0,0), // Center - Geodetic2(M_PI / 2, M_PI / 2)); // Halfsize - - // Get its index - ci = provider.getTileIndex(patch); - ciExpected = {0, 0, 1}; - - ASSERT_EQ(ciExpected, ci); - - // Patch positioned at the border of 1 in x index - patch = GeodeticPatch( - Geodetic2(0, M_PI / 2), // Center - Geodetic2(M_PI / 2, M_PI / 2)); // Halfsize); - - // Get its index - ci = provider.getTileIndex(patch); - ciExpected = { 1, 0, 1 }; - - ASSERT_EQ(ciExpected, ci); - - // Patch positioned at a little less than the border of 1 in x index - patch = GeodeticPatch( - Geodetic2(0, M_PI / 2 - 0.0001), // Center - Geodetic2(M_PI / 2, M_PI / 2)); // Halfsize); - - // Get its index - ci = provider.getTileIndex(patch); - ciExpected = { 0, 0, 1 }; - - ASSERT_EQ(ciExpected, ci); -} - -TEST_F(PatchCoverageProviderTest, getTileIndexHigherDepthWithBigPatch) { - - // Allocate data - GeodeticPatch patch(0, 0, 0, 0); - ChunkIndex ci; - ChunkIndex ciExpected; - - // Create a provider with 3 in depth - // We still expect the same result since the patches are big - PatchCoverageProvider provider( - Geodetic2(M_PI * 2, M_PI * 2), // size at level 0 - Geodetic2(- M_PI, -M_PI), // offset at level 0 - 3); // depth - - // A big patch - patch = GeodeticPatch( - Geodetic2(0, 0), // Center - Geodetic2(M_PI / 2, M_PI / 2)); // Halfsize - - // Get its index - ci = provider.getTileIndex(patch); - ciExpected = { 0, 0, 1 }; - - ASSERT_EQ(ciExpected, ci); - - // Patch positioned at the border of 1 in x index - patch = GeodeticPatch( - Geodetic2(0, M_PI / 2), // Center - Geodetic2(M_PI / 2, M_PI / 2)); // Halfsize); - - // Get its index - ci = provider.getTileIndex(patch); - ciExpected = { 1, 0, 1 }; - - ASSERT_EQ(ciExpected, ci); - - // Patch positioned at a little less than the border of 1 in x index - patch = GeodeticPatch( - Geodetic2(0, M_PI / 2 - 0.0001), // Center - Geodetic2(M_PI / 2, M_PI / 2)); // Halfsize); - - // Get its index - ci = provider.getTileIndex(patch); - ciExpected = { 0, 0, 1 }; - - ASSERT_EQ(ciExpected, ci); -} - - -TEST_F(PatchCoverageProviderTest, getTileIndexHigherDepthWithSmallPatch) { - - // Allocate data - GeodeticPatch patch(0, 0, 0, 0); - ChunkIndex ci; - ChunkIndex ciExpected; - - // Create a provider with 3 in depth - // We still expect the same result since the patches are big - PatchCoverageProvider provider( - Geodetic2(M_PI * 2, M_PI * 2), // size at level 0 - Geodetic2(- M_PI, - M_PI), // offset at level 0 - 3); // depth - - // A small patch - patch = GeodeticPatch( - Geodetic2(0, 0), // Center - Geodetic2(M_PI / 8, M_PI / 8)); // Halfsize - - // Get its index - ci = provider.getTileIndex(patch); - ciExpected = { 3, 3, 3 }; - - ASSERT_EQ(ciExpected, ci); - - // A small patch near edge case - patch = GeodeticPatch( - Geodetic2(2 * M_PI / 8 + 2 * M_PI / 16 + 0.001, 2 * 2 * M_PI / 8 + 2 * M_PI / 16 - 0.001), // Center - Geodetic2(M_PI / 8, M_PI / 8)); // Halfsize - - // Get its index - ci = provider.getTileIndex(patch); - ciExpected = { 5, 1, 3 }; - - // A small patch near edge case other side - patch = GeodeticPatch( - Geodetic2(2 * M_PI / 8 + 2 * M_PI / 16 - 0.001, 2 * 2 * M_PI / 8 + 2 * M_PI / 16 + 0.001), // Center - Geodetic2(M_PI / 8, M_PI / 8)); // Halfsize - - // Get its index - ci = provider.getTileIndex(patch); - ciExpected = { 6, 2, 3 }; - - ASSERT_EQ(ciExpected, ci); -} - - -TEST_F(PatchCoverageProviderTest, getTileIndexWrapAround) { - - // Allocate data - GeodeticPatch patch(0, 0, 0, 0); - ChunkIndex ci; - ChunkIndex ciExpected; - - // Create a provider with 2 in depth - // We still expect the same result since the patches are big - PatchCoverageProvider provider( - Geodetic2(M_PI * 2, M_PI * 2), // size at level 0 - Geodetic2(-M_PI, -M_PI), // offset at level 0 - 2); // depth - - // A small patch - patch = GeodeticPatch( - Geodetic2(0, - M_PI + M_PI / 16), // Center - Geodetic2(M_PI / 8, M_PI / 8)); // Halfsize - - // Get its index - // We want negative indices - ci = provider.getTileIndex(patch); - ciExpected = { -1, 1, 2 }; - - ASSERT_EQ(ciExpected, ci); -} diff --git a/tests/test_rawvolumeio.inl b/tests/test_rawvolumeio.cpp similarity index 88% rename from tests/test_rawvolumeio.inl rename to tests/test_rawvolumeio.cpp index f68e3a0ce1..c4b4b9703b 100644 --- a/tests/test_rawvolumeio.inl +++ b/tests/test_rawvolumeio.cpp @@ -22,30 +22,26 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include "gtest/gtest.h" - -#include -#include +#include "catch2/catch.hpp" #include #include #include - -#include +#include +#include #include +#include -class RawVolumeIoTest : public testing::Test {}; - -TEST_F(RawVolumeIoTest, TinyInputOutput) { +TEST_CASE("RawVolumeIO: TinyInputOutput", "[rawvolumeio]") { using namespace openspace::volume; - glm::uvec3 dims{ 1, 1, 1 }; - float value = 0.5; + glm::uvec3 dims(1); + float value = 0.5f; RawVolume vol(dims); vol.set({ 0, 0, 0 }, value); - ASSERT_EQ(vol.get({ 0, 0, 0 }), value); + REQUIRE(vol.get({ 0, 0, 0 }) == value); std::string volumePath = absPath("${TESTDIR}/tinyvolume.rawvolume"); @@ -56,13 +52,13 @@ TEST_F(RawVolumeIoTest, TinyInputOutput) { // Read the 1x1x1 volume and make sure the value is the same. RawVolumeReader reader(volumePath, dims); std::unique_ptr> storedVolume = reader.read(); - ASSERT_EQ(storedVolume->get({ 0, 0, 0 }), value); + REQUIRE(storedVolume->get({ 0, 0, 0 }) == value); } -TEST_F(RawVolumeIoTest, BasicInputOutput) { +TEST_CASE("RawVolumeIO: BasicInputOutput", "[rawvolumeio]") { using namespace openspace::volume; - glm::uvec3 dims{ 2, 4, 8 }; + glm::uvec3 dims(2, 4, 8); auto value = [dims](glm::uvec3 v) { return static_cast(v.z * dims.z * dims.y + v.y * dims.y + v.x); }; @@ -70,7 +66,7 @@ TEST_F(RawVolumeIoTest, BasicInputOutput) { RawVolume vol(dims); vol.forEachVoxel([&vol, &value](glm::uvec3 x, float) { vol.set(x, value(x)); }); - vol.forEachVoxel([&value](glm::uvec3 x, float v) { ASSERT_EQ(v, value(x)); }); + vol.forEachVoxel([&value](glm::uvec3 x, float v) { REQUIRE(v == value(x)); }); std::string volumePath = absPath("${TESTDIR}/basicvolume.rawvolume"); @@ -82,6 +78,6 @@ TEST_F(RawVolumeIoTest, BasicInputOutput) { RawVolumeReader reader(volumePath, dims); std::unique_ptr> storedVolume = reader.read(); vol.forEachVoxel([&value](glm::uvec3 x, float v) { - ASSERT_EQ(v, value(x)); + REQUIRE(v == value(x)); }); } diff --git a/tests/test_screenspaceimage.inl b/tests/test_screenspaceimage.inl deleted file mode 100644 index e2bdb5cb37..0000000000 --- a/tests/test_screenspaceimage.inl +++ /dev/null @@ -1,69 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2019 * - * * - * 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 private public -// #include -// #define private private -// /* -// * For each test the following is run: -// * Constructor() -> setUp() -> test -> tearDown() -> Deconstructor() -// */ - -// namespace openspace { - -// class ScreenSpaceRenderableTest : public testing::Test{ -// protected: - -// ScreenSpaceRenderableTest() -// // _ssr(texturePath) -// { -// // _sharedSsr = std::make_shared("${DATA}/test3.jpg"); -// } - -// ~ScreenSpaceRenderableTest(){} - - -// void reset() {} - -// // These variables are shared by all tests -// std::string texturePath = "${DATA}/test2.jpg"; -// ScreenSpaceImage _ssr; -// std::shared_ptr _sharedSsr; -// }; - - -// TEST_F(ScreenSpaceRenderableTest, initialize){ -// bool isReady = _ssr.isReady(); -// ASSERT_TRUE(!isReady) << "ScreenSpaceImage is ready before initialize"; - -// // cannot test initialize, crashes at createplane becasue of opengl functions. needs mocking -// //_ssr.initialize(); -// //isReady = _ssr.isReady(); -// //ASSERT_TRUE(!isReady) << "ScreenSpaceImage is not ready after initialize"; -// //_ssr.deinitialize(); -// //isReady = _ssr.isReady(); -// //ASSERT_TRUE(!isReady) << "ScreenSpaceImage is still ready after deinitialize"; -// } -// }//namespace openspace diff --git a/tests/test_scriptscheduler.inl b/tests/test_scriptscheduler.cpp similarity index 58% rename from tests/test_scriptscheduler.inl rename to tests/test_scriptscheduler.cpp index a12b363b05..c652deb570 100644 --- a/tests/test_scriptscheduler.inl +++ b/tests/test_scriptscheduler.cpp @@ -22,31 +22,21 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include +#include "catch2/catch.hpp" -// This include should be removed after the time class is not dependent on -// Spice anymore +#include #include #include +#include #include - #include -class ScriptSchedulerTest : public testing::Test { -protected: - void SetUp() override { - openspace::SpiceManager::initialize(); - openspace::SpiceManager::ref().loadKernel( - absPath("${TESTDIR}/SpiceTest/spicekernels/naif0008.tls") - ); - } - - void TearDown() override { - openspace::SpiceManager::deinitialize(); - } -}; +TEST_CASE("ScriptScheduler: Simple Forward", "[scriptscheduler]") { + openspace::SpiceManager::initialize(); + openspace::SpiceManager::ref().loadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/naif0008.tls") + ); -TEST_F(ScriptSchedulerTest, SimpleForward) { using namespace openspace::scripting; using namespace std::string_literals; @@ -59,21 +49,24 @@ TEST_F(ScriptSchedulerTest, SimpleForward) { }; scheduler.progressTo(openspace::Time::convertTime("2000 JAN 01")); - scheduler.loadScripts({ - { "1", testDictionary } - }); + scheduler.loadScripts({ { "1", testDictionary } }); auto res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 02")); - ASSERT_EQ(res.first, res.second); + REQUIRE(res.first == res.second); - res = scheduler.progressTo( - openspace::Time::convertTime("2000 JAN 03") - ); - ASSERT_EQ(1, std::distance(res.first, res.second)); - EXPECT_EQ("ForwardScript1", *(res.first)); + res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 03")); + REQUIRE(std::distance(res.first, res.second) == 1); + REQUIRE(*(res.first) == "ForwardScript1"); + + openspace::SpiceManager::deinitialize(); } -TEST_F(ScriptSchedulerTest, MultipleForwardSingleJump) { +TEST_CASE("ScriptScheduler: Multiple Forward Single Jump", "[scriptscheduler]") { + openspace::SpiceManager::initialize(); + openspace::SpiceManager::ref().loadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/naif0008.tls") + ); + using namespace openspace::scripting; using namespace std::string_literals; @@ -99,18 +92,25 @@ TEST_F(ScriptSchedulerTest, MultipleForwardSingleJump) { }); auto res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 02")); - ASSERT_EQ(res.first, res.second); + REQUIRE(res.first == res.second); res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 04")); - ASSERT_EQ(1, std::distance(res.first, res.second)); - EXPECT_EQ("ForwardScript1", *(res.first)); + REQUIRE(std::distance(res.first, res.second) == 1); + REQUIRE(*(res.first) == "ForwardScript1"); res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 06")); - ASSERT_EQ(1, std::distance(res.first, res.second)); - EXPECT_EQ("ForwardScript2", *(res.first)); + REQUIRE(std::distance(res.first, res.second) == 1); + REQUIRE(*(res.first) == "ForwardScript2"); + + openspace::SpiceManager::deinitialize(); } -TEST_F(ScriptSchedulerTest, MultipleForwardOrdering) { +TEST_CASE("ScriptScheduler: Multiple Forward Ordering", "[scriptscheduler]") { + openspace::SpiceManager::initialize(); + openspace::SpiceManager::ref().loadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/naif0008.tls") + ); + using namespace openspace::scripting; using namespace std::string_literals; @@ -135,15 +135,22 @@ TEST_F(ScriptSchedulerTest, MultipleForwardOrdering) { }); auto res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 02")); - ASSERT_EQ(res.first, res.second); + REQUIRE(res.first == res.second); res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 06")); - ASSERT_EQ(2, std::distance(res.first, res.second)); - EXPECT_EQ("ForwardScript1", *(res.first)); - EXPECT_EQ("ForwardScript2", *(std::next(res.first))); + REQUIRE(std::distance(res.first, res.second) == 2); + REQUIRE(*(res.first) == "ForwardScript1"); + REQUIRE(*(std::next(res.first)) == "ForwardScript2"); + + openspace::SpiceManager::deinitialize(); } -TEST_F(ScriptSchedulerTest, SimpleBackward) { +TEST_CASE("ScriptScheduler: Simple Backward", "[scriptscheduler]") { + openspace::SpiceManager::initialize(); + openspace::SpiceManager::ref().loadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/naif0008.tls") + ); + using namespace openspace::scripting; using namespace std::string_literals; @@ -161,14 +168,21 @@ TEST_F(ScriptSchedulerTest, SimpleBackward) { }); auto res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 04")); - ASSERT_EQ(res.first, res.second); + REQUIRE(res.first == res.second); res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 02")); - ASSERT_EQ(1, std::distance(res.first, res.second)); - EXPECT_EQ("BackwardScript1", *(res.first)); + REQUIRE(std::distance(res.first, res.second) == 1); + REQUIRE(*(res.first) == "BackwardScript1"); + + openspace::SpiceManager::deinitialize(); } -TEST_F(ScriptSchedulerTest, MultipleBackwardSingleJump) { +TEST_CASE("ScriptScheduler: Multiple Backward Single Jump", "[scriptscheduler]") { + openspace::SpiceManager::initialize(); + openspace::SpiceManager::ref().loadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/naif0008.tls") + ); + using namespace openspace::scripting; using namespace std::string_literals; @@ -193,18 +207,25 @@ TEST_F(ScriptSchedulerTest, MultipleBackwardSingleJump) { }); auto res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 06")); - ASSERT_EQ(res.first, res.second); + REQUIRE(res.first == res.second); res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 04")); - ASSERT_EQ(1, std::distance(res.first, res.second)); - EXPECT_EQ("BackwardScript2", *(res.first)); + REQUIRE(std::distance(res.first, res.second) == 1); + REQUIRE(*(res.first) == "BackwardScript2"); res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 01")); - ASSERT_EQ(1, std::distance(res.first, res.second)); - EXPECT_EQ("BackwardScript1", *(res.first)); + REQUIRE(std::distance(res.first, res.second) == 1); + REQUIRE(*(res.first) == "BackwardScript1"); + + openspace::SpiceManager::deinitialize(); } -TEST_F(ScriptSchedulerTest, MultipleBackwardOrdering) { +TEST_CASE("ScriptScheduler: Multiple Backward Ordering", "[scriptscheduler]") { + openspace::SpiceManager::initialize(); + openspace::SpiceManager::ref().loadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/naif0008.tls") + ); + using namespace openspace::scripting; using namespace std::string_literals; @@ -229,15 +250,22 @@ TEST_F(ScriptSchedulerTest, MultipleBackwardOrdering) { }); auto res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 06")); - ASSERT_EQ(res.first, res.second); + REQUIRE(res.first == res.second); res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 01")); - ASSERT_EQ(2, std::distance(res.first, res.second)); - EXPECT_EQ("BackwardScript2", *(res.first)); - EXPECT_EQ("BackwardScript1", *(std::next(res.first))); + REQUIRE(std::distance(res.first, res.second) == 2); + REQUIRE(*(res.first) == "BackwardScript2"); + REQUIRE(*(std::next(res.first)) == "BackwardScript1"); + + openspace::SpiceManager::deinitialize(); } -TEST_F(ScriptSchedulerTest, Empty) { +TEST_CASE("ScriptScheduler: Empty", "[scriptscheduler]") { + openspace::SpiceManager::initialize(); + openspace::SpiceManager::ref().loadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/naif0008.tls") + ); + using namespace openspace::scripting; static const std::vector TestTimes = { @@ -249,18 +277,25 @@ TEST_F(ScriptSchedulerTest, Empty) { for (double t : TestTimes) { ScriptScheduler scheduler; auto res = scheduler.progressTo(t); - EXPECT_EQ(res.first, res.second); + REQUIRE(res.first == res.second); } // Then test the same thing but keeping the same ScriptScheduler ScriptScheduler scheduler; for (double t : TestTimes) { auto res = scheduler.progressTo(t); - EXPECT_EQ(res.first, res.second); + REQUIRE(res.first == res.second); } + + openspace::SpiceManager::deinitialize(); } -TEST_F(ScriptSchedulerTest, ForwardBackwards) { +TEST_CASE("ScriptScheduler: Forward Backwards", "[scriptscheduler]") { + openspace::SpiceManager::initialize(); + openspace::SpiceManager::ref().loadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/naif0008.tls") + ); + using namespace openspace::scripting; using namespace std::string_literals; @@ -285,22 +320,29 @@ TEST_F(ScriptSchedulerTest, ForwardBackwards) { }); auto res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 04")); - ASSERT_EQ(1, std::distance(res.first, res.second)); - EXPECT_EQ("ForwardScript1", *(res.first)); + REQUIRE(std::distance(res.first, res.second) == 1); + REQUIRE(*(res.first) == "ForwardScript1"); res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 01")); - ASSERT_EQ(1, std::distance(res.first, res.second)); - EXPECT_EQ("BackwardScript1", *(res.first)); + REQUIRE(std::distance(res.first, res.second) == 1); + REQUIRE(*(res.first) == "BackwardScript1"); res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 07")); - ASSERT_EQ(2, std::distance(res.first, res.second)); + REQUIRE(std::distance(res.first, res.second) == 2); res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 04")); - ASSERT_EQ(1, std::distance(res.first, res.second)); - EXPECT_EQ("BackwardScript2", *(res.first)); + REQUIRE(std::distance(res.first, res.second) == 1); + REQUIRE(*(res.first) == "BackwardScript2"); + + openspace::SpiceManager::deinitialize(); } -TEST_F(ScriptSchedulerTest, Rewind) { +TEST_CASE("ScriptScheduler: Rewind", "[scriptscheduler]") { + openspace::SpiceManager::initialize(); + openspace::SpiceManager::ref().loadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/naif0008.tls") + ); + using namespace openspace::scripting; using namespace std::string_literals; @@ -325,16 +367,23 @@ TEST_F(ScriptSchedulerTest, Rewind) { }); auto res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 07")); - ASSERT_EQ(2, std::distance(res.first, res.second)); + REQUIRE(std::distance(res.first, res.second) == 2); scheduler.rewind(); res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 04")); - ASSERT_EQ(1, std::distance(res.first, res.second)); - EXPECT_EQ("ForwardScript1", *(res.first)); + REQUIRE(std::distance(res.first, res.second) == 1); + REQUIRE(*(res.first) == "ForwardScript1"); + + openspace::SpiceManager::deinitialize(); } -TEST_F(ScriptSchedulerTest, CurrentTime) { +TEST_CASE("ScriptScheduler: CurrentTime", "[scriptscheduler]") { + openspace::SpiceManager::initialize(); + openspace::SpiceManager::ref().loadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/naif0008.tls") + ); + using namespace openspace::scripting; static const std::vector TestValues = { @@ -345,17 +394,23 @@ TEST_F(ScriptSchedulerTest, CurrentTime) { for (double t : TestValues) { ScriptScheduler scheduler; scheduler.progressTo(t); - EXPECT_EQ(t, scheduler.currentTime()); + REQUIRE(t == scheduler.currentTime()); } + + openspace::SpiceManager::deinitialize(); } -TEST_F(ScriptSchedulerTest, AllScripts) { +TEST_CASE("ScriptScheduler: All Scripts", "[scriptscheduler]") { + openspace::SpiceManager::initialize(); + openspace::SpiceManager::ref().loadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/naif0008.tls") + ); + using namespace openspace::scripting; using namespace std::string_literals; ScriptScheduler scheduler; - ghoul::Dictionary testDictionary1 = { { "Time", "2000 JAN 03"s }, { "ForwardScript", "ForwardScript1"s }, @@ -379,15 +434,22 @@ TEST_F(ScriptSchedulerTest, AllScripts) { { "2", testDictionary2 }, { "3", testDictionary3 } }); - + auto allScripts = scheduler.allScripts(); - ASSERT_EQ(3, allScripts.size()); - - EXPECT_LE(allScripts[0].time, allScripts[1].time); - EXPECT_LE(allScripts[1].time, allScripts[2].time); + REQUIRE(allScripts.size() == 3); + + REQUIRE(allScripts[0].time < allScripts[1].time); + REQUIRE(allScripts[1].time < allScripts[2].time); + + openspace::SpiceManager::deinitialize(); } -TEST_F(ScriptSchedulerTest, JumpEqual) { +TEST_CASE("ScriptScheduler: Jump Equal", "[scriptscheduler]") { + openspace::SpiceManager::initialize(); + openspace::SpiceManager::ref().loadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/naif0008.tls") + ); + using namespace openspace::scripting; using namespace std::string_literals; @@ -403,30 +465,29 @@ TEST_F(ScriptSchedulerTest, JumpEqual) { { "1", testDictionary1 } }); - auto res = scheduler.progressTo( - openspace::Time::convertTime("2000 JAN 03 11:00:00") - ); - ASSERT_EQ(res.first, res.second); + auto res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 03 11:00:00")); + REQUIRE(res.first == res.second); - res = scheduler.progressTo( - openspace::Time::convertTime("2000 JAN 03 12:00:00") - ); - ASSERT_EQ(1, std::distance(res.first, res.second)); - EXPECT_EQ("ForwardScript1", *(res.first)); + res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 03 12:00:00")); + REQUIRE(std::distance(res.first, res.second) == 1); + REQUIRE(*(res.first) == "ForwardScript1"); - res = scheduler.progressTo( - openspace::Time::convertTime("2000 JAN 03 12:01:00") - ); - ASSERT_EQ(res.first, res.second); + res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 03 12:01:00")); + REQUIRE(res.first == res.second); - res = scheduler.progressTo( - openspace::Time::convertTime("2000 JAN 03 12:00:00") - ); - ASSERT_EQ(1, std::distance(res.first, res.second)); - EXPECT_EQ("BackwardScript1", *(res.first)); + res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 03 12:00:00")); + REQUIRE(std::distance(res.first, res.second) == 1); + REQUIRE(*(res.first) == "BackwardScript1"); + + openspace::SpiceManager::deinitialize(); } -TEST_F(ScriptSchedulerTest, SameTime) { +TEST_CASE("ScriptScheduler: Same Time", "[scriptscheduler]") { + openspace::SpiceManager::initialize(); + openspace::SpiceManager::ref().loadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/naif0008.tls") + ); + using namespace openspace::scripting; using namespace std::string_literals; @@ -438,23 +499,24 @@ TEST_F(ScriptSchedulerTest, SameTime) { { "BackwardScript", "BackwardScript1"s } }; - scheduler.loadScripts({ - { "1", testDictionary1 } - }); + scheduler.loadScripts({ { "1", testDictionary1 } }); - auto res = scheduler.progressTo( - openspace::Time::convertTime("2000 JAN 03 12:00:00") - ); - ASSERT_EQ(1, std::distance(res.first, res.second)); - EXPECT_EQ("ForwardScript1", *(res.first)); + auto res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 03 12:00:00")); + REQUIRE(std::distance(res.first, res.second) == 1); + REQUIRE(*(res.first) == "ForwardScript1"); - res = scheduler.progressTo( - openspace::Time::convertTime("2000 JAN 03 12:00:00") - ); - ASSERT_EQ(res.first, res.second); + res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 03 12:00:00")); + REQUIRE(res.first == res.second); + + openspace::SpiceManager::deinitialize(); } -TEST_F(ScriptSchedulerTest, MultiInnerJump) { +TEST_CASE("ScriptScheduler: Multi Inner Jump", "[scriptscheduler]") { + openspace::SpiceManager::initialize(); + openspace::SpiceManager::ref().loadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/naif0008.tls") + ); + using namespace openspace::scripting; using namespace std::string_literals; @@ -466,33 +528,33 @@ TEST_F(ScriptSchedulerTest, MultiInnerJump) { { "BackwardScript", "BackwardScript1"s } }; - scheduler.loadScripts({ - { "1", testDictionary1 } - }); + scheduler.loadScripts({ { "1", testDictionary1 } }); - auto res = scheduler.progressTo( - openspace::Time::convertTime("2000 JAN 03 10:00:00") - ); - ASSERT_EQ(res.first, res.second); + auto res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 03 10:00:00")); + REQUIRE(res.first == res.second); - res = scheduler.progressTo( - openspace::Time::convertTime("2000 JAN 03 11:00:00") - ); - ASSERT_EQ(res.first, res.second); + res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 03 11:00:00")); + REQUIRE(res.first == res.second); - res = scheduler.progressTo( - openspace::Time::convertTime("2000 JAN 03 13:00:00") - ); - ASSERT_EQ(1, std::distance(res.first, res.second)); - EXPECT_EQ("ForwardScript1", *(res.first)); + res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 03 13:00:00")); + REQUIRE(std::distance(res.first, res.second) == 1); + REQUIRE(*(res.first) == "ForwardScript1"); - res = scheduler.progressTo( - openspace::Time::convertTime("2000 JAN 03 12:30:00") - ); - ASSERT_EQ(res.first, res.second); + res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 03 12:30:00")); + REQUIRE(res.first == res.second); + + openspace::SpiceManager::deinitialize(); } -TEST_F(ScriptSchedulerTest, MultipleForwardSingleJumpMultipleLoad) { +TEST_CASE( + "ScriptScheduler: Multiple Forward Single Jump Multiple Load", + "[scriptscheduler]") +{ + openspace::SpiceManager::initialize(); + openspace::SpiceManager::ref().loadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/naif0008.tls") + ); + using namespace openspace::scripting; using namespace std::string_literals; @@ -512,27 +574,31 @@ TEST_F(ScriptSchedulerTest, MultipleForwardSingleJumpMultipleLoad) { ScriptScheduler scheduler; scheduler.progressTo(openspace::Time::convertTime("2000 JAN 01")); - scheduler.loadScripts({ - { "1", testDictionary1 } - }); + scheduler.loadScripts({ { "1", testDictionary1 } }); - scheduler.loadScripts({ - { "1", testDictionary2 } - }); + scheduler.loadScripts({ { "1", testDictionary2 } }); auto res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 02")); - ASSERT_EQ(res.first, res.second); + REQUIRE(res.first == res.second); res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 04")); - ASSERT_EQ(1, std::distance(res.first, res.second)); - EXPECT_EQ("ForwardScript1", *(res.first)); + REQUIRE(std::distance(res.first, res.second) == 1); + REQUIRE(*(res.first) == "ForwardScript1"); res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 06")); - ASSERT_EQ(1, std::distance(res.first, res.second)); - EXPECT_EQ("ForwardScript2", *(res.first)); + REQUIRE(std::distance(res.first, res.second) == 1); + REQUIRE(*(res.first) == "ForwardScript2"); + + openspace::SpiceManager::deinitialize(); } -TEST_F(ScriptSchedulerTest, MultipleForwardOrderingMultipleLoad) { +TEST_CASE("ScriptScheduler: Multiple Forward Ordering Multiple Load" "[scriptscheduler]") +{ + openspace::SpiceManager::initialize(); + openspace::SpiceManager::ref().loadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/naif0008.tls") + ); + using namespace openspace::scripting; using namespace std::string_literals; @@ -551,23 +617,29 @@ TEST_F(ScriptSchedulerTest, MultipleForwardOrderingMultipleLoad) { ScriptScheduler scheduler; scheduler.progressTo(openspace::Time::convertTime("2000 JAN 01")); - scheduler.loadScripts({ - { "1", testDictionary1 } - }); - scheduler.loadScripts({ - { "1", testDictionary2 } - }); + scheduler.loadScripts({ { "1", testDictionary1 } }); + scheduler.loadScripts({ { "1", testDictionary2 } }); auto res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 02")); - ASSERT_EQ(res.first, res.second); + REQUIRE(res.first == res.second); res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 06")); - ASSERT_EQ(2, std::distance(res.first, res.second)); - EXPECT_EQ("ForwardScript1", *(res.first)); - EXPECT_EQ("ForwardScript2", *(std::next(res.first))); + REQUIRE(std::distance(res.first, res.second) == 2); + REQUIRE(*(res.first) == "ForwardScript1"); + REQUIRE(*(std::next(res.first)) == "ForwardScript2"); + + openspace::SpiceManager::deinitialize(); } -TEST_F(ScriptSchedulerTest, MultipleBackwardSingleJumpMultipleLoad) { +TEST_CASE( + "ScriptScheduler: Multiple Backward Single Jump Multiple Load", + "[scriptscheduler]") +{ + openspace::SpiceManager::initialize(); + openspace::SpiceManager::ref().loadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/naif0008.tls") + ); + using namespace openspace::scripting; using namespace std::string_literals; @@ -586,26 +658,32 @@ TEST_F(ScriptSchedulerTest, MultipleBackwardSingleJumpMultipleLoad) { }; scheduler.progressTo(openspace::Time::convertTime("2000 JAN 07")); - scheduler.loadScripts({ - { "1", testDictionary1 } - }); - scheduler.loadScripts({ - { "1", testDictionary2 } - }); + scheduler.loadScripts({ { "1", testDictionary1 } }); + scheduler.loadScripts({ { "1", testDictionary2 } }); auto res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 06")); - ASSERT_EQ(res.first, res.second); + REQUIRE(res.first == res.second); res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 04")); - ASSERT_EQ(1, std::distance(res.first, res.second)); - EXPECT_EQ("BackwardScript2", *(res.first)); + REQUIRE(std::distance(res.first, res.second) == 1); + REQUIRE(*(res.first) == "BackwardScript2"); res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 01")); - ASSERT_EQ(1, std::distance(res.first, res.second)); - EXPECT_EQ("BackwardScript1", *(res.first)); + REQUIRE(std::distance(res.first, res.second) == 1); + REQUIRE(*(res.first) == "BackwardScript1"); + + openspace::SpiceManager::deinitialize(); } -TEST_F(ScriptSchedulerTest, MultipleBackwardOrderingMultipleLoad) { +TEST_CASE( + "ScriptScheduler: Multiple Backward Ordering Multiple Load", + "[scriptscheduler]") +{ + openspace::SpiceManager::initialize(); + openspace::SpiceManager::ref().loadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/naif0008.tls") + ); + using namespace openspace::scripting; using namespace std::string_literals; @@ -624,23 +702,27 @@ TEST_F(ScriptSchedulerTest, MultipleBackwardOrderingMultipleLoad) { }; scheduler.progressTo(openspace::Time::convertTime("2000 JAN 07")); - scheduler.loadScripts({ - { "1", testDictionary1 } - }); - scheduler.loadScripts({ - { "1", testDictionary2 } - }); + scheduler.loadScripts({ { "1", testDictionary1 } }); + scheduler.loadScripts({ { "1", testDictionary2 } }); - auto res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 06")); - ASSERT_EQ(res.first, res.second); + std::pair res = + scheduler.progressTo(openspace::Time::convertTime("2000 JAN 06")); + REQUIRE(res.first == res.second); res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 01")); - ASSERT_EQ(2, std::distance(res.first, res.second)); - EXPECT_EQ("BackwardScript2", *(res.first)); - EXPECT_EQ("BackwardScript1", *(std::next(res.first))); + REQUIRE(std::distance(res.first, res.second) == 2); + REQUIRE(*(res.first) == "BackwardScript2"); + REQUIRE(*(std::next(res.first)) == "BackwardScript1"); + + openspace::SpiceManager::deinitialize(); } -TEST_F(ScriptSchedulerTest, ForwardBackwardsMultipleLoad) { +TEST_CASE("ScriptScheduler: Forward Backwards Multiple Load", "[scriptscheduler]") { + openspace::SpiceManager::initialize(); + openspace::SpiceManager::ref().loadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/naif0008.tls") + ); + using namespace openspace::scripting; using namespace std::string_literals; @@ -659,30 +741,33 @@ TEST_F(ScriptSchedulerTest, ForwardBackwardsMultipleLoad) { }; scheduler.progressTo(openspace::Time::convertTime("2000 JAN 01")); - scheduler.loadScripts({ - { "1", testDictionary1 } - }); - scheduler.loadScripts({ - { "1", testDictionary2 } - }); + scheduler.loadScripts({ { "1", testDictionary1 } }); + scheduler.loadScripts({ { "1", testDictionary2 } }); auto res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 04")); - ASSERT_EQ(1, std::distance(res.first, res.second)); - EXPECT_EQ("ForwardScript1", *(res.first)); + REQUIRE(std::distance(res.first, res.second) == 1); + REQUIRE(*(res.first) == "ForwardScript1"); res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 01")); - ASSERT_EQ(1, std::distance(res.first, res.second)); - EXPECT_EQ("BackwardScript1", *(res.first)); + REQUIRE(std::distance(res.first, res.second) == 1); + REQUIRE(*(res.first) == "BackwardScript1"); res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 07")); - ASSERT_EQ(2, std::distance(res.first, res.second)); + REQUIRE(std::distance(res.first, res.second) == 2); res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 04")); - ASSERT_EQ(1, std::distance(res.first, res.second)); - EXPECT_EQ("BackwardScript2", *(res.first)); + REQUIRE(std::distance(res.first, res.second) == 1); + REQUIRE(*(res.first) == "BackwardScript2"); + + openspace::SpiceManager::deinitialize(); } -TEST_F(ScriptSchedulerTest, RewindMultipleLoad) { +TEST_CASE("ScriptScheduler: Rewind Multiple Load", "[scriptscheduler]") { + openspace::SpiceManager::initialize(); + openspace::SpiceManager::ref().loadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/naif0008.tls") + ); + using namespace openspace::scripting; using namespace std::string_literals; @@ -701,24 +786,27 @@ TEST_F(ScriptSchedulerTest, RewindMultipleLoad) { }; scheduler.progressTo(openspace::Time::convertTime("2000 JAN 01")); - scheduler.loadScripts({ - { "1", testDictionary1 } - }); - scheduler.loadScripts({ - { "1", testDictionary2 } - }); + scheduler.loadScripts({ { "1", testDictionary1 } }); + scheduler.loadScripts({ { "1", testDictionary2 } }); auto res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 07")); - ASSERT_EQ(2, std::distance(res.first, res.second)); + REQUIRE(std::distance(res.first, res.second) == 2); scheduler.rewind(); res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 04")); - ASSERT_EQ(1, std::distance(res.first, res.second)); - EXPECT_EQ("ForwardScript1", *(res.first)); + REQUIRE(std::distance(res.first, res.second) == 1); + REQUIRE(*(res.first) == "ForwardScript1"); + + openspace::SpiceManager::deinitialize(); } -TEST_F(ScriptSchedulerTest, AllScriptsMultipleLoad) { +TEST_CASE("ScriptScheduler: All Scripts Multiple Load", "[scriptscheduler]") { + openspace::SpiceManager::initialize(); + openspace::SpiceManager::ref().loadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/naif0008.tls") + ); + using namespace openspace::scripting; using namespace std::string_literals; @@ -743,26 +831,25 @@ TEST_F(ScriptSchedulerTest, AllScriptsMultipleLoad) { { "BackwardScript", "BackwardScript3"s } }; - scheduler.loadScripts({ - { "1", testDictionary1 } - }); - - scheduler.loadScripts({ - { "1", testDictionary2 } - }); - - scheduler.loadScripts({ - { "1", testDictionary3 } - }); + scheduler.loadScripts({ { "1", testDictionary1 } }); + scheduler.loadScripts({ { "1", testDictionary2 } }); + scheduler.loadScripts({ { "1", testDictionary3 } }); auto allScripts = scheduler.allScripts(); - ASSERT_EQ(3, allScripts.size()); + REQUIRE(allScripts.size() == 3); - EXPECT_LE(allScripts[0].time, allScripts[1].time); - EXPECT_LE(allScripts[1].time, allScripts[2].time); + REQUIRE(allScripts[0].time < allScripts[1].time); + REQUIRE(allScripts[1].time < allScripts[2].time); + + openspace::SpiceManager::deinitialize(); } -TEST_F(ScriptSchedulerTest, AllScriptsMixedLoad) { +TEST_CASE("ScriptScheduler: All Scripts Mixed Load", "[scriptscheduler]") { + openspace::SpiceManager::initialize(); + openspace::SpiceManager::ref().loadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/naif0008.tls") + ); + using namespace openspace::scripting; using namespace std::string_literals; @@ -787,18 +874,14 @@ TEST_F(ScriptSchedulerTest, AllScriptsMixedLoad) { { "BackwardScript", "BackwardScript3"s } }; - scheduler.loadScripts({ - { "1", testDictionary1 } - }); - - scheduler.loadScripts({ - { "1", testDictionary2 }, - { "2", testDictionary3 } - }); + scheduler.loadScripts({ { "1", testDictionary1 } }); + scheduler.loadScripts({ { "1", testDictionary2 }, { "2", testDictionary3 } }); auto allScripts = scheduler.allScripts(); - ASSERT_EQ(3, allScripts.size()); + REQUIRE(allScripts.size() == 3); - EXPECT_LE(allScripts[0].time, allScripts[1].time); - EXPECT_LE(allScripts[1].time, allScripts[2].time); + REQUIRE(allScripts[0].time < allScripts[1].time); + REQUIRE(allScripts[1].time < allScripts[2].time); + + openspace::SpiceManager::deinitialize(); } diff --git a/tests/test_spicemanager.cpp b/tests/test_spicemanager.cpp new file mode 100644 index 0000000000..33293ba2b0 --- /dev/null +++ b/tests/test_spicemanager.cpp @@ -0,0 +1,493 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2019 * + * * + * 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 "catch2/catch.hpp" + +#include +#include +#include "SpiceUsr.h" +#include "SpiceZpr.h" + +namespace { + constexpr const int FILLEN = 128; + constexpr const int TYPLEN = 32; + constexpr const int SRCLEN = 128; + + namespace spicemanager_constants { + SpiceInt handle; + char file[FILLEN], filtyp[TYPLEN], source[SRCLEN]; + } // namespace spicemanager_constants + + + + // In this testclass only a handset of the testfunctions require a single kernel. + // The remaining methods rely on multiple kernels, loaded as a SPICE 'meta-kernel' + void loadMetaKernel() { + const int k1 = openspace::SpiceManager::ref().loadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/naif0008.tls") + ); + REQUIRE(k1 == 1); + + const int k2 = openspace::SpiceManager::ref().loadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/cas00084.tsc") + ); + REQUIRE(k2 == 2); + + const int k3 = openspace::SpiceManager::ref().loadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/981005_PLTEPH-DE405S.bsp") + ); + REQUIRE(k3 == 3); + + const int k4 = openspace::SpiceManager::ref().loadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/020514_SE_SAT105.bsp") + ); + REQUIRE(k4 == 4); + + const int k5 = openspace::SpiceManager::ref().loadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/030201AP_SK_SM546_T45.bsp") + ); + REQUIRE(k5 == 5); + + const int k6 = openspace::SpiceManager::ref().loadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/cas_v37.tf") + ); + REQUIRE(k6 == 6); + + const int k7 = openspace::SpiceManager::ref().loadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/04135_04171pc_psiv2.bc") + ); + REQUIRE(k7 == 7); + + const int k8 = openspace::SpiceManager::ref().loadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/cpck05Mar2004.tpc") + ); + REQUIRE(k8 == 8); + + const int k9 = openspace::SpiceManager::ref().loadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/cas_iss_v09.ti") + ); + REQUIRE(k9 == 9); + } + + int loadLSKKernel() { + int kernelID = openspace::SpiceManager::ref().loadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/naif0008.tls") + ); + REQUIRE(kernelID == 1); + return kernelID; + } + + int loadPCKKernel() { + int kernelID = openspace::SpiceManager::ref().loadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/cpck05Mar2004.tpc") + ); + REQUIRE(kernelID == 1); + return kernelID; + } +} // namespace + +TEST_CASE("SpiceManager: Load Single Kernel", "[spicemanager]") { + openspace::SpiceManager::initialize(); + + loadLSKKernel(); + // naif0008.tls is a text file, check if loaded. + SpiceBoolean found; + kdata_c( + 0, + "text", + FILLEN, + TYPLEN, + SRCLEN, + spicemanager_constants::file, + spicemanager_constants::filtyp, + spicemanager_constants::source, + &spicemanager_constants::handle, + &found + ); + + REQUIRE(found == SPICETRUE); + + openspace::SpiceManager::deinitialize(); +} + +TEST_CASE("SpiceManager: Unload Kernel String", "[spicemanager]") { + openspace::SpiceManager::initialize(); + + loadLSKKernel(); + // naif0008.tls is a text file, check if loaded. + SpiceBoolean found; + kdata_c( + 0, + "text", + FILLEN, + TYPLEN, + SRCLEN, + spicemanager_constants::file, + spicemanager_constants::filtyp, + spicemanager_constants::source, + &spicemanager_constants::handle, + &found + ); + REQUIRE(found == SPICETRUE); + + // unload using string keyword + openspace::SpiceManager::ref().unloadKernel( + absPath("${TESTDIR}/SpiceTest/spicekernels/naif0008.tls") + ); + + found = SPICEFALSE; + kdata_c( + 0, + "text", + FILLEN, + TYPLEN, + SRCLEN, + spicemanager_constants::file, + spicemanager_constants::filtyp, + spicemanager_constants::source, + &spicemanager_constants::handle, + &found + ); + REQUIRE_FALSE(found == SPICETRUE); + + openspace::SpiceManager::deinitialize(); +} + +TEST_CASE("SpiceManager: Unload Kernel Integer", "[spicemanager]") { + openspace::SpiceManager::initialize(); + + int kernelID = loadLSKKernel(); + // naif0008.tls is a text file, check if loaded. + SpiceBoolean found; + kdata_c( + 0, + "text", + FILLEN, + TYPLEN, + SRCLEN, + spicemanager_constants::file, + spicemanager_constants::filtyp, + spicemanager_constants::source, + &spicemanager_constants::handle, + &found + ); + REQUIRE(found == SPICETRUE); + + // unload using unique int ID + openspace::SpiceManager::ref().unloadKernel(kernelID); + + found = SPICEFALSE; + kdata_c( + 0, + "text", + FILLEN, + TYPLEN, + SRCLEN, + spicemanager_constants::file, + spicemanager_constants::filtyp, + spicemanager_constants::source, + &spicemanager_constants::handle, + &found + ); + REQUIRE_FALSE(found == SPICETRUE); + + openspace::SpiceManager::deinitialize(); +} + +TEST_CASE("SpiceManager: Has Value", "[spicemanager]") { + openspace::SpiceManager::initialize(); + + loadPCKKernel(); + + int naifId = 399; // Earth + + std::string kernelPoolValue = "RADII"; + + const bool found = openspace::SpiceManager::ref().hasValue(naifId, kernelPoolValue); + REQUIRE(found); + + + openspace::SpiceManager::deinitialize(); +} + +TEST_CASE("SpiceManager: Get Value From ID 1D", "[spicemanager]") { + openspace::SpiceManager::initialize(); + + loadPCKKernel(); + + std::string target = "EARTH"; + std::string value1D = "MAG_NORTH_POLE_LAT"; + + double return1D; + REQUIRE_NOTHROW(openspace::SpiceManager::ref().getValue(target, value1D, return1D)); + REQUIRE(return1D == 78.565); + + openspace::SpiceManager::deinitialize(); +} + +TEST_CASE("SpiceManager: Get Value From ID 3D", "[spicemanager]") { + openspace::SpiceManager::initialize(); + + loadPCKKernel(); + + std::string target = "EARTH"; + std::string value3D = "RADII"; + + glm::dvec3 return3D = glm::dvec3(0.0); + REQUIRE_NOTHROW(openspace::SpiceManager::ref().getValue(target, value3D, return3D)); + + REQUIRE(return3D.x == 6378.14); + REQUIRE(return3D.y == 6378.14); + REQUIRE(return3D.z == 6356.75); + + openspace::SpiceManager::deinitialize(); +} + +TEST_CASE("SpiceManager: Get Value From ID ND", "[spicemanager]") { + openspace::SpiceManager::initialize(); + + loadPCKKernel(); + + std::string target = "SATURN"; + std::string valueND = "RING6_A"; + + std::vector returnND(5); + REQUIRE_NOTHROW(openspace::SpiceManager::ref().getValue(target, valueND, returnND)); + + std::vector controlVec{ 189870.0, 256900.0, 9000.0, 9000.0, 0.000003 }; + + REQUIRE(controlVec.size() == returnND.size()); + + for (unsigned int i = 0; i < returnND.size(); ++i){ + REQUIRE(controlVec[i] == returnND[i]); + } + + openspace::SpiceManager::deinitialize(); +} + +TEST_CASE("SpiceManager: String To Ephemeris Time", "[spicemanager]") { + openspace::SpiceManager::initialize(); + + loadLSKKernel(); + + double ephemerisTime; + double control_ephemerisTime; + char date[SRCLEN] = "Thu Mar 20 12:53:29 PST 1997"; + str2et_c(date, &control_ephemerisTime); + + REQUIRE_NOTHROW( + ephemerisTime = openspace::SpiceManager::ref().ephemerisTimeFromDate(date) + ); + + REQUIRE(ephemerisTime == control_ephemerisTime); + + openspace::SpiceManager::deinitialize(); +} + +TEST_CASE("SpiceManager: Get Target Position", "[spicemanager]") { + openspace::SpiceManager::initialize(); + + using openspace::SpiceManager; + loadMetaKernel(); + + double et = 0.0; + double pos[3] = { 0.0, 0.0, 0.0 }; + double lt = 0.0; + char utctime[SRCLEN] = "2004 jun 11 19:32:00"; + + str2et_c(utctime, &et); + spkpos_c("EARTH", et, "J2000", "LT+S", "CASSINI", pos, <); + + glm::dvec3 targetPosition =glm::dvec3(0.0); + double lightTime = 0.0; + SpiceManager::AberrationCorrection corr = { + SpiceManager::AberrationCorrection::Type::LightTimeStellar, + SpiceManager::AberrationCorrection::Direction::Reception + }; + + REQUIRE_NOTHROW(targetPosition = SpiceManager::ref().targetPosition( + "EARTH", "CASSINI", "J2000", corr, et, lightTime) + ); + REQUIRE(pos[0] == Approx(targetPosition[0])); + REQUIRE(pos[1] == Approx(targetPosition[1])); + REQUIRE(pos[2] == Approx(targetPosition[2])); + + openspace::SpiceManager::deinitialize(); +} + +TEST_CASE("SpiceManager: Get Target State", "[spicemanager]") { + openspace::SpiceManager::initialize(); + + using openspace::SpiceManager; + loadMetaKernel(); + + double et; + double state[6]; + double lt; + char utctime[SRCLEN] = "2004 jun 11 19:32:00"; + + str2et_c(utctime, &et); + spkezr_c("EARTH", et, "J2000", "LT+S", "CASSINI", state, <); + + SpiceManager::AberrationCorrection corr = { + SpiceManager::AberrationCorrection::Type::LightTimeStellar, + SpiceManager::AberrationCorrection::Direction::Reception + }; + + SpiceManager::TargetStateResult res; + REQUIRE_NOTHROW( + res = SpiceManager::ref().targetState("EARTH", "CASSINI", "J2000", corr, et) + ); + + // x,y,z + for (int i = 0; i < 3; i++){ + REQUIRE(state[i] == Approx(res.position[i])); + REQUIRE(state[i+3] == Approx(res.velocity[i])); + } + + openspace::SpiceManager::deinitialize(); +} + +TEST_CASE("SpiceManager: Transform matrix", "[spicemanager]") { + openspace::SpiceManager::initialize(); + + loadMetaKernel(); + + double et; + double state[6]; + double state_t[6]; + double lt; + double referenceMatrix[6][6]; + + str2et_c("2004 jun 11 19:32:00", &et); + spkezr_c("PHOEBE", et, "J2000", "LT+S", "CASSINI", state, <); + sxform_c("J2000", "IAU_PHOEBE", et, referenceMatrix); + + openspace::SpiceManager::TransformMatrix stateMatrix; + REQUIRE_NOTHROW( + stateMatrix = openspace::SpiceManager::ref().stateTransformMatrix( + "J2000", "IAU_PHOEBE", et) + ); + + // check for matrix consistency + for (int i = 0; i < 6; i++) { + for (int j = 0; j < 6; j++) { + REQUIRE(referenceMatrix[i][j] == Approx(stateMatrix[i * 6 + j])); + } + } + + openspace::SpiceManager::deinitialize(); +} + +TEST_CASE("SpiceManager: Get Position Transform Matrix", "[spicemanager]") { + openspace::SpiceManager::initialize(); + + using openspace::SpiceManager; + loadMetaKernel(); + + double et; + double state[3] = { 1.0, 1.0, 1.0 }; + double state_t[3]; + double referenceMatrix[3][3]; + + str2et_c("2004 jun 11 19:32:00", &et); + pxform_c("CASSINI_HGA", "J2000", et, referenceMatrix); + + glm::dmat3 positionMatrix = glm::dmat3(1.0); + glm::dvec3 position(state[0], state[1], state[2]); + REQUIRE_NOTHROW(positionMatrix = SpiceManager::ref().positionTransformMatrix( + "CASSINI_HGA", "J2000", et) + ); + + // check for matrix consistency + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + REQUIRE(referenceMatrix[i][j] == Approx(positionMatrix[j][i])); + } + } + +#if defined __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wold-style-cast" +#elif defined __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" +#endif + + // transform reference position into new frame + mxvg_c(referenceMatrix, state, 3, 3, state_t); + +#if defined __clang__ +#pragma clang diagnostic pop +#elif defined __GNUC__ +#pragma GCC diagnostic pop +#endif + + position = positionMatrix * position; + // check transformed values match + for (int i = 0; i < 3; i++) { + REQUIRE(position[i] == Approx(state_t[i])); + } + + openspace::SpiceManager::deinitialize(); +} + +TEST_CASE("SpiceManager: Get Field Of View", "[spicemanager]") { + openspace::SpiceManager::initialize(); + + using openspace::SpiceManager; + loadMetaKernel(); + + SpiceInt n; + SpiceInt cassini_ID; + double et; + double bounds_ref[5][3]; + char shape_ref[TYPLEN]; + char name_ref[FILLEN]; + double boresightVec[3]; + + str2et_c("2004 jun 11 19:32:00", &et); + SpiceBoolean found; + bodn2c_c("CASSINI_ISS_NAC", &cassini_ID, &found); + REQUIRE(found == SPICETRUE); + + getfov_c(cassini_ID, 5, TYPLEN, TYPLEN, shape_ref, name_ref, boresightVec, &n, bounds_ref); + + SpiceManager::FieldOfViewResult res; + + REQUIRE_NOTHROW(res = SpiceManager::ref().fieldOfView("CASSINI_ISS_NAC")); + + REQUIRE(found == SPICETRUE); + //check vectors have correct values + for (size_t i = 0; i < res.bounds.size(); i++) { + for (size_t j = 0; j < 3; j++) { + REQUIRE( + bounds_ref[i][j] == + Approx(res.bounds[i][static_cast(j)]) + ); + } + } + + openspace::SpiceManager::deinitialize(); +} diff --git a/tests/test_spicemanager.inl b/tests/test_spicemanager.inl deleted file mode 100644 index 619c6fb6b0..0000000000 --- a/tests/test_spicemanager.inl +++ /dev/null @@ -1,476 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2019 * - * * - * 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 - -#include "SpiceUsr.h" -#include "SpiceZpr.h" - -class SpiceManagerTest : public testing::Test { -protected: - void SetUp() override { - openspace::SpiceManager::initialize(); - } - - void TearDown() override { - openspace::SpiceManager::deinitialize(); - - } -}; - -//global constants -#define FILLEN 128 -#define TYPLEN 32 -#define SRCLEN 128 - -namespace spicemanager_constants { - const int nrMetaKernels = 9; - SpiceInt which, handle, count = 0; - char file[FILLEN], filtyp[TYPLEN], source[SRCLEN]; - double abs_error = 0.00001; -} // namespace spicemanager_constants - -// In this testclass only a handset of the testfunctions require a single kernel. -// The remaining methods rely on multiple kernels, loaded as a SPICE 'meta-kernel'. - -void loadMetaKernel() { - int k1 = openspace::SpiceManager::ref().loadKernel( - absPath("${TESTDIR}/SpiceTest/spicekernels/naif0008.tls") - ); - EXPECT_EQ(1, k1) << "loadKernel did not return proper id"; - - int k2 = openspace::SpiceManager::ref().loadKernel( - absPath("${TESTDIR}/SpiceTest/spicekernels/cas00084.tsc") - ); - EXPECT_EQ(2, k2) << "loadKernel did not return proper id"; - - int k3 = openspace::SpiceManager::ref().loadKernel( - absPath("${TESTDIR}/SpiceTest/spicekernels/981005_PLTEPH-DE405S.bsp") - ); - EXPECT_EQ(3, k3) << "loadKernel did not return proper id"; - - int k4 = openspace::SpiceManager::ref().loadKernel( - absPath("${TESTDIR}/SpiceTest/spicekernels/020514_SE_SAT105.bsp") - ); - EXPECT_EQ(4, k4) << "loadKernel did not return proper id"; - - int k5 = openspace::SpiceManager::ref().loadKernel( - absPath("${TESTDIR}/SpiceTest/spicekernels/030201AP_SK_SM546_T45.bsp") - ); - EXPECT_EQ(5, k5) << "loadKernel did not return proper id"; - - int k6 = openspace::SpiceManager::ref().loadKernel( - absPath("${TESTDIR}/SpiceTest/spicekernels/cas_v37.tf") - ); - EXPECT_EQ(6, k6) << "loadKernel did not return proper id"; - - int k7 = openspace::SpiceManager::ref().loadKernel( - absPath("${TESTDIR}/SpiceTest/spicekernels/04135_04171pc_psiv2.bc") - ); - EXPECT_EQ(7, k7) << "loadKernel did not return proper id"; - - int k8 = openspace::SpiceManager::ref().loadKernel( - absPath("${TESTDIR}/SpiceTest/spicekernels/cpck05Mar2004.tpc") - ); - EXPECT_EQ(8, k8) << "loadKernel did not return proper id"; - - int k9 = openspace::SpiceManager::ref().loadKernel( - absPath("${TESTDIR}/SpiceTest/spicekernels/cas_iss_v09.ti") - ); - EXPECT_EQ(9, k9) << "loadKernel did not return proper id"; -} - -#define LSK absPath("${TESTDIR}/SpiceTest/spicekernels/naif0008.tls") - -int loadLSKKernel() { - int kernelID = openspace::SpiceManager::ref().loadKernel( - LSK - ); - EXPECT_EQ(1, kernelID) << "loadKernel did not return proper id"; - return kernelID; -} - -#define PCK absPath("${TESTDIR}/SpiceTest/spicekernels/cpck05Mar2004.tpc") - -int loadPCKKernel() { - int kernelID = openspace::SpiceManager::ref().loadKernel( - PCK - ); - EXPECT_EQ(1, kernelID) << "loadKernel did not return proper id"; - return kernelID; -} - -std::string fileType(char type[]){ - std::string str(type); - return str; -} - -// Try loading single kernel -TEST_F(SpiceManagerTest, loadSingleKernel) { - loadLSKKernel(); - // naif0008.tls is a text file, check if loaded. - SpiceBoolean found; - kdata_c( - 0, - "text", - FILLEN, - TYPLEN, - SRCLEN, - spicemanager_constants::file, - spicemanager_constants::filtyp, - spicemanager_constants::source, - &spicemanager_constants::handle, - &found - ); - - ASSERT_TRUE(found == SPICETRUE) << "Kernel not loaded"; -} - -// Try unloading kernel using user assigned keyword -TEST_F(SpiceManagerTest, unloadKernelString) { - loadLSKKernel(); - // naif0008.tls is a text file, check if loaded. - SpiceBoolean found; - kdata_c( - 0, - "text", - FILLEN, - TYPLEN, - SRCLEN, - spicemanager_constants::file, - spicemanager_constants::filtyp, - spicemanager_constants::source, - &spicemanager_constants::handle, - &found - ); - ASSERT_TRUE(found == SPICETRUE); - - // unload using string keyword - openspace::SpiceManager::ref().unloadKernel(LSK); - - found = SPICEFALSE; - kdata_c( - 0, - "text", - FILLEN, - TYPLEN, - SRCLEN, - spicemanager_constants::file, - spicemanager_constants::filtyp, - spicemanager_constants::source, - &spicemanager_constants::handle, - &found - ); - EXPECT_FALSE(found == SPICETRUE); -} - -// Try unloading kernel using integer as ID -TEST_F(SpiceManagerTest, unloadKernelInteger) { - int kernelID = loadLSKKernel(); - // naif0008.tls is a text file, check if loaded. - SpiceBoolean found; - kdata_c( - 0, - "text", - FILLEN, - TYPLEN, - SRCLEN, - spicemanager_constants::file, - spicemanager_constants::filtyp, - spicemanager_constants::source, - &spicemanager_constants::handle, - &found - ); - ASSERT_TRUE(found == SPICETRUE); - - // unload using unique int ID - openspace::SpiceManager::ref().unloadKernel(kernelID); - - found = SPICEFALSE; - kdata_c( - 0, - "text", - FILLEN, - TYPLEN, - SRCLEN, - spicemanager_constants::file, - spicemanager_constants::filtyp, - spicemanager_constants::source, - &spicemanager_constants::handle, - &found - ); - EXPECT_FALSE(found == SPICETRUE) << "One or more kernels still present in kernel-pool"; -} - -// Attempt finding a value in kernelpool -TEST_F(SpiceManagerTest, hasValue) { - loadPCKKernel(); - - int naifId = 399; // Earth - - std::string kernelPoolValue = "RADII"; - - bool found = openspace::SpiceManager::ref().hasValue(naifId, kernelPoolValue); - ASSERT_TRUE(found) << "Could not find value for specified kernel"; -} - -// Get 1dim value from kernelpool -TEST_F(SpiceManagerTest, getValueFromID_1D) { - loadPCKKernel(); - - std::string target = "EARTH"; - std::string value1D = "MAG_NORTH_POLE_LAT"; - - double return1D; - ASSERT_NO_THROW(openspace::SpiceManager::ref().getValue(target, value1D, return1D)); - EXPECT_EQ(return1D, 78.565) << "Value not found / differs from expected return"; -} - -// Get 2dim value from kernelpool -TEST_F(SpiceManagerTest, getValueFromID_3D) { - loadPCKKernel(); - - std::string target = "EARTH"; - std::string value3D = "RADII"; - - glm::dvec3 return3D; - ASSERT_NO_THROW(openspace::SpiceManager::ref().getValue(target, value3D, return3D)); - - EXPECT_EQ(return3D.x, 6378.14) << "Value not found / differs from expected return"; - EXPECT_EQ(return3D.y, 6378.14) << "Value not found / differs from expected return"; - EXPECT_EQ(return3D.z, 6356.75) << "Value not found / differs from expected return"; -} - -// Get Ndim value from kernelpool -TEST_F(SpiceManagerTest, getValueFromID_ND) { - loadPCKKernel(); - - std::string target = "SATURN"; - std::string valueND = "RING6_A"; - - std::vector returnND(5); - ASSERT_NO_THROW(openspace::SpiceManager::ref().getValue(target, valueND, returnND)); - - std::vector controlVec{ 189870.0, 256900.0, 9000.0, 9000.0, 0.000003 }; - - ASSERT_EQ(controlVec.size(), returnND.size()) << "Vectors differ in size"; - - for (unsigned int i = 0; i < returnND.size(); ++i){ - EXPECT_EQ(controlVec[i], returnND[i]) << "Vector value not equal"; - } -} - -// Try converting string to Ephemeris time -TEST_F(SpiceManagerTest, stringToEphemerisTime) { - loadLSKKernel(); - - double ephemerisTime; - double control_ephemerisTime; - char date[SRCLEN] = "Thu Mar 20 12:53:29 PST 1997"; - str2et_c(date, &control_ephemerisTime); - - ASSERT_NO_THROW(ephemerisTime = openspace::SpiceManager::ref().ephemerisTimeFromDate(date)); - - EXPECT_EQ(ephemerisTime, control_ephemerisTime) << "Ephemeries times differ / not found"; -} - -// Try getting positional vector of target -TEST_F(SpiceManagerTest, getTargetPosition) { - using openspace::SpiceManager; - loadMetaKernel(); - - double et; - double pos[3]; - double lt; - char utctime[SRCLEN] = "2004 jun 11 19:32:00"; - - str2et_c(utctime, &et); - spkpos_c("EARTH", et, "J2000", "LT+S", "CASSINI", pos, <); - - glm::dvec3 targetPosition; - double lightTime = 0.0; - SpiceManager::AberrationCorrection corr = { - SpiceManager::AberrationCorrection::Type::LightTimeStellar, - SpiceManager::AberrationCorrection::Direction::Reception - }; - - ASSERT_NO_THROW(targetPosition = SpiceManager::ref().targetPosition( - "EARTH", "CASSINI", "J2000", corr, et, lightTime) - ); - EXPECT_DOUBLE_EQ(pos[0], targetPosition[0]) << "Position not found or differs from expected return"; - EXPECT_DOUBLE_EQ(pos[1], targetPosition[1]) << "Position not found or differs from expected return"; - EXPECT_DOUBLE_EQ(pos[2], targetPosition[2]) << "Position not found or differs from expected return"; -} - -// Try getting position & velocity vectors of target -TEST_F(SpiceManagerTest, getTargetState) { - using openspace::SpiceManager; - loadMetaKernel(); - - double et; - double state[6]; - double lt; - char utctime[SRCLEN] = "2004 jun 11 19:32:00"; - - str2et_c(utctime, &et); - spkezr_c("EARTH", et, "J2000", "LT+S", "CASSINI", state, <); - - SpiceManager::AberrationCorrection corr = { - SpiceManager::AberrationCorrection::Type::LightTimeStellar, - SpiceManager::AberrationCorrection::Direction::Reception - }; - - SpiceManager::TargetStateResult res; - ASSERT_NO_THROW(res = SpiceManager::ref().targetState("EARTH", "CASSINI", "J2000", corr, et)); - - // x,y,z - for (int i = 0; i < 3; i++){ - EXPECT_DOUBLE_EQ(state[i], res.position[i]) << "Position not found or differs from expected return"; - EXPECT_DOUBLE_EQ(state[i+3], res.velocity[i]) << "Velocity not found or differs from expected return"; - } -} - -// Try getting transformation matrix and transform position and velocity into new reference frame -//TEST_F(SpiceManagerTest, getStateTransformMatrix) { -// loadMetaKernel(); -// -// double et; -// double state[6]; -// double state_t[6]; -// double lt; -// double referenceMatrix[6][6]; -// -// str2et_c("2004 jun 11 19:32:00", &et); -// spkezr_c("PHOEBE", et, "J2000", "LT+S", "CASSINI", state, <); -// sxform_c("J2000", "IAU_PHOEBE", et, referenceMatrix); -// -// glm::dvec3 position(state[0], state[1], state[2]); -// glm::dvec3 velocity(state[3], state[4], state[5]); -// -// openspace::SpiceManager::TransformMatrix stateMatrix; -// ASSERT_NO_THROW(stateMatrix = openspace::SpiceManager::ref().stateTransformMatrix( -// "J2000", "IAU_PHOEBE", et)); -// -// // check for matrix consistency -// for (int i = 0; i < 6; i++) { -// for (int j = 0; j < 6; j++) { -// EXPECT_DOUBLE_EQ(referenceMatrix[i][j], stateMatrix[i * 6 + j]) << "State-matrix not set or has wrong values"; -// } -// } -// mxvg_c(referenceMatrix, state, 6, 6, state_t); -// -// -// for (int i = 0; i < 3; i++) { -// EXPECT_DOUBLE_EQ(position[i], state_t[i]) << "Position vector differs from its reference"; -// EXPECT_DOUBLE_EQ(velocity[i], state_t[i + 3]) << "Velocity vector differs from its reference"; -// } -//} - -// Try getting transformation matrix and transform the position only into new reference frame -TEST_F(SpiceManagerTest, getPositionTransformMatrix) { - using openspace::SpiceManager; - loadMetaKernel(); - - double et; - double state[3] = { 1.0, 1.0, 1.0 }; - double state_t[3]; - double referenceMatrix[3][3]; - - str2et_c("2004 jun 11 19:32:00", &et); - pxform_c("CASSINI_HGA", "J2000", et, referenceMatrix); - - glm::dmat3 positionMatrix; - glm::dvec3 position(state[0], state[1], state[2]); - ASSERT_NO_THROW(positionMatrix = SpiceManager::ref().positionTransformMatrix( - "CASSINI_HGA", "J2000", et) - ); - - // check for matrix consistency - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 3; j++) { - EXPECT_DOUBLE_EQ(referenceMatrix[i][j], positionMatrix[j][i]) << "Position-matrix not set or has wrong values"; - } - } - -#if defined __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wold-style-cast" -#elif defined __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wold-style-cast" -#endif - - // transform reference position into new frame - mxvg_c(referenceMatrix, state, 3, 3, state_t); - -#if defined __clang__ -#pragma clang diagnostic pop -#elif defined __GNUC__ -#pragma GCC diagnostic pop -#endif - - position = positionMatrix * position; - // check transformed values match - for (int i = 0; i < 3; i++) { - EXPECT_DOUBLE_EQ(position[i], state_t[i]) << "Position vector differs from its reference"; - } -} - -// Try to get boresight vector and instrument field of view boundary vectors -TEST_F(SpiceManagerTest, getFieldOfView) { - using openspace::SpiceManager; - loadMetaKernel(); - - SpiceInt n; - SpiceInt cassini_ID; - double et; - double bounds_ref[5][3]; - char shape_ref[TYPLEN]; - char name_ref[FILLEN]; - double boresightVec[3]; - - str2et_c("2004 jun 11 19:32:00", &et); - SpiceBoolean found; - bodn2c_c("CASSINI_ISS_NAC", &cassini_ID, &found); - ASSERT_TRUE(found == SPICETRUE) << "Cannot locate ID for Cassini"; - - getfov_c(cassini_ID, 5, TYPLEN, TYPLEN, shape_ref, name_ref, boresightVec, &n, bounds_ref); - - SpiceManager::FieldOfViewResult res; - - ASSERT_NO_THROW(res = SpiceManager::ref().fieldOfView("CASSINI_ISS_NAC")); - - ASSERT_TRUE(found == SPICETRUE); - //check vectors have correct values - for (size_t i = 0; i < res.bounds.size(); i++) { - for (size_t j = 0; j < 3; j++) { - EXPECT_DOUBLE_EQ( - bounds_ref[i][j], - res.bounds[i][static_cast(j)] - ) << "One or more Field of View Boundary vectors differ from expected output"; - } - } -} diff --git a/tests/test_ellipsoid.inl b/tests/test_temporaltileprovider.cpp similarity index 83% rename from tests/test_ellipsoid.inl rename to tests/test_temporaltileprovider.cpp index 05c283da28..fcee4fd269 100644 --- a/tests/test_ellipsoid.inl +++ b/tests/test_temporaltileprovider.cpp @@ -22,22 +22,14 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include -#include +#include "catch2/catch.hpp" -#define _USE_MATH_DEFINES -#include +#include +#include #include -class EllipsoidTest : public testing::Test {}; +namespace { + constexpr const char* fileName = "data/scene/debugglobe/map_service_configs/" + "VIIRS_SNPP_CorrectedReflectance_TrueColor_temporal.xml"; +} // namespace -using namespace openspace; - -TEST_F(EllipsoidTest, GeodeticSurfaceNormal) { - Ellipsoid ellipsoid(Vec3(1, 1, 1)); - - Vec3 geodeticNormal = ellipsoid.geodeticSurfaceNormal(Vec3(0, 0, 1)); - Vec3 expectedNormal = Vec3(0, 0, 1); - - ASSERT_EQ(geodeticNormal, expectedNormal); -} diff --git a/tests/test_timeline.inl b/tests/test_timeline.cpp similarity index 71% rename from tests/test_timeline.inl rename to tests/test_timeline.cpp index 61f3e600d6..cd25f0589b 100644 --- a/tests/test_timeline.inl +++ b/tests/test_timeline.cpp @@ -22,60 +22,61 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ +#include "catch2/catch.hpp" + #include #include -class TimelineTest : public testing::Test {}; - -TEST_F(TimelineTest, AddAndCountKeyframes) { +TEST_CASE("TimeLine: Add and Count Keyframes", "[timeline]") { openspace::Timeline timeline; timeline.addKeyframe(0.0, openspace::Time::now()); timeline.addKeyframe(1.0, openspace::Time::now()); - ASSERT_EQ(timeline.nKeyframes(), 2); + REQUIRE(timeline.nKeyframes() == 2); + } -TEST_F(TimelineTest, QueryKeyframes) { +TEST_CASE("TimeLine: Query Keyframes", "[timeline]") { openspace::Timeline timeline; timeline.addKeyframe(0.0, 0.f); timeline.addKeyframe(1.0, 1.f); - ASSERT_EQ(timeline.nKeyframes(), 2); + REQUIRE(timeline.nKeyframes() == 2); - ASSERT_EQ(timeline.firstKeyframeAfter(0.0)->data, 1.f) << "Incorrect keyframe returned"; - ASSERT_EQ(timeline.firstKeyframeAfter(0.0, false)->data, 1.f) << "Incorrect keyframe returned"; - ASSERT_EQ(timeline.firstKeyframeAfter(0.0, true)->data, 0.f) << "Incorrect keyframe returned"; + REQUIRE(timeline.firstKeyframeAfter(0.0)->data == Approx(1.f)); + REQUIRE(timeline.firstKeyframeAfter(0.0, false)->data == Approx(1.f)); + REQUIRE(timeline.firstKeyframeAfter(0.0, true)->data == Approx(0.f)); - ASSERT_EQ(timeline.lastKeyframeBefore(1.0)->data, 0.f) << "Incorrect keyframe returned"; - ASSERT_EQ(timeline.lastKeyframeBefore(1.0, false)->data, 0.f) << "Incorrect keyframe returned"; - ASSERT_EQ(timeline.lastKeyframeBefore(1.0, true)->data, 1.f) << "Incorrect keyframe returned"; + REQUIRE(timeline.lastKeyframeBefore(1.0)->data == Approx(0.f)); + REQUIRE(timeline.lastKeyframeBefore(1.0, false)->data == Approx(0.f)); + REQUIRE(timeline.lastKeyframeBefore(1.0, true)->data == Approx(1.f)); } -TEST_F(TimelineTest, RemoveKeyframes) { +TEST_CASE("TimeLine: Remove Keyframes", "[timeline]") { openspace::Timeline timeline; timeline.addKeyframe(0.0, 0.f); timeline.addKeyframe(1.0, 1.f); timeline.removeKeyframesBefore(0.0); - ASSERT_EQ(timeline.nKeyframes(), 2); + REQUIRE(timeline.nKeyframes() == 2); timeline.removeKeyframesBefore(0.0, false); - ASSERT_EQ(timeline.nKeyframes(), 2); + REQUIRE(timeline.nKeyframes() == 2); timeline.removeKeyframesBefore(0.0, true); - ASSERT_EQ(timeline.nKeyframes(), 1); + REQUIRE(timeline.nKeyframes() == 1); timeline.removeKeyframesAfter(1.0); - ASSERT_EQ(timeline.nKeyframes(), 1); + REQUIRE(timeline.nKeyframes() == 1); timeline.removeKeyframesAfter(1.0, false); - ASSERT_EQ(timeline.nKeyframes(), 1); + REQUIRE(timeline.nKeyframes() == 1); timeline.removeKeyframesAfter(1.0, true); - ASSERT_EQ(timeline.nKeyframes(), 0); + REQUIRE(timeline.nKeyframes() == 0); } -TEST_F(TimelineTest, RemoveKeyframesInRange) { +TEST_CASE("TimeLine: Remove Keyframes In Range", "[timeline]") { openspace::Timeline timeline; timeline.addKeyframe(0.0, 0.f); timeline.addKeyframe(1.0, 1.f); @@ -83,14 +84,14 @@ TEST_F(TimelineTest, RemoveKeyframesInRange) { timeline.addKeyframe(3.0, 3.f); timeline.removeKeyframesBetween(1.0, 2.0); - ASSERT_EQ(timeline.nKeyframes(), 4); + REQUIRE(timeline.nKeyframes() == 4); timeline.removeKeyframesBetween(1.0, 2.0, false, true); - ASSERT_EQ(timeline.nKeyframes(), 3); + REQUIRE(timeline.nKeyframes() == 3); timeline.removeKeyframesBetween(1.0, 2.0, true, true); - ASSERT_EQ(timeline.nKeyframes(), 2); + REQUIRE(timeline.nKeyframes() == 2); timeline.removeKeyframesBetween(-1.0, 4.0); - ASSERT_EQ(timeline.nKeyframes(), 0); + REQUIRE(timeline.nKeyframes() == 0); } diff --git a/tests/tinyvolume.rawvolume b/tests/tinyvolume.rawvolume new file mode 100644 index 0000000000000000000000000000000000000000..2c7d7c4dad3fb608f3de6737d969277dfab5ead5 GIT binary patch literal 4 LcmZQzV6X=O07C#k literal 0 HcmV?d00001