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.hpp> 14 : 15 : #include "mcrl2/atermpp/aterm_io.h" 16 : #include "mcrl2/atermpp/aterm_string.h" 17 : 18 : using namespace atermpp; 19 : 20 2 : 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 1 : atermpp::aterm_int d = aterm_int(10); 26 1 : BOOST_CHECK(aterm_int(d).value() == 10); 27 : 28 1 : atermpp::aterm e = atermpp::aterm(); 29 1 : BOOST_CHECK(e==atermpp::aterm()); 30 1 : } 31 : 32 2 : BOOST_AUTO_TEST_CASE(test_aterm_string) 33 : { 34 1 : const aterm_string& empty = empty_string(); 35 1 : 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 6 : const aterm input=read_term_from_string(input_string); 43 6 : std::ostringstream out; 44 6 : write_term_to_text_stream(input, out); 45 6 : std::istringstream in(out.str()); 46 6 : aterm text_output; 47 6 : read_term_from_text_stream(in, text_output); 48 6 : if (input!=text_output) 49 : { 50 0 : std::cerr << "Expected the following terms to be the same (aterm textual save and load):\n"; 51 0 : std::cerr << "Input " << input << "\n"; 52 0 : std::cerr << "Output " << text_output << "\n"; 53 0 : std::cerr << "----------------------------------------------------------------- (textual save/load)\n"; 54 : } 55 6 : BOOST_CHECK(input == text_output); 56 : 57 6 : std::stringbuf buf; 58 6 : std::iostream binary_stream(&buf); 59 6 : write_term_to_binary_stream(input, binary_stream); 60 6 : aterm binary_output; 61 6 : read_term_from_binary_stream(binary_stream, binary_output); 62 6 : if (input!=binary_output) 63 : { 64 0 : std::cerr << "Expected the following terms to be the same (aterm binary save and load):\n"; 65 0 : std::cerr << "Input " << input << "\n"; 66 0 : std::cerr << "Output " << binary_output << "\n"; 67 0 : std::cerr << "----------------------------------------------------------------- (binary save/load)\n"; 68 : } 69 6 : BOOST_CHECK(input == binary_output); 70 6 : } 71 : 72 2 : BOOST_AUTO_TEST_CASE(test_several_aterm_io) 73 : { 74 1 : test_aterm_io("a_somewhat_longer_constant_name_with_some_blah_blah_at_the_end_to_make_it_longer"); 75 1 : test_aterm_io("f(g,h)"); 76 1 : test_aterm_io("[]"); 77 1 : test_aterm_io("[a]"); 78 1 : test_aterm_io("[a,b,[]]"); 79 1 : test_aterm_io("f([a,f(x),[]],2,[g,g(34566)])"); 80 1 : }