LCOV - code coverage report
Current view: top level - tests/module - instance_test.cpp (source / functions) Hit Total Coverage
Test: wfc-coverage.info Lines: 38 45 84.4 %
Date: 2019-09-17 Functions: 12 15 80.0 %

          Line data    Source code
       1             : #define IOW_DISABLE_LOG
       2             : #include <iow/logger.hpp>
       3             : #include <wfc/domain_object.hpp>
       4             : #include <wfc/module/instance.hpp>
       5             : 
       6           5 : struct options1
       7             : {
       8             :   bool test = false;
       9             : };
      10             : 
      11           2 : struct itest
      12             :   : public wfc::iinterface
      13             : {
      14           2 :   virtual ~itest(){}
      15             :   virtual bool testtest() = 0;
      16             : };
      17             : 
      18           4 : class test
      19             :   : public wfc::domain_object<itest, options1>
      20             : {
      21             : public:
      22             :   typedef domain_object::domain_config config_type;
      23           2 :   virtual void initialize() override
      24             :   {
      25           2 :     testval = true;
      26           2 :   }
      27             :   
      28           2 :   virtual bool testtest() override
      29             :   {
      30           2 :     return testval; 
      31             :   }
      32             :   
      33           1 :   virtual config_type generate(const std::string&) override
      34             :   {
      35           1 :     config_type opt;
      36           1 :     opt.test = true;
      37           1 :     return opt;
      38             :   }
      39             :   
      40             :   // restart
      41           0 :   virtual void restart() override
      42             :   {
      43           0 :     std::cout << "RESTART!!!!!!" << std::endl;
      44           0 :   }
      45             : 
      46             :   // start
      47           1 :   virtual void start() override
      48             :   {
      49           1 :     std::cout << "START!!!!!!" << std::endl;
      50           1 :   }
      51             :   bool testval = false;
      52             : };
      53             : 
      54             : //class test_impl: public ::wfc::instance<test> {};
      55             : typedef ::wfc::instance<test> test_impl;
      56             : 
      57           1 : int main()
      58             : {
      59           1 :   test_impl t;
      60           2 :   ::iow::asio::io_service io;
      61           2 :   auto g = std::make_shared<wfc::wfcglobal>(io);
      62           1 :   t.create(g);
      63           2 :   test_impl::domain_config opt;
      64           1 :   t.generate(opt, "true");
      65             :   
      66           3 :   if ( !opt.test || !opt.enabled || !opt.name.empty() 
      67           2 :         || opt.startup_priority!=0 || opt.shutdown_priority!=0)
      68           0 :     return 1;
      69             : 
      70           1 :   opt.name = "test";
      71           1 :   t.configure(opt);
      72           2 :   auto tmp1 = g->registry.get_target<itest>("test");
      73             :   
      74           1 :   if ( tmp1 == nullptr )
      75           0 :     return 2;
      76           1 :   if ( tmp1->testtest() != false )
      77           0 :     return 3;
      78           1 :   t.initialize();
      79           1 :   if ( tmp1->testtest() != true )
      80           0 :     return 4;
      81           1 :   t.start("");
      82           1 :   t.configure(opt);
      83           1 :   t.initialize();
      84           1 :   t.stop("");
      85             :   
      86           2 :   return 0;
      87           3 : }

Generated by: LCOV version 1.10