4#define BOOST_TEST_DYN_LINK
5#define BOOST_TEST_MODULE MapFileSearch
6#include <boost/test/unit_test.hpp>
7using namespace boost::unit_test_framework;
15#include <boost/filesystem.hpp>
22namespace fs = std::filesystem;
43 baseDir = fs::temp_directory_path() /
"testMapFileSearch";
46 fs::create_directories(
workDir);
59 static void writeMapFile(
const fs::path& path,
const std::string& registerName) {
60 if(!path.parent_path().empty()) {
61 fs::create_directories(path.parent_path());
63 std::ofstream file(path);
64 file <<
"/Board/" << registerName <<
" 1 0 4 1 32 0 1 RW\n";
68 static void writeDMapFile(
const fs::path& path,
const std::string& mapName) {
69 if(!path.parent_path().empty()) {
70 fs::create_directories(path.parent_path());
72 std::ofstream file(path);
73 file <<
"DUMMY (dummy?map=" << mapName <<
")\n";
78 static std::string
canonical(
const std::string& path) {
return boost::filesystem::canonical(path).string(); }
83BOOST_AUTO_TEST_SUITE(MapFileSearchTestSuite)
89 writeDMapFile(
"dmapdir/test.dmap",
"map1.map");
90 writeMapFile(
"dmapdir/map1.map",
"fromDmapDir");
91 setDMapPath(
"dmapdir/test.dmap");
103 writeDMapFile(
"dmapdir/test.dmap",
"map2.map");
104 writeMapFile(
"map2.map",
"fromCwd");
105 setDMapPath(
"dmapdir/test.dmap");
117 writeDMapFile(
"dmapdir/test.dmap",
"map3.map");
118 writeMapFile(
"dmapdir/map3.map",
"fromDmapDir");
119 writeMapFile(
"map3.map",
"fromCwd");
120 setDMapPath(
"dmapdir/test.dmap");
133 writeDMapFile(
"dmapdir/test.dmap",
"map4.map");
134 writeMapFile(
"other/map4.map",
"fromAbsolute");
135 setDMapPath(
"dmapdir/test.dmap");
137 std::string absolutePath = canonical(
"other/map4.map");
148 writeMapFile(
"map5.map",
"fromCwd");
160 writeDMapFile(
"dmapdir/sub/test.dmap",
"map6.map");
161 writeMapFile(
"dmapdir/sub/map6.map",
"fromDmapDirSub");
162 setDMapPath(
"dmapdir/sub/test.dmap");
174 writeDMapFile(
"dmapdir/test.dmap",
"nonexistent.map");
175 setDMapPath(
"dmapdir/test.dmap");
187 writeMapFile(
"shared.map",
"fromCwd");
203BOOST_AUTO_TEST_SUITE_END()
std::string getUserName()
static BackendFactory & getInstance()
Static function to get an instance of factory.
void setDMapFilePath(std::string dMapFilePath)
This function sets the _DMapFilePath.
The dummy device opens a mapping file instead of a device, and implements all registers defined in th...
DummyBackend(const std::string &mapFileName, const std::string &dataConsistencyKeyDescriptor="")
RegisterCatalogue getRegisterCatalogue() const override
Return the register catalogue with detailed information on all registers.
std::string _resolvedMapFileName
The resolved absolute path of the map file used for parsing and for any derived naming (e....
bool hasRegister(const RegisterPath ®isterPathName) const
Check if register with the given path name exists.
Exception thrown when a logic error has occured.
std::size_t shmDummyInstanceIdHash(const std::string &address, const std::map< std::string, std::string > ¶meters)
Generates shm dummy instanceId hash from address and parameter map, Intended for use with parseDevice...
std::string createShmName(std::size_t instanceIdHash, const std::string &mapFileName, const std::string &userName)
Generates shm dummy name from parameter hashes.
Test-only backend exposing the resolved map file name computed by the NumericAddressedBackend base cl...
std::string resolvedMapFileName() const
static void setDMapPath(const std::string &dmapPath)
static void writeMapFile(const fs::path &path, const std::string ®isterName)
Write a map file containing a single register with the given name.
static void writeDMapFile(const fs::path &path, const std::string &mapName)
Write a minimal, parseable dmap file referencing the given map file.
static std::string canonical(const std::string &path)
BOOST_FIXTURE_TEST_CASE(RelativeMapResolvedRelativeToDmapDirectory, MapFileSearchFixture)