LCOV - code coverage report
Current view: top level - atermpp/test - aterm_test.cpp (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 37 45 82.2 %
Date: 2020-10-20 00:45:57 Functions: 9 9 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Author(s): Wieger Wesselink
       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             : /// \file aterm_test.cpp
      10             : /// \brief Add your file description here.
      11             : 
      12             : #define BOOST_TEST_MODULE aterm_test
      13             : #include <boost/test/included/unit_test_framework.hpp>
      14             : 
      15             : #include "mcrl2/atermpp/aterm_io.h"
      16             : #include "mcrl2/atermpp/aterm_string.h"
      17             : 
      18             : using namespace atermpp;
      19             : 
      20           3 : BOOST_AUTO_TEST_CASE(test_aterm)
      21             : {
      22           2 :   atermpp::aterm a = read_term_from_string("f(x)");
      23           2 :   atermpp::aterm label = read_term_from_string("label");
      24             : 
      25           2 :   atermpp::aterm_int d = aterm_int(10);
      26           1 :   BOOST_CHECK(aterm_int(d).value() == 10);
      27             : 
      28           2 :   atermpp::aterm e = atermpp::aterm();
      29           1 :   BOOST_CHECK(e==atermpp::aterm());
      30           1 : }
      31             : 
      32           3 : BOOST_AUTO_TEST_CASE(test_aterm_string)
      33             : {
      34           1 :   const aterm_string& empty = empty_string();
      35           2 :   std::ostringstream out;
      36           1 :   out << empty;
      37           1 :   BOOST_CHECK(out.str() == "");
      38           1 : }
      39             : 
      40           6 : void test_aterm_io(const std::string& input_string)
      41             : {
      42          12 :   const aterm input=read_term_from_string(input_string);
      43          12 :   std::ostringstream out;
      44           6 :   write_term_to_text_stream(input, out);
      45          12 :   std::istringstream in(out.str());
      46          12 :   const aterm text_output = read_term_from_text_stream(in);
      47           6 :   if (input!=text_output)
      48             :   {
      49           0 :     std::cerr << "Expected the following terms to be the same (aterm textual save and load):\n";
      50           0 :     std::cerr << "Input " << input << "\n";
      51           0 :     std::cerr << "Output " << text_output << "\n";
      52           0 :     std::cerr << "----------------------------------------------------------------- (textual save/load)\n";
      53             :   }
      54           6 :   BOOST_CHECK(input == text_output);
      55             : 
      56          12 :   std::stringbuf buf;
      57          12 :   std::iostream binary_stream(&buf);
      58           6 :   write_term_to_binary_stream(input, binary_stream);
      59          12 :   const aterm binary_output = read_term_from_binary_stream(binary_stream);
      60           6 :   if (input!=binary_output)
      61             :   {
      62           0 :     std::cerr << "Expected the following terms to be the same (aterm binary save and load):\n";
      63           0 :     std::cerr << "Input " << input << "\n";
      64           0 :     std::cerr << "Output " << binary_output << "\n";
      65           0 :     std::cerr << "----------------------------------------------------------------- (binary save/load)\n";
      66             :   }
      67           6 :   BOOST_CHECK(input == binary_output);
      68           6 : }
      69             : 
      70           3 : BOOST_AUTO_TEST_CASE(test_several_aterm_io)
      71             : {
      72           1 :   test_aterm_io("a_somewhat_longer_constant_name_with_some_blah_blah_at_the_end_to_make_it_longer");
      73           1 :   test_aterm_io("f(g,h)");
      74           1 :   test_aterm_io("[]");
      75           1 :   test_aterm_io("[a]");
      76           1 :   test_aterm_io("[a,b,[]]");
      77           1 :   test_aterm_io("f([a,f(x),[]],2,[g,g(34566)])"); 
      78           4 : }

Generated by: LCOV version 1.13