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-09-22 00:46:14 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          12 : class t1 : public atermpp::aterm
      18             : {
      19             : public:
      20           2 :   t1(const int x) {}
      21             : };
      22             : 
      23           2 : class t2 : public t1
      24             : {
      25             : public:
      26           2 :   t2(const t1& x)
      27           2 :     : t1(x)
      28           2 :   {}
      29             : };
      30             : 
      31           3 : class t3: public t1
      32             : {
      33             : public:
      34           3 :   explicit t3(const t1& x)
      35           3 :     : t1(x)
      36           3 :   {}
      37             : };
      38             : 
      39             : inline
      40           1 : void f(const t3& t)
      41             : {
      42           1 : }
      43             : 
      44           3 : BOOST_AUTO_TEST_CASE(aterm_down_cast)
      45             : {
      46           2 :   atermpp::function_symbol fs("f",2);
      47           2 :   atermpp::function_symbol x("x",0);
      48           2 :   atermpp::function_symbol y("y",0);
      49           2 :   atermpp::aterm_appl fxy(fs,atermpp::aterm_appl(x),atermpp::aterm_appl(y));
      50           2 :   atermpp::aterm fxy_term(fxy);
      51             : 
      52           1 :   const atermpp::aterm_appl& test = atermpp::down_cast<atermpp::aterm_appl>(fxy_term);
      53           1 :   BOOST_CHECK(fxy_term == test);
      54           1 :   BOOST_CHECK(fxy == test);
      55           1 :   BOOST_CHECK(fxy == fxy_term);
      56             : 
      57           1 :   const atermpp::aterm& t1(fxy);
      58           1 :   const atermpp::aterm_appl& t2 = atermpp::down_cast<atermpp::aterm_appl>(t1);
      59           1 :   f(atermpp::down_cast<t3>(t1));
      60           1 : }
      61             : 
      62           3 : BOOST_AUTO_TEST_CASE(aterm_container_cast)
      63             : {
      64           2 :   atermpp::term_list<t1> s1;
      65           2 :   atermpp::term_list<t2> s2;
      66           1 :   s2 = atermpp::container_cast< atermpp::term_list<t2> >(s1);
      67           1 :   s1 = atermpp::container_cast< atermpp::term_list<t1> >(s2);
      68           1 : }
      69             : 
      70           3 : BOOST_AUTO_TEST_CASE(no_down_cast_needed)
      71             : {
      72           2 :   t1 x1(1);
      73           2 :   t2 x2(x1);
      74           2 :   t3 x31(x1);
      75           2 :   t3 x32(x2);
      76           1 :   const t3& x33(x31);
      77           1 : }
      78             : 
      79           3 : BOOST_AUTO_TEST_CASE(function_calls)
      80             : {
      81           2 :   t1 x1(1);
      82           2 :   t2 x2(x1);
      83           1 :   t3 x31(x1);
      84             :   const t1& y(t3);
      85           4 : }
      86             : 

Generated by: LCOV version 1.13