summaryrefslogtreecommitdiff
path: root/slicer/test/compilation.cpp
blob: bea08a53a2f2fe70b09ada58366ec80bffa8333d (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
#define BOOST_TEST_MODULE compilation
#include <boost/test/unit_test.hpp>

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

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

#define TypeTest(Var, Expr, Explicit, Expected) \
	Var obj = Expr; \
	Slicer::ModelPartPtr mpp = Slicer::ModelPart::CreateFor(obj); \
	BOOST_REQUIRE_EQUAL(Slicer::Expected, mpp->GetType()); \
	\
	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, new TestModule::BuiltIns(), ModelPartForClass, mpt_Complex);
	BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());
}

void
hookHandler(std::vector<std::string> * names, const std::string & name, Slicer::ModelPartPtr mpp, Slicer::HookCommonPtr 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(boost::bind(&hookHandler, &names, _1, _2, _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(boost::bind(&hookHandler, &names, _1, _2, _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());
}