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 % 106 106
Test Date: 2025-12-21 13:07:08 Functions: 100.0 % 18 18

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

Generated by: LCOV version 2.0-1