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

Generated by: LCOV version 2.0-1