Commit 8f813606 authored by Alexander Bock's avatar Alexander Bock
Browse files

Move the OpenSpace unit tests from GTest to Catch2

Fix for default.scene
parent f6507b9b
Showing with 3459 additions and 1929 deletions
+3459 -1929
......@@ -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 ()
......
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()
......
......@@ -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")
......
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
##########################################################################################
# #
# 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")
File added
......@@ -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 <openspace/engine/configuration.h>
#include <openspace/engine/globals.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/engine/windowdelegate.h>
#include <openspace/util/factorymanager.h>
#include <openspace/util/spicemanager.h>
#include <openspace/util/time.h>
#include <ghoul/filesystem/file.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/lua/ghoul_lua.h>
#include <ghoul/misc/dictionary.h>
#include <ghoul/ghoul.h>
#include <iostream>
#include <test_common.inl>
#include <test_assetloader.inl>
#include <test_documentation.inl>
#include <test_luaconversions.inl>
#include <test_optionproperty.inl>
#include <test_scriptscheduler.inl>
#include <test_spicemanager.inl>
#include <test_timeline.inl>
#ifdef OPENSPACE_MODULE_GLOBEBROWSING_ENABLED
#include <test_angle.inl>
#include <test_concurrentjobmanager.inl>
#include <test_concurrentqueue.inl>
#include <test_lrucache.inl>
#include <test_gdalwms.inl>
#endif
#ifdef OPENSPACE_MODULE_ISWA_ENABLED
#include <test_screenspaceimage.inl>
#endif
#ifdef OPENSPACE_MODULE_VOLUME_ENABLED
#include <test_rawvolumeio.inl>
#endif
// Regression tests
#include <regression/517.inl>
using namespace ghoul::filesystem;
using namespace ghoul::logging;
//#define PRINT_OUTPUT
namespace {
std::string _loggerCat = "OpenSpaceTest";
}
int main(int argc, char** argv) {
std::vector<std::string> args;
// Workaround for Visual Studio Google Test Adapter:
// Do not try to initialize osengine if gtest is just listing tests
std::vector<std::string> gtestArgs(argv, argv + argc);
if (std::find(gtestArgs.begin(), gtestArgs.end(), "--gtest_list_tests") != gtestArgs.end()) {
using namespace openspace;
ghoul::initialize();
std::string configFile = configuration::findConfiguration();
global::configuration = configuration::loadConfigurationFromFile(configFile);
global::openSpaceEngine.initialize();
FileSys.registerPathToken("${TESTDIR}", "${BASE}/tests");
using namespace openspace;
ghoul::initialize();
// All of the relevant tests initialize the SpiceManager
openspace::SpiceManager::deinitialize();
}
// 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
);
testing::InitGoogleTest(&argc, argv);
std::string configFile = configuration::findConfiguration();
global::configuration = configuration::loadConfigurationFromFile(configFile);
global::openSpaceEngine.registerPathTokens();
global::openSpaceEngine.initialize();
#ifdef PRINT_OUTPUT
testing::internal::CaptureStdout();
testing::internal::CaptureStderr();
#endif
FileSys.registerPathToken("${TESTDIR}", "${BASE}/tests");
#ifdef PRINT_OUTPUT
// All of the relevant tests initialize the SpiceManager
openspace::SpiceManager::deinitialize();
// Stop capturing std out
std::string output = testing::internal::GetCapturedStdout();
std::string error = testing::internal::GetCapturedStderr();
int result = Catch::Session().run(argc, argv);
//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__
......@@ -22,20 +22,20 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <openspace/properties/optionproperty.h>
#include "catch2/catch.hpp"
class Issue527 : public testing::Test {};
#include <openspace/properties/optionproperty.h>
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");
}
/*****************************************************************************************
* *
* 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 <openspace/scene/scenegraphnode.h>
//#include <modules/globebrowsing/geometry/angle.h>
//
//#include <fstream>
//#include <glm/glm.hpp>
//
//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<double>()) << "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<float>()) << "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]";
//}
......@@ -22,127 +22,90 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include "gtest/gtest.h"
#include "catch2/catch.hpp"
#include <openspace/documentation/documentation.h>
#include <openspace/engine/globals.h>
#include <openspace/engine/windowdelegate.h>
#include <openspace/scene/assetloader.h>
#include <openspace/scene/asset.h>
#include <openspace/scene/scene.h>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/scene/sceneinitializer.h>
#include <openspace/scripting/scriptengine.h>
#include <openspace/util/synchronizationwatcher.h>
#include <openspace/documentation/documentation.h>
#include <openspace/scene/scene.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/lua/lua_helper.h>
#include <fstream>
#include <ghoul/misc/dictionaryluaformatter.h>
#include <ghoul/filesystem/filesystem.h>
#include <exception>
#include <memory>
#include <openspace/engine/globals.h>
//#include <openspace/engine/openspaceengine.h>
#include <openspace/engine/windowdelegate.h>
class AssetLoaderTest;
namespace {
int passTest(lua_State* state);
}
class AssetLoaderTest : public ::testing::Test {
public:
void pass() {
_passedTest = true;
}
bool passed() {
return _passedTest;
}
protected:
virtual void SetUp() {
_scene = std::make_unique<openspace::Scene>(
std::make_unique<openspace::SingleThreadedSceneInitializer>()
);
ghoul::lua::LuaState* state = openspace::global::scriptEngine.luaState();
openspace::global::scriptEngine.initialize();
_syncWatcher = std::make_unique<openspace::SynchronizationWatcher>();
_assetLoader = std::make_unique<openspace::AssetLoader>(
*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<openspace::Scene> _scene;
std::unique_ptr<openspace::AssetLoader> _assetLoader;
std::unique_ptr<openspace::SynchronizationWatcher> _syncWatcher;
bool _passedTest;
};
namespace {
int passTest(lua_State* state) {
AssetLoaderTest *test =
reinterpret_cast<AssetLoaderTest*>(lua_touserdata(state, lua_upvalueindex(1)));
test->pass();
return 0;
}
}
TEST_F(AssetLoaderTest, Assertions) {
EXPECT_NO_THROW(_assetLoader->add("passassertion"));
EXPECT_NO_THROW(_assetLoader->add("failassertion"));
}
TEST_F(AssetLoaderTest, BasicExportImport) {
try {
_assetLoader->add("require");
}
catch (const std::exception& e) {
EXPECT_TRUE(false) << e.what();
int passTest(lua_State* state) {
bool* test = reinterpret_cast<bool*>(lua_touserdata(state, lua_upvalueindex(1)));
*test = true;
return 0;
}
} // namespace
TEST_CASE("AssetLoader: Assertion", "[assetloader]") {
openspace::Scene scene(std::make_unique<openspace::SingleThreadedSceneInitializer>());
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"));
}
TEST_F(AssetLoaderTest, AssetFunctions) {
try {
_assetLoader->add("assetfunctionsexist");
} catch (const std::exception& e) {
EXPECT_TRUE(false) << e.what();
}
TEST_CASE("AssetLoader: Basic Export Import", "[assetloader]") {
openspace::Scene scene(std::make_unique<openspace::SingleThreadedSceneInitializer>());
ghoul::lua::LuaState* state = openspace::global::scriptEngine.luaState();
openspace::SynchronizationWatcher syncWatcher;
openspace::AssetLoader assetLoader(
*state,
&syncWatcher,
FileSys.absolutePath("${TESTDIR}/AssetLoaderTest/")
);
REQUIRE_NOTHROW(assetLoader.add("require"));
}
TEST_F(AssetLoaderTest, DependencyFunctions) {
try {
_assetLoader->add("dependencyfunctionsexist");
}
catch (const std::exception& e) {
EXPECT_TRUE(false) << e.what();
}
TEST_CASE("AssetLoader: Asset Functions", "[assetloader]") {
openspace::Scene scene(std::make_unique<openspace::SingleThreadedSceneInitializer>());
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, AssetInitialization) {
try {
std::shared_ptr<openspace::Asset> asset = _assetLoader->add("initialization");
asset->initialize();
EXPECT_TRUE(passed());
}
catch (const std::exception& e) {
EXPECT_TRUE(false) << e.what();
}
TEST_CASE("AssetLoader: Asset Initialization", "[assetloader]") {
openspace::Scene scene(std::make_unique<openspace::SingleThreadedSceneInitializer>());
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<openspace::Asset> asset = assetLoader.add("initialization");
REQUIRE_NOTHROW(asset->initialize());
REQUIRE(passed);
}
/*****************************************************************************************
* *
* 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 <openspace/scene/scenegraphnode.h>
#include <modules/globebrowsing/globes/chunkedlodglobe.h>
#include <modules/globebrowsing/globes/chunknode.h>
#include <fstream>
#include <glm/glm.hpp>
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
/*****************************************************************************************
* *
* 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 <chrono>
#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
......@@ -22,44 +22,64 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include "gtest/gtest.h"
#include "catch2/catch.hpp"
#include <openspace/util/concurrentjobmanager.h>
#include <ghoul/misc/threadpool.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <glm/glm.hpp>
class ConcurrentJobManagerTest : public testing::Test {};
namespace {
struct TestJob : public openspace::Job<int> {
TestJob(int jobExecutingTime)
: _jobExecutingTime(jobExecutingTime)
{}
struct TestJob : public openspace::Job<int> {
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);
}
private:
int _jobExecutingTime;
int prod;
};
struct VerboseProduct {
VerboseProduct(int v) : val(v) {}
~VerboseProduct() {}
int val;
};
virtual int product() {
return int(prod);
}
private:
int _jobExecutingTime;
int prod;
};
struct VerboseJob : public openspace::Job<VerboseProduct> {
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;
}
TEST_F(ConcurrentJobManagerTest, Basic) {
int _jobExecutingTime;
VerboseProduct _product;
};
} // namespace
TEST_CASE("ConcurrentJobmanager: Basic", "[concurrentjobmanager]") {
using namespace openspace;
ConcurrentJobManager<int> 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";
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() == 1);
std::this_thread::sleep_for(std::chrono::milliseconds(20));
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<VerboseProduct> {
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<VerboseProduct> jobManager(ThreadPool(1));
auto testJob1 = std::shared_ptr<VerboseJob>(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();
{
......
......@@ -22,32 +22,15 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include "gtest/gtest.h"
#include "catch2/catch.hpp"
#include <openspace/util/concurrentqueue.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <glm/glm.hpp>
class ConcurrentQueueTest : public testing::Test {};
TEST_F(ConcurrentQueueTest, Basic) {
TEST_CASE("ConcurrentQueue: Basic", "[concurrentqueue]") {
using namespace openspace;
ConcurrentQueue<int> q1;
q1.push(4);
int val = q1.pop();
std::cout << val << std::endl;
}
/*
TEST_F(ConcurrentQueueTest, SharedPtr) {
ConcurrentQueue<std::shared_ptr<int>> q1;
std::shared_ptr<int> i1 = std::shared_ptr<int>(new int(1337));
q1.push(i1);
auto val = q1.pop();
std::cout << *val << std::endl;
REQUIRE(val == 4);
}
*/
This diff is collapsed.
/*****************************************************************************************
* *
* 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 <ogr_spatialref.h>
#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";
}
......@@ -22,25 +22,21 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <modules/globebrowsing/other/temporaltileprovider.h>
#ifdef OPENSPACE_MODULE_ISWA_ENABLED
#include <openspace/util/time.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <glm/glm.hpp>
#include <iostream>
#include "catch2/catch.hpp"
#include <modules/iswa/util/iswamanager.h>
#include <openspace/engine/downloadmanager.h>
#include <openspace/util/time.h>
class TemporalTileProviderTest : public testing::Test {};
std::string fileName = "data/scene/debugglobe/map_service_configs/VIIRS_SNPP_CorrectedReflectance_TrueColor_temporal.xml";
TEST_CASE("ISWAManager: Initialize", "[iswamanager]") {
openspace::IswaManager::deinitialize();
REQUIRE_FALSE(openspace::IswaManager::isInitialized());
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
/*****************************************************************************************
* *
* 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 <modules/iswa/util/iswamanager.h>
#define private private
#include <openspace/engine/downloadmanager.h>
#include <openspace/util/time.h>
/*
* 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
......@@ -22,146 +22,121 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <modules/globebrowsing/geodetics/geodetic2.h>
#include "catch2/catch.hpp"
#define _USE_MATH_DEFINES
#include <math.h>
#include <glm/glm.hpp>
#include <modules/globebrowsing/src/basictypes.h>
#include <modules/globebrowsing/src/geodeticpatch.h>
#include <ghoul/glm.h>
class LatLonPatchTest : public testing::Test {};
using namespace openspace;
TEST_F(LatLonPatchTest, findCenterControlPoint) {
GeodeticPatch patch(0, 0, M_PI / 4, M_PI / 4);
TEST_CASE("LatLonPatch: findCenterControlPoint", "[latlonpatch]") {
using namespace openspace::globebrowsing;
GeodeticPatch patch(0, 0, glm::pi<float>() / 4.f, glm::pi<float>() / 4.f);
}
TEST_CASE("LatLonPatch: Find Closest Corner", "[latlonpatch]") {
using namespace openspace::globebrowsing;
constexpr float piOver4 = glm::pi<float>() / 4.f;
Geodetic2 halfSize { piOver4, piOver4 };
Geodetic2 center { 0, 0 };
GeodeticPatch patch(center, halfSize);
TEST_F(LatLonPatchTest, TestFindClosestCorner) {
Scalar piOver4 = M_PI / 4;
Geodetic2 halfSize(piOver4, piOver4);
Geodetic2 center(0, 0);
GeodeticPatch patch(center, halfSize);
constexpr float piOver3 = glm::pi<float>() / 3.f;
Geodetic2 point { piOver3, piOver3 };
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);
Geodetic2 closestCorner = patch.closestCorner(point);
Geodetic2 northEastCorner = patch.corner(NORTH_EAST);
REQUIRE(closestCorner.lat == northEastCorner.lat);
REQUIRE(closestCorner.lon == northEastCorner.lon);
}
TEST_F(LatLonPatchTest, TestFindClosestCorner2) {
Scalar piOver6 = M_PI / 4;
Scalar piOver3 = M_PI / 3;
TEST_CASE("LatLonPatch: Find Closest Corner 2", "[latlonpatch]") {
using namespace openspace::globebrowsing;
Geodetic2 halfSize(1.1*piOver6, 1.1*piOver6);
Geodetic2 center(piOver6, piOver6);
GeodeticPatch patch(center, halfSize);
constexpr float piOver6 = glm::pi<float>() / 4.f;
Geodetic2 point(0, 0);
Geodetic2 halfSize { 1.1 * piOver6, 1.1 * piOver6 };
Geodetic2 center { piOver6, piOver6 };
GeodeticPatch patch(center, halfSize);
Geodetic2 closestCorner = patch.closestCorner(point);
Geodetic2 expectedCorner = patch.southWestCorner();
Geodetic2 point { 0, 0 };
ASSERT_EQ(closestCorner.lat, expectedCorner.lat);
ASSERT_EQ(closestCorner.lon, expectedCorner.lon);
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;
TEST_F(LatLonPatchTest, TestSphericalClamp1) {
GeodeticPatch patch(0, 0, M_PI / 4, M_PI / 4);
GeodeticPatch patch(0, 0, glm::pi<float>() / 4.f, glm::pi<float>() / 4.f);
// inside patch latitude-wise, east of patch longitude-wise
Geodetic2 point(M_PI / 6, M_PI - 0.01);
// inside patch latitude-wise, east of patch longitude-wise
Geodetic2 point { glm::pi<double>() / 6.0, glm::pi<double>() / 4.0 - 0.01 };
Geodetic2 clampedPoint = patch.closestPoint(point);
Geodetic2 neCorner = patch.northEastCorner();
ASSERT_EQ(clampedPoint.lat, neCorner.lat);
ASSERT_EQ(clampedPoint.lon, neCorner.lon);
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;
TEST_F(LatLonPatchTest, TestSphericalClamp2) {
GeodeticPatch patch(0, 0, M_PI / 4, M_PI / 4);
GeodeticPatch patch(0, 0, glm::pi<float>() / 4.f, glm::pi<float>() / 4.f);
// inside patch latitude-wise, west of patch longitude-wise
Geodetic2 point(M_PI / 6, M_PI + 0.01);
// inside patch latitude-wise, west of patch longitude-wise
Geodetic2 point { glm::pi<double>() / 6.0, glm::pi<double>() / 4.0 + 0.01 };
Geodetic2 clampedPoint = patch.closestPoint(point);
Geodetic2 nwCorner = patch.northWestCorner();
ASSERT_EQ(clampedPoint.lat, nwCorner.lat);
ASSERT_EQ(clampedPoint.lon, nwCorner.lon);
Geodetic2 clampedPoint = patch.closestPoint(point);
Geodetic2 nwCorner = patch.corner(NORTH_WEST);
//REQUIRE(clampedPoint.lat == nwCorner.lat);
//REQUIRE(clampedPoint.lon == nwCorner.lon);
}
TEST_F(LatLonPatchTest, TestSphericalClamp3) {
GeodeticPatch patch(0, 0, M_PI / 4, M_PI / 4);
TEST_CASE("LatLonPatch: Spherical Clamp 3", "[latlonpatch]") {
using namespace openspace::globebrowsing;
// North east of patch
Geodetic2 point(M_PI / 3, M_PI - 0.01);
GeodeticPatch patch(0, 0, glm::pi<float>() / 4.f, glm::pi<float>() / 4.f);
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);
// North east of patch
Geodetic2 point { glm::pi<double>() / 3.0, glm::pi<double>() / 4.0 - 0.01 };
Geodetic2 clampedPoint = patch.closestPoint(point);
Geodetic2 seCorner = patch.southEastCorner();
ASSERT_EQ(clampedPoint.lat, seCorner.lat);
ASSERT_EQ(clampedPoint.lon, seCorner.lon);
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;
TEST_F(LatLonPatchTest, TestSphericalClamp5) {
GeodeticPatch patch(0, 0, M_PI / 4, M_PI / 4);
GeodeticPatch patch(0, 0, glm::pi<float>() / 4.f, glm::pi<float>() / 4.f);
// South west of patch
Geodetic2 point(-M_PI / 3, 3*M_PI + 0.01);
// South east of patch
Geodetic2 point { -glm::pi<double>() / 3.0, glm::pi<double>() / 4.0 - 0.01 };
Geodetic2 clampedPoint = patch.closestPoint(point);
Geodetic2 swCorner = patch.southWestCorner();
ASSERT_EQ(clampedPoint.lat, swCorner.lat);
ASSERT_EQ(clampedPoint.lon, swCorner.lon);
Geodetic2 clampedPoint = patch.closestPoint(point);
Geodetic2 seCorner = patch.corner(SOUTH_EAST);
//REQUIRE(clampedPoint.lat == seCorner.lat);
//REQUIRE(clampedPoint.lon == seCorner.lon);
}
int radAsDeg(double rads) {
return floorf(Angle<Scalar>::fromRadians(rads).asDegrees());
}
TEST_CASE("LatLonPatch: Spherical Clamp 5", "[latlonpatch]") {
using namespace openspace::globebrowsing;
GeodeticPatch patch(0, 0, glm::pi<float>() / 4.f, glm::pi<float>() / 4.f);
// South west of patch
Geodetic2 point { -glm::pi<double>() / 3.0, 3 * glm::pi<double>() / 4.0 + 0.01 };
TEST_F(LatLonPatchTest, PrintingSphericalClamp) {
GeodeticPatch patch(0, 0, M_PI / 4, M_PI / 4);
using Ang = Angle<Scalar>;
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;
}
Geodetic2 clampedPoint = patch.closestPoint(point);
Geodetic2 swCorner = patch.corner(SOUTH_WEST);
//REQUIRE(clampedPoint.lat == swCorner.lat);
//REQUIRE(clampedPoint.lon == swCorner.lon);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment