LCOV - code coverage report
Current view: top level - src/compat - glibcxx_sanity.cpp (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 27 30 90.0 %
Date: 2021-06-29 14:35:33 Functions: 4 4 100.0 %
Legend: Modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed

Not modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed
Branches: 9 14 64.3 %

           Branch data     Line data    Source code
#       1                 :            : // Copyright (c) 2009-2018 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 <list>
#       6                 :            : #include <locale>
#       7                 :            : #include <stdexcept>
#       8                 :            : 
#       9                 :            : namespace
#      10                 :            : {
#      11                 :            : // trigger: use ctype<char>::widen to trigger ctype<char>::_M_widen_init().
#      12                 :            : // test: convert a char from narrow to wide and back. Verify that the result
#      13                 :            : //   matches the original.
#      14                 :            : bool sanity_test_widen(char testchar)
#      15                 :        666 : {
#      16                 :        666 :     const std::ctype<char>& test(std::use_facet<std::ctype<char> >(std::locale()));
#      17                 :        666 :     return test.narrow(test.widen(testchar), 'b') == testchar;
#      18                 :        666 : }
#      19                 :            : 
#      20                 :            : // trigger: use list::push_back and list::pop_back to trigger _M_hook and
#      21                 :            : //   _M_unhook.
#      22                 :            : // test: Push a sequence of integers into a list. Pop them off and verify that
#      23                 :            : //   they match the original sequence.
#      24                 :            : bool sanity_test_list(unsigned int size)
#      25                 :        666 : {
#      26                 :        666 :     std::list<unsigned int> test;
#      27         [ +  + ]:      67266 :     for (unsigned int i = 0; i != size; ++i)
#      28                 :      66600 :         test.push_back(i + 1);
#      29                 :            : 
#      30         [ -  + ]:        666 :     if (test.size() != size)
#      31                 :          0 :         return false;
#      32                 :            : 
#      33         [ +  + ]:      67266 :     while (!test.empty()) {
#      34         [ -  + ]:      66600 :         if (test.back() != test.size())
#      35                 :          0 :             return false;
#      36                 :      66600 :         test.pop_back();
#      37                 :      66600 :     }
#      38                 :        666 :     return true;
#      39                 :        666 : }
#      40                 :            : 
#      41                 :            : } // namespace
#      42                 :            : 
#      43                 :            : // trigger: string::at(x) on an empty string to trigger __throw_out_of_range_fmt.
#      44                 :            : // test: force std::string to throw an out_of_range exception. Verify that
#      45                 :            : //   it's caught correctly.
#      46                 :            : bool sanity_test_range_fmt()
#      47                 :        666 : {
#      48                 :        666 :     std::string test;
#      49                 :        666 :     try {
#      50                 :        666 :         test.at(1);
#      51                 :        666 :     } catch (const std::out_of_range&) {
#      52                 :        666 :         return true;
#      53                 :        666 :     } catch (...) {
#      54                 :          0 :     }
#      55                 :        666 :     return false;
#      56                 :        666 : }
#      57                 :            : 
#      58                 :            : bool glibcxx_sanity_test()
#      59                 :        666 : {
#      60 [ +  - ][ +  - ]:        666 :     return sanity_test_widen('a') && sanity_test_list(100) && sanity_test_range_fmt();
#                 [ +  - ]
#      61                 :        666 : }

Generated by: LCOV version 1.14