mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-24 22:09:10 -06:00
Simplify property handling; Fix unit tests
This commit is contained in:
@@ -199,10 +199,8 @@ public:
|
||||
* no-op.
|
||||
*
|
||||
* \param state The Lua state from which the value will be decoded
|
||||
* \return `true` if the decoding and setting of the value succeeded, `false`
|
||||
* otherwise
|
||||
*/
|
||||
virtual bool setLuaValue(lua_State* state);
|
||||
virtual void setLuaValue(lua_State* state);
|
||||
|
||||
/**
|
||||
* Returns the Lua type that will be put onto the stack in the Property::getLua method
|
||||
|
||||
@@ -115,7 +115,7 @@ public:
|
||||
* \param state The Lua state from which the value will be decoded
|
||||
* \return `true` if the decoding succeeded; `false` otherwise
|
||||
*/
|
||||
virtual bool setLuaValue(lua_State* state) override;
|
||||
virtual void setLuaValue(lua_State* state) override;
|
||||
|
||||
/// \see Property::typeLua
|
||||
virtual int typeLua() const override = 0;
|
||||
|
||||
@@ -85,15 +85,9 @@ bool TemplateProperty<T>::getLuaValue(lua_State* state) const {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool TemplateProperty<T>::setLuaValue(lua_State* state) {
|
||||
try {
|
||||
T thisValue = fromLuaConversion(state);
|
||||
set(std::any(thisValue));
|
||||
return true;
|
||||
}
|
||||
catch (const ghoul::lua::LuaFormatException&) {
|
||||
return false;
|
||||
}
|
||||
void TemplateProperty<T>::setLuaValue(lua_State* state) {
|
||||
T thisValue = fromLuaConversion(state);
|
||||
set(std::any(thisValue));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
* \param state The unused Lua state
|
||||
* \return Returns always `true`
|
||||
*/
|
||||
bool setLuaValue(lua_State* state) override;
|
||||
void setLuaValue(lua_State* state) override;
|
||||
|
||||
/**
|
||||
* Silently ignores any value that is passed into this function and will trigger the
|
||||
|
||||
@@ -98,9 +98,7 @@ bool Property::getLuaValue(lua_State*) const {
|
||||
|
||||
void Property::set(std::any) {}
|
||||
|
||||
bool Property::setLuaValue(lua_State*) {
|
||||
return false;
|
||||
}
|
||||
void Property::setLuaValue(lua_State*) {}
|
||||
|
||||
const std::type_info& Property::type() const {
|
||||
return typeid(void);
|
||||
|
||||
@@ -34,9 +34,8 @@ std::string_view TriggerProperty::className() const {
|
||||
return "TriggerProperty";
|
||||
}
|
||||
|
||||
bool TriggerProperty::setLuaValue(lua_State*) {
|
||||
void TriggerProperty::setLuaValue(lua_State*) {
|
||||
notifyChangeListeners();
|
||||
return true;
|
||||
}
|
||||
|
||||
void TriggerProperty::set(std::any) {
|
||||
|
||||
@@ -94,9 +94,7 @@ TEST_CASE("StringListProperty: Invalid Set Lua Value - Not List", "[stringlistpr
|
||||
ghoul::lua::LuaState L;
|
||||
ghoul::lua::push(L, 2); // Not a list
|
||||
|
||||
bool success = p.setLuaValue(L);
|
||||
|
||||
CHECK(!success);
|
||||
CHECK_THROWS(p.setLuaValue(L));
|
||||
}
|
||||
|
||||
TEST_CASE("StringListProperty: Get Lua Value", "[stringlistproperty]") {
|
||||
@@ -192,9 +190,7 @@ TEST_CASE("IntListProperty: Set Lua Value - Non-number", "[intlistproperty]") {
|
||||
|
||||
ghoul::lua::LuaState L;
|
||||
ghoul::lua::push(L, std::vector{ "not a number", "oops" });
|
||||
bool success = p.setLuaValue(L);
|
||||
|
||||
CHECK(success == false);
|
||||
CHECK_THROWS(p.setLuaValue(L));
|
||||
CHECK(p.value() == std::vector<int>());
|
||||
}
|
||||
|
||||
@@ -204,9 +200,7 @@ TEST_CASE("IntListProperty: Invalid Set Lua Value - Not List", "[intlistproperty
|
||||
ghoul::lua::LuaState L;
|
||||
ghoul::lua::push(L, 2); // Not a list
|
||||
|
||||
bool success = p.setLuaValue(L);
|
||||
|
||||
CHECK(!success);
|
||||
CHECK_THROWS(p.setLuaValue(L));
|
||||
}
|
||||
|
||||
TEST_CASE("IntListProperty: Get Lua Value", "[intlistproperty]") {
|
||||
@@ -302,9 +296,7 @@ TEST_CASE("DoubleListProperty: Set Lua Value - Non-number", "[doublelistproperty
|
||||
|
||||
ghoul::lua::LuaState L;
|
||||
ghoul::lua::push(L, std::vector{"not a number", "oops"});
|
||||
bool success = p.setLuaValue(L);
|
||||
|
||||
CHECK(success == false);
|
||||
CHECK_THROWS(p.setLuaValue(L));
|
||||
CHECK(p.value() == std::vector<double>());
|
||||
}
|
||||
|
||||
@@ -314,8 +306,7 @@ TEST_CASE("DoubleListProperty: Invalid Set Lua Value - Not List", "[doublelistpr
|
||||
ghoul::lua::LuaState L;
|
||||
ghoul::lua::push(L, 2); // Not a list
|
||||
|
||||
bool success = p.setLuaValue(L);
|
||||
CHECK(!success);
|
||||
CHECK_THROWS(p.setLuaValue(L));
|
||||
}
|
||||
|
||||
TEST_CASE("DoubleListProperty: Get Lua Value", "[doublelistproperty]") {
|
||||
|
||||
@@ -167,7 +167,7 @@ TEST_CASE("Minimal", "[profile]") {
|
||||
|
||||
Profile ref;
|
||||
ref.version.major = 1;
|
||||
ref.version.minor = 1;
|
||||
ref.version.minor = 2;
|
||||
CHECK(profile == ref);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user