ChimeraTK-DeviceAccess  03.18.00
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"
9 namespace ChimeraTK {
10  using namespace ChimeraTK;
11 }
12 
13 using namespace boost::unit_test_framework;
14 using namespace ChimeraTK;
16 
18  public:
19  void testRegisterPath();
20  void testNumericAddresses();
21  void testComponents();
22 };
23 
24 class 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 }
RegisterPathTestSuite::RegisterPathTestSuite
RegisterPathTestSuite()
Definition: testRegisterPath.cpp:26
RegisterPathTest::testRegisterPath
void testRegisterPath()
Definition: testRegisterPath.cpp:42
boost_dynamic_init_test.h
RegisterPathTestSuite
Definition: testRegisterPath.cpp:24
ChimeraTK::RegisterPath::setAltSeparator
void setAltSeparator(const std::string &altSeparator)
set alternative separator.
Definition: RegisterPath.h:37
ChimeraTK::RegisterPath::getWithAltSeparator
std::string getWithAltSeparator() const
obtain path with alternative separator character instead of "/".
Definition: RegisterPath.h:48
ChimeraTK::numeric_address::BAR
RegisterPath BAR()
The numeric_address::BAR() function can be used to directly access registers by numeric addresses,...
Definition: NumericAddress.cc:7
RegisterPathTest::testNumericAddresses
void testNumericAddresses()
Definition: testRegisterPath.cpp:89
NumericAddress.h
ChimeraTK::RegisterPath::length
size_t length() const
return the length of the path (including leading slash)
Definition: RegisterPath.h:138
ChimeraTK::RegisterPath
Class to store a register path name.
Definition: RegisterPath.h:16
ChimeraTK::RegisterPath::getComponents
std::vector< std::string > getComponents() const
split path into components
Definition: RegisterPath.h:158
init_unit_test
bool init_unit_test()
Definition: testRegisterPath.cpp:35
ChimeraTK
Definition: DummyBackend.h:16
RegisterPathTest::testComponents
void testComponents()
Definition: testRegisterPath.cpp:105
RegisterPathTest
Definition: testRegisterPath.cpp:17
RegisterPath.h