ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
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
13namespace ChimeraTK {
14 using namespace ChimeraTK;
15}
16using namespace boost::unit_test_framework;
17
19 public:
20 void testFileNotFound();
23 void testParseFile();
24};
25
26class 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";
55
56 BOOST_CHECK_THROW(fileParser.parse(file_path), ChimeraTK::logic_error);
57}
58
60 std::string incorrect_dmap_file = "invalid.dmap";
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";
73
74 BOOST_CHECK_THROW(fileParser.parse(empty_dmap_file), ChimeraTK::logic_error);
75}
76
78 std::string file_path = "valid.dmap";
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}
Provides method to parse DMAP file.
static DeviceInfoMapPointer parse(const std::string &file_name)
Performs parsing of specified DMAP file.
Stores information about one device.
uint32_t dmapFileLineNumber
line number in DMAP file storing listed above information
std::vector< DeviceInfo >::const_iterator const_iterator
Exception thrown when a logic error has occured.
Definition Exception.h:51
bool compareDeviceInfos(const ChimeraTK::DeviceInfoMap::DeviceInfo &deviceInfo1, const ChimeraTK::DeviceInfoMap::DeviceInfo &deviceInfo2)
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")
std::string getCurrentWorkingDirectory()
Returns absolute path to current working directory. The returned path ends with a forward slash.
std::string concatenatePaths(const std::string &path1, const std::string &path2)
Concatenates two given paths using custom rules.
std::string convertToAbsolutePath(std::string const &relativePath)
Converts a relative path to its absolute path.
bool init_unit_test()