LCOV - code coverage report
Current view: top level - atermpp/test - down_cast_test.cpp (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 44 44 100.0 %
Date: 2020-02-13 00:44:47 Functions: 18 18 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Author(s): Jeroen Keiren
       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 down_cast_test.cpp
      10             : /// \brief Test for down casting
      11             : 
      12             : #define BOOST_TEST_MODULE down_cast_test
      13             : #include <boost/test/included/unit_test_framework.hpp>
      14             : 
      15             : #include "mcrl2/atermpp/aterm_list.h"
      16             : 
      17             : using namespace std;
      18             : 
      19          12 : class t1 : public atermpp::aterm
      20             : {
      21             : public:
      22           2 :   t1(const int x) {}
      23             : };
      24             : 
      25           2 : class t2 : public t1
      26             : {
      27             : public:
      28           2 :   t2(const t1& x)
      29           2 :     : t1(x)
      30           2 :   {}
      31             : };
      32             : 
      33           3 : class t3: public t1
      34             : {
      35             : public:
      36           3 :   explicit t3(const t1& x)
      37           3 :     : t1(x)
      38           3 :   {}
      39             : };
      40             : 
      41             : inline
      42           1 : void f(const t3& t)
      43             : {
      44           1 : }
      45             : 
      46           3 : BOOST_AUTO_TEST_CASE(aterm_down_cast)
      47             : {
      48           2 :   atermpp::function_symbol fs("f",2);
      49           2 :   atermpp::function_symbol x("x",0);
      50           2 :   atermpp::function_symbol y("y",0);
      51           2 :   atermpp::aterm_appl fxy(fs,atermpp::aterm_appl(x),atermpp::aterm_appl(y));
      52           2 :   atermpp::aterm fxy_term(fxy);
      53             : 
      54           1 :   const atermpp::aterm_appl& test = atermpp::down_cast<atermpp::aterm_appl>(fxy_term);
      55           1 :   BOOST_CHECK(fxy_term == test);
      56           1 :   BOOST_CHECK(fxy == test);
      57           1 :   BOOST_CHECK(fxy == fxy_term);
      58             : 
      59           1 :   const atermpp::aterm& t1(fxy);
      60           1 :   const atermpp::aterm_appl& t2 = atermpp::down_cast<atermpp::aterm_appl>(t1);
      61           1 :   f(atermpp::down_cast<t3>(t1));
      62           1 : }
      63             : 
      64           3 : BOOST_AUTO_TEST_CASE(aterm_container_cast)
      65             : {
      66           2 :   atermpp::term_list<t1> s1;
      67           2 :   atermpp::term_list<t2> s2;
      68           1 :   s2 = atermpp::container_cast< atermpp::term_list<t2> >(s1);
      69           1 :   s1 = atermpp::container_cast< atermpp::term_list<t1> >(s2);
      70           1 : }
      71             : 
      72           3 : BOOST_AUTO_TEST_CASE(no_down_cast_needed)
      73             : {
      74           2 :   t1 x1(1);
      75           2 :   t2 x2(x1);
      76           2 :   t3 x31(x1);
      77           2 :   t3 x32(x2);
      78           1 :   const t3& x33(x31);
      79           1 : }
      80             : 
      81           3 : BOOST_AUTO_TEST_CASE(function_calls)
      82             : {
      83           2 :   t1 x1(1);
      84           2 :   t2 x2(x1);
      85           1 :   t3 x31(x1);
      86             :   const t1& y(t3);
      87           4 : }
      88             : 

Generated by: LCOV version 1.13