Branch data Line data Source code
1 : : #include "TestRunner.hpp"
2 : : #include "iMesh.h"
3 : : #include "iMesh_extensions.h"
4 : : #include "MBiMesh.hpp"
5 : : #include "moab/Core.hpp"
6 : : #include <algorithm>
7 : :
8 : : void test_tag_iterate();
9 : : void test_step_iter();
10 : :
11 : 1 : int main( int argc, char* argv[] )
12 : : {
13 : 1 : REGISTER_TEST( test_tag_iterate );
14 : 1 : REGISTER_TEST( test_step_iter );
15 : :
16 : 1 : return RUN_TESTS( argc, argv );
17 : : }
18 : :
19 : 1 : void test_tag_iterate()
20 : : {
21 : : iMesh_Instance mesh;
22 : : int err;
23 [ + - ]: 1 : iMesh_newMesh( "", &mesh, &err, 0 );
24 [ + - ]: 1 : CHECK_EQUAL( iBase_SUCCESS, err );
25 : :
26 : : iBase_EntitySetHandle root_set, entset;
27 [ + - ]: 1 : iMesh_getRootSet( mesh, &root_set, &err );
28 [ + - ]: 1 : CHECK_EQUAL( iBase_SUCCESS, err );
29 : :
30 : 1 : iBase_EntityHandle* verts = 0;
31 : 1 : int verts_alloc = 0, verts_size = 0;
32 : 1 : double coords[] = { 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5 };
33 [ + - ]: 1 : iMesh_createVtxArr( mesh, 6, iBase_INTERLEAVED, coords, 18, &verts, &verts_alloc, &verts_size, &err );
34 [ + - ]: 1 : CHECK_EQUAL( iBase_SUCCESS, err );
35 : :
36 : : /* create an entity set with two subranges */
37 [ + - ]: 1 : iMesh_createEntSet( mesh, 0, &entset, &err );
38 [ + - ]: 1 : CHECK_EQUAL( iBase_SUCCESS, err );
39 [ + - ]: 1 : iMesh_addEntArrToSet( mesh, verts, 2, entset, &err );
40 [ + - ]: 1 : CHECK_EQUAL( iBase_SUCCESS, err );
41 [ + - ]: 1 : iMesh_addEntArrToSet( mesh, &verts[3], 3, entset, &err );
42 [ + - ]: 1 : CHECK_EQUAL( iBase_SUCCESS, err );
43 : :
44 : : /* create a dbl tag and set vertices */
45 : : iBase_TagHandle tagh;
46 [ + - ]: 1 : iMesh_createTagWithOptions( mesh, "dum", "moab:TAG_STORAGE_TYPE=DENSE", 1, iBase_DOUBLE, &tagh, &err, 3, 27 );
47 [ + - ]: 1 : CHECK_EQUAL( iBase_SUCCESS, err );
48 [ + - ]: 1 : iMesh_setDblArrData( mesh, verts, 6, tagh, coords + 3, 6, &err );
49 [ + - ]: 1 : CHECK_EQUAL( iBase_SUCCESS, err );
50 : :
51 : : /* get an iterator over the root set, and check tag iterator for that */
52 : : iBase_EntityArrIterator iter;
53 : : int count, atend;
54 : : double* data;
55 [ + - ]: 1 : iMesh_initEntArrIter( mesh, root_set, iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, 6, 0, &iter, &err );
56 [ + - ]: 1 : CHECK_EQUAL( iBase_SUCCESS, err );
57 [ + - ]: 1 : iMesh_tagIterate( mesh, tagh, iter, &data, &count, &err );
58 [ + - ]: 1 : CHECK_EQUAL( iBase_SUCCESS, err );
59 [ - + ][ # # ]: 1 : if( count != 6 ) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE );
60 : :
61 [ + + ]: 7 : for( int i = 0; i < 6; i++ )
62 : : {
63 [ - + ][ # # ]: 6 : if( data[i] != coords[i + 3] ) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE );
64 : : }
65 [ + - ]: 1 : iMesh_endEntArrIter( mesh, iter, &err );
66 [ + - ]: 1 : CHECK_EQUAL( iBase_SUCCESS, err );
67 : 1 : iter = 0; // iMesh_endEntArrIter frees iter
68 : :
69 : : /* get an iterator over the set with two subranges, and check tag iterator for that */
70 [ + - ]: 1 : iMesh_initEntArrIter( mesh, entset, iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, 6, 0, &iter, &err );
71 [ + - ]: 1 : CHECK_EQUAL( iBase_SUCCESS, err );
72 [ + - ]: 1 : iMesh_tagIterate( mesh, tagh, iter, &data, &count, &err );
73 [ + - ]: 1 : CHECK_EQUAL( iBase_SUCCESS, err );
74 [ + - ][ + - ]: 1 : if( count != 2 || data[0] != coords[3] || data[1] != coords[4] ) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE );
[ - + ][ # # ]
75 [ + - ]: 1 : iMesh_stepEntArrIter( mesh, iter, 2, &atend, &err );
76 [ + - ]: 1 : CHECK_EQUAL( iBase_SUCCESS, err );
77 : : /* shouldn't be at end yet */
78 [ - + ][ # # ]: 1 : if( atend ) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE );
79 : :
80 [ + - ]: 1 : iMesh_tagIterate( mesh, tagh, iter, &data, &count, &err );
81 [ + - ]: 1 : CHECK_EQUAL( iBase_SUCCESS, err );
82 [ + - ][ + - ]: 1 : if( count != 3 || data[0] != coords[6] || data[1] != coords[7] ) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE );
[ - + ][ # # ]
83 [ + - ]: 1 : iMesh_stepEntArrIter( mesh, iter, 3, &atend, &err );
84 [ + - ]: 1 : CHECK_EQUAL( iBase_SUCCESS, err );
85 : : /* should be at end now */
86 [ - + ][ # # ]: 1 : if( !atend ) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE );
87 [ + - ]: 1 : iMesh_endEntArrIter( mesh, iter, &err );
88 [ + - ]: 1 : CHECK_EQUAL( iBase_SUCCESS, err );
89 : :
90 [ + - ]: 1 : iMesh_dtor( mesh, &err );
91 [ + - ]: 1 : CHECK_EQUAL( iBase_SUCCESS, err );
92 : :
93 : 1 : free( verts );
94 : 1 : }
95 : :
96 : 1 : void test_step_iter()
97 : : {
98 : : iMesh_Instance mesh;
99 : : int err;
100 [ + - ]: 1 : iMesh_newMesh( "", &mesh, &err, 0 );
101 [ + - ]: 1 : CHECK_EQUAL( iBase_SUCCESS, err );
102 : :
103 : : iBase_EntitySetHandle root_set;
104 [ + - ]: 1 : iMesh_getRootSet( mesh, &root_set, &err );
105 [ + - ]: 1 : CHECK_EQUAL( iBase_SUCCESS, err );
106 : :
107 : 1 : iBase_EntityHandle* verts = 0;
108 : 1 : int verts_alloc = 0, verts_size = 0;
109 : 1 : double coords[] = { 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5 };
110 [ + - ]: 1 : iMesh_createVtxArr( mesh, 6, iBase_INTERLEAVED, coords, 18, &verts, &verts_alloc, &verts_size, &err );
111 [ + - ]: 1 : CHECK_EQUAL( iBase_SUCCESS, err );
112 : :
113 : : /* make a non-array iterator and test stepping over it */
114 : : iBase_EntityIterator iter;
115 : : int atend;
116 [ + - ]: 1 : iMesh_initEntIter( mesh, root_set, iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, 0, &iter, &err );
117 [ + - ]: 1 : CHECK_EQUAL( iBase_SUCCESS, err );
118 [ + - ]: 1 : iMesh_stepEntIter( mesh, iter, 2, &atend, &err );
119 [ + - ]: 1 : CHECK_EQUAL( iBase_SUCCESS, err );
120 : : /* shouldn't be at end yet */
121 [ - + ][ # # ]: 1 : if( atend ) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE );
122 : :
123 [ + - ]: 1 : iMesh_stepEntIter( mesh, iter, 4, &atend, &err );
124 [ + - ]: 1 : CHECK_EQUAL( iBase_SUCCESS, err );
125 : : /* should be at end now */
126 [ - + ][ # # ]: 1 : if( !atend ) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE );
127 [ + - ]: 1 : iMesh_endEntIter( mesh, iter, &err );
128 [ + - ]: 1 : CHECK_EQUAL( iBase_SUCCESS, err );
129 : :
130 : : /* make an array iterator and test stepping over it */
131 : : iBase_EntityArrIterator arr_iter;
132 [ + - ]: 1 : iMesh_initEntArrIter( mesh, root_set, iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, 6, 0, &arr_iter, &err );
133 [ + - ]: 1 : CHECK_EQUAL( iBase_SUCCESS, err );
134 [ + - ]: 1 : iMesh_stepEntArrIter( mesh, arr_iter, 2, &atend, &err );
135 [ + - ]: 1 : CHECK_EQUAL( iBase_SUCCESS, err );
136 : : /* shouldn't be at end yet */
137 [ - + ][ # # ]: 1 : if( atend ) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE );
138 : :
139 [ + - ]: 1 : iMesh_stepEntArrIter( mesh, arr_iter, 4, &atend, &err );
140 [ + - ]: 1 : CHECK_EQUAL( iBase_SUCCESS, err );
141 : : /* should be at end now */
142 [ - + ][ # # ]: 1 : if( !atend ) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE );
143 [ + - ]: 1 : iMesh_endEntArrIter( mesh, arr_iter, &err );
144 [ + - ]: 1 : CHECK_EQUAL( iBase_SUCCESS, err );
145 : :
146 [ + - ]: 1 : iMesh_dtor( mesh, &err );
147 [ + - ]: 1 : CHECK_EQUAL( iBase_SUCCESS, err );
148 : :
149 : 1 : free( verts );
150 [ + - ][ + - ]: 5 : }
|