mirror of
https://gitlab.com/splashmapper/splash.git
synced 2026-06-16 12:33:50 +02:00
Reorganized tests
This commit is contained in:
committed by
Nicolas Bouillot
parent
132c4a209f
commit
8ac1a9d49e
@@ -0,0 +1,78 @@
|
||||
#include <doctest.h>
|
||||
|
||||
#include "./splash.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace Splash;
|
||||
|
||||
/*************/
|
||||
TEST_CASE("Testing Attribute usage")
|
||||
{
|
||||
int value = 0;
|
||||
auto attr = Attribute("attribute",
|
||||
[&](const Values& args) {
|
||||
value = args[0].as<int>();
|
||||
return true;
|
||||
},
|
||||
[&]() -> Values { return {value}; },
|
||||
{'n'});
|
||||
attr.setDescription("A very simple attribute");
|
||||
CHECK_EQ(attr.getDescription(), "A very simple attribute");
|
||||
CHECK_EQ(attr.getSyncMethod(), Attribute::Sync::auto_sync);
|
||||
|
||||
attr.setSyncMethod(Attribute::Sync::force_sync);
|
||||
CHECK_EQ(attr.getSyncMethod(), Attribute::Sync::force_sync);
|
||||
|
||||
CHECK(attr.hasGetter());
|
||||
CHECK_FALSE(attr.isDefault());
|
||||
|
||||
CHECK(attr({42}));
|
||||
CHECK_EQ(attr()[0].as<int>(), 42);
|
||||
CHECK_FALSE(attr({"Patate"}));
|
||||
CHECK(attr({42, "Patate"}));
|
||||
|
||||
CHECK(attr({42}));
|
||||
attr.lock();
|
||||
CHECK(attr.isLocked());
|
||||
CHECK_FALSE(attr({512}));
|
||||
CHECK_EQ(attr()[0].as<int>(), 42);
|
||||
attr.unlock();
|
||||
|
||||
attr = Attribute(
|
||||
"attribute",
|
||||
[&](const Values& args) {
|
||||
value = args[0].as<int>();
|
||||
return true;
|
||||
},
|
||||
[&]() -> Values {
|
||||
return {value, "some string"};
|
||||
},
|
||||
{'n', 's'});
|
||||
CHECK_FALSE(attr({3.14159}));
|
||||
|
||||
attr = Attribute("attribute",
|
||||
[&](const Values& args) {
|
||||
value = args[0].as<int>();
|
||||
return true;
|
||||
},
|
||||
nullptr,
|
||||
{'s'});
|
||||
CHECK(attr({"A girl has no name"}));
|
||||
CHECK(attr().empty());
|
||||
}
|
||||
|
||||
/*************/
|
||||
TEST_CASE("Testing Attribute constructors")
|
||||
{
|
||||
auto attr = Attribute();
|
||||
CHECK_FALSE(attr.hasGetter());
|
||||
CHECK(attr.isDefault());
|
||||
attr({38});
|
||||
CHECK_EQ(attr()[0].as<int>(), 38);
|
||||
|
||||
attr = Attribute("attribute");
|
||||
CHECK_FALSE(attr.hasGetter());
|
||||
CHECK(attr.isDefault());
|
||||
attr({"Flying machine"});
|
||||
CHECK_EQ(attr()[0].as<string>(), "Flying machine");
|
||||
}
|
||||
Reference in New Issue
Block a user