LCOV - code coverage report
Current view: top level - atermpp/test - aterm_io_binary_test.cpp (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 41 41 100.0 %
Date: 2020-09-22 00:46:14 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Author(s): Maurice Laveaux
       2             : // Copyright: see the accompanying file COPYING or copy at
       3             : // https://github.com/mCRL2org/mCRL2/blob/master/COPYING
       4             : //
       5             : // Distributed under the Boost Software License, Version 1.0.
       6             : // (See accompanying file LICENSE_1_0.txt or copy at
       7             : // http://www.boost.org/LICENSE_1_0.txt)
       8             : //
       9             : 
      10             : #include "mcrl2/atermpp/aterm_io_binary.h"
      11             : 
      12             : #define BOOST_AUTO_TEST_MAIN
      13             : #include <boost/test/included/unit_test.hpp>
      14             : 
      15             : using namespace atermpp;
      16             : 
      17           3 : BOOST_AUTO_TEST_CASE(simple_int_test)
      18             : {
      19           2 :   std::stringstream stream;
      20             :   {
      21           2 :     binary_aterm_ostream output(stream);
      22           1 :     output << aterm_int(50);
      23             :   }
      24             : 
      25           2 :   binary_aterm_istream input(stream);
      26           1 :   BOOST_CHECK_EQUAL(input.get(), aterm_int(50));
      27           1 : }
      28             : 
      29           3 : BOOST_AUTO_TEST_CASE(simple_term_test)
      30             : {
      31             : 
      32             :   // The sequence of terms to send.
      33           2 :   std::vector<aterm_appl> sequence;
      34             : 
      35           2 :   aterm f = aterm_appl(function_symbol("f", 0));
      36           2 :   aterm g = aterm_appl(function_symbol("g", 0));
      37             : 
      38           1 :   sequence.emplace_back(function_symbol("test", 2), f, g);
      39           1 :   sequence.push_back(static_cast<const aterm_appl&>(f));
      40           1 :   sequence.emplace_back(function_symbol("nested", 2), sequence.front(), g);
      41           1 :   sequence.push_back(static_cast<const aterm_appl&>(g));
      42           1 :   sequence.emplace_back(function_symbol("deeply_nested", 3), sequence[3], sequence.front(), sequence[3]);
      43             : 
      44           2 :   std::stringstream stream;
      45             :   {
      46           2 :     binary_aterm_ostream output(stream);
      47             : 
      48           6 :     for (const auto& term : sequence)
      49             :     {
      50           5 :       output << term;
      51             :     }
      52             : 
      53             :     // The buffer is flushed here.
      54             :   }
      55             : 
      56           2 :   binary_aterm_istream input(stream);
      57             : 
      58           6 :   for (std::size_t index = 0; index < sequence.size(); ++index)
      59             :   {
      60           5 :     BOOST_CHECK_EQUAL(input.get(), sequence[index]);
      61             :   }
      62           1 : }
      63             : 
      64           3 : BOOST_AUTO_TEST_CASE(transitions_test)
      65             : {
      66           2 :   std::vector<aterm_appl> sequence;
      67             : 
      68           2 :   function_symbol transition("transition", 2);
      69           2 :   aterm label = aterm_appl(function_symbol("state", 1), aterm_int(0));
      70           2 :   aterm time = aterm_appl(function_symbol("time", 1), aterm_int(50));
      71             : 
      72           2 :   aterm_list states;
      73             : 
      74           3 :   for (std::size_t index = 0; index < 2; ++index)
      75             :   {
      76           2 :     sequence.emplace_back(transition, states, time);
      77             : 
      78             :     // Increase the state labels size.
      79           2 :     states.push_front(label);
      80             :   }
      81             : 
      82           2 :   std::stringstream stream;
      83             :   {
      84           2 :     binary_aterm_ostream output(stream);
      85             : 
      86           3 :     for (const auto& term : sequence)
      87             :     {
      88           2 :       output << term;
      89             :     }
      90             : 
      91             :     // The buffer is flushed here.
      92             :   }
      93             : 
      94           2 :   binary_aterm_istream input(stream);
      95             : 
      96           3 :   for (std::size_t index = 0; index < sequence.size(); ++index)
      97             :   {
      98           2 :     BOOST_CHECK_EQUAL(input.get(), sequence[index]);
      99             :   }
     100           4 : }

Generated by: LCOV version 1.13