Skip to content

Commit

Permalink
test: Fix outstanding -Wsign-compare errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Empact committed May 8, 2020
1 parent 5b24f60 commit df37377
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 74 deletions.
9 changes: 5 additions & 4 deletions src/test/blockfilter_index_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ static bool CheckFilterLookups(BlockFilterIndex& filter_index, const CBlockIndex
BOOST_CHECK(filter_index.LookupFilterHashRange(block_index->nHeight, block_index,
filter_hashes));

BOOST_CHECK_EQUAL(filters.size(), 1);
BOOST_CHECK_EQUAL(filter_hashes.size(), 1);
BOOST_CHECK_EQUAL(filters.size(), 1U);
BOOST_CHECK_EQUAL(filter_hashes.size(), 1U);

BOOST_CHECK_EQUAL(filter.GetHash(), expected_filter.GetHash());
BOOST_CHECK_EQUAL(filter_header, expected_filter.ComputeHeader(last_header));
Expand Down Expand Up @@ -255,8 +255,9 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup)
BOOST_CHECK(filter_index.LookupFilterRange(0, tip, filters));
BOOST_CHECK(filter_index.LookupFilterHashRange(0, tip, filter_hashes));

BOOST_CHECK_EQUAL(filters.size(), tip->nHeight + 1);
BOOST_CHECK_EQUAL(filter_hashes.size(), tip->nHeight + 1);
assert(tip->nHeight >= 0);
BOOST_CHECK_EQUAL(filters.size(), tip->nHeight + 1U);
BOOST_CHECK_EQUAL(filter_hashes.size(), tip->nHeight + 1U);

filters.clear();
filter_hashes.clear();
Expand Down
10 changes: 5 additions & 5 deletions src/test/blockfilter_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ BOOST_AUTO_TEST_CASE(gcsfilter_test)
BOOST_AUTO_TEST_CASE(gcsfilter_default_constructor)
{
GCSFilter filter;
BOOST_CHECK_EQUAL(filter.GetN(), 0);
BOOST_CHECK_EQUAL(filter.GetEncoded().size(), 1);
BOOST_CHECK_EQUAL(filter.GetN(), 0U);
BOOST_CHECK_EQUAL(filter.GetEncoded().size(), 1U);

const GCSFilter::Params& params = filter.GetParams();
BOOST_CHECK_EQUAL(params.m_siphash_k0, 0);
BOOST_CHECK_EQUAL(params.m_siphash_k1, 0);
BOOST_CHECK_EQUAL(params.m_siphash_k0, 0U);
BOOST_CHECK_EQUAL(params.m_siphash_k1, 0U);
BOOST_CHECK_EQUAL(params.m_P, 0);
BOOST_CHECK_EQUAL(params.m_M, 1);
BOOST_CHECK_EQUAL(params.m_M, 1U);
}

BOOST_AUTO_TEST_CASE(blockfilter_basic_test)
Expand Down
4 changes: 2 additions & 2 deletions src/test/bloom_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ BOOST_AUTO_TEST_CASE(rolling_bloom)
++nHits;
}
// Expect about 100 hits
BOOST_CHECK_EQUAL(nHits, 75);
BOOST_CHECK_EQUAL(nHits, 75U);

BOOST_CHECK(rb1.contains(data[DATASIZE-1]));
rb1.reset();
Expand Down Expand Up @@ -516,7 +516,7 @@ BOOST_AUTO_TEST_CASE(rolling_bloom)
++nHits;
}
// Expect about 5 false positives
BOOST_CHECK_EQUAL(nHits, 6);
BOOST_CHECK_EQUAL(nHits, 6U);

// last-1000-entry, 0.01% false positive:
CRollingBloomFilter rb2(1000, 0.001);
Expand Down
16 changes: 8 additions & 8 deletions src/test/compress_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ BOOST_AUTO_TEST_CASE(compress_script_to_ckey_id)
CPubKey pubkey = key.GetPubKey();

CScript script = CScript() << OP_DUP << OP_HASH160 << ToByteVector(pubkey.GetID()) << OP_EQUALVERIFY << OP_CHECKSIG;
BOOST_CHECK_EQUAL(script.size(), 25);
BOOST_CHECK_EQUAL(script.size(), 25U);

std::vector<unsigned char> out;
bool done = CompressScript(script, out);
BOOST_CHECK_EQUAL(done, true);

// Check compressed script
BOOST_CHECK_EQUAL(out.size(), 21);
BOOST_CHECK_EQUAL(out.size(), 21U);
BOOST_CHECK_EQUAL(out[0], 0x00);
BOOST_CHECK_EQUAL(memcmp(&out[1], &script[3], 20), 0); // compare the 20 relevant chars of the CKeyId in the script
}
Expand All @@ -87,14 +87,14 @@ BOOST_AUTO_TEST_CASE(compress_script_to_cscript_id)
// case CScriptID
CScript script, redeemScript;
script << OP_HASH160 << ToByteVector(CScriptID(redeemScript)) << OP_EQUAL;
BOOST_CHECK_EQUAL(script.size(), 23);
BOOST_CHECK_EQUAL(script.size(), 23U);

std::vector<unsigned char> out;
bool done = CompressScript(script, out);
BOOST_CHECK_EQUAL(done, true);

// Check compressed script
BOOST_CHECK_EQUAL(out.size(), 21);
BOOST_CHECK_EQUAL(out.size(), 21U);
BOOST_CHECK_EQUAL(out[0], 0x01);
BOOST_CHECK_EQUAL(memcmp(&out[1], &script[2], 20), 0); // compare the 20 relevant chars of the CScriptId in the script
}
Expand All @@ -105,14 +105,14 @@ BOOST_AUTO_TEST_CASE(compress_script_to_compressed_pubkey_id)
key.MakeNewKey(true); // case compressed PubKeyID

CScript script = CScript() << ToByteVector(key.GetPubKey()) << OP_CHECKSIG; // COMPRESSED_PUBLIC_KEY_SIZE (33)
BOOST_CHECK_EQUAL(script.size(), 35);
BOOST_CHECK_EQUAL(script.size(), 35U);

std::vector<unsigned char> out;
bool done = CompressScript(script, out);
BOOST_CHECK_EQUAL(done, true);

// Check compressed script
BOOST_CHECK_EQUAL(out.size(), 33);
BOOST_CHECK_EQUAL(out.size(), 33U);
BOOST_CHECK_EQUAL(memcmp(&out[0], &script[1], 1), 0);
BOOST_CHECK_EQUAL(memcmp(&out[1], &script[2], 32), 0); // compare the 32 chars of the compressed CPubKey
}
Expand All @@ -122,14 +122,14 @@ BOOST_AUTO_TEST_CASE(compress_script_to_uncompressed_pubkey_id)
CKey key;
key.MakeNewKey(false); // case uncompressed PubKeyID
CScript script = CScript() << ToByteVector(key.GetPubKey()) << OP_CHECKSIG; // PUBLIC_KEY_SIZE (65)
BOOST_CHECK_EQUAL(script.size(), 67); // 1 char code + 65 char pubkey + OP_CHECKSIG
BOOST_CHECK_EQUAL(script.size(), 67U); // 1 char code + 65 char pubkey + OP_CHECKSIG

std::vector<unsigned char> out;
bool done = CompressScript(script, out);
BOOST_CHECK_EQUAL(done, true);

// Check compressed script
BOOST_CHECK_EQUAL(out.size(), 33);
BOOST_CHECK_EQUAL(out.size(), 33U);
BOOST_CHECK_EQUAL(memcmp(&out[1], &script[2], 32), 0); // first 32 chars of CPubKey are copied into out[1:]
BOOST_CHECK_EQUAL(out[0], 0x04 | (script[65] & 0x01)); // least significant bit (lsb) of last char of pubkey is mapped into out[0]
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/descriptor_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void DoCheck(const std::string& prv, const std::string& pub, int flags, const st
std::vector<CScript> spks_inferred;
FlatSigningProvider provider_inferred;
BOOST_CHECK(inferred->Expand(0, provider_inferred, spks_inferred, provider_inferred));
BOOST_CHECK_EQUAL(spks_inferred.size(), 1);
BOOST_CHECK_EQUAL(spks_inferred.size(), 1U);
BOOST_CHECK(spks_inferred[0] == spks[n]);
BOOST_CHECK_EQUAL(IsSolvable(provider_inferred, spks_inferred[0]), !(flags & UNSOLVABLE));
BOOST_CHECK(provider_inferred.origins == script_provider.origins);
Expand Down
16 changes: 8 additions & 8 deletions src/test/flatfile_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,16 @@ BOOST_AUTO_TEST_CASE(flatfile_allocate)

bool out_of_space;

BOOST_CHECK_EQUAL(seq.Allocate(FlatFilePos(0, 0), 1, out_of_space), 100);
BOOST_CHECK_EQUAL(fs::file_size(seq.FileName(FlatFilePos(0, 0))), 100);
BOOST_CHECK_EQUAL(seq.Allocate(FlatFilePos(0, 0), 1, out_of_space), 100U);
BOOST_CHECK_EQUAL(fs::file_size(seq.FileName(FlatFilePos(0, 0))), 100U);
BOOST_CHECK(!out_of_space);

BOOST_CHECK_EQUAL(seq.Allocate(FlatFilePos(0, 99), 1, out_of_space), 0);
BOOST_CHECK_EQUAL(fs::file_size(seq.FileName(FlatFilePos(0, 99))), 100);
BOOST_CHECK_EQUAL(seq.Allocate(FlatFilePos(0, 99), 1, out_of_space), 0U);
BOOST_CHECK_EQUAL(fs::file_size(seq.FileName(FlatFilePos(0, 99))), 100U);
BOOST_CHECK(!out_of_space);

BOOST_CHECK_EQUAL(seq.Allocate(FlatFilePos(0, 99), 2, out_of_space), 101);
BOOST_CHECK_EQUAL(fs::file_size(seq.FileName(FlatFilePos(0, 99))), 200);
BOOST_CHECK_EQUAL(seq.Allocate(FlatFilePos(0, 99), 2, out_of_space), 101U);
BOOST_CHECK_EQUAL(fs::file_size(seq.FileName(FlatFilePos(0, 99))), 200U);
BOOST_CHECK(!out_of_space);
}

Expand All @@ -116,11 +116,11 @@ BOOST_AUTO_TEST_CASE(flatfile_flush)

// Flush without finalize should not truncate file.
seq.Flush(FlatFilePos(0, 1));
BOOST_CHECK_EQUAL(fs::file_size(seq.FileName(FlatFilePos(0, 1))), 100);
BOOST_CHECK_EQUAL(fs::file_size(seq.FileName(FlatFilePos(0, 1))), 100U);

// Flush with finalize should truncate file.
seq.Flush(FlatFilePos(0, 1), true);
BOOST_CHECK_EQUAL(fs::file_size(seq.FileName(FlatFilePos(0, 1))), 1);
BOOST_CHECK_EQUAL(fs::file_size(seq.FileName(FlatFilePos(0, 1))), 1U);
}

BOOST_AUTO_TEST_SUITE_END()
2 changes: 1 addition & 1 deletion src/test/netbase_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ BOOST_AUTO_TEST_CASE(netpermissions_test)
BOOST_CHECK(NetWhitelistPermissions::TryParse("bloom,forcerelay,noban,relay,mempool@1.2.3.4/32", whitelistPermissions, error));

const auto strings = NetPermissions::ToStrings(PF_ALL);
BOOST_CHECK_EQUAL(strings.size(), 5);
BOOST_CHECK_EQUAL(strings.size(), 5U);
BOOST_CHECK(std::find(strings.begin(), strings.end(), "bloomfilter") != strings.end());
BOOST_CHECK(std::find(strings.begin(), strings.end(), "forcerelay") != strings.end());
BOOST_CHECK(std::find(strings.begin(), strings.end(), "relay") != strings.end());
Expand Down
2 changes: 1 addition & 1 deletion src/test/random_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ BOOST_AUTO_TEST_CASE(shuffle_stat_test)
}
BOOST_CHECK(chi_score > 58.1411); // 99.9999% confidence interval
BOOST_CHECK(chi_score < 210.275);
BOOST_CHECK_EQUAL(sum, 12000);
BOOST_CHECK_EQUAL(sum, 12000U);
}

BOOST_AUTO_TEST_SUITE_END()
46 changes: 23 additions & 23 deletions src/test/streams_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,28 @@ BOOST_AUTO_TEST_CASE(streams_vector_reader)
std::vector<unsigned char> vch = {1, 255, 3, 4, 5, 6};

VectorReader reader(SER_NETWORK, INIT_PROTO_VERSION, vch, 0);
BOOST_CHECK_EQUAL(reader.size(), 6);
BOOST_CHECK_EQUAL(reader.size(), 6U);
BOOST_CHECK(!reader.empty());

// Read a single byte as an unsigned char.
unsigned char a;
reader >> a;
BOOST_CHECK_EQUAL(a, 1);
BOOST_CHECK_EQUAL(reader.size(), 5);
BOOST_CHECK_EQUAL(reader.size(), 5U);
BOOST_CHECK(!reader.empty());

// Read a single byte as a signed char.
signed char b;
reader >> b;
BOOST_CHECK_EQUAL(b, -1);
BOOST_CHECK_EQUAL(reader.size(), 4);
BOOST_CHECK_EQUAL(reader.size(), 4U);
BOOST_CHECK(!reader.empty());

// Read a 4 bytes as an unsigned int.
unsigned int c;
reader >> c;
BOOST_CHECK_EQUAL(c, 100992003); // 3,4,5,6 in little-endian base-256
BOOST_CHECK_EQUAL(reader.size(), 0);
BOOST_CHECK_EQUAL(c, 100992003U); // 3,4,5,6 in little-endian base-256
BOOST_CHECK_EQUAL(reader.size(), 0U);
BOOST_CHECK(reader.empty());

// Reading after end of byte vector throws an error.
Expand All @@ -104,7 +104,7 @@ BOOST_AUTO_TEST_CASE(streams_vector_reader)
VectorReader new_reader(SER_NETWORK, INIT_PROTO_VERSION, vch, 0);
new_reader >> d;
BOOST_CHECK_EQUAL(d, 67370753); // 1,255,3,4 in little-endian base-256
BOOST_CHECK_EQUAL(new_reader.size(), 2);
BOOST_CHECK_EQUAL(new_reader.size(), 2U);
BOOST_CHECK(!new_reader.empty());

// Reading after end of byte vector throws an error even if the reader is
Expand Down Expand Up @@ -136,14 +136,14 @@ BOOST_AUTO_TEST_CASE(bitstream_reader_writer)
BOOST_CHECK_EQUAL(serialized_int2, (uint16_t)0x1072); // NOTE: Serialized as LE

BitStreamReader<CDataStream> bit_reader(data_copy);
BOOST_CHECK_EQUAL(bit_reader.Read(1), 0);
BOOST_CHECK_EQUAL(bit_reader.Read(2), 2);
BOOST_CHECK_EQUAL(bit_reader.Read(3), 6);
BOOST_CHECK_EQUAL(bit_reader.Read(4), 11);
BOOST_CHECK_EQUAL(bit_reader.Read(5), 1);
BOOST_CHECK_EQUAL(bit_reader.Read(6), 32);
BOOST_CHECK_EQUAL(bit_reader.Read(7), 7);
BOOST_CHECK_EQUAL(bit_reader.Read(16), 30497);
BOOST_CHECK_EQUAL(bit_reader.Read(1), 0U);
BOOST_CHECK_EQUAL(bit_reader.Read(2), 2U);
BOOST_CHECK_EQUAL(bit_reader.Read(3), 6U);
BOOST_CHECK_EQUAL(bit_reader.Read(4), 11U);
BOOST_CHECK_EQUAL(bit_reader.Read(5), 1U);
BOOST_CHECK_EQUAL(bit_reader.Read(6), 32U);
BOOST_CHECK_EQUAL(bit_reader.Read(7), 7U);
BOOST_CHECK_EQUAL(bit_reader.Read(16), 30497U);
BOOST_CHECK_THROW(bit_reader.Read(8), std::ios_base::failure);
}

Expand Down Expand Up @@ -236,7 +236,7 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file)
BOOST_CHECK_EQUAL(i, 1);

// After reading bytes 0 and 1, we're positioned at 2.
BOOST_CHECK_EQUAL(bf.GetPos(), 2);
BOOST_CHECK_EQUAL(bf.GetPos(), 2U);

// Rewind to offset 0, ok (within the 10 byte window).
BOOST_CHECK(bf.SetPos(0));
Expand All @@ -263,18 +263,18 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file)
// The default argument removes the limit completely.
BOOST_CHECK(bf.SetLimit());
// The read position should still be at 3 (no change).
BOOST_CHECK_EQUAL(bf.GetPos(), 3);
BOOST_CHECK_EQUAL(bf.GetPos(), 3U);

// Read from current offset, 3, forward until position 10.
for (uint8_t j = 3; j < 10; ++j) {
bf >> i;
BOOST_CHECK_EQUAL(i, j);
}
BOOST_CHECK_EQUAL(bf.GetPos(), 10);
BOOST_CHECK_EQUAL(bf.GetPos(), 10U);

// We're guaranteed (just barely) to be able to rewind to zero.
BOOST_CHECK(bf.SetPos(0));
BOOST_CHECK_EQUAL(bf.GetPos(), 0);
BOOST_CHECK_EQUAL(bf.GetPos(), 0U);
bf >> i;
BOOST_CHECK_EQUAL(i, 0);

Expand All @@ -284,12 +284,12 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file)
BOOST_CHECK(bf.SetPos(10));
bf >> i;
BOOST_CHECK_EQUAL(i, 10);
BOOST_CHECK_EQUAL(bf.GetPos(), 11);
BOOST_CHECK_EQUAL(bf.GetPos(), 11U);

// Now it's only guaranteed that we can rewind to offset 1
// (current read position, 11, minus rewind amount, 10).
BOOST_CHECK(bf.SetPos(1));
BOOST_CHECK_EQUAL(bf.GetPos(), 1);
BOOST_CHECK_EQUAL(bf.GetPos(), 1U);
bf >> i;
BOOST_CHECK_EQUAL(i, 1);

Expand All @@ -303,7 +303,7 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file)
BOOST_CHECK_EQUAL(a[j], 11 + j);
}
}
BOOST_CHECK_EQUAL(bf.GetPos(), 40);
BOOST_CHECK_EQUAL(bf.GetPos(), 40U);

// We've read the entire file, the next read should throw.
try {
Expand All @@ -317,11 +317,11 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file)
BOOST_CHECK(bf.eof());

// Still at offset 40, we can go back 10, to 30.
BOOST_CHECK_EQUAL(bf.GetPos(), 40);
BOOST_CHECK_EQUAL(bf.GetPos(), 40U);
BOOST_CHECK(bf.SetPos(30));
bf >> i;
BOOST_CHECK_EQUAL(i, 30);
BOOST_CHECK_EQUAL(bf.GetPos(), 31);
BOOST_CHECK_EQUAL(bf.GetPos(), 31U);

// We're too far to rewind to position zero.
BOOST_CHECK(!bf.SetPos(0));
Expand Down
Loading

0 comments on commit df37377

Please sign in to comment.