LCOV - code coverage report
Current view: top level - src/test - ref_tests.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 22 22 100.0 %
Date: 2020-09-26 01:30:44 Functions: 5 5 100.0 %

          Line data    Source code
       1             : // Copyright (c) 2020 The Bitcoin Core developers
       2             : // Distributed under the MIT software license, see the accompanying
       3             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4             : 
       5             : #include <util/ref.h>
       6             : 
       7             : #include <boost/test/unit_test.hpp>
       8             : 
       9          89 : BOOST_AUTO_TEST_SUITE(ref_tests)
      10             : 
      11          91 : BOOST_AUTO_TEST_CASE(ref_test)
      12             : {
      13           1 :     util::Ref ref;
      14           1 :     BOOST_CHECK(!ref.Has<int>());
      15           2 :     BOOST_CHECK_THROW(ref.Get<int>(), NonFatalCheckError);
      16           1 :     int value = 5;
      17           1 :     ref.Set(value);
      18           1 :     BOOST_CHECK(ref.Has<int>());
      19           1 :     BOOST_CHECK_EQUAL(ref.Get<int>(), 5);
      20           1 :     ++ref.Get<int>();
      21           1 :     BOOST_CHECK_EQUAL(ref.Get<int>(), 6);
      22           1 :     BOOST_CHECK_EQUAL(value, 6);
      23           1 :     ++value;
      24           1 :     BOOST_CHECK_EQUAL(value, 7);
      25           1 :     BOOST_CHECK_EQUAL(ref.Get<int>(), 7);
      26           1 :     BOOST_CHECK(!ref.Has<bool>());
      27           2 :     BOOST_CHECK_THROW(ref.Get<bool>(), NonFatalCheckError);
      28           1 :     ref.Clear();
      29           1 :     BOOST_CHECK(!ref.Has<int>());
      30           2 :     BOOST_CHECK_THROW(ref.Get<int>(), NonFatalCheckError);
      31           4 : }
      32             : 
      33          89 : BOOST_AUTO_TEST_SUITE_END()

Generated by: LCOV version 1.15