property_test.cpp 1.04 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
#include <QtTest/QtTest>

#include "cellulut_tests.hpp"

#include "property.hpp"

class PropertyClass : public HasUserProperties
{
public:
    DEFINE_CONFIGURABLE_PROPERTY(StringProperty, test_str, "Test String", "hello world");
11
    DEFINE_CONFIGURABLE_DYNLIST(CoordinateProperty, coords, "Coordinates", ());
12
13
14
15
16
17
18
};

void CellulutTests::test_property()
{
    PropertyClass test;

    QVERIFY(test.test_str.str == "hello world");
19
20
    QVERIFY(test.test_str.identifier() == "test_str");
    QVERIFY(test.test_str.display_name() == "Test String");
21
    QVERIFY(test.get_properties().size() == 2);
22
    QVERIFY(test.get_properties()[0].get() == &test.test_str);
23
24
25
26
27
28
29
30

    Neighborhood n;
    n.addNeighbor({0, 1}, 1);
    n.addNeighbor({-2, 1}, 1);
    n.addNeighbor({1, 1}, 2);

    test.coords.load_from_neighborhood(n);

31
    QCOMPARE(test.coords.size(), 3u);
32
33
34
35
36
    for (unsigned i = 0; i < test.coords.size(); ++i)
    {
        CoordinateProperty& coord = static_cast<CoordinateProperty&>(test.coords.at(i));
        QCOMPARE(coord.c, n.neighbor_at_index(i).first);
    }
37
38
}