/***************************************************************************************** * * * OpenSpace * * * * Copyright (c) 2014-2021 * * * * Permission is hereby granted, free of charge, to any person obtaining a copy of this * * software and associated documentation files (the "Software"), to deal in the Software * * without restriction, including without limitation the rights to use, copy, modify, * * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * * permit persons to whom the Software is furnished to do so, subject to the following * * conditions: * * * * The above copyright notice and this permission notice shall be included in all copies * * or substantial portions of the Software. * * * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ #include "catch2/catch.hpp" #include #include #include #include #include #include #include #include #include TEST_CASE("StringListProperty: Class Name and Default Value", "[stringlistproperty]") { openspace::properties::StringListProperty p({ "id", "gui", "desc" }); REQUIRE(p.className() == "StringListProperty"); REQUIRE(p.value() == std::vector()); } TEST_CASE("StringListProperty: Set Value", "[stringlistproperty]") { openspace::properties::StringListProperty p({ "id", "gui", "desc" }); const std::vector list{ "a", "b", "c" }; p.setValue(list); REQUIRE(p.value() == list); // Empty value p.setValue({}); REQUIRE(p.value() == std::vector()); } TEST_CASE("StringListProperty: Get String Value", "[stringlistproperty]") { openspace::properties::StringListProperty p({ "id", "gui", "desc" }); const std::vector list{ "a", "b", "c" }; p.setValue(list); std::string res; p.getStringValue(res); REQUIRE(res == "[\"a\",\"b\",\"c\"]"); } TEST_CASE("StringListProperty: Set Lua Value", "[stringlistproperty]") { openspace::properties::StringListProperty p({ "id", "gui", "desc" }); const std::vector list{ "a", "b", "c" }; ghoul::lua::LuaState L; ghoul::lua::push(L, list); p.setLuaValue(L); REQUIRE(p.value() == list); } TEST_CASE("StringListProperty: Set Lua Value - Empty", "[stringlistproperty]") { openspace::properties::StringListProperty p({ "id", "gui", "desc" }); ghoul::lua::LuaState L; ghoul::lua::push(L, std::vector{}); p.setLuaValue(L); REQUIRE(p.value() == std::vector{}); } TEST_CASE("StringListProperty: Invalid Set Lua Value - Not List", "[stringlistproperty]") { openspace::properties::StringListProperty p({ "id", "gui", "desc" }); ghoul::lua::LuaState L; ghoul::lua::push(L, 2); // Not a list bool success = p.setLuaValue(L); REQUIRE(!success); } TEST_CASE("StringListProperty: Get Lua Value", "[stringlistproperty]") { openspace::properties::StringListProperty p({ "id", "gui", "desc" }); const std::vector list{ "a", "b", "c" }; p.setValue(list); ghoul::lua::LuaState L; p.getLuaValue(L); REQUIRE(ghoul::lua::luaValueToString(L, 1) == "{ 1.000000 = a, 2.000000 = b, 3.000000 = c }" ); } TEST_CASE("StringListProperty: Get Empty Lua Value", "[stringlistproperty]") { openspace::properties::StringListProperty p({ "id", "gui", "desc" }); ghoul::lua::LuaState L; p.getLuaValue(L); REQUIRE(ghoul::lua::luaValueToString(L, 1) == "{}"); } TEST_CASE("StringListProperty: Value From Copying Variable", "[stringlistproperty]") { openspace::properties::StringListProperty p({ "id", "gui", "desc" }); const std::vector list{ "a", "b", "c" }; p = list; REQUIRE(p.value() == list); } // IntListProperty TEST_CASE("IntListProperty: Class Name and Default Value", "[intlistproperty]") { openspace::properties::IntListProperty p({ "id", "gui", "desc" }); REQUIRE(p.className() == "IntListProperty"); REQUIRE(p.value() == std::vector()); } TEST_CASE("IntListProperty: Set Value", "[intlistproperty]") { openspace::properties::IntListProperty p({ "id", "gui", "desc" }); const std::vector list{ 1, 2, 3}; p.setValue(list); REQUIRE(p.value() == list); // Empty value p.setValue({}); REQUIRE(p.value() == std::vector()); } TEST_CASE("IntListProperty: Get String Value", "[intlistproperty]") { openspace::properties::IntListProperty p({ "id", "gui", "desc" }); const std::vector list{ 1, 2, 3 }; p.setValue(list); std::string res; p.getStringValue(res); REQUIRE(res == "[1,2,3]"); } TEST_CASE("IntListProperty: Set Lua Value", "[intlistproperty]") { openspace::properties::IntListProperty p({ "id", "gui", "desc" }); const std::vector list{ 1, 2, 3 }; ghoul::lua::LuaState L; ghoul::lua::push(L, list); p.setLuaValue(L); REQUIRE(p.value() == list); } TEST_CASE("IntListProperty: Set Lua Value - Empty", "[intlistproperty]") { openspace::properties::IntListProperty p({ "id", "gui", "desc" }); ghoul::lua::LuaState L; ghoul::lua::push(L, std::vector()); p.setLuaValue(L); REQUIRE(p.value() == std::vector()); } TEST_CASE("IntListProperty: Set Lua Value - Non-number", "[intlistproperty]") { openspace::properties::IntListProperty p({ "id", "gui", "desc" }); ghoul::lua::LuaState L; ghoul::lua::push(L, std::vector{ "not a number", "oops" }); bool success = p.setLuaValue(L); REQUIRE(success == false); REQUIRE(p.value() == std::vector()); } TEST_CASE("IntListProperty: Invalid Set Lua Value - Not List", "[intlistproperty]") { openspace::properties::IntListProperty p({ "id", "gui", "desc" }); ghoul::lua::LuaState L; ghoul::lua::push(L, 2); // Not a list bool success = p.setLuaValue(L); REQUIRE(!success); } TEST_CASE("IntListProperty: Get Lua Value", "[intlistproperty]") { openspace::properties::IntListProperty p({ "id", "gui", "desc" }); const std::vector list{ 1, 2, 3 }; p.setValue(list); ghoul::lua::LuaState L; p.getLuaValue(L); REQUIRE(ghoul::lua::luaValueToString(L, 1) == "{ 1.000000 = 1.000000, 2.000000 = 2.000000, 3.000000 = 3.000000 }" ); } TEST_CASE("IntListProperty: Get Empty Lua Value", "[intlistproperty]") { openspace::properties::IntListProperty p({ "id", "gui", "desc" }); ghoul::lua::LuaState L; p.getLuaValue(L); REQUIRE(ghoul::lua::luaValueToString(L, 1) == "{}"); } TEST_CASE("IntListProperty: Value From Copying Variable", "[intlistproperty]") { openspace::properties::IntListProperty p({ "id", "gui", "desc" }); const std::vector list{ 1, 2, 3 }; p = list; REQUIRE(p.value() == list); } // DoubleListProperty TEST_CASE("DoubleListProperty: Class Name and Default Value", "[doublelistproperty]") { openspace::properties::DoubleListProperty p({ "id", "gui", "desc" }); REQUIRE(p.className() == "DoubleListProperty"); REQUIRE(p.value() == std::vector()); } TEST_CASE("DoubleListProperty: Set Value", "[doublelistproperty]") { openspace::properties::DoubleListProperty p({ "id", "gui", "desc" }); const std::vector list{ 1.0, 2.0, 3.0 }; p.setValue(list); REQUIRE(p.value() == list); // Empty value p.setValue({}); REQUIRE(p.value() == std::vector()); } TEST_CASE("DoubleListProperty: Get String Value", "[doublelistproperty]") { openspace::properties::DoubleListProperty p({ "id", "gui", "desc" }); const std::vector list{ 1.0, 2.0, 3.0 }; p.setValue(list); std::string res; p.getStringValue(res); REQUIRE(res == "[1.0,2.0,3.0]"); } TEST_CASE("DoubleListProperty: Set Lua Value", "[doublelistproperty]") { openspace::properties::DoubleListProperty p({ "id", "gui", "desc" }); const std::vector list{ 1.0, 2.0, 3.0 }; ghoul::lua::LuaState L; ghoul::lua::push(L, list); p.setLuaValue(L); REQUIRE(p.value() == list); } TEST_CASE("DoubleListProperty: Set Lua Value - Empty", "[doublelistproperty]") { openspace::properties::DoubleListProperty p({ "id", "gui", "desc" }); ghoul::lua::LuaState L; ghoul::lua::push(L, std::vector()); p.setLuaValue(L); REQUIRE(p.value() == std::vector()); } TEST_CASE("DoubleListProperty: Set Lua Value - Non-number", "[doublelistproperty]") { openspace::properties::DoubleListProperty p({ "id", "gui", "desc" }); ghoul::lua::LuaState L; ghoul::lua::push(L, std::vector{"not a number", "oops"}); bool success = p.setLuaValue(L); REQUIRE(success == false); REQUIRE(p.value() == std::vector()); } TEST_CASE("DoubleListProperty: Invalid Set Lua Value - Not List", "[doublelistproperty]") { openspace::properties::DoubleListProperty p({ "id", "gui", "desc" }); ghoul::lua::LuaState L; ghoul::lua::push(L, 2); // Not a list bool success = p.setLuaValue(L); REQUIRE(!success); } TEST_CASE("DoubleListProperty: Get Lua Value", "[doublelistproperty]") { openspace::properties::DoubleListProperty p({ "id", "gui", "desc" }); const std::vector list{ 1.0, 2.0, 3.0 }; p.setValue(list); ghoul::lua::LuaState L; p.getLuaValue(L); REQUIRE(ghoul::lua::luaValueToString(L, 1) == "{ 1.000000 = 1.000000, 2.000000 = 2.000000, 3.000000 = 3.000000 }" ); } TEST_CASE("DoubleListProperty: Get Empty Lua Value", "[doublelistproperty]") { openspace::properties::DoubleListProperty p({ "id", "gui", "desc" }); ghoul::lua::LuaState L; p.getLuaValue(L); REQUIRE(ghoul::lua::luaValueToString(L, 1) == "{}"); } TEST_CASE("DoubleListProperty: Value From Copying Variable", "[doublelistproperty]") { openspace::properties::DoubleListProperty p({ "id", "gui", "desc" }); const std::vector list{ 1.0, 2.0, 3.0 }; p = list; REQUIRE(p.value() == list); }