tests: Move CaseInsensitiveEqual to test/util/str

This commit is contained in:
practicalswift 2019-11-05 08:25:00 +00:00
parent 463eab5e14
commit 85a34b1683
4 changed files with 37 additions and 14 deletions

View File

@ -60,7 +60,9 @@ BITCOIN_TEST_SUITE = \
test/lib/transaction_utils.cpp \
test/main.cpp \
test/setup_common.h \
test/setup_common.cpp
test/setup_common.cpp \
test/util/str.h \
test/util/str.cpp
FUZZ_SUITE = \
test/setup_common.h \

View File

@ -4,24 +4,12 @@
#include <bech32.h>
#include <test/setup_common.h>
#include <test/util/str.h>
#include <boost/test/unit_test.hpp>
BOOST_FIXTURE_TEST_SUITE(bech32_tests, BasicTestingSetup)
static bool CaseInsensitiveEqual(const std::string &s1, const std::string &s2)
{
if (s1.size() != s2.size()) return false;
for (size_t i = 0; i < s1.size(); ++i) {
char c1 = s1[i];
if (c1 >= 'A' && c1 <= 'Z') c1 -= ('A' - 'a');
char c2 = s2[i];
if (c2 >= 'A' && c2 <= 'Z') c2 -= ('A' - 'a');
if (c1 != c2) return false;
}
return true;
}
BOOST_AUTO_TEST_CASE(bip173_testvectors_valid)
{
static const std::string CASES[] = {

21
src/test/util/str.cpp Normal file
View File

@ -0,0 +1,21 @@
// Copyright (c) 2019 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <test/util/str.h>
#include <cstdint>
#include <string>
bool CaseInsensitiveEqual(const std::string& s1, const std::string& s2)
{
if (s1.size() != s2.size()) return false;
for (size_t i = 0; i < s1.size(); ++i) {
char c1 = s1[i];
if (c1 >= 'A' && c1 <= 'Z') c1 -= ('A' - 'a');
char c2 = s2[i];
if (c2 >= 'A' && c2 <= 'Z') c2 -= ('A' - 'a');
if (c1 != c2) return false;
}
return true;
}

12
src/test/util/str.h Normal file
View File

@ -0,0 +1,12 @@
// Copyright (c) 2019 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_TEST_UTIL_STR_H
#define BITCOIN_TEST_UTIL_STR_H
#include <string>
bool CaseInsensitiveEqual(const std::string& s1, const std::string& s2);
#endif // BITCOIN_TEST_UTIL_STR_H