Raven Core  3.0.0
P2P Digital Currency
glibcxx_sanity.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2014 The Bitcoin Core developers
2 // Copyright (c) 2017-2019 The Raven Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include <list>
7 #include <locale>
8 #include <stdexcept>
9 
10 namespace
11 {
12 // trigger: use ctype<char>::widen to trigger ctype<char>::_M_widen_init().
13 // test: convert a char from narrow to wide and back. Verify that the result
14 // matches the original.
15 bool sanity_test_widen(char testchar)
16 {
17  const std::ctype<char>& test(std::use_facet<std::ctype<char> >(std::locale()));
18  return test.narrow(test.widen(testchar), 'b') == testchar;
19 }
20 
21 // trigger: use list::push_back and list::pop_back to trigger _M_hook and
22 // _M_unhook.
23 // test: Push a sequence of integers into a list. Pop them off and verify that
24 // they match the original sequence.
25 bool sanity_test_list(unsigned int size)
26 {
27  std::list<unsigned int> test;
28  for (unsigned int i = 0; i != size; ++i)
29  test.push_back(i + 1);
30 
31  if (test.size() != size)
32  return false;
33 
34  while (!test.empty()) {
35  if (test.back() != test.size())
36  return false;
37  test.pop_back();
38  }
39  return true;
40 }
41 
42 } // namespace
43 
44 // trigger: string::at(x) on an empty string to trigger __throw_out_of_range_fmt.
45 // test: force std::string to throw an out_of_range exception. Verify that
46 // it's caught correctly.
48 {
49  std::string test;
50  try {
51  test.at(1);
52  } catch (const std::out_of_range&) {
53  return true;
54  } catch (...) {
55  }
56  return false;
57 }
58 
60 {
61  return sanity_test_widen('a') && sanity_test_list(100) && sanity_test_range_fmt();
62 }
bool sanity_test_range_fmt()
bool glibcxx_sanity_test()