ChimeraTK-DeviceAccess  03.18.00
testDMapFileParser.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2 // SPDX-License-Identifier: LGPL-3.0-or-later
3 
7 #include "DMapFileParser.h"
8 #include "Exception.h"
9 #include "helperFunctions.h"
10 #include "parserUtilities.h"
11 #include "Utilities.h"
12 
13 namespace ChimeraTK {
14  using namespace ChimeraTK;
15 }
16 using namespace boost::unit_test_framework;
17 
19  public:
20  void testFileNotFound();
21  void testErrorInDmapFile();
22  void testNoDataInDmapFile();
23  void testParseFile();
24 };
25 
26 class DMapFileParserTestSuite : public test_suite {
27  public:
28  DMapFileParserTestSuite() : test_suite("DMapFileParser class test suite") {
29  boost::shared_ptr<DMapFileParserTest> dMapFileParserTest(new DMapFileParserTest);
30 
31  test_case* testFileNotFound = BOOST_CLASS_TEST_CASE(&DMapFileParserTest::testFileNotFound, dMapFileParserTest);
32  test_case* testErrorInDmapFile =
33  BOOST_CLASS_TEST_CASE(&DMapFileParserTest::testErrorInDmapFile, dMapFileParserTest);
34  test_case* testNoDataInDmapFile =
35  BOOST_CLASS_TEST_CASE(&DMapFileParserTest::testNoDataInDmapFile, dMapFileParserTest);
36  test_case* testParseFile = BOOST_CLASS_TEST_CASE(&DMapFileParserTest::testParseFile, dMapFileParserTest);
37 
38  add(testFileNotFound);
39  add(testErrorInDmapFile);
40  add(testParseFile);
41  add(testNoDataInDmapFile);
42  }
43 };
44 
46  framework::master_test_suite().p_name.value = "DMapFileParser class test suite";
47  framework::master_test_suite().add(new DMapFileParserTestSuite());
48 
49  return true;
50 }
51 
53  std::string file_path = "../dummypath.dmap";
54  ChimeraTK::DMapFileParser fileParser;
55 
56  BOOST_CHECK_THROW(fileParser.parse(file_path), ChimeraTK::logic_error);
57 }
58 
60  std::string incorrect_dmap_file = "invalid.dmap";
61  ChimeraTK::DMapFileParser fileParser;
62 
63  BOOST_CHECK_THROW(fileParser.parse(incorrect_dmap_file), ChimeraTK::logic_error);
64 
65  BOOST_CHECK_THROW(fileParser.parse("badLoadlib.dmap"), ChimeraTK::logic_error);
66  BOOST_CHECK_THROW(fileParser.parse("badLoadlib2.dmap"), ChimeraTK::logic_error);
67  BOOST_CHECK_THROW(fileParser.parse("unkownKey.dmap"), ChimeraTK::logic_error);
68 }
69 
71  std::string empty_dmap_file = "empty.dmap";
72  ChimeraTK::DMapFileParser fileParser;
73 
74  BOOST_CHECK_THROW(fileParser.parse(empty_dmap_file), ChimeraTK::logic_error);
75 }
76 
78  std::string file_path = "valid.dmap";
79  ChimeraTK::DMapFileParser fileParser;
80  boost::shared_ptr<ChimeraTK::DeviceInfoMap> mapFilePtr = fileParser.parse(file_path);
81 
86 
87  std::string absPathToDmap = ChimeraTK::parserUtilities::convertToAbsolutePath("valid.dmap");
88  std::string absPathToDmapDir = ChimeraTK::parserUtilities::getCurrentWorkingDirectory();
89 
90  populateDummyDeviceInfo(deviceInfo1, absPathToDmap, "card1", "/dev/dev1",
91  ChimeraTK::parserUtilities::concatenatePaths(absPathToDmapDir, "goodMapFile_withoutModules.map"));
92  populateDummyDeviceInfo(deviceInfo2, absPathToDmap, "card2", "/dev/dev2",
93  ChimeraTK::parserUtilities::concatenatePaths(absPathToDmapDir, "./goodMapFile_withoutModules.map"));
94  populateDummyDeviceInfo(deviceInfo3, absPathToDmap, "card3", "/dev/dev3",
95  ChimeraTK::parserUtilities::getCurrentWorkingDirectory() + "goodMapFile_withoutModules.map");
97  deviceInfo4, absPathToDmap, "card4", "(pci:mtcadummys0?map=goodMapFile_withoutModules.map)", "");
98 
99  deviceInfo1.dmapFileLineNumber = 6;
100  deviceInfo2.dmapFileLineNumber = 7;
101  deviceInfo3.dmapFileLineNumber = 8;
102  deviceInfo4.dmapFileLineNumber = 9;
103 
104  // we use require here so it is safe to increase and dereference the iterator
105  // below
106  BOOST_REQUIRE(mapFilePtr->getSize() == 4);
107 
108  ChimeraTK::DeviceInfoMap::const_iterator it = mapFilePtr->begin();
109 
110  BOOST_CHECK(compareDeviceInfos(deviceInfo1, *(it++)) == true);
111  BOOST_CHECK(compareDeviceInfos(deviceInfo2, *(it++)) == true);
112  BOOST_CHECK(compareDeviceInfos(deviceInfo3, *(it++)) == true);
113  BOOST_CHECK(compareDeviceInfos(deviceInfo4, *(it++)) == true);
114 
115  auto pluginLibraries = mapFilePtr->getPluginLibraries();
116 
117  BOOST_CHECK(pluginLibraries.size() == 2);
118  BOOST_CHECK(pluginLibraries[0] == absPathToDmapDir + "libMyLib.so");
119  BOOST_CHECK(pluginLibraries[1] == "/system/libAnotherLib.so");
120 }
ChimeraTK::DeviceInfoMap::const_iterator
std::vector< DeviceInfo >::const_iterator const_iterator
Definition: DeviceInfoMap.h:61
DMapFileParserTest::testParseFile
void testParseFile()
Definition: testDMapFileParser.cpp:77
ChimeraTK::DMapFileParser::parse
static DeviceInfoMapPointer parse(const std::string &file_name)
Performs parsing of specified DMAP file.
Definition: DMapFileParser.cpp:18
helperFunctions.h
ChimeraTK::parserUtilities::getCurrentWorkingDirectory
std::string getCurrentWorkingDirectory()
Returns absolute path to current working directory. The returned path ends with a forward slash.
Definition: parserUtilities.cc:19
Utilities.h
boost_dynamic_init_test.h
DMapFileParserTestSuite::DMapFileParserTestSuite
DMapFileParserTestSuite()
Definition: testDMapFileParser.cpp:28
DMapFileParserTest::testErrorInDmapFile
void testErrorInDmapFile()
Definition: testDMapFileParser.cpp:59
parserUtilities.h
ChimeraTK::parserUtilities::convertToAbsolutePath
std::string convertToAbsolutePath(std::string const &relativePath)
Converts a relative path to its absolute path.
Definition: parserUtilities.cc:23
populateDummyDeviceInfo
void populateDummyDeviceInfo(ChimeraTK::DeviceInfoMap::DeviceInfo &deviceInfo, std::string dmapFileName, std::string deviceName="card", std::string dev_file="/dev/dummy_device_identifier", std::string map_file_name="/dev/dummy_map_file")
Definition: helperFunctions.cc:8
ChimeraTK::DeviceInfoMap::DeviceInfo::dmapFileLineNumber
uint32_t dmapFileLineNumber
line number in DMAP file storing listed above information
Definition: DeviceInfoMap.h:38
ChimeraTK::DMapFileParser
Provides method to parse DMAP file.
Definition: DMapFileParser.h:19
compareDeviceInfos
bool compareDeviceInfos(const ChimeraTK::DeviceInfoMap::DeviceInfo &deviceInfo1, const ChimeraTK::DeviceInfoMap::DeviceInfo &deviceInfo2)
Definition: helperFunctions.cc:28
DMapFileParserTest::testNoDataInDmapFile
void testNoDataInDmapFile()
Definition: testDMapFileParser.cpp:70
ChimeraTK::parserUtilities::concatenatePaths
std::string concatenatePaths(const std::string &path1, const std::string &path2)
Concatenates two given paths using custom rules.
Definition: parserUtilities.cc:27
DMapFileParser.h
ChimeraTK::DeviceInfoMap::DeviceInfo
Stores information about one device.
Definition: DeviceInfoMap.h:30
DMapFileParserTest
Definition: testDMapFileParser.cpp:18
DMapFileParserTestSuite
Definition: testDMapFileParser.cpp:26
init_unit_test
bool init_unit_test()
Definition: testDMapFileParser.cpp:45
Exception.h
ChimeraTK
Definition: DummyBackend.h:16
DMapFileParserTest::testFileNotFound
void testFileNotFound()
Definition: testDMapFileParser.cpp:52
ChimeraTK::logic_error
Exception thrown when a logic error has occured.
Definition: Exception.h:51