LCOV - code coverage report
Current view: top level - restcmd/test/apps - test_rest_app.cxx (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 28 0
Test Date: 2025-12-21 13:07:08 Functions: 0.0 % 6 0

            Line data    Source code
       1              : /**
       2              :  * @file test_rest_app.cxx Test application for using the
       3              :  * restCommandFacility with a RestCommandedObject.
       4              :  * Showcases error handling of bad URIs and proper cleanup
       5              :  * of resources via the killswitch.
       6              :  *
       7              :  * This is part of the DUNE DAQ Application Framework, copyright 2020.
       8              :  * Licensing/copyright details are in the COPYING file that you should have
       9              :  * received with this code.
      10              :  */
      11              : #include "cmdlib/CommandFacility.hpp"
      12              : #include "cmdlib/CommandedObject.hpp"
      13              : #include "rest_commanded_object.hpp"
      14              : 
      15              : #include "logging/Logging.hpp"
      16              : 
      17              : #include <string>
      18              : #include <chrono>
      19              : #include <memory>
      20              : 
      21              : using namespace dunedaq::cmdlib;
      22              : 
      23              : // Expects the created CommandFacilities to have problems.
      24              : std::shared_ptr<CommandFacility>
      25            0 : create_facility(const std::string& uri) 
      26              : {
      27            0 :   try {
      28            0 :     return make_command_facility(uri);
      29              :   }
      30            0 :   catch (const std::exception& ex) {
      31            0 :     TLOG() << "Something is wrong -> " << ex.what();
      32            0 :   }
      33            0 :   return nullptr; 
      34              : }
      35              : 
      36              : int
      37            0 : main(int /*argc*/, char** /*argv[]*/)
      38              : {
      39              :   // Run marker
      40            0 :   std::atomic<bool> marker{true};
      41              : 
      42              :   // Killswitch that flips the run marker
      43            0 :   auto killswitch = std::thread([&]() {
      44            0 :     TLOG() << "Application will terminate in 20s...";
      45            0 :     std::this_thread::sleep_for(std::chrono::seconds(20));
      46            0 :     marker.store(false);
      47            0 :   });
      48              : 
      49              :   // Commanded object
      50            0 :   RestCommandedObject obj(marker);
      51              : 
      52              :   // Exercise bad URIs.
      53            0 :   auto fac = create_facility(std::string("rest://"));
      54            0 :   fac = create_facility(std::string("rest://localhost"));
      55            0 :   fac = create_facility(std::string("rest://localhost:"));
      56            0 :   fac = create_facility(std::string("rest://localhost:-1"));
      57            0 :   fac = create_facility(std::string("rest://localhost:9999999999"));
      58              : 
      59              :   // Create good facility
      60            0 :   fac = create_facility(std::string("rest://localhost:12345"));
      61              : 
      62              :   // Add commanded object to facility
      63            0 :   fac->set_commanded(obj, "pippo");
      64              : 
      65              :   // Run until marked
      66            0 :   fac->run(marker);
      67              : 
      68              :   // Join local threads
      69            0 :   if (killswitch.joinable()) {
      70            0 :     killswitch.join();
      71              :   }
      72              : 
      73              :   // Exit
      74            0 :   TLOG() << "Exiting.";
      75            0 :   return 0;
      76            0 : }
        

Generated by: LCOV version 2.0-1