Skip to content

Commit 85a34b1

Browse files
tests: Move CaseInsensitiveEqual to test/util/str
1 parent 463eab5 commit 85a34b1

File tree

4 files changed

+37
-14
lines changed

4 files changed

+37
-14
lines changed

src/Makefile.test.include

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ BITCOIN_TEST_SUITE = \
6060
test/lib/transaction_utils.cpp \
6161
test/main.cpp \
6262
test/setup_common.h \
63-
test/setup_common.cpp
63+
test/setup_common.cpp \
64+
test/util/str.h \
65+
test/util/str.cpp
6466

6567
FUZZ_SUITE = \
6668
test/setup_common.h \

src/test/bech32_tests.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,12 @@
44

55
#include <bech32.h>
66
#include <test/setup_common.h>
7+
#include <test/util/str.h>
78

89
#include <boost/test/unit_test.hpp>
910

1011
BOOST_FIXTURE_TEST_SUITE(bech32_tests, BasicTestingSetup)
1112

12-
static bool CaseInsensitiveEqual(const std::string &s1, const std::string &s2)
13-
{
14-
if (s1.size() != s2.size()) return false;
15-
for (size_t i = 0; i < s1.size(); ++i) {
16-
char c1 = s1[i];
17-
if (c1 >= 'A' && c1 <= 'Z') c1 -= ('A' - 'a');
18-
char c2 = s2[i];
19-
if (c2 >= 'A' && c2 <= 'Z') c2 -= ('A' - 'a');
20-
if (c1 != c2) return false;
21-
}
22-
return true;
23-
}
24-
2513
BOOST_AUTO_TEST_CASE(bip173_testvectors_valid)
2614
{
2715
static const std::string CASES[] = {

src/test/util/str.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) 2019 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 <test/util/str.h>
6+
7+
#include <cstdint>
8+
#include <string>
9+
10+
bool CaseInsensitiveEqual(const std::string& s1, const std::string& s2)
11+
{
12+
if (s1.size() != s2.size()) return false;
13+
for (size_t i = 0; i < s1.size(); ++i) {
14+
char c1 = s1[i];
15+
if (c1 >= 'A' && c1 <= 'Z') c1 -= ('A' - 'a');
16+
char c2 = s2[i];
17+
if (c2 >= 'A' && c2 <= 'Z') c2 -= ('A' - 'a');
18+
if (c1 != c2) return false;
19+
}
20+
return true;
21+
}

src/test/util/str.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (c) 2019 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+
#ifndef BITCOIN_TEST_UTIL_STR_H
6+
#define BITCOIN_TEST_UTIL_STR_H
7+
8+
#include <string>
9+
10+
bool CaseInsensitiveEqual(const std::string& s1, const std::string& s2);
11+
12+
#endif // BITCOIN_TEST_UTIL_STR_H

0 commit comments

Comments
 (0)