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 parse_test.cpp 10 : /// \brief Add your file description here. 11 : 12 : #define BOOST_TEST_MODULE parse_test 13 : #include <fstream> 14 : 15 : #include <boost/test/included/unit_test.hpp> 16 : 17 : #include "mcrl2/lts/parse.h" 18 : 19 : using namespace mcrl2; 20 : 21 3 : void test_fsm_parser(const std::string& text) 22 : { 23 : // parse the text 24 3 : lts::probabilistic_lts_fsm_t fsm; 25 3 : lts::parse_fsm_specification(text, fsm); 26 : 27 : // write the fsm to a file 28 3 : std::string temp_filename = "parse_test.tmp"; 29 3 : fsm.save(temp_filename); 30 : 31 : // read the fsm from the file 32 3 : std::string text1 = utilities::read_text(temp_filename); 33 : 34 : // remove the file 35 3 : std::remove(temp_filename.c_str()); 36 : 37 3 : if (text != text1) 38 : { 39 0 : std::cerr << "--- Error: difference detected ---\n" << text << "\n-------------------\n" << text1 << "\n-------------------\n"; 40 : } 41 : 42 : // the text should be the same 43 3 : BOOST_CHECK(text == text1); 44 3 : } 45 : 46 2 : BOOST_AUTO_TEST_CASE(fsm_parser_test) 47 : { 48 1 : test_fsm_parser( 49 : "b(2) Bool \"F\" \"T\"\n" 50 : "n(2) Nat \"1\" \"2\"\n" 51 : "---\n" 52 : "0 0\n" 53 : "0 1\n" 54 : "1 0\n" 55 : "1 1\n" 56 : "---\n" 57 : "1 2 \"increase\"\n" 58 : "1 3 \"on\"\n" 59 : "2 4 \"on\"\n" 60 : "2 1 \"decrease\"\n" 61 : "3 1 \"off\"\n" 62 : "3 4 \"increase\"\n" 63 : "4 2 \"off\"\n" 64 : "4 3 \"decrease\"\n" 65 : ); 66 : 67 1 : test_fsm_parser( 68 : "b(2) Bool # Bool -> Nat \"F\" \"T\"\n" 69 : "n(2) Nat -> Nat \"1\" \"2\"\n" 70 : "---\n" 71 : "0 0\n" 72 : "0 1\n" 73 : "1 0\n" 74 : "1 1\n" 75 : "---\n" 76 : "1 2 \"increase\"\n" 77 : "1 3 \"on\"\n" 78 : "2 4 \"on\"\n" 79 : "2 1 \"decrease\"\n" 80 : "3 1 \"off\"\n" 81 : "3 4 \"increase\"\n" 82 : "4 2 \"off\"\n" 83 : "4 3 \"decrease\"\n" 84 : ); 85 : 86 1 : test_fsm_parser( 87 : "---\n" 88 : "---\n" 89 : "1 1 \"tau\"\n" 90 : ); 91 1 : } 92 :