Bitcoin ABC
0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
src
compat
glibcxx_sanity.cpp
Go to the documentation of this file.
1
// Copyright (c) 2009-2014 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
// trigger: use ctype<char>::widen to trigger ctype<char>::_M_widen_init().
11
// test: convert a char from narrow to wide and back. Verify that the result
12
// matches the original.
13
bool
sanity_test_widen
(
char
testchar
) {
14
const
std::ctype<char> &
test
(
15
std::use_facet<std::ctype<char>>(std::locale()));
16
return
test
.narrow(
test
.widen(
testchar
),
'b'
) ==
testchar
;
17
}
18
19
// trigger: use list::push_back and list::pop_back to trigger _M_hook and
20
// _M_unhook.
21
// test: Push a sequence of integers into a list. Pop them off and verify that
22
// they match the original sequence.
23
bool
sanity_test_list
(
unsigned
int
size) {
24
std::list<unsigned int>
test
;
25
for
(
unsigned
int
i = 0; i != size; ++i) {
26
test
.push_back(i + 1);
27
}
28
29
if
(
test
.size() != size) {
30
return
false
;
31
}
32
33
while
(!
test
.empty()) {
34
if
(
test
.back() !=
test
.size()) {
35
return
false
;
36
}
37
test
.pop_back();
38
}
39
return
true
;
40
}
41
42
}
// namespace
43
44
// trigger: string::at(x) on an empty string to trigger
45
// __throw_out_of_range_fmt.
46
// test: force std::string to throw an out_of_range exception. Verify that
47
// it's caught correctly.
48
bool
sanity_test_range_fmt
() {
49
std::string
test
;
50
try
{
51
[[
maybe_unused
]]
auto
&
c
=
test
.at(1);
52
}
catch
(
const
std::out_of_range &) {
53
return
true
;
54
}
catch
(...) {
55
}
56
return
false
;
57
}
58
59
bool
glibcxx_sanity_test
() {
60
return
sanity_test_widen
(
'a'
) &&
sanity_test_list
(100) &&
61
sanity_test_range_fmt
();
62
}
glibcxx_sanity_test
bool glibcxx_sanity_test()
Definition
glibcxx_sanity.cpp:59
sanity_test_range_fmt
bool sanity_test_range_fmt()
Definition
glibcxx_sanity.cpp:48
GetRand
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition
random.h:85
Generated on Sun Nov 3 2024 02:38:35 for Bitcoin ABC by
1.9.8