Merge branch 'master' into blender2.8
[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         BMeshCreateParams bm_params;
13         bm_params.use_toolflags = true;
14         bm = BM_mesh_create(&bm_mesh_allocsize_default, &bm_params);
15         EXPECT_EQ(bm->totvert, 0);
16         /* make a custom layer so we can see if it is copied properly */
17         BM_data_layer_add(bm, &bm->vdata, CD_PROP_FLT);
18         bv1 = BM_vert_create(bm, co1, NULL, BM_CREATE_NOP);
19         ASSERT_TRUE(bv1 != NULL);
20         EXPECT_EQ(bv1->co[0], 1.0f);
21         EXPECT_EQ(bv1->co[1], 2.0f);
22         EXPECT_EQ(bv1->co[2], 0.0f);
23         EXPECT_TRUE(is_zero_v3(bv1->no));
24         EXPECT_EQ(bv1->head.htype, (char)BM_VERT);
25         EXPECT_EQ(bv1->head.hflag, 0);
26         EXPECT_EQ(bv1->head.api_flag, 0);
27         bv2 = BM_vert_create(bm, NULL, NULL, BM_CREATE_NOP);
28         ASSERT_TRUE(bv2 != NULL);
29         EXPECT_TRUE(is_zero_v3(bv2->co));
30         /* create with example should copy custom data but not select flag */
31         BM_vert_select_set(bm, bv2, true);
32         BM_elem_float_data_set(&bm->vdata, bv2, CD_PROP_FLT, 1.5f);
33         bv3 = BM_vert_create(bm, co1, bv2, BM_CREATE_NOP);
34         ASSERT_TRUE(bv3 != NULL);
35         EXPECT_FALSE(BM_elem_flag_test((BMElem *)bv3, BM_ELEM_SELECT));
36         EXPECT_EQ(BM_elem_float_data_get(&bm->vdata, bv3, CD_PROP_FLT), 1.5f);
37         EXPECT_EQ(BM_mesh_elem_count(bm, BM_VERT), 3);
38         BM_mesh_free(bm);
39 }