4 #define BOOST_TEST_DYN_LINK
5 #define BOOST_TEST_MODULE LMapBackendTest
6 #include <boost/test/unit_test.hpp>
7 using namespace boost::unit_test_framework;
14 BOOST_AUTO_TEST_SUITE(LMapFileTestSuite)
19 std::map<std::string, LNMVariable> variables;
27 std::cout <<
"******************************************************" << std::endl;
28 std::cout <<
"*** Warnings ahead. Testing for not existing file. ***" << std::endl;
30 std::cout <<
"*** End of not existing file test. *******************" << std::endl;
31 std::cout <<
"******************************************************" << std::endl;
37 std::cout <<
"********************************************************" << std::endl;
38 std::cout <<
"*** Warnings ahead. Testing for invalid xlmap files. ***" << std::endl;
50 std::cout <<
"*** End of invalid xlmap file test. ********************" << std::endl;
51 std::cout <<
"********************************************************" << std::endl;
57 std::map<std::string, LNMVariable> variables;
59 auto catalogue =
lmap.parseFile(
"valid.xlmap");
61 auto info = catalogue.getBackendRegister(
"SingleWord");
62 BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::REGISTER);
63 BOOST_CHECK(info.deviceName ==
"PCIE2");
64 BOOST_CHECK(info.registerName ==
"BOARD.WORD_USER");
66 info = catalogue.getBackendRegister(
"PartOfArea");
67 BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::REGISTER);
68 BOOST_CHECK(info.deviceName ==
"PCIE2");
69 BOOST_CHECK(info.registerName ==
"ADC.AREA_DMAABLE");
70 BOOST_CHECK(info.firstIndex == 10);
71 BOOST_CHECK(info.length == 20);
73 info = catalogue.getBackendRegister(
"FullArea");
74 BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::REGISTER);
75 BOOST_CHECK(info.deviceName ==
"PCIE2");
76 BOOST_CHECK(info.registerName ==
"ADC.AREA_DMAABLE");
78 info = catalogue.getBackendRegister(
"usingHexStartIndex");
79 BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::REGISTER);
80 BOOST_CHECK(info.registerName ==
"ADC.AREA_DMAABLE");
81 BOOST_CHECK(info.firstIndex == 0x10);
83 info = catalogue.getBackendRegister(
"Channel3");
84 BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::CHANNEL);
85 BOOST_CHECK(info.deviceName ==
"PCIE3");
86 BOOST_CHECK(info.registerName ==
"TEST.NODMA");
87 BOOST_CHECK(info.channel == 3);
89 info = catalogue.getBackendRegister(
"Channel4");
90 BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::CHANNEL);
91 BOOST_CHECK(info.deviceName ==
"PCIE3");
92 BOOST_CHECK(info.registerName ==
"TEST.NODMA");
93 BOOST_CHECK(info.channel == 4);
95 info = catalogue.getBackendRegister(
"Constant");
96 BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::CONSTANT);
98 BOOST_CHECK(boost::fusion::at_key<int32_t>(variables.at(info.name).valueTable.table).latestValue[0] == 42);
100 info = catalogue.getBackendRegister(
"/MyModule/SomeSubmodule/Variable");
101 BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::VARIABLE);
103 BOOST_CHECK(boost::fusion::at_key<int32_t>(variables.at(info.name).valueTable.table).latestValue[0] == 2);
104 info = catalogue.getBackendRegister(
"MyModule/ConfigurableChannel");
105 BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::CHANNEL);
106 BOOST_CHECK(info.deviceName ==
"PCIE3");
107 BOOST_CHECK(info.registerName ==
"TEST.NODMA");
108 BOOST_CHECK(info.channel == 42);
110 info = catalogue.getBackendRegister(
"ArrayConstant");
111 BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::CONSTANT);
113 BOOST_CHECK(info.length == 5);
114 BOOST_CHECK(boost::fusion::at_key<int32_t>(variables.at(info.name).valueTable.table).latestValue.size() == 5);
115 BOOST_CHECK(boost::fusion::at_key<int32_t>(variables.at(info.name).valueTable.table).latestValue[0] == 1111);
116 BOOST_CHECK(boost::fusion::at_key<int32_t>(variables.at(info.name).valueTable.table).latestValue[1] == 2222);
117 BOOST_CHECK(boost::fusion::at_key<int32_t>(variables.at(info.name).valueTable.table).latestValue[2] == 3333);
118 BOOST_CHECK(boost::fusion::at_key<int32_t>(variables.at(info.name).valueTable.table).latestValue[3] == 4444);
119 BOOST_CHECK(boost::fusion::at_key<int32_t>(variables.at(info.name).valueTable.table).latestValue[4] == 5555);
121 info = catalogue.getBackendRegister(
"Bit0ofVar");
122 BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::BIT);
123 BOOST_CHECK(info.deviceName ==
"this");
124 BOOST_CHECK(info.registerName ==
"/MyModule/SomeSubmodule/Variable");
125 BOOST_CHECK(info.bit == 0);
127 info = catalogue.getBackendRegister(
"Bit1ofVar");
128 BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::BIT);
129 BOOST_CHECK(info.deviceName ==
"this");
130 BOOST_CHECK(info.registerName ==
"/MyModule/SomeSubmodule/Variable");
131 BOOST_CHECK(info.bit == 1);
133 info = catalogue.getBackendRegister(
"Bit2ofVar");
134 BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::BIT);
135 BOOST_CHECK(info.deviceName ==
"this");
136 BOOST_CHECK(info.registerName ==
"/MyModule/SomeSubmodule/Variable");
137 BOOST_CHECK(info.bit == 2);
139 info = catalogue.getBackendRegister(
"Bit3ofVar");
140 BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::BIT);
141 BOOST_CHECK(info.deviceName ==
"this");
142 BOOST_CHECK(info.registerName ==
"/MyModule/SomeSubmodule/Variable");
143 BOOST_CHECK(info.bit == 3);
145 info = catalogue.getBackendRegister(
"/var_int8");
146 BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::VARIABLE);
148 BOOST_CHECK(boost::fusion::at_key<int8_t>(variables.at(info.name).valueTable.table).latestValue[0] == -128);
149 info = catalogue.getBackendRegister(
"/var_uint8");
150 BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::VARIABLE);
152 BOOST_CHECK(boost::fusion::at_key<uint8_t>(variables.at(info.name).valueTable.table).latestValue[0] == 255);
153 info = catalogue.getBackendRegister(
"/var_int16");
154 BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::VARIABLE);
156 BOOST_CHECK(boost::fusion::at_key<int16_t>(variables.at(info.name).valueTable.table).latestValue[0] == -32768);
157 info = catalogue.getBackendRegister(
"/var_uint16");
158 BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::VARIABLE);
160 BOOST_CHECK(boost::fusion::at_key<uint16_t>(variables.at(info.name).valueTable.table).latestValue[0] == 65535);
161 info = catalogue.getBackendRegister(
"/var_int32");
162 BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::VARIABLE);
164 BOOST_CHECK(boost::fusion::at_key<int32_t>(variables.at(info.name).valueTable.table).latestValue[0] == -1);
165 info = catalogue.getBackendRegister(
"/var_uint32");
166 BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::VARIABLE);
168 BOOST_CHECK(boost::fusion::at_key<uint32_t>(variables.at(info.name).valueTable.table).latestValue[0] == 0xfffffffe);
169 info = catalogue.getBackendRegister(
"/var_int64");
170 BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::VARIABLE);
172 BOOST_CHECK(boost::fusion::at_key<int64_t>(variables.at(info.name).valueTable.table).latestValue[0] == -1);
173 info = catalogue.getBackendRegister(
"/var_uint64");
174 BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::VARIABLE);
176 BOOST_CHECK(boost::fusion::at_key<uint64_t>(variables.at(info.name).valueTable.table).latestValue[0] == 0);
177 info = catalogue.getBackendRegister(
"/var_float32");
178 BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::VARIABLE);
181 boost::fusion::at_key<float>(variables.at(info.name).valueTable.table).latestValue[0], -1.2345e10, 1e-5);
182 info = catalogue.getBackendRegister(
"/var_float64");
183 BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::VARIABLE);
186 boost::fusion::at_key<double>(variables.at(info.name).valueTable.table).latestValue[0], -1.23456789e20, 1e-10);
187 info = catalogue.getBackendRegister(
"/var_string");
188 BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::VARIABLE);
191 boost::fusion::at_key<std::string>(variables.at(info.name).valueTable.table).latestValue[0] ==
"stringValue");
198 std::map<std::string, std::string> params;
199 params[
"ParamA"] =
"ValueA";
200 params[
"ParamB"] =
"ValueB";
201 std::map<std::string, LNMVariable> variables;
204 auto catalogue =
lmap.parseFile(
"withParams.xlmap");
206 auto info = catalogue.getBackendRegister(
"SingleWordWithParams");
207 BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::REGISTER);
208 BOOST_CHECK(info.deviceName ==
"ValueA");
209 BOOST_CHECK(info.registerName ==
"ValueB");
213 std::map<std::string, std::string> params;
214 params[
"ParamA"] =
"OtherValues";
215 params[
"ParamB"] =
"ThisTime";
216 std::map<std::string, LNMVariable> variables;
219 auto catalogue =
lmap.parseFile(
"withParams.xlmap");
221 auto info = catalogue.getBackendRegister(
"SingleWordWithParams");
222 BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::REGISTER);
223 BOOST_CHECK(info.deviceName ==
"OtherValues");
224 BOOST_CHECK(info.registerName ==
"ThisTime");
228 BOOST_AUTO_TEST_SUITE_END()