LCOV - code coverage report
Current view: top level - tests/jsonrpc - jsonrpc_test.cpp (source / functions) Hit Total Coverage
Test: wfc-coverage.info Lines: 34 54 63.0 %
Date: 2019-09-17 Functions: 9 12 75.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             : #include <wfc/jsonrpc/domain_proxy.hpp>
       6             : #include <wfc/jsonrpc.hpp>
       7             : #include <wfc/asio.hpp>
       8             : #include <wfc/name.hpp>
       9             : 
      10             : using namespace wfc;
      11             : 
      12          14 : struct options
      13             : {
      14             :   bool test = false;
      15             :   std::string target;
      16             : };
      17             : 
      18           1 : class test
      19             :   : public jsonrpc::domain_proxy<options, nostat>
      20             : {
      21             : public:
      22             :  
      23           2 :   virtual void reconfigure() override
      24             :   {
      25           2 :     testval = true;
      26           2 :   }
      27             :   
      28           0 :   virtual int testtest()
      29             :   {
      30           0 :     if ( !this->has_arg("param1") ) return 1001;
      31           0 :     if ( !this->has_arg("param2") ) return 1002;
      32           0 :     if ( !this->has_arg("param3") ) return 1003;
      33           0 :     if (  this->has_arg("param4") ) return 1004;
      34           0 :     if ( this->get_arg("param1")!="val1" ) return 1005;
      35           0 :     if ( this->get_arg("param2")!="100" ) return 1006;
      36           0 :     if ( this->get_arg("param3")!="" ) return 1007;
      37           0 :     if ( this->get_arg("param4")!="" ) return 1008;
      38             :     
      39           0 :     if ( this->get_arg_t<int>("param2")!=100 ) return 1007;
      40           0 :     if ( this->get_arg_t<int>("param1")!=0 ) return 1008;
      41           0 :     std::string err;
      42           0 :     if ( this->get_arg_t<int>("param1", &err)!=0 ) return 1008;
      43           0 :     if ( err!="Invalid Number" ) return 1009;
      44             :     
      45           0 :     return 0;
      46             :   }
      47             :   
      48             :   bool testval = false;
      49             : };
      50             : 
      51             : struct service_method_list: wfc::jsonrpc::method_list
      52             : <
      53             :   wfc::jsonrpc::target<iinterface>
      54             : >
      55             : {
      56             : };
      57             : 
      58             : WFC_NAME2(test_service_name, "test-service")
      59             : 
      60             : class test_service
      61             :   : public ::wfc::jsonrpc::service_multiton< test_service_name, service_method_list> 
      62             : {};
      63             :   
      64           1 : int main()
      65             : {
      66           1 :   wfc::asio::io_service ios;
      67           2 :   auto g = std::make_shared<wfc::wfcglobal>(ios);
      68           1 :   wfc::wfcglobal::static_global = g;
      69           2 :   wfc::instance<test> t;
      70             :     
      71           1 :   if ( t.object()!=nullptr )
      72           0 :     return 1;
      73             : 
      74           2 :   test::domain_config opt;
      75           1 :   opt.test = true;
      76           1 :   opt.name = "name";
      77             :   
      78           1 :   t.create("name", g);
      79           1 :   t.start("");
      80           1 :   t.configure(opt);
      81           1 :   t.initialize();
      82           1 :   t.reconfigure(opt);
      83             : 
      84           1 :   if ( t.object()->options().test != true )
      85           0 :     return 3;
      86             : 
      87             :   //std::cout << t.name() << std::endl;
      88           1 :   if ( t.object()->name() != "name" )
      89           0 :     return 5;
      90             : 
      91           1 :   if ( t.object()->testval != true )
      92           0 :     return 6;
      93             :   
      94           2 :   options opt2; 
      95           1 :   opt2 = t.object()->generate("");
      96           1 :   if ( opt2.test != false )
      97           0 :     return 7;
      98             :   
      99           2 :   std::map<std::string, std::string> args;
     100           1 :   args["param1"]="val1";
     101           1 :   args["param2"]="100";
     102           1 :   args["param3"]="";
     103           1 :   g->args.insert("name", wfc::instance_args("name", args) );
     104           1 :   if ( auto itst = g->registry.get_target<ijsonrpc>("name") )
     105           1 :     return 0;
     106             :   else
     107           1 :     return 8;
     108           3 : }

Generated by: LCOV version 1.10