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: 34 34 100.0 %
Date: 2020-02-13 00:44:47 Functions: 6 6 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_term_test)
      18             : {
      19             : 
      20             :   // The sequence of terms to send.
      21           2 :   std::vector<aterm_appl> sequence;
      22             : 
      23           2 :   aterm f = aterm_appl(function_symbol("f", 0));
      24           2 :   aterm g = aterm_appl(function_symbol("g", 0));
      25             : 
      26           1 :   sequence.emplace_back(function_symbol("test", 2), f, g);
      27           1 :   sequence.push_back(static_cast<const aterm_appl&>(f));
      28           1 :   sequence.emplace_back(function_symbol("nested", 2), sequence.front(), g);
      29           1 :   sequence.push_back(static_cast<const aterm_appl&>(g));
      30           1 :   sequence.emplace_back(function_symbol("deeply_nested", 3), sequence[3], sequence.front(), sequence[3]);
      31             : 
      32           2 :   std::stringstream stream;
      33             :   {
      34           2 :     binary_aterm_ostream input(stream);
      35             : 
      36           6 :     for (const auto& term : sequence)
      37             :     {
      38           5 :       input << term;
      39             :     }
      40             : 
      41             :     // The buffer is flushed here.
      42             :   }
      43             : 
      44           2 :   binary_aterm_istream output(stream);
      45             : 
      46           6 :   for (std::size_t index = 0; index < sequence.size(); ++index)
      47             :   {
      48           5 :     BOOST_CHECK_EQUAL(output.get(), sequence[index]);
      49             :   }
      50           1 : }
      51             : 
      52           3 : BOOST_AUTO_TEST_CASE(transitions_test)
      53             : {
      54           2 :   std::vector<aterm_appl> sequence;
      55             : 
      56           2 :   function_symbol transition("transition", 2);
      57           2 :   aterm label = aterm_appl(function_symbol("state", 1), aterm_int(0));
      58           2 :   aterm time = aterm_appl(function_symbol("time", 1), aterm_int(50));
      59             : 
      60           2 :   aterm_list states;
      61             : 
      62           3 :   for (std::size_t index = 0; index < 2; ++index)
      63             :   {
      64           2 :     sequence.emplace_back(transition, states, time);
      65             : 
      66             :     // Increase the state labels size.
      67           2 :     states.push_front(label);
      68             :   }
      69             : 
      70           2 :   std::stringstream stream;
      71             :   {
      72           2 :     binary_aterm_ostream input(stream);
      73             : 
      74           3 :     for (const auto& term : sequence)
      75             :     {
      76           2 :       input << term;
      77             :     }
      78             : 
      79             :     // The buffer is flushed here.
      80             :   }
      81             : 
      82           2 :   binary_aterm_istream output(stream);
      83             : 
      84           3 :   for (std::size_t index = 0; index < sequence.size(); ++index)
      85             :   {
      86           2 :     BOOST_CHECK_EQUAL(output.get(), sequence[index]);
      87             :   }
      88           4 : }

Generated by: LCOV version 1.13