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: 2025-12-21 13:07:08 Functions: 0.0 % 21 0

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

Generated by: LCOV version 2.0-1