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

          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 hooks_test.cpp
      10             : /// \brief Add your file description here.
      11             : 
      12             : #define BOOST_TEST_MODULE hooks_test
      13             : #include <boost/test/included/unit_test_framework.hpp>
      14             : 
      15             : #include "mcrl2/atermpp/aterm_list.h"
      16             : #include "mcrl2/atermpp/aterm_string.h"
      17             : 
      18             : using namespace atermpp;
      19             : 
      20             : static std::size_t variable_count = 0;
      21             : 
      22             : inline
      23           6 : const function_symbol& function_symbol_DataVarId()
      24             : {
      25           6 :   static function_symbol function_symbol_DataVarId = function_symbol("DataVarId", 1);
      26           6 :   return function_symbol_DataVarId;
      27             : }
      28             : 
      29           4 : class variable: public aterm_appl
      30             : {
      31             :   public:
      32           4 :     variable(const std::string& name)
      33           4 :       : aterm_appl(function_symbol_DataVarId(), aterm_string(name))
      34           4 :     {}
      35             : 
      36             :     variable(const aterm_string& name)
      37             :       : aterm_appl(function_symbol_DataVarId(), name)
      38             :     {}
      39             : };
      40             : 
      41           3 : void on_create_variable(const aterm&)
      42             : {
      43           3 :   variable_count++;
      44           3 : }
      45             : 
      46           1 : void on_delete_variable(const aterm&)
      47             : {
      48           1 :   variable_count--;
      49           1 : }
      50             : 
      51           1 : void f()
      52             : {
      53           1 :   BOOST_CHECK(variable_count == 1);
      54           2 :   variable v("v");
      55           1 :   BOOST_CHECK(variable_count == 1);
      56           2 :   variable w("w");
      57           1 :   BOOST_CHECK(variable_count == 2);
      58           1 : }
      59             : 
      60           1 : aterm_appl g()
      61             : {
      62           2 :   variable w("w");
      63           2 :   return aterm_appl(function_symbol("f", 1), w);
      64             : }
      65             : 
      66           3 : BOOST_AUTO_TEST_CASE(test_hooks)
      67             : {
      68           1 :   add_creation_hook(function_symbol_DataVarId(), on_create_variable);
      69           1 :   add_deletion_hook(function_symbol_DataVarId(), on_delete_variable);
      70           1 :   BOOST_CHECK(variable_count == 0);
      71           2 :   variable v("v");
      72           1 :   BOOST_CHECK(variable_count == 1);
      73           1 :   f();
      74           1 :   BOOST_CHECK(variable_count == 2);
      75           1 :   detail::g_term_pool().collect();
      76           1 :   BOOST_CHECK(variable_count == 1);
      77           2 :   aterm_appl a = g();
      78           1 :   BOOST_CHECK(variable_count == 2);
      79           1 :   detail::g_term_pool().collect();
      80           1 :   BOOST_CHECK(variable_count == 2);
      81           4 : }

Generated by: LCOV version 1.13