LCOV - code coverage report
Current view: top level - src/test - node_warnings_tests.cpp (source / functions) Coverage Total Hit
Test: total_coverage.info Lines: 100.0 % 20 20
Test Date: 2024-11-04 05:10:19 Functions: 100.0 % 2 2
Branches: 50.0 % 166 83

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2024-present 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                 :             : 
       6                 :             : #include <node/warnings.h>
       7                 :             : #include <util/translation.h>
       8                 :             : 
       9                 :             : #include <test/util/setup_common.h>
      10                 :             : 
      11                 :             : #include <boost/test/unit_test.hpp>
      12                 :             : 
      13                 :             : BOOST_FIXTURE_TEST_SUITE(node_warnings_tests, BasicTestingSetup)
      14                 :             : 
      15   [ +  -  +  -  :           7 : BOOST_AUTO_TEST_CASE(warnings)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
      16                 :             : {
      17                 :           1 :     node::Warnings warnings;
      18                 :             :     // On pre-release builds, a warning is generated automatically
      19         [ +  - ]:           1 :     warnings.Unset(node::Warning::PRE_RELEASE_TEST_BUILD);
      20                 :             : 
      21                 :             :     // For these tests, we don't care what the exact warnings are, so
      22                 :             :     // just refer to them as warning_1 and warning_2
      23                 :           1 :     const auto warning_1{node::Warning::CLOCK_OUT_OF_SYNC};
      24                 :           1 :     const auto warning_2{node::Warning::FATAL_INTERNAL_ERROR};
      25                 :             : 
      26                 :             :     // Ensure we start without any warnings
      27   [ +  -  +  -  :           2 :     BOOST_CHECK(warnings.GetMessages().size() == 0);
             +  -  +  - ]
      28                 :             :     // Add two warnings
      29   [ +  -  +  -  :           3 :     BOOST_CHECK(warnings.Set(warning_1, _("warning 1")));
          +  -  +  -  +  
                      - ]
      30   [ +  -  +  -  :           3 :     BOOST_CHECK(warnings.Set(warning_2, _("warning 2")));
          +  -  +  -  +  
                      - ]
      31                 :             :     // Unset the second one
      32   [ +  -  +  -  :           2 :     BOOST_CHECK(warnings.Unset(warning_2));
             +  -  +  - ]
      33                 :             :     // Since it's already been unset, this should return false
      34   [ +  -  +  -  :           2 :     BOOST_CHECK(!warnings.Unset(warning_2));
                   +  - ]
      35                 :             :     // We should now be able to set w2 again
      36   [ +  -  +  -  :           3 :     BOOST_CHECK(warnings.Set(warning_2, _("warning 2 - revision 1")));
          +  -  +  -  +  
                      - ]
      37                 :             :     // Setting w2 again should return false since it's already set
      38   [ +  -  +  -  :           3 :     BOOST_CHECK(!warnings.Set(warning_2, _("warning 2 - revision 2")));
          +  -  +  -  +  
                      - ]
      39                 :             : 
      40                 :             :     // Verify messages are correct
      41         [ +  - ]:           1 :     const auto messages{warnings.GetMessages()};
      42   [ +  -  +  -  :           2 :     BOOST_CHECK(messages.size() == 2);
                   +  - ]
      43   [ +  -  +  -  :           2 :     BOOST_CHECK(messages[0].original == "warning 1");
                   +  - ]
      44   [ +  -  +  -  :           2 :     BOOST_CHECK(messages[1].original == "warning 2 - revision 1");
                   +  - ]
      45                 :             : 
      46                 :             :     // Clearing all warnings should also clear all messages
      47   [ +  -  +  -  :           2 :     BOOST_CHECK(warnings.Unset(warning_1));
             +  -  +  - ]
      48   [ +  -  +  -  :           2 :     BOOST_CHECK(warnings.Unset(warning_2));
             +  -  +  - ]
      49   [ +  -  +  -  :           2 :     BOOST_CHECK(warnings.GetMessages().size() == 0);
                   +  - ]
      50                 :           1 : }
      51                 :             : 
      52                 :             : BOOST_AUTO_TEST_SUITE_END()
        

Generated by: LCOV version 2.0-1