summaryrefslogtreecommitdiff
path: root/slicer/test/compilation.cpp
blob: 445e8674e08c8349fdc7f3c3a7e443980dbdb43b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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
89
90
91
92
93
94
95
96
97
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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#define BOOST_TEST_MODULE compilation
#include <boost/test/unit_test.hpp>

#include <types.h>
#include <locals.h>
#include <slicer/modelParts.h>
#include <slicer/modelPartsTypes.h>

// LCOV_EXCL_START
BOOST_TEST_DONT_PRINT_LOG_VALUE(std::type_info);
// LCOV_EXCL_STOP

namespace pl = std::placeholders;

#define TypeTest(Var, Expr, Explicit, Expected) \
	Var obj = Expr; \
	Slicer::ModelPartPtr mpp = Slicer::ModelPart::CreateFor(obj); \
	BOOST_REQUIRE_EQUAL(Slicer::Expected, mpp->GetType()); \
	\
	BOOST_TEST_CONTEXT(#Var) { \
		auto mppvalue = mpp.get(); \
		auto amppvalue = mpp.get(); \
		auto apmppvalue = mpp.get(); \
		BOOST_TEST_CHECKPOINT(typeid(*mppvalue).name()); \
		BOOST_REQUIRE_EQUAL(typeid(*mppvalue), typeid(*amppvalue)); \
		BOOST_REQUIRE_EQUAL(typeid(*mppvalue), typeid(*apmppvalue)); \
	}

#define StackTypeTest(Var, Explicit, Expected) \
	TypeTest(Var, Var(), Explicit, Expected)

BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_class )
{
	TypeTest(TestModule::BuiltInsPtr, std::make_shared<TestModule::BuiltIns>(), ModelPartForClass, mpt_Complex);
	BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());
}

static
void
hookHandler(std::vector<std::string> * names, const std::string & name, const Slicer::ModelPartPtr & mpp, const Slicer::HookCommon * h)
{
	names->push_back(name);
	BOOST_REQUIRE(mpp);
	BOOST_REQUIRE(mpp->GetContainedModelPart());
	BOOST_REQUIRE(h);
	BOOST_REQUIRE_EQUAL(h->name, name);
}


BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_sequenceclasses )
{
	StackTypeTest(TestModule::Classes, ModelPartForSequence, mpt_Sequence);
	auto cmpp = mpp->GetContainedModelPart();
	BOOST_REQUIRE(cmpp);
	BOOST_REQUIRE_EQUAL(Slicer::mpt_Complex, cmpp->GetType());
	std::vector<std::string> names;
	cmpp->OnEachChild(std::bind(&hookHandler, &names, pl::_1, pl::_2, pl::_3));
	BOOST_REQUIRE_EQUAL(2, names.size());
	BOOST_REQUIRE_EQUAL("a", names.front());
	BOOST_REQUIRE_EQUAL("b", names.back());
}

BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_sequencestructs )
{
	StackTypeTest(TestModule::Structs, ModelPartForSequence, mpt_Sequence);
	auto cmpp = mpp->GetContainedModelPart();
	BOOST_REQUIRE(cmpp);
	BOOST_REQUIRE_EQUAL(Slicer::mpt_Complex, cmpp->GetType());
	std::vector<std::string> names;
	cmpp->OnEachChild(std::bind(&hookHandler, &names, pl::_1, pl::_2, pl::_3));
	BOOST_REQUIRE_EQUAL(2, names.size());
	BOOST_REQUIRE_EQUAL("a", names.front());
	BOOST_REQUIRE_EQUAL("b", names.back());
}

BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_mapclasses )
{
	StackTypeTest(TestModule::ClassMap, ModelPartForDictionary, mpt_Dictionary);
	auto cmpp = mpp->GetContainedModelPart();
	BOOST_REQUIRE(cmpp);
	BOOST_REQUIRE_EQUAL(Slicer::mpt_Complex, cmpp->GetType());
}

BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_mapstructs )
{
	StackTypeTest(TestModule::StructMap, ModelPartForDictionary, mpt_Dictionary);
}

BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_bi_string )
{
	StackTypeTest(std::string, ModelPartForSimple, mpt_Simple);
	BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());
}

BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_bi_bool )
{
	StackTypeTest(bool, ModelPartForSimple, mpt_Simple);
	BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());
}

BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_bi_float )
{
	StackTypeTest(Ice::Float, ModelPartForSimple, mpt_Simple);
	BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());
}

BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_bi_double )
{
	StackTypeTest(Ice::Double, ModelPartForSimple, mpt_Simple);
	BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());
}

BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_bi_byte )
{
	StackTypeTest(Ice::Byte, ModelPartForSimple, mpt_Simple);
	BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());
}

BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_bi_short )
{
	StackTypeTest(Ice::Short, ModelPartForSimple, mpt_Simple);
	BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());
}

BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_bi_int )
{
	StackTypeTest(Ice::Int, ModelPartForSimple, mpt_Simple);
	BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());
}

BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_bi_long )
{
	StackTypeTest(Ice::Long, ModelPartForSimple, mpt_Simple);
	BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());
}

BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_struct )
{
	StackTypeTest(TestModule::StructType, ModelPartForStruct, mpt_Complex);
	BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());
}

BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_enum )
{
	StackTypeTest(TestModule::SomeNumbers, ModelPartForEnum, mpt_Simple);
	BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());
}

BOOST_AUTO_TEST_CASE( normalClassTypeId )
{
	TestModule::BasePtr base = std::make_shared<TestModule::Base>(1);
	BOOST_REQUIRE(base);
	auto a = Slicer::ModelPart::CreateFor(base);
	BOOST_REQUIRE(a);
	auto baseType = a->GetTypeId();
	BOOST_REQUIRE(!baseType);
}

BOOST_AUTO_TEST_CASE( normalSubClassTypeId )
{
	TestModule::BasePtr base = std::make_shared<TestModule::D1>(1, 2);
	BOOST_REQUIRE(base);
	auto a = Slicer::ModelPart::CreateFor(base);
	BOOST_REQUIRE(a);
	auto baseType = a->GetTypeId();
	BOOST_REQUIRE(baseType);
	BOOST_REQUIRE_EQUAL(*baseType, "::TestModule::D1");
}

BOOST_AUTO_TEST_CASE( normalSubSubClassTypeId )
{
	TestModule::BasePtr base = std::make_shared<TestModule::D3>(1, 2, 3);
	BOOST_REQUIRE(base);
	auto a = Slicer::ModelPart::CreateFor(base);
	BOOST_REQUIRE(a);
	auto baseType = a->GetTypeId();
	BOOST_REQUIRE(baseType);
	BOOST_REQUIRE_EQUAL(*baseType, "::TestModule::D3");
}

BOOST_AUTO_TEST_CASE( localClassTypeId )
{
	Locals::LocalClassPtr base = std::make_shared<Locals::LocalClass>(1, "One");
	BOOST_REQUIRE(base);
	auto a = Slicer::ModelPart::CreateFor(base);
	BOOST_REQUIRE(a);
	auto baseType = a->GetTypeId();
	BOOST_REQUIRE(!baseType);
}

BOOST_AUTO_TEST_CASE( localSubClassTypeId )
{
	Locals::LocalClassPtr base = std::make_shared<Locals::LocalSubClass>(1, "One", 3.1);
	BOOST_REQUIRE(base);
	auto a = Slicer::ModelPart::CreateFor(base);
	BOOST_REQUIRE(a);
	auto baseType = a->GetTypeId();
	BOOST_REQUIRE(baseType);
	BOOST_REQUIRE_EQUAL(*baseType, "::Locals::LocalSubClass");
}

BOOST_AUTO_TEST_CASE( localSubSubClassTypeId )
{
	Locals::LocalClassPtr base = std::make_shared<Locals::LocalSub2Class>(1, "One", 3.1, 1);
	BOOST_REQUIRE(base);
	auto a = Slicer::ModelPart::CreateFor(base);
	BOOST_REQUIRE(a);
	auto baseType = a->GetTypeId();
	BOOST_REQUIRE(baseType);
	BOOST_REQUIRE_EQUAL(*baseType, "::Locals::LocalSub2Class");
}