Fix memleaks in our gtests.
[blender.git] / tests / gtests / bmesh / bmesh_core_test.cc
1 #include "testing/testing.h"
2
3 #include "BLI_utildefines.h"
4 #include "bmesh.h"
5 #include "BLI_math.h"
6
7 TEST(bmesh_core, BMVertCreate) {
8         BMesh *bm;
9         BMVert *bv1, *bv2, *bv3;
10         const float co1[3] = {1.0f, 2.0f, 0.0f};
11
12         bm = BM_mesh_create(&bm_mesh_allocsize_default);
13         EXPECT_EQ(0, bm->totvert);
14         /* make a custom layer so we can see if it is copied properly */
15         BM_data_layer_add(bm, &bm->vdata, CD_PROP_FLT);
16         bv1 = BM_vert_create(bm, co1, NULL, BM_CREATE_NOP);
17         ASSERT_TRUE(bv1 != NULL);
18         EXPECT_EQ(1.0f, bv1->co[0]);
19         EXPECT_EQ(2.0f, bv1->co[1]);
20         EXPECT_EQ(0.0f, bv1->co[2]);
21         EXPECT_TRUE(is_zero_v3(bv1->no));
22         EXPECT_EQ((char)BM_VERT, bv1->head.htype);
23         EXPECT_EQ(0, bv1->head.hflag);
24         EXPECT_EQ(0, bv1->head.api_flag);
25         bv2 = BM_vert_create(bm, NULL, NULL, BM_CREATE_NOP);
26         ASSERT_TRUE(bv2 != NULL);
27         EXPECT_TRUE(is_zero_v3(bv2->co));
28         /* create with example should copy custom data but not select flag */
29         BM_vert_select_set(bm, bv2, true);
30         BM_elem_float_data_set(&bm->vdata, bv2, CD_PROP_FLT, 1.5f);
31         bv3 = BM_vert_create(bm, co1, bv2, BM_CREATE_NOP);
32         ASSERT_TRUE(bv3 != NULL);
33         EXPECT_FALSE(BM_elem_flag_test((BMElem *)bv3, BM_ELEM_SELECT));
34         EXPECT_EQ(1.5f, BM_elem_float_data_get(&bm->vdata, bv3, CD_PROP_FLT));
35         EXPECT_EQ(3, BM_mesh_elem_count(bm, BM_VERT));
36         BM_mesh_free(bm);
37 }