LCOV - code coverage report
Current view: top level - tests/module - domain_test.cpp (source / functions) Hit Total Coverage
Test: wfc-coverage.info Lines: 55 65 84.6 %
Date: 2019-09-17 Functions: 8 12 66.7 %

          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             : #include <wfc/asio.hpp>
       6             : 
       7             : using namespace wfc;
       8             : 
       9           4 : struct options
      10             : {
      11             :   bool test = false;
      12             : };
      13             : 
      14           1 : struct itest: iinterface
      15             : {
      16           0 :   virtual ~itest(){}
      17             :   virtual int testtest() = 0;
      18             : };
      19             : 
      20           1 : class test
      21             :   : public domain_object<itest, options>
      22             : {
      23             : public:
      24             : 
      25           2 :   virtual void reconfigure() override
      26             :   {
      27           2 :     testval = true;
      28           2 :   }
      29             : 
      30           1 :   virtual int testtest() override
      31             :   {
      32           1 :     if ( !this->has_arg("param1") ) return 1001;
      33           1 :     if ( !this->has_arg("param2") ) return 1002;
      34           1 :     if ( !this->has_arg("param3") ) return 1003;
      35           1 :     if (  this->has_arg("param4") ) return 1004;
      36           1 :     if ( this->get_arg("param1")!="val1" ) return 1005;
      37           1 :     if ( this->get_arg("param2")!="100" ) return 1006;
      38           1 :     if ( this->get_arg("param3")!="" ) return 1007;
      39           1 :     if ( this->get_arg("param4")!="" ) return 1008;
      40             : 
      41           1 :     if ( this->get_arg_t<int>("param2")!=100 ) return 1007;
      42           1 :     if ( this->get_arg_t<int>("param1")!=0 ) return 1008;
      43           1 :     std::string err;
      44           1 :     if ( this->get_arg_t<int>("param1", &err)!=0 ) return 1008;
      45           1 :     if ( err!="Invalid Number" ) return 1009;
      46             : 
      47           1 :     return 0;
      48             :   }
      49             : 
      50             :   bool testval = false;
      51             : };
      52             : 
      53           1 : int main()
      54             : {
      55           1 :   wfc::asio::io_service ios;
      56           2 :   auto g = std::make_shared<wfc::wfcglobal>(ios);
      57           1 :   wfc::wfcglobal::static_global = g;
      58           2 :   wfc::instance<test> t;
      59             : 
      60           1 :   if ( t.object()!=nullptr )
      61           0 :     return 1;
      62             : 
      63           2 :   test::domain_config opt;
      64           1 :   opt.test = true;
      65           1 :   opt.name = "name";
      66             : 
      67           1 :   t.create("name", g);
      68           1 :   t.start("");
      69           1 :   t.configure(opt);
      70           1 :   t.initialize();
      71           1 :   t.reconfigure(opt);
      72             : 
      73           1 :   if ( t.object()->options().test != true )
      74           0 :     return 3;
      75             : 
      76             :   //std::cout << t.name() << std::endl;
      77           1 :   if ( t.object()->name() != "name" )
      78           0 :     return 5;
      79             : 
      80           1 :   if ( t.object()->testval != true )
      81           0 :     return 6;
      82             : 
      83           1 :   options opt2;
      84           1 :   opt2 = t.object()->generate("");
      85           1 :   if ( opt2.test != false )
      86           0 :     return 7;
      87             : 
      88           1 :   if ( auto wflow = t.object()->create_workflow("test","{\"control_ms\":\"1h\"}") )
      89             :   {
      90           1 :     auto opt3 = wflow->get_options();
      91           1 :     if (opt3.id!="name:workflow.test")
      92           0 :       return 10;
      93           1 :     if (opt3.control_ms!=3600*1000)
      94             :     {
      95           0 :       std::cout << opt3.control_ms << std::endl;
      96           0 :       return 11;
      97           1 :     }
      98             :   }
      99             :   else
     100           0 :     return 9;
     101             : 
     102           2 :   std::map<std::string, std::string> args;
     103           1 :   args["param1"]="val1";
     104           1 :   args["param2"]="100";
     105           1 :   args["param3"]="";
     106           1 :   g->args.insert("name", wfc::instance_args("name", args) );
     107           1 :   if ( auto itst = g->registry.get_target<itest>("name") )
     108           1 :     return itst->testtest();
     109             :   else
     110           1 :     return 8;
     111           3 : }

Generated by: LCOV version 1.10