LCOV - code coverage report
Current view: top level - oksconflibs/test/apps - test_oksdb.cxx (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 171 0
Test Date: 2026-10-11 15:05:20 Functions: 0.0 % 21 0

            Line data    Source code
       1              : //
       2              : // DUNE DAQ modification notice:
       3              : // This file has been modified from the original ATLAS oksconfig source for the DUNE DAQ project.
       4              : // Fork baseline commit: oksconfig-03-02-00 (2021-04-20).
       5              : // Renamed since fork: yes (from test/test_oksdb.cpp to test/apps/test_oksdb.cxx).
       6              : //
       7              : 
       8              : #include <iostream>
       9              : #include <stdlib.h>
      10              : 
      11              : #include "conffwk/ConfigObject.hpp"
      12              : #include "conffwk/Configuration.hpp"
      13              : #include "conffwk/Schema.hpp"
      14              : 
      15              : using namespace dunedaq;
      16              : using namespace dunedaq::conffwk;
      17              : 
      18              : static const char*
      19            0 : all2string(bool direct)
      20              : {
      21            0 :   return (direct ? "direct " : "all ");
      22              : }
      23              : 
      24              : static void
      25            0 : show_info(Configuration& config, const char* name, bool direct)
      26              : {
      27            0 :   const dunedaq::conffwk::class_t& c = config.get_class_info(name, direct);
      28              : 
      29            0 :   std::cout << "class " << c.p_name << std::endl;
      30              : 
      31            0 :   if (!c.p_superclasses.empty()) {
      32            0 :     std::cout << "  " << all2string(direct) << "superclasses:\n";
      33            0 :     for (const auto& x : c.p_superclasses)
      34            0 :       std::cout << "    " << x << std::endl;
      35              :   }
      36              : 
      37            0 :   if (!c.p_subclasses.empty()) {
      38            0 :     std::cout << "  " << all2string(direct) << "subclasses:\n";
      39            0 :     for (const auto& x : c.p_subclasses)
      40            0 :       std::cout << "    " << x << std::endl;
      41              :   }
      42              : 
      43            0 :   if (!c.p_attributes.empty()) {
      44            0 :     std::cout << "  " << all2string(direct) << "attributes:\n";
      45            0 :     for (const auto& x : c.p_attributes) {
      46            0 :       x.print(std::cout, "    ");
      47            0 :       std::cout << std::endl;
      48              :     }
      49              :   }
      50              : 
      51            0 :   if (!c.p_relationships.empty()) {
      52            0 :     std::cout << "  " << all2string(direct) << "relationships:\n";
      53            0 :     for (const auto& x : c.p_relationships) {
      54            0 :       x.print(std::cout, "    ");
      55            0 :       std::cout << std::endl;
      56              :     }
      57              :   }
      58              : 
      59            0 :   std::cout << std::endl;
      60            0 : }
      61              : 
      62              : static void
      63            0 : check_meta_info(Configuration& config)
      64              : {
      65            0 :   show_info(config, "A", true);
      66            0 :   show_info(config, "B", true);
      67            0 :   show_info(config, "B", false);
      68            0 :   show_info(config, "C", true);
      69            0 :   show_info(config, "C", false);
      70            0 : }
      71              : 
      72              : template<class T>
      73              : void
      74            0 : get_attribute(ConfigObject& obj, const std::string& name)
      75              : {
      76              :   try {
      77            0 :     T value;
      78            0 :     obj.get(name, value);
      79            0 :     std::cout << name << " = " << value << std::endl;
      80            0 :   } catch (ers::Issue& ex) {
      81            0 :     std::cerr << "ERROR: cannot find attribute " << name << ":\n" << ex << std::endl;
      82              :   }
      83            0 : }
      84              : 
      85              : static void
      86            0 : show_primitive(ConfigObject& obj)
      87              : {
      88            0 :   get_attribute<uint8_t>(obj, "uc");
      89            0 :   get_attribute<bool>(obj, "b");
      90            0 :   get_attribute<uint16_t>(obj, "us");
      91            0 :   get_attribute<int16_t>(obj, "ss");
      92            0 :   get_attribute<uint32_t>(obj, "ui");
      93            0 :   get_attribute<int32_t>(obj, "si");
      94            0 :   get_attribute<uint64_t>(obj, "ul");
      95            0 :   get_attribute<int64_t>(obj, "sl");
      96            0 :   get_attribute<float>(obj, "f");
      97            0 :   get_attribute<double>(obj, "d");
      98            0 :   get_attribute<std::string>(obj, "str");
      99            0 :   get_attribute<std::string>(obj, "cls");
     100            0 : }
     101              : 
     102              : static void
     103            0 : check_primitives(Configuration& config)
     104              : {
     105            0 :   ConfigObject obj;
     106              : 
     107            0 :   try {
     108            0 :     config.get("TestPrimitive", "primitive", obj);
     109            0 :     show_primitive(obj);
     110            0 :     obj.print_ref(std::cout, config);
     111            0 :   } catch (ers::Issue& ex) {
     112            0 :     std::cerr << "ERROR: cannot find object 'primitive' of type 'TestPrimitive':\n" << ex << std::endl;
     113            0 :   }
     114            0 : }
     115              : 
     116              : static void
     117            0 : show_multiple(ConfigObject& obj)
     118              : {
     119            0 :   try {
     120            0 :     std::vector<unsigned short> numbers;
     121            0 :     obj.get("ui", numbers);
     122            0 :     for (size_t i = 0; i < numbers.size(); i++) {
     123            0 :       std::cout << "ui[" << i << "] = " << numbers[i] << std::endl;
     124              :     }
     125            0 :     std::cout << std::endl;
     126            0 :   } catch (ers::Issue& ex) {
     127            0 :     std::cerr << "ERROR: cannot find attribute 'ui':\n" << ex << std::endl;
     128            0 :   }
     129              : 
     130            0 :   try {
     131            0 :     std::vector<std::string> strings;
     132            0 :     obj.get("str", strings);
     133            0 :     for (size_t i = 0; i < strings.size(); i++) {
     134            0 :       std::cout << "str[" << i << "] = " << strings[i] << std::endl;
     135              :     }
     136            0 :     std::cout << std::endl;
     137            0 :   } catch (ers::Issue& ex) {
     138            0 :     std::cerr << "ERROR: cannot find attribute 'str':\n" << ex << std::endl;
     139            0 :   }
     140            0 : }
     141              : 
     142              : static void
     143            0 : check_multiple(Configuration& config)
     144              : {
     145            0 :   try {
     146            0 :     ConfigObject obj;
     147            0 :     config.get("TestMultiple", "multiple", obj);
     148            0 :     show_multiple(obj);
     149            0 :     obj.print_ref(std::cout, config);
     150            0 :   } catch (ers::Issue& ex) {
     151            0 :     std::cerr << "ERROR: cannot find object 'multiple' of type 'TestMultiple':\n" << ex << std::endl;
     152            0 :   }
     153            0 : }
     154              : 
     155              : static void
     156            0 : check_relations(Configuration& config)
     157              : {
     158            0 :   ConfigObject obj;
     159              : 
     160            0 :   try {
     161            0 :     config.get("TestRelation", "relation", obj);
     162            0 :     obj.print_ref(std::cout, config);
     163            0 :   } catch (ers::Issue& ex) {
     164            0 :     std::cerr << "ERROR: cannot find object 'relation' of type 'TestRelation':\n" << ex << std::endl;
     165            0 :     return;
     166            0 :   }
     167              : 
     168            0 :   try {
     169            0 :     ConfigObject prim;
     170            0 :     obj.get("prim", prim);
     171            0 :     show_primitive(prim);
     172            0 :     prim.print_ref(std::cout, config);
     173            0 :   } catch (ers::Issue& ex) {
     174            0 :     std::cerr << "ERROR: cannot find relation 'prim' in object 'relation':\n" << ex << std::endl;
     175            0 :   }
     176              : 
     177            0 :   try {
     178            0 :     std::vector<ConfigObject> mult;
     179            0 :     obj.get("mult", mult);
     180              : 
     181            0 :     for (std::vector<ConfigObject>::iterator it = mult.begin(); it != mult.end(); ++it) {
     182            0 :       show_multiple(*it);
     183            0 :       (*it).print_ref(std::cout, config);
     184              :     }
     185            0 :   } catch (ers::Issue& ex) {
     186            0 :     std::cerr << "ERROR: cannot find relation 'mult' in object 'relation':\n" << ex << std::endl;
     187            0 :   }
     188            0 : }
     189              : 
     190              : static void
     191            0 : check_enums(Configuration& config)
     192              : {
     193            0 :   ConfigObject obj;
     194              : 
     195            0 :   try {
     196            0 :     config.get("EnumTest", "e1", obj);
     197            0 :   } catch (ers::Issue& ex) {
     198            0 :     std::cerr << "ERROR: cannot find 'e1' of type 'EnumTest':\n" << ex << std::endl;
     199            0 :     return;
     200            0 :   }
     201              : 
     202            0 :   try {
     203            0 :     std::string value;
     204            0 :     obj.get("enum1", value);
     205            0 :     std::cout << "enum1 = " << value << std::endl;
     206            0 :   } catch (ers::Issue& ex) {
     207            0 :     std::cerr << "ERROR: cannot find 'enum1' attribute:\n" << ex << std::endl;
     208            0 :     return;
     209            0 :   }
     210              : 
     211            0 :   try {
     212            0 :     std::vector<std::string> values;
     213            0 :     std::cout << "enum2 = ";
     214            0 :     for (std::vector<std::string>::iterator it = values.begin(); it != values.end(); ++it) {
     215            0 :       std::cout << *it << " ";
     216              :     }
     217            0 :     std::cout << std::endl;
     218            0 :   } catch (ers::Issue& ex) {
     219            0 :     std::cerr << "ERROR: cannot find 'enum2' attribute:\n" << ex << std::endl;
     220            0 :     return;
     221            0 :   }
     222            0 : }
     223              : 
     224              : int
     225            0 : main(int argc, char* argv[])
     226              : {
     227            0 :   std::string dbname = "oksconflibs:../../oksconflibs/test/okstest.data.xml:../../oksconflibs/test/test2.data.xml";
     228              : 
     229            0 :   if (argc != 1)
     230            0 :     dbname = argv[1];
     231              : 
     232            0 :   try {
     233            0 :     Configuration config(dbname);
     234              : 
     235            0 :     check_primitives(config);
     236            0 :     check_multiple(config);
     237            0 :     check_relations(config);
     238            0 :     check_enums(config);
     239            0 :     check_meta_info(config);
     240              : 
     241            0 :     try {
     242            0 :       ConfigObject obj;
     243            0 :       config.get("OtherClass", "test2", obj);
     244            0 :       std::cout << "could get Test2 object" << std::endl;
     245            0 :     } catch (ers::Issue& ex) {
     246            0 :       std::cerr << "ERROR: cannot get Test2 object:\n" << ex << std::endl;
     247            0 :     }
     248            0 :   } catch (const ers::Issue& ex) {
     249            0 :     std::cerr << "ERROR: " << ex << std::endl;
     250            0 :     return EXIT_FAILURE;
     251            0 :   }
     252              : 
     253            0 :   return EXIT_SUCCESS;
     254            0 : }
        

Generated by: LCOV version 2.0-1