LCOV - code coverage report
Current view: top level - /opt/artdaq/srcs/artdaq-database/test/CaseStudy/OtsDaqCPPInterface/test008 - EntitySupport_t.cc (source / functions) Coverage Total Hit
Test: artdaq.info.cleaned Lines: 100.0 % 97 97
Test Date: 2026-10-29 00:35:58 Functions: 100.0 % 8 8

            Line data    Source code
       1              : #define BOOST_TEST_DYN_LINK
       2              : #define BOOST_TEST_MODULE (EntitySupport test)
       3              : 
       4              : #include <boost/test/unit_test.hpp>
       5              : 
       6              : #include <cstdlib>
       7              : #include <ctime>
       8              : #include <iostream>
       9              : #include <memory>
      10              : #include <string>
      11              : 
      12              : #include "../DatabaseConfigurationInterface.h"
      13              : 
      14              : using namespace ots;
      15              : 
      16              : struct EntitySupportTestData {
      17            2 :   EntitySupportTestData() {
      18            2 :     srand(time(nullptr));
      19            2 :     baseVersion = rand() % 99999 + 100000;
      20            2 :     std::cout << "=== ENTITY SUPPORT TEST SUITE ===\n";
      21            2 :     std::cout << "Base version: " << baseVersion << "\n\n";
      22            2 :   }
      23              : 
      24            2 :   ~EntitySupportTestData() { std::cout << "\n=== TEST SUITE COMPLETE ===\n"; }
      25              : 
      26              :   int baseVersion;
      27              : };
      28              : 
      29              : EntitySupportTestData fixture;
      30              : 
      31              : BOOST_AUTO_TEST_SUITE(entity_support_test)
      32              : 
      33            4 : BOOST_AUTO_TEST_CASE(store_same_version_different_config_types) {
      34            2 :   std::cout << "\n=== TEST 1: Store same version for different config types ===\n";
      35              : 
      36            2 :   auto ifc = DatabaseConfigurationInterface();
      37            2 :   int testVersion = fixture.baseVersion;
      38              : 
      39            2 :   std::shared_ptr<ConfigurationBase> cfg1 = std::make_shared<TestConfiguration001>();
      40            2 :   cfg1->getView().version = testVersion;
      41            4 :   cfg1->getView().fillFromJSON("{\"type\": \"config001\"}");
      42              : 
      43            2 :   auto result1 = ifc.saveActiveVersion(cfg1.get());
      44            2 :   BOOST_REQUIRE_EQUAL(result1, 0);
      45            2 :   std::cout << "Step 1: Saved TestConfiguration001 version " << testVersion << "\n";
      46              : 
      47            2 :   std::shared_ptr<ConfigurationBase> cfg2 = std::make_shared<TestConfiguration002>();
      48            2 :   cfg2->getView().version = testVersion;
      49            4 :   cfg2->getView().fillFromJSON("{\"type\": \"config002\"}");
      50              : 
      51            2 :   auto result2 = ifc.saveActiveVersion(cfg2.get());
      52            2 :   BOOST_REQUIRE_EQUAL(result2, 0);
      53            2 :   std::cout << "Step 2: Saved TestConfiguration002 version " << testVersion << "\n";
      54              : 
      55            2 :   std::shared_ptr<ConfigurationBase> read1 = std::make_shared<TestConfiguration001>();
      56            2 :   auto fillResult1 = ifc.fill(read1.get(), testVersion);
      57            2 :   BOOST_CHECK_EQUAL(fillResult1, 0);
      58              : 
      59            2 :   std::shared_ptr<ConfigurationBase> read2 = std::make_shared<TestConfiguration002>();
      60            2 :   auto fillResult2 = ifc.fill(read2.get(), testVersion);
      61            2 :   BOOST_CHECK_EQUAL(fillResult2, 0);
      62              : 
      63            2 :   bool has001 = (read1->getView()._json.find("config001") != std::string::npos);
      64            2 :   bool has002 = (read2->getView()._json.find("config002") != std::string::npos);
      65              : 
      66            2 :   BOOST_CHECK_MESSAGE(has001, "TestConfiguration001 should have config001 data");
      67            2 :   BOOST_CHECK_MESSAGE(has002, "TestConfiguration002 should have config002 data");
      68              : 
      69            2 :   std::cout << "  Verified: Same version stored independently for different config types\n";
      70            2 : }
      71              : 
      72            4 : BOOST_AUTO_TEST_CASE(composition_with_multiple_config_types) {
      73            2 :   std::cout << "\n=== TEST 2: Composition with multiple config types ===\n";
      74              : 
      75            2 :   auto ifc = DatabaseConfigurationInterface();
      76            2 :   int version1 = fixture.baseVersion + 1;
      77            2 :   int version2 = fixture.baseVersion + 2;
      78              : 
      79            2 :   std::shared_ptr<ConfigurationBase> cfg1 = std::make_shared<TestConfiguration001>();
      80            2 :   cfg1->getView().version = version1;
      81            4 :   cfg1->getView().fillFromJSON("{\"subsystem\": \"detector\"}");
      82            2 :   auto result1 = ifc.saveActiveVersion(cfg1.get());
      83            2 :   BOOST_REQUIRE_EQUAL(result1, 0);
      84            2 :   std::cout << "Step 1: Saved TestConfiguration001 v" << version1 << "\n";
      85              : 
      86            2 :   std::shared_ptr<ConfigurationBase> cfg2 = std::make_shared<TestConfiguration002>();
      87            2 :   cfg2->getView().version = version2;
      88            4 :   cfg2->getView().fillFromJSON("{\"subsystem\": \"trigger\"}");
      89            2 :   auto result2 = ifc.saveActiveVersion(cfg2.get());
      90            2 :   BOOST_REQUIRE_EQUAL(result2, 0);
      91            2 :   std::cout << "Step 2: Saved TestConfiguration002 v" << version2 << "\n";
      92              : 
      93            2 :   auto map = DatabaseConfigurationInterface::config_version_map_t{};
      94            2 :   map[cfg1->getConfigurationName()] = version1;
      95            2 :   map[cfg2->getConfigurationName()] = version2;
      96              : 
      97            2 :   std::string compName = "MultiType_" + std::to_string(fixture.baseVersion);
      98            2 :   BOOST_CHECK_NO_THROW(ifc.storeGlobalConfiguration(map, compName));
      99            2 :   std::cout << "Step 3: Created composition " << compName << "\n";
     100              : 
     101            2 :   auto loaded = ifc.loadGlobalConfiguration(compName);
     102            2 :   std::cout << "Step 4: Loaded composition with " << loaded.size() << " members\n";
     103              : 
     104            2 :   BOOST_CHECK_EQUAL(loaded.size(), 2);
     105            2 :   BOOST_CHECK_EQUAL(loaded.at(cfg1->getConfigurationName()), version1);
     106            2 :   BOOST_CHECK_EQUAL(loaded.at(cfg2->getConfigurationName()), version2);
     107              : 
     108            2 :   std::cout << "  Verified: Composition contains both configuration types\n";
     109            2 : }
     110              : 
     111            4 : BOOST_AUTO_TEST_CASE(version_isolation_per_config_type) {
     112            2 :   std::cout << "\n=== TEST 3: Version isolation per configuration type ===\n";
     113              : 
     114            2 :   auto ifc = DatabaseConfigurationInterface();
     115            2 :   int baseV = fixture.baseVersion + 10;
     116              : 
     117            8 :   for (int i = 0; i < 3; ++i) {
     118            6 :     std::shared_ptr<ConfigurationBase> cfg = std::make_shared<TestConfiguration001>();
     119            6 :     cfg->getView().version = baseV + i;
     120            6 :     auto result = ifc.saveActiveVersion(cfg.get());
     121            6 :     BOOST_REQUIRE_EQUAL(result, 0);
     122            6 :   }
     123            2 :   std::cout << "Step 1: Saved TestConfiguration001 versions " << baseV << "-" << (baseV + 2) << "\n";
     124              : 
     125            6 :   for (int i = 0; i < 2; ++i) {
     126            4 :     std::shared_ptr<ConfigurationBase> cfg = std::make_shared<TestConfiguration002>();
     127            4 :     cfg->getView().version = baseV + 100 + i;
     128            4 :     auto result = ifc.saveActiveVersion(cfg.get());
     129            4 :     BOOST_REQUIRE_EQUAL(result, 0);
     130            4 :   }
     131            2 :   std::cout << "Step 2: Saved TestConfiguration002 versions " << (baseV + 100) << "-" << (baseV + 101) << "\n";
     132              : 
     133            2 :   std::shared_ptr<ConfigurationBase> cfg1 = std::make_shared<TestConfiguration001>();
     134            2 :   auto versions1 = ifc.getVersions(cfg1.get());
     135              : 
     136            2 :   bool found1 = (versions1.find(baseV) != versions1.end());
     137            2 :   bool found2 = (versions1.find(baseV + 1) != versions1.end());
     138            2 :   bool found3 = (versions1.find(baseV + 2) != versions1.end());
     139              : 
     140            2 :   BOOST_CHECK_MESSAGE(found1, "Version " + std::to_string(baseV) + " should exist for TestConfiguration001");
     141            2 :   BOOST_CHECK_MESSAGE(found2, "Version " + std::to_string(baseV + 1) + " should exist for TestConfiguration001");
     142            2 :   BOOST_CHECK_MESSAGE(found3, "Version " + std::to_string(baseV + 2) + " should exist for TestConfiguration001");
     143              : 
     144            2 :   bool wrongVersion1 = (versions1.find(baseV + 100) != versions1.end());
     145            2 :   bool wrongVersion2 = (versions1.find(baseV + 101) != versions1.end());
     146              : 
     147            2 :   BOOST_CHECK_MESSAGE(!wrongVersion1, "TestConfiguration002's version should not appear in TestConfiguration001");
     148            2 :   BOOST_CHECK_MESSAGE(!wrongVersion2, "TestConfiguration002's version should not appear in TestConfiguration001");
     149              : 
     150            2 :   std::cout << "  Verified: Version lists are isolated per configuration type\n";
     151            2 : }
     152              : 
     153              : BOOST_AUTO_TEST_SUITE_END()
        

Generated by: LCOV version 2.0-1