Line data Source code
1 : // DUNE DAQ modification notice:
2 : // This file has been modified from the original ATLAS dbe source for the DUNE DAQ project.
3 : // Fork baseline commit: dbe-02-12-17 (2022-05-12).
4 : // Renamed since fork: yes (from test/config_api_info_test.cpp to unittest/config_api_info_test.cxx).
5 :
6 : /*
7 : * config_api_test.cpp
8 : *
9 : * Created on: Nov 2, 2015
10 : * Author: Leonidas Georgopoulos
11 : */
12 :
13 : #define BOOST_TEST_MAIN
14 :
15 : #include "dbe_test_defs.hpp"
16 : #include "dbe/config_api_info.hpp"
17 : #include "dbe/config_api.hpp"
18 : #include "dbe/confaccessor.hpp"
19 :
20 : #include <boost/test/unit_test.hpp>
21 :
22 : #include <algorithm>
23 : #include <iostream>
24 :
25 : namespace dbe
26 : {
27 : namespace config
28 : {
29 : namespace test
30 : {
31 : //------------------------------------------------------------------------------------------
32 : struct class_facilities_fix:
33 : dbe::test::oksfix
34 : {
35 : std::string const class_not_existent = "foo-man-tsu";
36 :
37 : std::string const class_abstract = "Application";
38 :
39 : std::string const class_non_abstract = "Detector";
40 : std::string const object_in_non_abstract_class = "ALFA";
41 :
42 4 : class_facilities_fix()
43 4 : {
44 4 : confaccessor::setdbinfo(QString::fromStdString(cdbpath + fn), dbtype);
45 4 : confaccessor::load();
46 4 : }
47 : };
48 :
49 : BOOST_FIXTURE_TEST_SUITE(info_class_facilities_suite, class_facilities_fix)
50 :
51 2 : BOOST_AUTO_TEST_CASE(get_allclasses_check)
52 : {
53 1 : BOOST_CHECK(confaccessor::is_database_loaded());
54 1 : {
55 1 : std::vector<std::string> allclasses =
56 1 : { config::api::info::onclass::allnames<std::vector<std::string>>() };
57 :
58 1 : BOOST_CHECK(not allclasses.empty());
59 1 : }
60 1 : {
61 : // can be loaded as a qstringlist
62 1 : QStringList allclasses =
63 1 : { config::api::info::onclass::allnames<QStringList>() };
64 :
65 1 : BOOST_CHECK(not allclasses.empty());
66 1 : }
67 1 : }
68 :
69 2 : BOOST_AUTO_TEST_CASE(on_not_existent_class)
70 : {
71 1 : BOOST_CHECK(confaccessor::is_database_loaded());
72 1 : {
73 : // catches the underlying NotFound exception
74 1 : BOOST_CHECK_NO_THROW(api::info::onclass::definition(class_not_existent, false));
75 :
76 : // Returns an empty object
77 1 : dunedaq::conffwk::class_t definition =
78 1 : { api::info::onclass::definition(class_not_existent, false) };
79 :
80 1 : BOOST_CHECK(definition.p_name.empty());
81 1 : BOOST_CHECK(not definition.p_abstract);
82 1 : BOOST_CHECK(definition.p_description.empty());
83 1 : BOOST_CHECK(definition.p_relationships.empty());
84 1 : BOOST_CHECK(definition.p_attributes.empty());
85 1 : BOOST_CHECK(definition.p_superclasses.empty());
86 1 : BOOST_CHECK(definition.p_subclasses.empty());
87 1 : }
88 1 : }
89 :
90 2 : BOOST_AUTO_TEST_CASE(on_abstract_class_definition)
91 : {
92 1 : BOOST_CHECK(confaccessor::is_database_loaded());
93 1 : {
94 1 : BOOST_CHECK_NO_THROW(api::info::onclass::definition(class_abstract, false));
95 :
96 1 : dunedaq::conffwk::class_t definition =
97 1 : { api::info::onclass::definition(class_abstract, false) };
98 :
99 1 : BOOST_CHECK(definition.p_abstract);
100 1 : }
101 :
102 1 : {
103 1 : BOOST_CHECK_NO_THROW(api::info::onclass::definition(class_non_abstract, false));
104 1 : dunedaq::conffwk::class_t definition =
105 1 : { api::info::onclass::definition(class_non_abstract, false) };
106 :
107 1 : BOOST_CHECK_EQUAL(definition.p_abstract, false);
108 1 : }
109 :
110 1 : }
111 :
112 2 : BOOST_AUTO_TEST_CASE(on_class_definition)
113 : {
114 1 : {
115 : // Can retrieve definition for a class and not-only direct relations
116 1 : BOOST_CHECK_NO_THROW(api::info::onclass::definition(class_non_abstract, false));
117 1 : dunedaq::conffwk::class_t definition = api::info::onclass::definition(class_non_abstract,
118 1 : false);
119 1 : BOOST_CHECK_EQUAL(definition.p_name, class_non_abstract);
120 1 : BOOST_CHECK(not definition.p_abstract);
121 1 : BOOST_CHECK(not definition.p_description.empty());
122 1 : BOOST_CHECK(not definition.p_relationships.empty());
123 1 : BOOST_CHECK(not definition.p_attributes.empty());
124 1 : BOOST_CHECK(not definition.p_superclasses.empty());
125 1 : BOOST_CHECK(definition.p_subclasses.empty());
126 1 : }
127 1 : {
128 :
129 :
130 : // Can retrieve definition for a class and direct only relations
131 1 : BOOST_CHECK_NO_THROW(api::info::onclass::definition(class_non_abstract, true));
132 1 : dunedaq::conffwk::class_t result_class = api::info::onclass::definition(class_non_abstract,
133 1 : true);
134 :
135 1 : BOOST_CHECK_EQUAL(result_class.p_name, class_non_abstract);
136 1 : BOOST_CHECK(not result_class.p_abstract);
137 1 : BOOST_CHECK(not result_class.p_description.empty());
138 1 : BOOST_CHECK(result_class.p_relationships.empty()); // class has no direct only relations
139 1 : BOOST_CHECK(not result_class.p_attributes.empty());
140 1 : BOOST_CHECK(not result_class.p_superclasses.empty());
141 1 : BOOST_CHECK(result_class.p_subclasses.empty());
142 1 : }
143 1 : }
144 :
145 : BOOST_AUTO_TEST_SUITE_END()
146 : //------------------------------------------------------------------------------------------
147 :
148 : //------------------------------------------------------------------------------------------
149 : struct object_facilities_fix:
150 : dbe::test::oksfix
151 : {
152 : std::string const class_abstract = "ComputerProgram";
153 : std::string const class_non_abstract = "Binary";
154 : std::string const class_derived_from_non_abstract_class = "ABinaryDerivedClass";
155 : std::string const object_in_non_abstract_class = "rc_controller";
156 : std::string const object_derived_from_non_abstract_class = "InstanceOfABinaryDerivedClass";
157 :
158 3 : object_facilities_fix()
159 3 : {
160 3 : confaccessor::setdbinfo(QString::fromStdString(cdbpath + fn), dbtype);
161 3 : confaccessor::load();
162 3 : }
163 : };
164 :
165 : BOOST_FIXTURE_TEST_SUITE(info_object_facilities_check, object_facilities_fix)
166 :
167 2 : BOOST_AUTO_TEST_CASE(object_facilities_check)
168 : {
169 1 : BOOST_CHECK(confaccessor::is_database_loaded());
170 1 : {
171 : // Check that has_obj accepts std::string of class Detector for object ALFA
172 1 : BOOST_CHECK(api::info::has_obj(class_non_abstract, object_in_non_abstract_class));
173 : }
174 1 : }
175 :
176 2 : BOOST_AUTO_TEST_CASE(objects_of_class)
177 : {
178 1 : std::vector<dbe::inner::configobject::tref> const & oinclass =
179 1 : api::info::onclass::objects(class_non_abstract, false);
180 1 : {
181 1 : auto foundpos = std::find_if(oinclass.begin(), oinclass.end(),
182 2 : [&](dbe::inner::configobject::tref const x)
183 2 : { return x.UID() == object_in_non_abstract_class;});
184 1 : BOOST_CHECK(foundpos != oinclass.end());
185 : }
186 :
187 1 : std::vector<dbe::inner::configobject::tref> const & derivedinclass =
188 1 : api::info::onclass::objects(class_non_abstract, true);
189 1 : {
190 1 : auto foundpos = std::find_if(
191 : derivedinclass.begin(), derivedinclass.end(),
192 1 : [&](dbe::inner::configobject::tref const x)
193 1 : { return x.UID() == object_derived_from_non_abstract_class;});
194 1 : BOOST_CHECK(foundpos != derivedinclass.end());
195 : }
196 :
197 1 : BOOST_CHECK_NE(oinclass.size(), derivedinclass.size());
198 1 : }
199 :
200 2 : BOOST_AUTO_TEST_CASE(derived_classes)
201 : {
202 1 : BOOST_CHECK(api::info::onclass::derived(class_abstract, class_non_abstract));
203 1 : BOOST_CHECK(
204 : api::info::onclass::derived(class_abstract, class_derived_from_non_abstract_class));
205 1 : BOOST_CHECK(
206 : api::info::onclass::derived(class_non_abstract,
207 : class_derived_from_non_abstract_class));
208 1 : }
209 :
210 : BOOST_AUTO_TEST_SUITE_END()
211 : //------------------------------------------------------------------------------------------
212 : }/* namespace test */
213 : } /* namespace config */
214 : } /* namespace dbe */
|