Files
hush3/src/compat/glibcxx_sanity.cpp
Duke Leto be16f80abc Hush Full Node is now GPLv3
Any projects which want to use Hush code from now on will need to be licensed as
GPLv3 or we will send the lawyers: https://www.softwarefreedom.org/

Notably, Komodo (KMD) is licensed as GPLv2 and is no longer compatible to receive
code changes, without causing legal issues. MIT projects, such as Zcash, also cannot pull
in changes from the Hush Full Node without permission from The Hush Developers,
which may in some circumstances grant an MIT license on a case-by-case basis.
2020-10-21 07:28:10 -04:00

62 lines
1.7 KiB
C++

// Copyright (c) 2009-2014 The Bitcoin Core developers
// Distributed under the GPLv3 software license, see the accompanying
// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#include <list>
#include <locale>
#include <stdexcept>
namespace
{
// 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)
{
const std::ctype<char>& test(std::use_facet<std::ctype<char> >(std::locale()));
return test.narrow(test.widen(testchar), 'b') == testchar;
}
// 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)
test.push_back(i + 1);
if (test.size() != size)
return false;
while (!test.empty()) {
if (test.back() != test.size())
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;
try {
test.at(1);
} catch (const std::out_of_range&) {
return true;
} catch (...) {
}
return false;
}
bool glibcxx_sanity_test()
{
return sanity_test_widen('a') && sanity_test_list(100) && sanity_test_range_fmt();
}