2014-06-21 14:26:21 +02:00
|
|
|
// Copyright (c) 2009-2014 The Bitcoin developers
|
2014-09-27 13:49:21 +02:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2014-06-21 14:26:21 +02:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2014-06-14 01:19:35 +02:00
|
|
|
#include <list>
|
2014-06-21 14:26:21 +02:00
|
|
|
#include <locale>
|
2014-06-14 01:19:35 +02:00
|
|
|
#include <stdexcept>
|
|
|
|
|
2014-09-25 08:23:32 +02:00
|
|
|
namespace
|
|
|
|
{
|
2014-06-14 01:19:35 +02:00
|
|
|
// trigger: use ctype<char>::widen to trigger ctype<char>::_M_widen_init().
|
|
|
|
// test: convert a char from narrow to wide and back. Verify that the result
|
|
|
|
// matches the original.
|
|
|
|
bool sanity_test_widen(char testchar)
|
|
|
|
{
|
2014-09-25 08:23:32 +02:00
|
|
|
const std::ctype<char>& test(std::use_facet<std::ctype<char> >(std::locale()));
|
|
|
|
return test.narrow(test.widen(testchar), 'b') == testchar;
|
2014-06-14 01:19:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// trigger: use list::push_back and list::pop_back to trigger _M_hook and
|
|
|
|
// _M_unhook.
|
|
|
|
// test: Push a sequence of integers into a list. Pop them off and verify that
|
|
|
|
// they match the original sequence.
|
|
|
|
bool sanity_test_list(unsigned int size)
|
|
|
|
{
|
|
|
|
std::list<unsigned int> test;
|
|
|
|
for (unsigned int i = 0; i != size; ++i)
|
2014-09-25 08:23:32 +02:00
|
|
|
test.push_back(i + 1);
|
2014-06-14 01:19:35 +02:00
|
|
|
|
|
|
|
if (test.size() != size)
|
|
|
|
return false;
|
|
|
|
|
2014-09-25 08:23:32 +02:00
|
|
|
while (!test.empty()) {
|
|
|
|
if (test.back() != test.size())
|
2014-06-14 01:19:35 +02:00
|
|
|
return false;
|
|
|
|
test.pop_back();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anon namespace
|
|
|
|
|
|
|
|
// trigger: string::at(x) on an empty string to trigger __throw_out_of_range_fmt.
|
|
|
|
// test: force std::string to throw an out_of_range exception. Verify that
|
|
|
|
// it's caught correctly.
|
|
|
|
bool sanity_test_range_fmt()
|
|
|
|
{
|
|
|
|
std::string test;
|
2014-09-25 08:23:32 +02:00
|
|
|
try {
|
2014-06-14 01:19:35 +02:00
|
|
|
test.at(1);
|
2014-09-25 08:23:32 +02:00
|
|
|
} catch (const std::out_of_range&) {
|
2014-06-14 01:19:35 +02:00
|
|
|
return true;
|
2014-09-25 08:23:32 +02:00
|
|
|
} catch (...) {
|
2014-06-14 01:19:35 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool glibcxx_sanity_test()
|
|
|
|
{
|
|
|
|
return sanity_test_widen('a') && sanity_test_list(100) && sanity_test_range_fmt();
|
|
|
|
}
|