ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
testRegisterPath.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 "NumericAddress.h"
8#include "RegisterPath.h"
9namespace ChimeraTK {
10 using namespace ChimeraTK;
11}
12
13using namespace boost::unit_test_framework;
14using namespace ChimeraTK;
16
18 public:
19 void testRegisterPath();
21 void testComponents();
22};
23
24class RegisterPathTestSuite : public test_suite {
25 public:
26 RegisterPathTestSuite() : test_suite("RegisterPath class test suite") {
27 boost::shared_ptr<RegisterPathTest> registerPathTest(new RegisterPathTest);
28
29 add(BOOST_CLASS_TEST_CASE(&RegisterPathTest::testRegisterPath, registerPathTest));
30 add(BOOST_CLASS_TEST_CASE(&RegisterPathTest::testNumericAddresses, registerPathTest));
31 add(BOOST_CLASS_TEST_CASE(&RegisterPathTest::testComponents, registerPathTest));
32 }
33};
34
36 framework::master_test_suite().p_name.value = "LogicalNameMap class test suite";
37 framework::master_test_suite().add(new RegisterPathTestSuite());
38
39 return true;
40}
41
43 RegisterPath path1;
44 RegisterPath path2("module1");
45 RegisterPath path3("//module//blah/");
46 RegisterPath path4("moduleX..Yblah./sub");
47 BOOST_CHECK(path1 == "/");
48 BOOST_CHECK(path1.length() == 1);
49 BOOST_CHECK(path2 == "/module1");
50 BOOST_CHECK(path2.length() == 8);
51 BOOST_CHECK(path3 == "/module/blah");
52 BOOST_CHECK(path3.length() == 12);
53
54 BOOST_CHECK(path3.getWithAltSeparator() == "module/blah");
55 path3.setAltSeparator(".");
56 BOOST_CHECK(path3 == "/module/blah");
57 BOOST_CHECK(path3.getWithAltSeparator() == "module.blah");
58 path3.setAltSeparator("");
59
60 BOOST_CHECK(path4 == "/moduleX..Yblah./sub");
61 path4.setAltSeparator(".");
62 BOOST_CHECK(path4 == "/moduleX/Yblah/sub");
63 BOOST_CHECK(path4.getWithAltSeparator() == "moduleX.Yblah.sub");
64 BOOST_CHECK((path4 / "next.register").getWithAltSeparator() == "moduleX.Yblah.sub.next.register");
65 path4.setAltSeparator("/"); // this should clear the alternate separator as well
66 BOOST_CHECK(path4 == "/moduleX..Yblah./sub");
67 path4.setAltSeparator("");
68 BOOST_CHECK(path4 == "/moduleX..Yblah./sub");
69
70 BOOST_CHECK(path3 / "register" == "/module/blah/register");
71 BOOST_CHECK("root" / path3 / "register" == "/root/module/blah/register");
72 BOOST_CHECK("root/" + path3 + "register" == "root//module/blahregister");
73 BOOST_CHECK("root" / path3 + "register" == "/root/module/blahregister");
74 BOOST_CHECK("root" + path3 / "register" == "root/module/blah/register");
75 BOOST_CHECK(path2 / path3 == "/module1/module/blah");
76
77 path3 /= "test";
78 BOOST_CHECK(path3 == "/module/blah/test");
79 path3--;
80 BOOST_CHECK(path3 == "/module/blah");
81 --path3;
82 BOOST_CHECK(path3 == "/blah");
83 path3--;
84 BOOST_CHECK(path3 == "/");
85 --path2;
86 BOOST_CHECK(path2 == "/");
87}
88
90 RegisterPath path1("/SomeModule/withSomeRegister/");
91 BOOST_CHECK(path1 == "/SomeModule/withSomeRegister");
92
93 RegisterPath path2;
94
95 path2 = path1 * 3;
96 BOOST_CHECK(path2 == "/SomeModule/withSomeRegister*3");
97
98 path2 = path1 / 3;
99 BOOST_CHECK(path2 == "/SomeModule/withSomeRegister/3");
100
101 BOOST_CHECK(BAR() == "/#");
102 BOOST_CHECK(BAR() / 0 / 32 * 8 == "/#/0/32*8");
103}
104
106 RegisterPath path1("/SomeModule/withSubModules/and/withSomeRegister/");
107 std::vector<std::string> comps1 = path1.getComponents();
108 BOOST_CHECK(comps1.size() == 4);
109 BOOST_CHECK(comps1[0] == "SomeModule");
110 BOOST_CHECK(comps1[1] == "withSubModules");
111 BOOST_CHECK(comps1[2] == "and");
112 BOOST_CHECK(comps1[3] == "withSomeRegister");
113
114 RegisterPath path2("");
115 std::vector<std::string> comps2 = path2.getComponents();
116 BOOST_CHECK(comps2.size() == 0);
117
118 RegisterPath path3("singleComponent");
119 std::vector<std::string> comps3 = path3.getComponents();
120 BOOST_CHECK(comps3.size() == 1);
121 BOOST_CHECK(comps3[0] == "singleComponent");
122}
Class to store a register path name.
std::vector< std::string > getComponents() const
split path into components
std::string getWithAltSeparator() const
obtain path with alternative separator character instead of "/".
void setAltSeparator(const std::string &altSeparator)
set alternative separator.
size_t length() const
return the length of the path (including leading slash)
RegisterPath BAR()
The numeric_address::BAR() function can be used to directly access registers by numeric addresses,...
bool init_unit_test()