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: 50 53 94.3 %
Date: 2024-03-08 02:52:28 Functions: 14 15 93.3 %
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.hpp>
      14             : 
      15             : #include "mcrl2/utilities/unused.h"
      16             : #include "mcrl2/atermpp/aterm_list.h"
      17             : 
      18             : class t1 : public atermpp::aterm
      19             : {
      20             : public:
      21           2 :   t1(const int ) 
      22           2 :   {}
      23             : 
      24           1 :   explicit t1(const aterm& x) 
      25           1 :    : atermpp::aterm(x)
      26           1 :   {}
      27             : };
      28             : 
      29             : class t2 : public t1
      30             : {
      31             : public:
      32           2 :   t2(const t1& x)
      33           2 :     : t1(x)
      34           2 :   {}
      35             : 
      36           0 :   explicit t2(const aterm& x)
      37           0 :    : t1(x)
      38           0 :   {}
      39             : };
      40             : 
      41             : class t3: public t1
      42             : {
      43             : public:
      44           3 :   explicit t3(const t1& x)
      45           3 :     : t1(x)
      46           3 :   {}
      47             : 
      48           1 :   explicit t3(const aterm& x)
      49           1 :    : t1(x)
      50           1 :   {}
      51             : };
      52             : 
      53             : inline
      54           1 : void f(const t3& )
      55             : {
      56           1 : }
      57             : 
      58           2 : BOOST_AUTO_TEST_CASE(aterm_down_cast)
      59             : {
      60           2 :   atermpp::function_symbol fs("f",2);
      61           2 :   atermpp::function_symbol x("x",0);
      62           2 :   atermpp::function_symbol y("y",0);
      63           2 :   atermpp::aterm_appl fxy(fs,atermpp::aterm_appl(x),atermpp::aterm_appl(y));
      64           1 :   atermpp::aterm fxy_term(fxy);
      65             : 
      66           1 :   const atermpp::aterm_appl& test = atermpp::down_cast<atermpp::aterm_appl>(fxy_term);
      67           1 :   BOOST_CHECK(fxy_term == test);
      68           1 :   BOOST_CHECK(fxy == test);
      69           1 :   BOOST_CHECK(fxy == fxy_term);
      70             : 
      71           1 :   const atermpp::aterm& t1(fxy);
      72           1 :   const atermpp::aterm_appl& t2 = atermpp::down_cast<atermpp::aterm_appl>(t1);
      73           1 :   mcrl2::utilities::mcrl2_unused(t2);
      74           1 :   f(atermpp::down_cast<t3>(t1));
      75           1 : }
      76             : 
      77           2 : BOOST_AUTO_TEST_CASE(aterm_container_cast)
      78             : {
      79           1 :   atermpp::term_list<t1> s1;
      80           1 :   atermpp::term_list<t2> s2;
      81           1 :   s2 = atermpp::container_cast< atermpp::term_list<t2> >(s1);
      82           1 :   s1 = atermpp::container_cast< atermpp::term_list<t1> >(s2);
      83           1 : }
      84             : 
      85           2 : BOOST_AUTO_TEST_CASE(no_down_cast_needed)
      86             : {
      87           1 :   t1 x1(1);
      88           1 :   t2 x2(x1);
      89           1 :   t3 x31(x1);
      90           1 :   t3 x32(x2);
      91           1 :   const t3& x33(x31);
      92           1 :   mcrl2::utilities::mcrl2_unused(x33);
      93           1 : }
      94             : 
      95           2 : BOOST_AUTO_TEST_CASE(function_calls)
      96             : {
      97           1 :   t1 x1(1);
      98           1 :   t2 x2(x1);
      99           1 :   t3 x31(x1);
     100             :   const t1& y(t3);
     101           1 : }
     102             : 

Generated by: LCOV version 1.14