LCOV - code coverage report
Current view: top level - tests/io - flow_suite.cpp (source / functions) Hit Total Coverage
Test: iow-coverage.info Lines: 44 44 100.0 %
Date: 2019-09-16 Functions: 23 23 100.0 %

          Line data    Source code
       1             : #include <iostream>
       2             : #include <iow/io/io_base.hpp>
       3             : #include <iow/io/basic/aspect.hpp>
       4             : #include <iow/io/reader/aspect.hpp>
       5             : #include <iow/memory.hpp>
       6             : #include <iow/asio.hpp>
       7             : 
       8             : #include <fas/testing.hpp>
       9             : 
      10             : #include <vector>
      11             : #include <memory>
      12             : #include <list>
      13             : 
      14             : typedef std::vector<char> data_type;
      15             : typedef std::unique_ptr<data_type> data_ptr;
      16             : struct _handler_;
      17           1 : struct ad_handler
      18             : {
      19             :   template<typename T>
      20           3 :   void operator()(T& t, typename T::input_t d) const
      21             :   {
      22           3 :     t.result += std::string(d->begin(), d->end());
      23           3 :   }
      24             : };
      25             : 
      26           1 : struct ad_some
      27             : {
      28             :   template<typename T>
      29           4 :   void operator()(T& t, typename T::input_t d) const
      30             :   {
      31           4 :     if ( t.input.empty() )
      32           5 :       return;
      33             :     
      34           3 :     auto dd = std::make_shared<typename T::input_t>( std::move(d) );
      35          27 :     t.service.post([&t, dd](){
      36           3 :       auto tmp = std::move(t.input.front());
      37           3 :       t.input.pop_front();
      38           3 :       std::copy(tmp->begin(), tmp->end(), (*dd)->begin());
      39           3 :       (*dd)->resize(tmp->size());
      40           3 :       t.get_aspect().template get< ::iow::io::reader::_complete_>()(t, std::move(*dd));
      41           6 :     });
      42             :   }
      43             : };
      44             : 
      45           1 : struct ad_factory
      46             : {
      47             :   template<typename T>
      48           4 :   typename T::input_t operator()(T& t) const
      49             :   {
      50           4 :     if ( t.input.empty() )
      51           1 :       return nullptr;
      52           3 :     return std::make_unique<data_type>(100ul);
      53             :   }
      54             : };
      55             : 
      56             : 
      57           1 : class flow1
      58             :   : public ::iow::io::io_base< fas::aspect< 
      59             :       //::iow::io::flow::aspect< _handler_ /*, data_ptr*/ >::advice_list,
      60             :       fas::advice<_handler_, ad_handler>,
      61             :       fas::advice< ::iow::io::reader::_next_, ad_factory>,
      62             :       fas::advice< ::iow::io::reader::_some_, ad_some>,
      63             :       fas::alias< ::iow::io::reader::_confirm_, _handler_>,
      64             :       fas::stub< ::iow::io::reader::_handler_ >,
      65             :       fas::stub< ::iow::io::_initialize_ >,
      66             :       ::iow::io::basic::aspect<std::recursive_mutex>::advice_list,
      67             :       ::iow::io::reader::aspect::advice_list,
      68             :       fas::type< ::iow::io::_options_type_, fas::empty_type >
      69             :     > >
      70             : {
      71             :   
      72             : public:
      73             :   typedef data_ptr input_t;
      74             : 
      75           1 :   explicit flow1(::iow::asio::io_service& io)
      76           1 :     : service(io) 
      77           1 :   {}
      78             :   
      79           1 :   void start() 
      80             :   {
      81           1 :     this->start_(*this, fas::empty_type() ); 
      82           1 :   }
      83             :   
      84           3 :   void add(std::string val)
      85             :   {
      86           3 :     input.push_back( std::make_unique<data_type>(val.begin(), val.end()) );
      87           3 :   }
      88             :   
      89             :   ::iow::asio::io_service& service;
      90             :   std::list<data_ptr> input;
      91             :   std::string result;
      92             : };
      93             : 
      94           3 : UNIT(flow, "")
      95             : {
      96             :   using namespace fas::testing;
      97           1 :   ::iow::asio::io_service io;
      98           2 :   flow1 f(io);
      99           1 :   f.add("Hello ");
     100           1 :   f.add("world");
     101           1 :   f.add("!");
     102           1 :   f.start();
     103           1 :   io.run();
     104           1 :   t << equal<expect, std::string>(f.result, "Hello world!") << f.result << FAS_TESTING_FILE_LINE;
     105           2 :   t<<nothing;
     106           1 : }
     107             : 
     108           1 : BEGIN_SUITE(flow,"")
     109             :   ADD_UNIT(flow)
     110           7 : END_SUITE(flow)
     111             : 

Generated by: LCOV version 1.10