LCOV - code coverage report
Current view: top level - dbe/unittest - config_api_info_test.cxx (source / functions) Coverage Total Hit
Test: code.result Lines: 100.0 % 97 97
Test Date: 2026-10-11 15:05:20 Functions: 100.0 % 18 18

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

Generated by: LCOV version 2.0-1