diff --git a/CMakeLists.txt b/CMakeLists.txt index c73f31f0f6..4f8b955a6f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -230,6 +230,8 @@ if (OPENSPACE_HAVE_TESTS) ) target_link_libraries(OpenSpaceTest gtest libOpenSpace) + set_property(TARGET OpenSpaceTest PROPERTY FOLDER "Unit Tests") + if (MSVC) set_target_properties(OpenSpaceTest PROPERTIES LINK_FLAGS "/NODEFAULTLIB:LIBCMTD.lib /NODEFAULTLIB:LIBCMT.lib" diff --git a/include/openspace/properties/optionproperty.h b/include/openspace/properties/optionproperty.h index 1ab8db03ba..f2945d6b83 100644 --- a/include/openspace/properties/optionproperty.h +++ b/include/openspace/properties/optionproperty.h @@ -122,6 +122,13 @@ public: */ void setValue(int value) override; + /** + * This method returns \c true if currently a valid option is selected. This might + * change as options are added or removed. + * \return true if a call to #option would return a valid Option + */ + bool hasOption() const; + /** * Returns the currently selected option. * \return The currently selected option diff --git a/src/properties/matrix/dmat2property.cpp b/src/properties/matrix/dmat2property.cpp index 11b26cda09..2b08b95d56 100644 --- a/src/properties/matrix/dmat2property.cpp +++ b/src/properties/matrix/dmat2property.cpp @@ -54,6 +54,8 @@ glm::dmat2x2 fromLuaConversion(lua_State* state, bool& success) { } } } + // The last accessor argument and the table are still on the stack + lua_pop(state, 2); success = true; return result; } @@ -64,7 +66,7 @@ bool toLuaConversion(lua_State* state, glm::dmat2x2 value) { for (glm::length_t i = 0; i < ghoul::glm_cols::value; ++i) { for (glm::length_t j = 0; j < ghoul::glm_rows::value; ++j) { lua_pushnumber(state, value[i][j]); - lua_setfield(state, -2, std::to_string(number).c_str()); + lua_rawseti(state, -2, number); ++number; } } diff --git a/src/properties/matrix/dmat2x3property.cpp b/src/properties/matrix/dmat2x3property.cpp index b32a125090..663a52f6f3 100644 --- a/src/properties/matrix/dmat2x3property.cpp +++ b/src/properties/matrix/dmat2x3property.cpp @@ -54,6 +54,8 @@ glm::dmat2x3 fromLuaConversion(lua_State* state, bool& success) { } } } + // The last accessor argument and the table are still on the stack + lua_pop(state, 2); success = true; return result; } @@ -64,7 +66,7 @@ bool toLuaConversion(lua_State* state, glm::dmat2x3 value) { for (glm::length_t i = 0; i < ghoul::glm_cols::value; ++i) { for (glm::length_t j = 0; j < ghoul::glm_rows::value; ++j) { lua_pushnumber(state, value[i][j]); - lua_setfield(state, -2, std::to_string(number).c_str()); + lua_rawseti(state, -2, number); ++number; } } diff --git a/src/properties/matrix/dmat2x4property.cpp b/src/properties/matrix/dmat2x4property.cpp index 5189eecd90..fd56c94b7b 100644 --- a/src/properties/matrix/dmat2x4property.cpp +++ b/src/properties/matrix/dmat2x4property.cpp @@ -54,6 +54,8 @@ glm::dmat2x4 fromLuaConversion(lua_State* state, bool& success) { } } } + // The last accessor argument and the table are still on the stack + lua_pop(state, 2); success = true; return result; } @@ -64,7 +66,7 @@ bool toLuaConversion(lua_State* state, glm::dmat2x4 value) { for (glm::length_t i = 0; i < ghoul::glm_cols::value; ++i) { for (glm::length_t j = 0; j < ghoul::glm_rows::value; ++j) { lua_pushnumber(state, value[i][j]); - lua_setfield(state, -2, std::to_string(number).c_str()); + lua_rawseti(state, -2, number); ++number; } } diff --git a/src/properties/matrix/dmat3property.cpp b/src/properties/matrix/dmat3property.cpp index e236d6eba1..5cf23f3ecd 100644 --- a/src/properties/matrix/dmat3property.cpp +++ b/src/properties/matrix/dmat3property.cpp @@ -54,6 +54,8 @@ glm::dmat3x3 fromLuaConversion(lua_State* state, bool& success) { } } } + // The last accessor argument and the table are still on the stack + lua_pop(state, 2); success = true; return result; } @@ -64,7 +66,7 @@ bool toLuaConversion(lua_State* state, glm::dmat3x3 value) { for (glm::length_t i = 0; i < ghoul::glm_cols::value; ++i) { for (glm::length_t j = 0; j < ghoul::glm_rows::value; ++j) { lua_pushnumber(state, value[i][j]); - lua_setfield(state, -2, std::to_string(number).c_str()); + lua_rawseti(state, -2, number); ++number; } } diff --git a/src/properties/matrix/dmat3x2property.cpp b/src/properties/matrix/dmat3x2property.cpp index 4326635578..3181893074 100644 --- a/src/properties/matrix/dmat3x2property.cpp +++ b/src/properties/matrix/dmat3x2property.cpp @@ -54,6 +54,8 @@ glm::dmat3x2 fromLuaConversion(lua_State* state, bool& success) { } } } + // The last accessor argument and the table are still on the stack + lua_pop(state, 2); success = true; return result; } @@ -64,7 +66,7 @@ bool toLuaConversion(lua_State* state, glm::dmat3x2 value) { for (glm::length_t i = 0; i < ghoul::glm_cols::value; ++i) { for (glm::length_t j = 0; j < ghoul::glm_rows::value; ++j) { lua_pushnumber(state, value[i][j]); - lua_setfield(state, -2, std::to_string(number).c_str()); + lua_rawseti(state, -2, number); ++number; } } diff --git a/src/properties/matrix/dmat3x4property.cpp b/src/properties/matrix/dmat3x4property.cpp index 3fa1419785..b2a2a04cc3 100644 --- a/src/properties/matrix/dmat3x4property.cpp +++ b/src/properties/matrix/dmat3x4property.cpp @@ -54,6 +54,8 @@ glm::dmat3x4 fromLuaConversion(lua_State* state, bool& success) { } } } + // The last accessor argument and the table are still on the stack + lua_pop(state, 2); success = true; return result; } @@ -64,7 +66,7 @@ bool toLuaConversion(lua_State* state, glm::dmat3x4 value) { for (glm::length_t i = 0; i < ghoul::glm_cols::value; ++i) { for (glm::length_t j = 0; j < ghoul::glm_rows::value; ++j) { lua_pushnumber(state, value[i][j]); - lua_setfield(state, -2, std::to_string(number).c_str()); + lua_rawseti(state, -2, number); ++number; } } diff --git a/src/properties/matrix/dmat4property.cpp b/src/properties/matrix/dmat4property.cpp index 793594572b..65b8f00410 100644 --- a/src/properties/matrix/dmat4property.cpp +++ b/src/properties/matrix/dmat4property.cpp @@ -54,6 +54,8 @@ glm::dmat4x4 fromLuaConversion(lua_State* state, bool& success) { } } } + // The last accessor argument and the table are still on the stack + lua_pop(state, 2); success = true; return result; } @@ -64,7 +66,7 @@ bool toLuaConversion(lua_State* state, glm::dmat4x4 value) { for (glm::length_t i = 0; i < ghoul::glm_cols::value; ++i) { for (glm::length_t j = 0; j < ghoul::glm_rows::value; ++j) { lua_pushnumber(state, value[i][j]); - lua_setfield(state, -2, std::to_string(number).c_str()); + lua_rawseti(state, -2, number); ++number; } } diff --git a/src/properties/matrix/dmat4x2property.cpp b/src/properties/matrix/dmat4x2property.cpp index bbf556403e..afd643184d 100644 --- a/src/properties/matrix/dmat4x2property.cpp +++ b/src/properties/matrix/dmat4x2property.cpp @@ -34,20 +34,29 @@ namespace { glm::dmat4x2 fromLuaConversion(lua_State* state, bool& success) { glm::dmat4x2 result; + lua_pushnil(state); int number = 1; for (glm::length_t i = 0; i < ghoul::glm_cols::value; ++i) { for (glm::length_t j = 0; j < ghoul::glm_rows::value; ++j) { - lua_getfield(state, -1, std::to_string(number).c_str()); + int hasNext = lua_next(state, -2); + if (hasNext != 1) { + success = false; + return glm::dmat4x2(0); + } if (lua_isnumber(state, -1) != 1) { success = false; return glm::dmat4x2(0); - } else { - result[i][j] = lua_tonumber(state, -1); + } + else { + result[i][j] + = static_cast(lua_tonumber(state, -1)); lua_pop(state, 1); ++number; } } } + // The last accessor argument and the table are still on the stack + lua_pop(state, 2); success = true; return result; } @@ -58,7 +67,7 @@ bool toLuaConversion(lua_State* state, glm::dmat4x2 value) { for (glm::length_t i = 0; i < ghoul::glm_cols::value; ++i) { for (glm::length_t j = 0; j < ghoul::glm_rows::value; ++j) { lua_pushnumber(state, value[i][j]); - lua_setfield(state, -2, std::to_string(number).c_str()); + lua_rawseti(state, -2, number); ++number; } } diff --git a/src/properties/matrix/dmat4x3property.cpp b/src/properties/matrix/dmat4x3property.cpp index 247677ad2d..36e84fe4e0 100644 --- a/src/properties/matrix/dmat4x3property.cpp +++ b/src/properties/matrix/dmat4x3property.cpp @@ -53,6 +53,8 @@ glm::dmat4x3 fromLuaConversion(lua_State* state, bool& success) { } } } + // The last accessor argument and the table are still on the stack + lua_pop(state, 2); success = true; return result; } @@ -63,7 +65,7 @@ bool toLuaConversion(lua_State* state, glm::dmat4x3 value) { for (glm::length_t i = 0; i < ghoul::glm_cols::value; ++i) { for (glm::length_t j = 0; j < ghoul::glm_rows::value; ++j) { lua_pushnumber(state, value[i][j]); - lua_setfield(state, -2, std::to_string(number).c_str()); + lua_rawseti(state, -2, number); ++number; } } diff --git a/src/properties/matrix/mat2property.cpp b/src/properties/matrix/mat2property.cpp index 7f7a702e30..1751a05e43 100644 --- a/src/properties/matrix/mat2property.cpp +++ b/src/properties/matrix/mat2property.cpp @@ -47,13 +47,16 @@ glm::mat2x2 fromLuaConversion(lua_State* state, bool& success) { success = false; return glm::mat2x2(0); } else { - result[i][j] - = static_cast(lua_tonumber(state, -1)); + result[i][j] = static_cast( + lua_tonumber(state, -1) + ); lua_pop(state, 1); ++number; } } } + // The last accessor argument and the table are still on the stack + lua_pop(state, 2); success = true; return result; } @@ -64,7 +67,7 @@ bool toLuaConversion(lua_State* state, glm::mat2x2 value) { for (glm::length_t i = 0; i < ghoul::glm_cols::value; ++i) { for (glm::length_t j = 0; j < ghoul::glm_rows::value; ++j) { lua_pushnumber(state, static_cast(value[i][j])); - lua_setfield(state, -2, std::to_string(number).c_str()); + lua_rawseti(state, -2, number); ++number; } } diff --git a/src/properties/matrix/mat2x3property.cpp b/src/properties/matrix/mat2x3property.cpp index 0b55352a18..ccc72e9111 100644 --- a/src/properties/matrix/mat2x3property.cpp +++ b/src/properties/matrix/mat2x3property.cpp @@ -57,6 +57,8 @@ glm::mat2x3 fromLuaConversion(lua_State* state, bool& success) { } } } + // The last accessor argument and the table are still on the stack + lua_pop(state, 2); success = true; return result; } @@ -67,7 +69,7 @@ bool toLuaConversion(lua_State* state, glm::mat2x3 value) { for (glm::length_t i = 0; i < ghoul::glm_cols::value; ++i) { for (glm::length_t j = 0; j < ghoul::glm_rows::value; ++j) { lua_pushnumber(state, static_cast(value[i][j])); - lua_setfield(state, -2, std::to_string(number).c_str()); + lua_rawseti(state, -2, number); ++number; } } diff --git a/src/properties/matrix/mat2x4property.cpp b/src/properties/matrix/mat2x4property.cpp index f99bee1802..c6a61afb34 100644 --- a/src/properties/matrix/mat2x4property.cpp +++ b/src/properties/matrix/mat2x4property.cpp @@ -55,6 +55,8 @@ glm::mat2x4 fromLuaConversion(lua_State* state, bool& success) { } } } + // The last accessor argument and the table are still on the stack + lua_pop(state, 2); success = true; return result; } @@ -65,7 +67,7 @@ bool toLuaConversion(lua_State* state, glm::mat2x4 value) { for (glm::length_t i = 0; i < ghoul::glm_cols::value; ++i) { for (glm::length_t j = 0; j < ghoul::glm_rows::value; ++j) { lua_pushnumber(state, static_cast(value[i][j])); - lua_setfield(state, -2, std::to_string(number).c_str()); + lua_rawseti(state, -2, number); ++number; } } diff --git a/src/properties/matrix/mat3property.cpp b/src/properties/matrix/mat3property.cpp index 7bce40c406..e571c9f5d7 100644 --- a/src/properties/matrix/mat3property.cpp +++ b/src/properties/matrix/mat3property.cpp @@ -54,6 +54,8 @@ glm::mat3x3 fromLuaConversion(lua_State* state, bool& success) { } } } + // The last accessor argument and the table are still on the stack + lua_pop(state, 2); success = true; return result; } @@ -64,7 +66,7 @@ bool toLuaConversion(lua_State* state, glm::mat3x3 value) { for (glm::length_t i = 0; i < ghoul::glm_cols::value; ++i) { for (glm::length_t j = 0; j < ghoul::glm_rows::value; ++j) { lua_pushnumber(state, static_cast(value[i][j])); - lua_setfield(state, -2, std::to_string(number).c_str()); + lua_rawseti(state, -2, number); ++number; } } diff --git a/src/properties/matrix/mat3x2property.cpp b/src/properties/matrix/mat3x2property.cpp index 0c55f45a8e..2398de47c7 100644 --- a/src/properties/matrix/mat3x2property.cpp +++ b/src/properties/matrix/mat3x2property.cpp @@ -54,6 +54,8 @@ glm::mat3x2 fromLuaConversion(lua_State* state, bool& success) { } } } + // The last accessor argument and the table are still on the stack + lua_pop(state, 2); success = true; return result; } @@ -64,7 +66,7 @@ bool toLuaConversion(lua_State* state, glm::mat3x2 value) { for (glm::length_t i = 0; i < ghoul::glm_cols::value; ++i) { for (glm::length_t j = 0; j < ghoul::glm_rows::value; ++j) { lua_pushnumber(state, static_cast(value[i][j])); - lua_setfield(state, -2, std::to_string(number).c_str()); + lua_rawseti(state, -2, number); ++number; } } diff --git a/src/properties/matrix/mat3x4property.cpp b/src/properties/matrix/mat3x4property.cpp index adb40acadd..e175cf0884 100644 --- a/src/properties/matrix/mat3x4property.cpp +++ b/src/properties/matrix/mat3x4property.cpp @@ -54,6 +54,8 @@ glm::mat3x4 fromLuaConversion(lua_State* state, bool& success) { } } } + // The last accessor argument and the table are still on the stack + lua_pop(state, 2); success = true; return result; } @@ -64,7 +66,7 @@ bool toLuaConversion(lua_State* state, glm::mat3x4 value) { for (glm::length_t i = 0; i < ghoul::glm_cols::value; ++i) { for (glm::length_t j = 0; j < ghoul::glm_rows::value; ++j) { lua_pushnumber(state, static_cast(value[i][j])); - lua_setfield(state, -2, std::to_string(number).c_str()); + lua_rawseti(state, -2, number); ++number; } } diff --git a/src/properties/matrix/mat4property.cpp b/src/properties/matrix/mat4property.cpp index 84e04a849c..1c7bb75602 100644 --- a/src/properties/matrix/mat4property.cpp +++ b/src/properties/matrix/mat4property.cpp @@ -56,6 +56,8 @@ glm::mat4x4 fromLuaConversion(lua_State* state, bool& success) { } } } + // The last accessor argument and the table are still on the stack + lua_pop(state, 2); success = true; return result; } @@ -66,7 +68,7 @@ bool toLuaConversion(lua_State* state, glm::mat4x4 value) { for (glm::length_t i = 0; i < ghoul::glm_cols::value; ++i) { for (glm::length_t j = 0; j < ghoul::glm_rows::value; ++j) { lua_pushnumber(state, static_cast(value[i][j])); - lua_setfield(state, -2, std::to_string(number).c_str()); + lua_rawseti(state, -2, number); ++number; } } diff --git a/src/properties/matrix/mat4x2property.cpp b/src/properties/matrix/mat4x2property.cpp index 6148f5e952..74ff32121c 100644 --- a/src/properties/matrix/mat4x2property.cpp +++ b/src/properties/matrix/mat4x2property.cpp @@ -54,6 +54,8 @@ glm::mat4x2 fromLuaConversion(lua_State* state, bool& success) { } } } + // The last accessor argument and the table are still on the stack + lua_pop(state, 2); success = true; return result; } @@ -64,7 +66,7 @@ bool toLuaConversion(lua_State* state, glm::mat4x2 value) { for (glm::length_t i = 0; i < ghoul::glm_cols::value; ++i) { for (glm::length_t j = 0; j < ghoul::glm_rows::value; ++j) { lua_pushnumber(state, static_cast(value[i][j])); - lua_setfield(state, -2, std::to_string(number).c_str()); + lua_rawseti(state, -2, number); ++number; } } diff --git a/src/properties/matrix/mat4x3property.cpp b/src/properties/matrix/mat4x3property.cpp index 8a768a0b4a..e67e14fc27 100644 --- a/src/properties/matrix/mat4x3property.cpp +++ b/src/properties/matrix/mat4x3property.cpp @@ -54,6 +54,8 @@ glm::mat4x3 fromLuaConversion(lua_State* state, bool& success) { } } } + // The last accessor argument and the table are still on the stack + lua_pop(state, 2); success = true; return result; } @@ -64,7 +66,7 @@ bool toLuaConversion(lua_State* state, glm::mat4x3 value) { for (glm::length_t i = 0; i < ghoul::glm_cols::value; ++i) { for (glm::length_t j = 0; j < ghoul::glm_rows::value; ++j) { lua_pushnumber(state, static_cast(value[i][j])); - lua_setfield(state, -2, std::to_string(number).c_str()); + lua_rawseti(state, -2, number); ++number; } } diff --git a/src/properties/optionproperty.cpp b/src/properties/optionproperty.cpp index 8fb89d3696..169118d93d 100644 --- a/src/properties/optionproperty.cpp +++ b/src/properties/optionproperty.cpp @@ -95,6 +95,11 @@ void OptionProperty::setValue(int value) { LERROR("Could not find an option for value '" << value << "' in OptionProperty"); } +bool OptionProperty::hasOption() const { + return value() >= 0 && value() < _options.size(); +} + + const OptionProperty::Option& OptionProperty::option() const { return _options[value()]; } diff --git a/src/properties/scalar/charproperty.cpp b/src/properties/scalar/charproperty.cpp index f11a33b602..1e247a746c 100644 --- a/src/properties/scalar/charproperty.cpp +++ b/src/properties/scalar/charproperty.cpp @@ -34,7 +34,9 @@ namespace { char fromLuaConversion(lua_State* state, bool& success) { success = (lua_isnumber(state, -1) == 1); if (success) { - return static_cast(lua_tonumber(state, -1)); + char val = static_cast(lua_tonumber(state, -1)); + lua_pop(state, 1); + return val; } else { return char(0); diff --git a/src/properties/scalar/doubleproperty.cpp b/src/properties/scalar/doubleproperty.cpp index 3d15bb635e..d9c1971558 100644 --- a/src/properties/scalar/doubleproperty.cpp +++ b/src/properties/scalar/doubleproperty.cpp @@ -34,7 +34,9 @@ namespace { double fromLuaConversion(lua_State* state, bool& success) { success = (lua_isnumber(state, -1) == 1); if (success) { - return lua_tonumber(state, -1); + double val = lua_tonumber(state, -1); + lua_pop(state, 1); + return val; } else { return 0.0; diff --git a/src/properties/scalar/floatproperty.cpp b/src/properties/scalar/floatproperty.cpp index 859aeec7f6..27de379ec3 100644 --- a/src/properties/scalar/floatproperty.cpp +++ b/src/properties/scalar/floatproperty.cpp @@ -34,7 +34,9 @@ namespace { float fromLuaConversion(lua_State* state, bool& success) { success = (lua_isnumber(state, -1) == 1); if (success) { - return static_cast(lua_tonumber(state, -1)); + float val = static_cast(lua_tonumber(state, -1)); + lua_pop(state, 1); + return val; } else { return 0.f; diff --git a/src/properties/scalar/intproperty.cpp b/src/properties/scalar/intproperty.cpp index 4c29cf668b..675e9c8379 100644 --- a/src/properties/scalar/intproperty.cpp +++ b/src/properties/scalar/intproperty.cpp @@ -34,7 +34,9 @@ namespace { int fromLuaConversion(lua_State* state, bool& success) { success = (lua_isnumber(state, -1) == 1); if (success) { - return static_cast(lua_tonumber(state, -1)); + int val = static_cast(lua_tonumber(state, -1)); + lua_pop(state, 1); + return val; } else { return 0; diff --git a/src/properties/scalar/longdoubleproperty.cpp b/src/properties/scalar/longdoubleproperty.cpp index 12be311787..fb1229522d 100644 --- a/src/properties/scalar/longdoubleproperty.cpp +++ b/src/properties/scalar/longdoubleproperty.cpp @@ -34,7 +34,9 @@ namespace { long double fromLuaConversion(lua_State* state, bool& success) { success = (lua_isnumber(state, -1) == 1); if (success) { - return static_cast(lua_tonumber(state, -1)); + long double val = static_cast(lua_tonumber(state, -1)); + lua_pop(state, 1); + return val; } else { return 0l; diff --git a/src/properties/scalar/longlongproperty.cpp b/src/properties/scalar/longlongproperty.cpp index 32ac3b28bf..3fa2700c8c 100644 --- a/src/properties/scalar/longlongproperty.cpp +++ b/src/properties/scalar/longlongproperty.cpp @@ -34,7 +34,9 @@ namespace { long long fromLuaConversion(lua_State* state, bool& success) { success = (lua_isnumber(state, -1) == 1); if (success) { - return static_cast(lua_tonumber(state, -1)); + long long val = static_cast(lua_tonumber(state, -1)); + lua_pop(state, 1); + return val; } else { return 0; diff --git a/src/properties/scalar/longproperty.cpp b/src/properties/scalar/longproperty.cpp index 3ba2d7e0b1..57c6344aa4 100644 --- a/src/properties/scalar/longproperty.cpp +++ b/src/properties/scalar/longproperty.cpp @@ -34,7 +34,9 @@ namespace { long fromLuaConversion(lua_State* state, bool& success) { success = (lua_isnumber(state, -1) == 1); if (success) { - return static_cast(lua_tonumber(state, -1)); + long val = static_cast(lua_tonumber(state, -1)); + lua_pop(state, 1); + return val; } else { return 0; diff --git a/src/properties/scalar/shortproperty.cpp b/src/properties/scalar/shortproperty.cpp index 0a252a4a04..b2b8d8bd34 100644 --- a/src/properties/scalar/shortproperty.cpp +++ b/src/properties/scalar/shortproperty.cpp @@ -34,7 +34,9 @@ namespace { short fromLuaConversion(lua_State* state, bool& success) { success = (lua_isnumber(state, -1) == 1); if (success) { - return static_cast(lua_tonumber(state, -1)); + short val = static_cast(lua_tonumber(state, -1)); + lua_pop(state, 1); + return val; } else { return 0; diff --git a/src/properties/scalar/signedcharproperty.cpp b/src/properties/scalar/signedcharproperty.cpp index 2e387a4ae5..ab34f455da 100644 --- a/src/properties/scalar/signedcharproperty.cpp +++ b/src/properties/scalar/signedcharproperty.cpp @@ -34,7 +34,9 @@ namespace { signed char fromLuaConversion(lua_State* state, bool& success) { success = (lua_isnumber(state, -1) == 1); if (success) { - return static_cast(lua_tonumber(state, -1)); + signed char val = static_cast(lua_tonumber(state, -1)); + lua_pop(state, 1); + return val; } else { return 0; diff --git a/src/properties/scalar/ucharproperty.cpp b/src/properties/scalar/ucharproperty.cpp index 540e903623..d8e34420a2 100644 --- a/src/properties/scalar/ucharproperty.cpp +++ b/src/properties/scalar/ucharproperty.cpp @@ -34,7 +34,9 @@ namespace { unsigned char fromLuaConversion(lua_State* state, bool& success) { success = (lua_isnumber(state, -1) == 1); if (success) { - return static_cast(lua_tonumber(state, -1)); + unsigned char val = static_cast(lua_tonumber(state, -1)); + lua_pop(state, 1); + return val; } else { return 0; diff --git a/src/properties/scalar/uintproperty.cpp b/src/properties/scalar/uintproperty.cpp index 18f78e4792..1d30943755 100644 --- a/src/properties/scalar/uintproperty.cpp +++ b/src/properties/scalar/uintproperty.cpp @@ -34,7 +34,9 @@ namespace { unsigned int fromLuaConversion(lua_State* state, bool& success) { success = (lua_isnumber(state, -1) == 1); if (success) { - return static_cast(lua_tonumber(state, -1)); + unsigned int val = static_cast(lua_tonumber(state, -1)); + lua_pop(state, 1); + return val; } else { return 0; diff --git a/src/properties/scalar/ulonglongproperty.cpp b/src/properties/scalar/ulonglongproperty.cpp index a15bad7143..023397c584 100644 --- a/src/properties/scalar/ulonglongproperty.cpp +++ b/src/properties/scalar/ulonglongproperty.cpp @@ -34,7 +34,9 @@ namespace { unsigned long long fromLuaConversion(lua_State* state, bool& success) { success = (lua_isnumber(state, -1) == 1); if (success) { - return static_cast(lua_tonumber(state, -1)); + unsigned long long val = static_cast(lua_tonumber(state, -1)); + lua_pop(state, 1); + return val; } else { return 0ull; diff --git a/src/properties/scalar/ulongproperty.cpp b/src/properties/scalar/ulongproperty.cpp index 5291a85655..27e562c998 100644 --- a/src/properties/scalar/ulongproperty.cpp +++ b/src/properties/scalar/ulongproperty.cpp @@ -34,7 +34,9 @@ namespace { unsigned long fromLuaConversion(lua_State* state, bool& success) { success = (lua_isnumber(state, -1) == 1); if (success) { - return static_cast(lua_tonumber(state, -1)); + unsigned long val = static_cast(lua_tonumber(state, -1)); + lua_pop(state, 1); + return val; } else { return 0ul; diff --git a/src/properties/scalar/ushortproperty.cpp b/src/properties/scalar/ushortproperty.cpp index 60345eafa1..4420b40787 100644 --- a/src/properties/scalar/ushortproperty.cpp +++ b/src/properties/scalar/ushortproperty.cpp @@ -34,7 +34,9 @@ namespace { unsigned short fromLuaConversion(lua_State* state, bool& success) { success = (lua_isnumber(state, -1) == 1); if (success) { - return static_cast(lua_tonumber(state, -1)); + unsigned short val = static_cast(lua_tonumber(state, -1)); + lua_pop(state, 1); + return val; } else { return 0; diff --git a/src/properties/vector/dvec2property.cpp b/src/properties/vector/dvec2property.cpp index b3905a80dc..de3d293a7d 100644 --- a/src/properties/vector/dvec2property.cpp +++ b/src/properties/vector/dvec2property.cpp @@ -50,6 +50,8 @@ glm::dvec2 fromLuaConversion(lua_State* state, bool& success) { lua_pop(state, 1); } } + // The last accessor argument and the table are still on the stack + lua_pop(state, 2); success = true; return result; } @@ -59,7 +61,7 @@ bool toLuaConversion(lua_State* state, glm::dvec2 value) { int number = 1; for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { lua_pushnumber(state, value[i]); - lua_setfield(state, -2, std::to_string(number).c_str()); + lua_rawseti(state, -2, number); ++number; } return true; diff --git a/src/properties/vector/dvec3property.cpp b/src/properties/vector/dvec3property.cpp index 2ca4c0e827..85d5d68b7f 100644 --- a/src/properties/vector/dvec3property.cpp +++ b/src/properties/vector/dvec3property.cpp @@ -50,6 +50,8 @@ glm::dvec3 fromLuaConversion(lua_State* state, bool& success) { lua_pop(state, 1); } } + // The last accessor argument and the table are still on the stack + lua_pop(state, 2); success = true; return result; } @@ -59,7 +61,7 @@ bool toLuaConversion(lua_State* state, glm::dvec3 value) { int number = 1; for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { lua_pushnumber(state, value[i]); - lua_setfield(state, -2, std::to_string(number).c_str()); + lua_rawseti(state, -2, number); ++number; } return true; diff --git a/src/properties/vector/dvec4property.cpp b/src/properties/vector/dvec4property.cpp index a555bd049e..b465c1c9d1 100644 --- a/src/properties/vector/dvec4property.cpp +++ b/src/properties/vector/dvec4property.cpp @@ -50,6 +50,8 @@ glm::dvec4 fromLuaConversion(lua_State* state, bool& success) { lua_pop(state, 1); } } + // The last accessor argument and the table are still on the stack + lua_pop(state, 2); success = true; return result; } @@ -59,7 +61,7 @@ bool toLuaConversion(lua_State* state, glm::dvec4 value) { int number = 1; for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { lua_pushnumber(state, value[i]); - lua_setfield(state, -2, std::to_string(number).c_str()); + lua_rawseti(state, -2, number); ++number; } return true; diff --git a/src/properties/vector/ivec2property.cpp b/src/properties/vector/ivec2property.cpp index 15b35d3799..616f99fba3 100644 --- a/src/properties/vector/ivec2property.cpp +++ b/src/properties/vector/ivec2property.cpp @@ -50,6 +50,8 @@ glm::ivec2 fromLuaConversion(lua_State* state, bool& success) { lua_pop(state, 1); } } + // The last accessor argument and the table are still on the stack + lua_pop(state, 2); success = true; return result; } @@ -59,7 +61,7 @@ bool toLuaConversion(lua_State* state, glm::ivec2 value) { int number = 1; for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { lua_pushnumber(state, static_cast(value[i])); - lua_setfield(state, -2, std::to_string(number).c_str()); + lua_rawseti(state, -2, number); ++number; } return true; diff --git a/src/properties/vector/ivec3property.cpp b/src/properties/vector/ivec3property.cpp index dc2e93fcab..023dbca754 100644 --- a/src/properties/vector/ivec3property.cpp +++ b/src/properties/vector/ivec3property.cpp @@ -50,6 +50,8 @@ glm::ivec3 fromLuaConversion(lua_State* state, bool& success) { lua_pop(state, 1); } } + // The last accessor argument and the table are still on the stack + lua_pop(state, 2); success = true; return result; } @@ -59,7 +61,7 @@ bool toLuaConversion(lua_State* state, glm::ivec3 value) { int number = 1; for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { lua_pushnumber(state, static_cast(value[i])); - lua_setfield(state, -2, std::to_string(number).c_str()); + lua_rawseti(state, -2, number); ++number; } return true; diff --git a/src/properties/vector/ivec4property.cpp b/src/properties/vector/ivec4property.cpp index 45a72a4596..d5a6608031 100644 --- a/src/properties/vector/ivec4property.cpp +++ b/src/properties/vector/ivec4property.cpp @@ -50,6 +50,8 @@ glm::ivec4 fromLuaConversion(lua_State* state, bool& success) { lua_pop(state, 1); } } + // The last accessor argument and the table are still on the stack + lua_pop(state, 2); success = true; return result; } @@ -59,7 +61,7 @@ bool toLuaConversion(lua_State* state, glm::ivec4 value) { int number = 1; for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { lua_pushnumber(state, static_cast(value[i])); - lua_setfield(state, -2, std::to_string(number).c_str()); + lua_rawseti(state, -2, number); ++number; } return true; diff --git a/src/properties/vector/uvec2property.cpp b/src/properties/vector/uvec2property.cpp index e1bdb0f949..526bf5e2a9 100644 --- a/src/properties/vector/uvec2property.cpp +++ b/src/properties/vector/uvec2property.cpp @@ -50,6 +50,8 @@ glm::uvec2 fromLuaConversion(lua_State* state, bool& success) { lua_pop(state, 1); } } + // The last accessor argument and the table are still on the stack + lua_pop(state, 2); success = true; return result; } @@ -59,7 +61,7 @@ bool toLuaConversion(lua_State* state, glm::uvec2 value) { int number = 1; for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { lua_pushnumber(state, static_cast(value[i])); - lua_setfield(state, -2, std::to_string(number).c_str()); + lua_rawseti(state, -2, number); ++number; } return true; diff --git a/src/properties/vector/uvec3property.cpp b/src/properties/vector/uvec3property.cpp index d6cb92f525..24164a3e14 100644 --- a/src/properties/vector/uvec3property.cpp +++ b/src/properties/vector/uvec3property.cpp @@ -50,6 +50,8 @@ glm::uvec3 fromLuaConversion(lua_State* state, bool& success) { lua_pop(state, 1); } } + // The last accessor argument and the table are still on the stack + lua_pop(state, 2); success = true; return result; } @@ -59,7 +61,7 @@ bool toLuaConversion(lua_State* state, glm::uvec3 value) { int number = 1; for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { lua_pushnumber(state, static_cast(value[i])); - lua_setfield(state, -2, std::to_string(number).c_str()); + lua_rawseti(state, -2, number); ++number; } return true; diff --git a/src/properties/vector/uvec4property.cpp b/src/properties/vector/uvec4property.cpp index 9306ff1f59..f218040e9c 100644 --- a/src/properties/vector/uvec4property.cpp +++ b/src/properties/vector/uvec4property.cpp @@ -50,6 +50,8 @@ glm::uvec4 fromLuaConversion(lua_State* state, bool& success) { lua_pop(state, 1); } } + // The last accessor argument and the table are still on the stack + lua_pop(state, 2); success = true; return result; } @@ -59,7 +61,7 @@ bool toLuaConversion(lua_State* state, glm::uvec4 value) { int number = 1; for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { lua_pushnumber(state, static_cast(value[i])); - lua_setfield(state, -2, std::to_string(number).c_str()); + lua_rawseti(state, -2, number); ++number; } return true; diff --git a/src/properties/vector/vec2property.cpp b/src/properties/vector/vec2property.cpp index f12da692a6..aa57af300c 100644 --- a/src/properties/vector/vec2property.cpp +++ b/src/properties/vector/vec2property.cpp @@ -50,6 +50,8 @@ glm::vec2 fromLuaConversion(lua_State* state, bool& success) { lua_pop(state, 1); } } + // The last accessor argument and the table are still on the stack + lua_pop(state, 2); success = true; return result; } @@ -59,7 +61,7 @@ bool toLuaConversion(lua_State* state, glm::vec2 value) { int number = 1; for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { lua_pushnumber(state, static_cast(value[i])); - lua_setfield(state, -2, std::to_string(number).c_str()); + lua_rawseti(state, -2, number); ++number; } return true; diff --git a/src/properties/vector/vec3property.cpp b/src/properties/vector/vec3property.cpp index e6600b9246..d0a846838d 100644 --- a/src/properties/vector/vec3property.cpp +++ b/src/properties/vector/vec3property.cpp @@ -50,6 +50,8 @@ glm::vec3 fromLuaConversion(lua_State* state, bool& success) { lua_pop(state, 1); } } + // The last accessor argument and the table are still on the stack + lua_pop(state, 2); success = true; return result; } @@ -59,7 +61,7 @@ bool toLuaConversion(lua_State* state, glm::vec3 value) { int number = 1; for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { lua_pushnumber(state, static_cast(value[i])); - lua_setfield(state, -2, std::to_string(number).c_str()); + lua_rawseti(state, -2, number); ++number; } return true; diff --git a/src/properties/vector/vec4property.cpp b/src/properties/vector/vec4property.cpp index 8d3dc4ad8e..8118df03eb 100644 --- a/src/properties/vector/vec4property.cpp +++ b/src/properties/vector/vec4property.cpp @@ -50,6 +50,8 @@ glm::vec4 fromLuaConversion(lua_State* state, bool& success) { lua_pop(state, 1); } } + // The last accessor argument and the table are still on the stack + lua_pop(state, 2); success = true; return result; } @@ -59,7 +61,7 @@ bool toLuaConversion(lua_State* state, glm::vec4 value) { int number = 1; for (glm::length_t i = 0; i < ghoul::glm_components::value; ++i) { lua_pushnumber(state, static_cast(value[i])); - lua_setfield(state, -2, std::to_string(number).c_str()); + lua_rawseti(state, -2, number); ++number; } return true; diff --git a/tests/main.cpp b/tests/main.cpp index cbf2f5c82b..7d828d58ed 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -48,57 +48,51 @@ #define GHL_THROW_ON_ASSERT #endif // GHL_THROW_ON_ASSERTGHL_THROW_ON_ASSERT +#include +#include +#include +#include +#include +#include #include #include #include -#include #include +#include +#include -// test files #include -#include #include +#include +#include +#include +#include +#include +#include #include #ifdef OPENSPACE_MODULE_GLOBEBROWSING_ENABLED -//#include -#include #include - #include -//#include -#include -//#include - -#include #include +#include +#include +#include #endif -#include -#include - #ifdef OPENSPACE_MODULE_ISWA_ENABLED #include -//#include #endif #ifdef OPENSPACE_MODULE_VOLUME_ENABLED #include #endif -#include +// Regression tests +#include -#include -#include -#include -#include -#include -#include -#include - -#include using namespace ghoul::cmdparser; using namespace ghoul::filesystem; @@ -124,7 +118,18 @@ int main(int argc, char** argv) { } if (!skipOsEng) { - openspace::OpenSpaceEngine::create(argc, argv, std::make_unique(), args, close, consoleLog); + openspace::OpenSpaceEngine::create( + argc, + argv, + std::make_unique(), + args, + close, + consoleLog + ); + FileSys.registerPathToken("${TESTDIR}" , "${BASE}/tests"); + + // All of the relevant tests initialize the SpiceManager + openspace::SpiceManager::deinitialize(); } testing::InitGoogleTest(&argc, argv); diff --git a/tests/regression/517.inl b/tests/regression/517.inl new file mode 100644 index 0000000000..a4a1ecd104 --- /dev/null +++ b/tests/regression/517.inl @@ -0,0 +1,44 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-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 + +using namespace openspace::properties; + +class Issue527 : public testing::Test {}; + +TEST_F(Issue527, Regression) { + // Error in OptionProperty if values not starting at 0 are used + + OptionProperty p({ "id", "gui", "desc"}); + + p.addOptions({ + {-1, "a" }, + {-2, "b" } + }); + + + p = -1; + ASSERT_EQ("a", p.option().description); +} diff --git a/tests/test_assetloader.inl b/tests/test_assetloader.inl index dea709d733..9b0de4f808 100644 --- a/tests/test_assetloader.inl +++ b/tests/test_assetloader.inl @@ -102,13 +102,8 @@ int passTest(lua_State* state) { } TEST_F(AssetLoaderTest, Assertions) { - try { - _assetLoader->add("passassertion"); - } - catch (const std::exception& e) { - EXPECT_TRUE(false) << e.what(); - } - EXPECT_THROW(_assetLoader->add("failassertion"), ghoul::lua::LuaRuntimeException); + EXPECT_NO_THROW(_assetLoader->add("passassertion")); + EXPECT_NO_THROW(_assetLoader->add("failassertion")); } TEST_F(AssetLoaderTest, BasicExportImport) { @@ -120,7 +115,7 @@ TEST_F(AssetLoaderTest, BasicExportImport) { } } -TEST_F(AssetLoaderTest, AssetFuncitons) { +TEST_F(AssetLoaderTest, AssetFunctions) { try { _assetLoader->add("assetfunctionsexist"); } catch (const std::exception& e) { @@ -128,7 +123,7 @@ TEST_F(AssetLoaderTest, AssetFuncitons) { } } -TEST_F(AssetLoaderTest, DependencyFuncitons) { +TEST_F(AssetLoaderTest, DependencyFunctions) { try { _assetLoader->add("dependencyfunctionsexist"); } diff --git a/tests/test_documentation.inl b/tests/test_documentation.inl index f52201e635..90ae1a3a06 100644 --- a/tests/test_documentation.inl +++ b/tests/test_documentation.inl @@ -770,6 +770,7 @@ TEST_F(DocumentationTest, RequiredInOptional) { 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; @@ -789,22 +790,18 @@ TEST_F(DocumentationTest, Exhaustive) { }; TestResult negativeRes = testSpecification(doc, negative); EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(2, negativeRes.offenses.size()); - EXPECT_EQ("False_Int", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::ExtraKey, negativeRes.offenses[0].reason); - EXPECT_EQ("Int", negativeRes.offenses[1].offender); - EXPECT_EQ(TestResult::Offense::Reason::MissingKey, negativeRes.offenses[1].reason); + 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(2, negativeRes.offenses.size()); - EXPECT_EQ("Double", negativeRes.offenses[0].offender); - EXPECT_EQ(TestResult::Offense::Reason::ExtraKey, negativeRes.offenses[0].reason); - EXPECT_EQ("Int", negativeRes.offenses[1].offender); - EXPECT_EQ(TestResult::Offense::Reason::MissingKey, negativeRes.offenses[1].reason); + 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) { @@ -829,11 +826,9 @@ TEST_F(DocumentationTest, NestedExhaustive) { }; TestResult negativeRes = testSpecification(doc, negative); EXPECT_FALSE(negativeRes.success); - ASSERT_EQ(2, negativeRes.offenses.size()); + ASSERT_EQ(1, negativeRes.offenses.size()); EXPECT_EQ("Table.a", negativeRes.offenses[0].offender); EXPECT_EQ(TestResult::Offense::Reason::MissingKey, negativeRes.offenses[0].reason); - EXPECT_EQ("Table.b", negativeRes.offenses[1].offender); - EXPECT_EQ(TestResult::Offense::Reason::ExtraKey, negativeRes.offenses[1].reason); } TEST_F(DocumentationTest, EmptyEntriesNonExhaustive) { @@ -876,14 +871,10 @@ TEST_F(DocumentationTest, EmptyNestedExhaustive) { { "Table", ghoul::Dictionary{ { "a", 1 }}} }; 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::ExtraKey, negativeRes.offenses[0].reason); + EXPECT_TRUE(negativeRes.success); + ASSERT_EQ(0, negativeRes.offenses.size()); } - - TEST_F(DocumentationTest, LessInt) { using namespace openspace::documentation; diff --git a/tests/test_luaconversions.inl b/tests/test_luaconversions.inl index 16fc1ba5cb..a344eefca1 100644 --- a/tests/test_luaconversions.inl +++ b/tests/test_luaconversions.inl @@ -29,6 +29,12 @@ #include #include +#include + +namespace { + constexpr int NumberFuzzTests = 100000; +} // namespace + class LuaConversionTest : public testing::Test { protected: lua_State* state; @@ -54,101 +60,2098 @@ TEST_F(LuaConversionTest, LuaExecution) { EXPECT_EQ(status, LUA_OK); } -#define CONVERSION_TEST_TEMPLATE(__NAME__, __TYPE__, __VALUE__) \ - TEST_F(LuaConversionTest, __NAME__) \ - { \ - using namespace openspace::properties; \ - bool success \ - = PropertyDelegate>::toLuaValue<__TYPE__>( \ - state, __VALUE__); \ - EXPECT_TRUE(success) << "toLuaValue"; \ - __TYPE__ value = static_cast<__TYPE__>(0); \ - value = PropertyDelegate>::fromLuaValue<__TYPE__>( \ - state, success); \ - EXPECT_TRUE(success) << "fromLuaValue"; \ - EXPECT_EQ(value, __VALUE__) << "fromLuaValue"; \ - } - -#define CONVERSION_TEST_NUMERICAL(__NAME__, __TYPE__, __VALUE__) \ - TEST_F(LuaConversionTest, __NAME__) \ - { \ - using namespace openspace::properties; \ - bool success \ - = PropertyDelegate>::toLuaValue<__TYPE__>( \ - state, __VALUE__); \ - EXPECT_TRUE(success) << "toLuaValue"; \ - __TYPE__ value = static_cast<__TYPE__>(0); \ - value = PropertyDelegate>::fromLuaValue<__TYPE__>( \ - state, success); \ - EXPECT_TRUE(success) << "fromLuaValue"; \ - EXPECT_EQ(value, __VALUE__) << "fromLuaValue"; \ - } - -CONVERSION_TEST_TEMPLATE(Bool, bool, true) - -CONVERSION_TEST_NUMERICAL(Char, char, 1) -//CONVERSION_TEST_NUMERICAL(WChar, wchar_t, 1); -CONVERSION_TEST_NUMERICAL(SignedChar, signed char, 1) -CONVERSION_TEST_NUMERICAL(UnsignedChar, unsigned char, 1) -CONVERSION_TEST_NUMERICAL(Short, short, 1) -CONVERSION_TEST_NUMERICAL(UnsignedShort, unsigned short, 1) - -//CONVERSION_TEST_NUMERICAL(Int, int, 1) -// Need to separate int into its own test as otherwise static_cast(1) would throw a -// useless cast warning -TEST_F(LuaConversionTest, Int) { +TEST_F(LuaConversionTest, Bool) { using namespace openspace::properties; - bool success = PropertyDelegate>::toLuaValue(state, 1); - EXPECT_TRUE(success) << "toLuaValue"; - int value = 0; - value = PropertyDelegate>::fromLuaValue(state, success); - EXPECT_TRUE(success) << "fromLuaValue"; - EXPECT_EQ(value, 1) << "fromLuaValue"; + 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"; } -CONVERSION_TEST_NUMERICAL(UnsignedInt, unsigned int, 1) -CONVERSION_TEST_NUMERICAL(Long, long, 1) -CONVERSION_TEST_NUMERICAL(UnsignedLong, unsigned long, 1) -CONVERSION_TEST_NUMERICAL(LongLong, long long, 1) -CONVERSION_TEST_NUMERICAL(UnsignedLongLong, unsigned long long, 1) -CONVERSION_TEST_NUMERICAL(Float, float, 1.f) -CONVERSION_TEST_NUMERICAL(Double, double, 1.0) -CONVERSION_TEST_NUMERICAL(LongDouble, long double, 1.0) +TEST_F(LuaConversionTest, Char) { + using namespace openspace::properties; + using T = char; + T val = T(1); -CONVERSION_TEST_NUMERICAL(Vec2, glm::vec2, glm::vec2(1.f)) -CONVERSION_TEST_NUMERICAL(Vec3, glm::vec3, glm::vec3(1.f)) -CONVERSION_TEST_NUMERICAL(Vec4, glm::vec4, glm::vec4(1.f)) -CONVERSION_TEST_NUMERICAL(DVec2, glm::dvec2, glm::dvec2(1.0)) -CONVERSION_TEST_NUMERICAL(DVec3, glm::dvec3, glm::dvec3(1.0)) -CONVERSION_TEST_NUMERICAL(DVec4, glm::dvec4, glm::dvec4(1.0)) -CONVERSION_TEST_NUMERICAL(IVec2, glm::ivec2, glm::ivec2(1)) -CONVERSION_TEST_NUMERICAL(IVec3, glm::ivec3, glm::ivec3(1)) -CONVERSION_TEST_NUMERICAL(IVec4, glm::ivec4, glm::ivec4(1)) -CONVERSION_TEST_NUMERICAL(UVec2, glm::uvec2, glm::uvec2(1)) -CONVERSION_TEST_NUMERICAL(UVec3, glm::uvec3, glm::uvec3(1)) -CONVERSION_TEST_NUMERICAL(UVec4, glm::uvec4, glm::uvec4(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"; +} -CONVERSION_TEST_NUMERICAL(Mat2x2, glm::mat2x2, glm::mat2x2(1.f)) -CONVERSION_TEST_NUMERICAL(Mat2x3, glm::mat2x3, glm::mat2x3(1.f)) -CONVERSION_TEST_NUMERICAL(Mat2x4, glm::mat2x4, glm::mat2x4(1.f)) -CONVERSION_TEST_NUMERICAL(Mat3x2, glm::mat3x2, glm::mat3x2(1.f)) -CONVERSION_TEST_NUMERICAL(Mat3x3, glm::mat3x3, glm::mat3x3(1.f)) -CONVERSION_TEST_NUMERICAL(Mat3x4, glm::mat3x4, glm::mat3x4(1.f)) -CONVERSION_TEST_NUMERICAL(Mat4x2, glm::mat4x2, glm::mat4x2(1.f)) -CONVERSION_TEST_NUMERICAL(Mat4x3, glm::mat4x3, glm::mat4x3(1.f)) -CONVERSION_TEST_NUMERICAL(Mat4x4, glm::mat4x4, glm::mat4x4(1.f)) -CONVERSION_TEST_NUMERICAL(DMat2x2, glm::dmat2x2, glm::dmat2x2(1.f)) -CONVERSION_TEST_NUMERICAL(DMat2x3, glm::dmat2x3, glm::dmat2x3(1.f)) -CONVERSION_TEST_NUMERICAL(DMat2x4, glm::dmat2x4, glm::dmat2x4(1.f)) -CONVERSION_TEST_NUMERICAL(DMat3x2, glm::dmat3x2, glm::dmat3x2(1.f)) -CONVERSION_TEST_NUMERICAL(DMat3x3, glm::dmat3x3, glm::dmat3x3(1.f)) -CONVERSION_TEST_NUMERICAL(DMat3x4, glm::dmat3x4, glm::dmat3x4(1.f)) -CONVERSION_TEST_NUMERICAL(DMat4x2, glm::dmat4x2, glm::dmat4x2(1.f)) -CONVERSION_TEST_NUMERICAL(DMat4x3, glm::dmat4x3, glm::dmat4x3(1.f)) -CONVERSION_TEST_NUMERICAL(DMat4x4, glm::dmat4x4, glm::dmat4x4(1.f)) +TEST_F(LuaConversionTest, CharFuzz) { + using namespace openspace::properties; + using T = char; -TEST_F(LuaConversionTest, String) -{ + 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( diff --git a/tests/test_optionproperty.inl b/tests/test_optionproperty.inl new file mode 100644 index 0000000000..5a82ffe71b --- /dev/null +++ b/tests/test_optionproperty.inl @@ -0,0 +1,224 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-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 + +using namespace openspace::properties; + +class OptionPropertyTest : public testing::Test {}; + +TEST_F(OptionPropertyTest, NoOption) { + OptionProperty p({ "id", "gui", "desc" }); + + ASSERT_EQ(false, p.hasOption()); +} + +TEST_F(OptionPropertyTest, SingleOptionSingleZero) { + OptionProperty p({ "id", "gui", "desc"}); + + p.addOption(0, "a"); + + p = 0; + + ASSERT_EQ(0, p.option().value); + ASSERT_EQ("a", p.option().description); +} + +TEST_F(OptionPropertyTest, SingleOptionSingleNegative) { + OptionProperty p({ "id", "gui", "desc" }); + + p.addOption(-1, "a"); + p = -1; + + ASSERT_EQ(-1, p.option().value); + ASSERT_EQ("a", p.option().description); +} + +TEST_F(OptionPropertyTest, SingleOptionSinglePositive) { + OptionProperty p({ "id", "gui", "desc" }); + + p.addOptions({ + { 1, "a" } + }); + p = 1; + + ASSERT_EQ(1, p.option().value); + ASSERT_EQ("a", p.option().description); +} + +TEST_F(OptionPropertyTest, SingleOptionMultipleZero) { + OptionProperty p({ "id", "gui", "desc" }); + + p.addOptions({ + { 0, "a" } + }); + p = 0; + + ASSERT_EQ(0, p.option().value); + ASSERT_EQ("a", p.option().description); +} + +TEST_F(OptionPropertyTest, SingleOptionMultipleNegative) { + OptionProperty p({ "id", "gui", "desc" }); + + p.addOptions({ + { -1, "a" } + }); + p = -1; + + ASSERT_EQ(-1, p.option().value); + ASSERT_EQ("a", p.option().description); +} + +TEST_F(OptionPropertyTest, SingleOptionMultiplePositive) { + OptionProperty p({ "id", "gui", "desc" }); + + p.addOptions({ + { 1, "a" } + }); + p = 1; + + ASSERT_EQ(1, p.option().value); + ASSERT_EQ("a", p.option().description); +} + +TEST_F(OptionPropertyTest, SingleOptionsZeroBasedConsecutive) { + OptionProperty p({ "id", "gui", "desc" }); + + p.addOption(0, "a"); + p.addOption(1, "b"); + p.addOption(2, "c"); + + p = 0; + ASSERT_EQ(0, p.option().value); + ASSERT_EQ("a", p.option().description); + + p = 1; + ASSERT_EQ(1, p.option().value); + ASSERT_EQ("b", p.option().description); + + p = 2; + ASSERT_EQ(2, p.option().value); + ASSERT_EQ("c", p.option().description); +} + +TEST_F(OptionPropertyTest, SingleOptionsZeroBasedNonConsecutive) { + OptionProperty p({ "id", "gui", "desc" }); + + p.addOption(0, "a"); + p.addOption(2, "b"); + p.addOption(4, "c"); + + p = 0; + ASSERT_EQ(0, p.option().value); + ASSERT_EQ("a", p.option().description); + + p = 2; + ASSERT_EQ(2, p.option().value); + ASSERT_EQ("b", p.option().description); + + p = 4; + ASSERT_EQ(4, p.option().value); + ASSERT_EQ("c", p.option().description); +} + +TEST_F(OptionPropertyTest, SingleOptionsNegativeBasedConsecutive) { + OptionProperty p({ "id", "gui", "desc" }); + + p.addOption(-1, "a"); + p.addOption(-2, "b"); + p.addOption(-3, "c"); + + p = -1; + ASSERT_EQ(-1, p.option().value); + ASSERT_EQ("a", p.option().description); + + p = -2; + ASSERT_EQ(-2, p.option().value); + ASSERT_EQ("b", p.option().description); + + p = -3; + ASSERT_EQ(-3, p.option().value); + ASSERT_EQ("c", p.option().description); +} + +TEST_F(OptionPropertyTest, SingleOptionsNonZeroBasedNonConsecutive) { + OptionProperty p({ "id", "gui", "desc" }); + + p.addOption(-1, "a"); + p.addOption(-3, "b"); + p.addOption(-5, "c"); + + p = -1; + ASSERT_EQ(-1, p.option().value); + ASSERT_EQ("a", p.option().description); + + p = -3; + ASSERT_EQ(-3, p.option().value); + ASSERT_EQ("b", p.option().description); + + p = -5; + ASSERT_EQ(-5, p.option().value); + ASSERT_EQ("c", p.option().description); +} + +TEST_F(OptionPropertyTest, SingleOptionsZeroBasedAlternating) { + OptionProperty p({ "id", "gui", "desc" }); + + p.addOption(0, "a"); + p.addOption(2, "b"); + p.addOption(-4, "c"); + + p = 0; + ASSERT_EQ(0, p.option().value); + ASSERT_EQ("a", p.option().description); + + p = 2; + ASSERT_EQ(2, p.option().value); + ASSERT_EQ("b", p.option().description); + + p = -4; + ASSERT_EQ(-4, p.option().value); + ASSERT_EQ("c", p.option().description); +} + +TEST_F(OptionPropertyTest, SingleOptionsNonZeroBasedAlternating) { + OptionProperty p({ "id", "gui", "desc" }); + + p.addOption(-20, "a"); + p.addOption(2, "b"); + p.addOption(-10, "c"); + + p = -20; + ASSERT_EQ(-20, p.option().value); + ASSERT_EQ("a", p.option().description); + + p = 2; + ASSERT_EQ(2, p.option().value); + ASSERT_EQ("b", p.option().description); + + p = -10; + ASSERT_EQ(-10, p.option().value); + ASSERT_EQ("c", p.option().description); +} diff --git a/tests/test_scriptscheduler.inl b/tests/test_scriptscheduler.inl index 318359dd4a..24ef3b76ab 100644 --- a/tests/test_scriptscheduler.inl +++ b/tests/test_scriptscheduler.inl @@ -37,7 +37,7 @@ protected: void SetUp() override { openspace::SpiceManager::initialize(); openspace::SpiceManager::ref().loadKernel( - "${TESTDIR}/SpiceTest/spicekernels/naif0008.tls" + absPath("${TESTDIR}/SpiceTest/spicekernels/naif0008.tls") ); } diff --git a/tests/test_spicemanager.inl b/tests/test_spicemanager.inl index db78b25f3d..437a69aacc 100644 --- a/tests/test_spicemanager.inl +++ b/tests/test_spicemanager.inl @@ -58,47 +58,47 @@ namespace spicemanager_constants { void loadMetaKernel() { int k1 = openspace::SpiceManager::ref().loadKernel( - ("${TESTDIR}/SpiceTest/spicekernels/naif0008.tls") + absPath("${TESTDIR}/SpiceTest/spicekernels/naif0008.tls") ); EXPECT_EQ(1, k1) << "loadKernel did not return proper id"; int k2 = openspace::SpiceManager::ref().loadKernel( - ("${TESTDIR}/SpiceTest/spicekernels/cas00084.tsc") + absPath("${TESTDIR}/SpiceTest/spicekernels/cas00084.tsc") ); EXPECT_EQ(2, k2) << "loadKernel did not return proper id"; int k3 = openspace::SpiceManager::ref().loadKernel( - ("${TESTDIR}/SpiceTest/spicekernels/981005_PLTEPH-DE405S.bsp") + absPath("${TESTDIR}/SpiceTest/spicekernels/981005_PLTEPH-DE405S.bsp") ); EXPECT_EQ(3, k3) << "loadKernel did not return proper id"; int k4 = openspace::SpiceManager::ref().loadKernel( - ("${TESTDIR}/SpiceTest/spicekernels/020514_SE_SAT105.bsp") + absPath("${TESTDIR}/SpiceTest/spicekernels/020514_SE_SAT105.bsp") ); EXPECT_EQ(4, k4) << "loadKernel did not return proper id"; int k5 = openspace::SpiceManager::ref().loadKernel( - ("${TESTDIR}/SpiceTest/spicekernels/030201AP_SK_SM546_T45.bsp") + 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( - ("${TESTDIR}/SpiceTest/spicekernels/cas_v37.tf") + absPath("${TESTDIR}/SpiceTest/spicekernels/cas_v37.tf") ); EXPECT_EQ(6, k6) << "loadKernel did not return proper id"; int k7 = openspace::SpiceManager::ref().loadKernel( - ("${TESTDIR}/SpiceTest/spicekernels/04135_04171pc_psiv2.bc") + absPath("${TESTDIR}/SpiceTest/spicekernels/04135_04171pc_psiv2.bc") ); EXPECT_EQ(7, k7) << "loadKernel did not return proper id"; int k8 = openspace::SpiceManager::ref().loadKernel( - ("${TESTDIR}/SpiceTest/spicekernels/cpck05Mar2004.tpc") + absPath("${TESTDIR}/SpiceTest/spicekernels/cpck05Mar2004.tpc") ); EXPECT_EQ(8, k8) << "loadKernel did not return proper id"; int k9 = openspace::SpiceManager::ref().loadKernel( - ("${TESTDIR}/SpiceTest/spicekernels/cas_iss_v09.ti") + absPath("${TESTDIR}/SpiceTest/spicekernels/cas_iss_v09.ti") ); EXPECT_EQ(9, k9) << "loadKernel did not return proper id"; }