unittests_properties.hh 3.91 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
#ifndef UNITTESTS_BASICS_HH_
#define UNITTESTS_BASICS_HH_

#include <iostream>

#include <gtest/gtest.h>

#include "unittests_common.hh"

#include <OpenVolumeMesh/Attribs/StatusAttrib.hh>

using namespace OpenVolumeMesh;

14
15
16
17
18
19
20
21
22
23
TEST_F(PolyhedralMeshBase, PropertySmartPointerTestSimple) {

    generatePolyhedralMesh(mesh_);

    for(int i = 0; i < 1; ++i) {

        VertexPropertyT<float> v_prop = mesh_.request_vertex_property<float>("SimpleTestProp");
    }
}

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
TEST_F(PolyhedralMeshBase, PropertySmartPointerTest1) {

    generatePolyhedralMesh(mesh_);

    EXPECT_EQ(12u, mesh_.n_vertices());

    VertexPropertyT<double> v_prop_d = mesh_.request_vertex_property<double>("MyVPropDbl");

    for(int i = 0; i < 1; ++i) {

        VertexPropertyT<float> v_prop = mesh_.request_vertex_property<float>("MyVProp");

        v_prop[0] = 1.4f;

        VertexPropertyT<float> v_prop2(v_prop);

        VertexPropertyT<float> v_prop3 = v_prop;

        EXPECT_EQ(12u, v_prop3->n_elements());

        EXPECT_EQ(2u, mesh_.n_vertex_props());

        VertexPropertyT<float> v_prop_duplicate = mesh_.request_vertex_property<float>("MyVProp");

48
        EXPECT_EQ(2u, mesh_.n_vertex_props());
49
50
51
52
53

        EXPECT_FLOAT_EQ(1.4f, v_prop3[0]);

        VertexPropertyT<std::string> v_prop_duplicate_2 = mesh_.request_vertex_property<std::string>("MyVProp");

54
        EXPECT_EQ(3u, mesh_.n_vertex_props());
55
56
    }

Mike Kremer's avatar
Mike Kremer committed
57
    mesh_.set_persistent(v_prop_d);
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

    EXPECT_EQ(1u, mesh_.n_vertex_props());

    mesh_.add_vertex(Vec3d(0.0, 0.0, 0.0));

    EXPECT_EQ(13u, mesh_.n_vertices());

    VertexPropertyT<double> v_prop_d2 = mesh_.request_vertex_property<double>("MyVPropDbl");

    EXPECT_EQ(1u, mesh_.n_vertex_props());

    HalfEdgePropertyT<int> he_prop = mesh_.request_halfedge_property<int>("MyHEProp");

    EXPECT_EQ(40u, he_prop->n_elements());

    mesh_.add_edge(VertexHandle(0), VertexHandle(2));

    EXPECT_EQ(42u, he_prop->n_elements());
}

TEST_F(HexahedralMeshBase, PropertySmartPointerPersistencyTest1) {

    generateHexahedralMesh(mesh_);

    for(int i = 0; i < 1; ++i) {

        VertexPropertyT<float> v_prop = mesh_.request_vertex_property<float>("FloatVProp");

        v_prop[0] = 24.5f;
        v_prop[11] = 2.34f;

Mike Kremer's avatar
Mike Kremer committed
89
        mesh_.set_persistent(v_prop);
90
91
92
93
94
95
96
97
    }

    VertexPropertyT<float> v_prop2 = mesh_.request_vertex_property<float>("FloatVProp");

    EXPECT_FLOAT_EQ(24.5f, v_prop2[0]);
    EXPECT_FLOAT_EQ(2.34f, v_prop2[11]);
}

98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
TEST_F(HexahedralMeshBase, PropertySmartPointerPersistencyTest2) {

    generateHexahedralMesh(mesh_);

    for(int i = 0; i < 1; ++i) {

        VertexPropertyT<float> v_prop = mesh_.request_vertex_property<float>("FloatVProp");

        mesh_.set_persistent(v_prop);
    }

    EXPECT_EQ(1u, mesh_.n_vertex_props());

    for(int i = 0; i < 1; ++i) {

        VertexPropertyT<float> v_prop = mesh_.request_vertex_property<float>("FloatVProp");

        EXPECT_EQ(1u, mesh_.n_vertex_props());

        mesh_.set_persistent(v_prop, false);
    }

    EXPECT_EQ(0u, mesh_.n_vertex_props());
}

Mike Kremer's avatar
Mike Kremer committed
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
TEST_F(HexahedralMeshBase, AnonymousPropertiesTest1) {

    generateHexahedralMesh(mesh_);

    CellPropertyT<float> c_prop = mesh_.request_cell_property<float>();
    CellPropertyT<float> c_prop2 = c_prop;

    EXPECT_EQ(1u, mesh_.n_cell_props());

    mesh_.set_persistent(c_prop);

    EXPECT_EQ(1u, mesh_.n_cell_props());

    mesh_.set_persistent(c_prop2, false);

    EXPECT_EQ(1u, mesh_.n_cell_props());
}

TEST_F(HexahedralMeshBase, AnonymousPropertiesTest2) {

    generateHexahedralMesh(mesh_);

    CellPropertyT<float> c_prop1 = mesh_.request_cell_property<float>();

    for(int i = 0; i < 1; ++i) {

        CellPropertyT<float> c_prop2 = mesh_.request_cell_property<float>();
        EXPECT_EQ(2u, mesh_.n_cell_props());
    }

    EXPECT_EQ(1u, mesh_.n_cell_props());
}

156
157
158
159
160
161
162
163
164
165
TEST_F(PolyhedralMeshBase, StatusTest) {

    generatePolyhedralMesh(mesh_);

    EXPECT_EQ(12u, mesh_.n_vertices());

    StatusAttrib status(mesh_);
}

#endif /* UNITTESTS_BASICS_HH_ */