mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 23:03:45 +01:00
scripted-diff: [test] Use g_rng/m_rng directly
-BEGIN VERIFY SCRIPT-
# Use m_rng in unit test files
ren() { sed -i "s:\<$1\>:$2:g" $( git grep -l "$1" src/test/*.cpp src/wallet/test/*.cpp src/test/util/setup_common.cpp ) ; }
ren InsecureRand32 m_rng.rand32
ren InsecureRand256 m_rng.rand256
ren InsecureRandBits m_rng.randbits
ren InsecureRandRange m_rng.randrange
ren InsecureRandBool m_rng.randbool
ren g_insecure_rand_ctx m_rng
ren g_insecure_rand_ctx_temp_path g_rng_temp_path
-END VERIFY SCRIPT-
This commit is contained in:
@@ -218,72 +218,72 @@ BOOST_AUTO_TEST_CASE(PrevectorTestInt)
|
||||
for (int j = 0; j < 64; j++) {
|
||||
prevector_tester<8, int> test{m_rng};
|
||||
for (int i = 0; i < 2048; i++) {
|
||||
if (InsecureRandBits(2) == 0) {
|
||||
test.insert(InsecureRandRange(test.size() + 1), int(InsecureRand32()));
|
||||
if (m_rng.randbits(2) == 0) {
|
||||
test.insert(m_rng.randrange(test.size() + 1), int(m_rng.rand32()));
|
||||
}
|
||||
if (test.size() > 0 && InsecureRandBits(2) == 1) {
|
||||
test.erase(InsecureRandRange(test.size()));
|
||||
if (test.size() > 0 && m_rng.randbits(2) == 1) {
|
||||
test.erase(m_rng.randrange(test.size()));
|
||||
}
|
||||
if (InsecureRandBits(3) == 2) {
|
||||
int new_size = std::max(0, std::min(30, (int)test.size() + (int)InsecureRandRange(5) - 2));
|
||||
if (m_rng.randbits(3) == 2) {
|
||||
int new_size = std::max(0, std::min(30, (int)test.size() + (int)m_rng.randrange(5) - 2));
|
||||
test.resize(new_size);
|
||||
}
|
||||
if (InsecureRandBits(3) == 3) {
|
||||
test.insert(InsecureRandRange(test.size() + 1), 1 + InsecureRandBool(), int(InsecureRand32()));
|
||||
if (m_rng.randbits(3) == 3) {
|
||||
test.insert(m_rng.randrange(test.size() + 1), 1 + m_rng.randbool(), int(m_rng.rand32()));
|
||||
}
|
||||
if (InsecureRandBits(3) == 4) {
|
||||
int del = std::min<int>(test.size(), 1 + (InsecureRandBool()));
|
||||
int beg = InsecureRandRange(test.size() + 1 - del);
|
||||
if (m_rng.randbits(3) == 4) {
|
||||
int del = std::min<int>(test.size(), 1 + (m_rng.randbool()));
|
||||
int beg = m_rng.randrange(test.size() + 1 - del);
|
||||
test.erase(beg, beg + del);
|
||||
}
|
||||
if (InsecureRandBits(4) == 5) {
|
||||
test.push_back(int(InsecureRand32()));
|
||||
if (m_rng.randbits(4) == 5) {
|
||||
test.push_back(int(m_rng.rand32()));
|
||||
}
|
||||
if (test.size() > 0 && InsecureRandBits(4) == 6) {
|
||||
if (test.size() > 0 && m_rng.randbits(4) == 6) {
|
||||
test.pop_back();
|
||||
}
|
||||
if (InsecureRandBits(5) == 7) {
|
||||
if (m_rng.randbits(5) == 7) {
|
||||
int values[4];
|
||||
int num = 1 + (InsecureRandBits(2));
|
||||
int num = 1 + (m_rng.randbits(2));
|
||||
for (int k = 0; k < num; k++) {
|
||||
values[k] = int(InsecureRand32());
|
||||
values[k] = int(m_rng.rand32());
|
||||
}
|
||||
test.insert_range(InsecureRandRange(test.size() + 1), values, values + num);
|
||||
test.insert_range(m_rng.randrange(test.size() + 1), values, values + num);
|
||||
}
|
||||
if (InsecureRandBits(5) == 8) {
|
||||
int del = std::min<int>(test.size(), 1 + (InsecureRandBits(2)));
|
||||
int beg = InsecureRandRange(test.size() + 1 - del);
|
||||
if (m_rng.randbits(5) == 8) {
|
||||
int del = std::min<int>(test.size(), 1 + (m_rng.randbits(2)));
|
||||
int beg = m_rng.randrange(test.size() + 1 - del);
|
||||
test.erase(beg, beg + del);
|
||||
}
|
||||
if (InsecureRandBits(5) == 9) {
|
||||
test.reserve(InsecureRandBits(5));
|
||||
if (m_rng.randbits(5) == 9) {
|
||||
test.reserve(m_rng.randbits(5));
|
||||
}
|
||||
if (InsecureRandBits(6) == 10) {
|
||||
if (m_rng.randbits(6) == 10) {
|
||||
test.shrink_to_fit();
|
||||
}
|
||||
if (test.size() > 0) {
|
||||
test.update(InsecureRandRange(test.size()), int(InsecureRand32()));
|
||||
test.update(m_rng.randrange(test.size()), int(m_rng.rand32()));
|
||||
}
|
||||
if (InsecureRandBits(10) == 11) {
|
||||
if (m_rng.randbits(10) == 11) {
|
||||
test.clear();
|
||||
}
|
||||
if (InsecureRandBits(9) == 12) {
|
||||
test.assign(InsecureRandBits(5), int(InsecureRand32()));
|
||||
if (m_rng.randbits(9) == 12) {
|
||||
test.assign(m_rng.randbits(5), int(m_rng.rand32()));
|
||||
}
|
||||
if (InsecureRandBits(3) == 3) {
|
||||
if (m_rng.randbits(3) == 3) {
|
||||
test.swap();
|
||||
}
|
||||
if (InsecureRandBits(4) == 8) {
|
||||
if (m_rng.randbits(4) == 8) {
|
||||
test.copy();
|
||||
}
|
||||
if (InsecureRandBits(5) == 18) {
|
||||
if (m_rng.randbits(5) == 18) {
|
||||
test.move();
|
||||
}
|
||||
if (InsecureRandBits(5) == 19) {
|
||||
unsigned int num = 1 + (InsecureRandBits(4));
|
||||
if (m_rng.randbits(5) == 19) {
|
||||
unsigned int num = 1 + (m_rng.randbits(4));
|
||||
std::vector<int> values(num);
|
||||
for (int& v : values) {
|
||||
v = int(InsecureRand32());
|
||||
v = int(m_rng.rand32());
|
||||
}
|
||||
test.resize_uninitialized(values);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user