Blender  V2.93
hierarchy_context_order_test.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2019 Blender Foundation.
17  * All rights reserved.
18  */
20 
21 #include "testing/testing.h"
22 
23 #include "BLI_utildefines.h"
24 
25 namespace blender::io {
26 
27 namespace {
28 
29 Object *fake_pointer(int value)
30 {
31  return static_cast<Object *>(POINTER_FROM_INT(value));
32 }
33 
34 } // namespace
35 
36 class HierarchyContextOrderTest : public testing::Test {
37 };
38 
39 TEST_F(HierarchyContextOrderTest, ObjectPointerTest)
40 {
41  HierarchyContext ctx_a = {nullptr};
42  ctx_a.object = fake_pointer(1);
43  ctx_a.duplicator = nullptr;
44 
45  HierarchyContext ctx_b = {nullptr};
46  ctx_b.object = fake_pointer(2);
47  ctx_b.duplicator = nullptr;
48 
49  EXPECT_LT(ctx_a, ctx_b);
50  EXPECT_FALSE(ctx_b < ctx_a);
51  EXPECT_FALSE(ctx_a < ctx_a);
52 }
53 
54 TEST_F(HierarchyContextOrderTest, DuplicatorPointerTest)
55 {
56  HierarchyContext ctx_a = {nullptr};
57  ctx_a.object = fake_pointer(1);
58  ctx_a.duplicator = fake_pointer(1);
59  ctx_a.export_name = "A";
60 
61  HierarchyContext ctx_b = {nullptr};
62  ctx_b.object = fake_pointer(1);
63  ctx_b.duplicator = fake_pointer(1);
64  ctx_b.export_name = "B";
65 
66  EXPECT_LT(ctx_a, ctx_b);
67  EXPECT_FALSE(ctx_b < ctx_a);
68  EXPECT_FALSE(ctx_a < ctx_a);
69 }
70 
72 {
73  HierarchyContext ctx_a = {nullptr};
74  ctx_a.object = fake_pointer(1);
75  ctx_a.export_parent = fake_pointer(1);
76 
77  HierarchyContext ctx_b = {nullptr};
78  ctx_b.object = fake_pointer(1);
79  ctx_b.export_parent = fake_pointer(2);
80 
81  EXPECT_LT(ctx_a, ctx_b);
82  EXPECT_FALSE(ctx_b < ctx_a);
83  EXPECT_FALSE(ctx_a < ctx_a);
84 }
85 
87 {
88  HierarchyContext ctx_a = {nullptr};
89  ctx_a.object = fake_pointer(1);
90  ctx_a.export_parent = fake_pointer(1);
91  ctx_a.duplicator = nullptr;
92  ctx_a.export_name = "A";
93 
94  HierarchyContext ctx_b = {nullptr};
95  ctx_b.object = fake_pointer(2);
96  ctx_b.export_parent = nullptr;
97  ctx_b.duplicator = fake_pointer(1);
98  ctx_b.export_name = "B";
99 
100  HierarchyContext ctx_c = {nullptr};
101  ctx_c.object = fake_pointer(2);
102  ctx_c.export_parent = fake_pointer(2);
103  ctx_c.duplicator = fake_pointer(1);
104  ctx_c.export_name = "C";
105 
106  HierarchyContext ctx_d = {nullptr};
107  ctx_d.object = fake_pointer(2);
108  ctx_d.export_parent = fake_pointer(3);
109  ctx_d.duplicator = nullptr;
110  ctx_d.export_name = "D";
111 
112  EXPECT_LT(ctx_a, ctx_b);
113  EXPECT_LT(ctx_a, ctx_c);
114  EXPECT_LT(ctx_a, ctx_d);
115  EXPECT_LT(ctx_b, ctx_c);
116  EXPECT_LT(ctx_b, ctx_d);
117  EXPECT_LT(ctx_c, ctx_d);
118 
119  EXPECT_FALSE(ctx_b < ctx_a);
120  EXPECT_FALSE(ctx_c < ctx_a);
121  EXPECT_FALSE(ctx_d < ctx_a);
122  EXPECT_FALSE(ctx_c < ctx_b);
123  EXPECT_FALSE(ctx_d < ctx_b);
124  EXPECT_FALSE(ctx_d < ctx_c);
125 }
126 
127 } // namespace blender::io
#define POINTER_FROM_INT(i)
TEST_F(AbstractHierarchyIteratorTest, ExportHierarchyTest)