Use range based for loop

Instead of iterating over 0 .. 1 and then deciding on an actual desired
value, use a range based for loop for the desired value.
This commit is contained in:
René Nyffenegger 2017-07-16 15:52:19 +02:00
parent 5cfdda2503
commit d0413c670b

View File

@ -24,8 +24,7 @@ BOOST_FIXTURE_TEST_SUITE(dbwrapper_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(dbwrapper) BOOST_AUTO_TEST_CASE(dbwrapper)
{ {
// Perform tests both obfuscated and non-obfuscated. // Perform tests both obfuscated and non-obfuscated.
for (int i = 0; i < 2; i++) { for (bool obfuscate : {false, true}) {
bool obfuscate = (bool)i;
fs::path ph = fs::temp_directory_path() / fs::unique_path(); fs::path ph = fs::temp_directory_path() / fs::unique_path();
CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate); CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate);
char key = 'k'; char key = 'k';
@ -45,8 +44,7 @@ BOOST_AUTO_TEST_CASE(dbwrapper)
BOOST_AUTO_TEST_CASE(dbwrapper_batch) BOOST_AUTO_TEST_CASE(dbwrapper_batch)
{ {
// Perform tests both obfuscated and non-obfuscated. // Perform tests both obfuscated and non-obfuscated.
for (int i = 0; i < 2; i++) { for (bool obfuscate : {false, true}) {
bool obfuscate = (bool)i;
fs::path ph = fs::temp_directory_path() / fs::unique_path(); fs::path ph = fs::temp_directory_path() / fs::unique_path();
CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate); CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate);
@ -82,8 +80,7 @@ BOOST_AUTO_TEST_CASE(dbwrapper_batch)
BOOST_AUTO_TEST_CASE(dbwrapper_iterator) BOOST_AUTO_TEST_CASE(dbwrapper_iterator)
{ {
// Perform tests both obfuscated and non-obfuscated. // Perform tests both obfuscated and non-obfuscated.
for (int i = 0; i < 2; i++) { for (bool obfuscate : {false, true}) {
bool obfuscate = (bool)i;
fs::path ph = fs::temp_directory_path() / fs::unique_path(); fs::path ph = fs::temp_directory_path() / fs::unique_path();
CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate); CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate);
@ -211,12 +208,7 @@ BOOST_AUTO_TEST_CASE(iterator_ordering)
} }
std::unique_ptr<CDBIterator> it(const_cast<CDBWrapper&>(dbw).NewIterator()); std::unique_ptr<CDBIterator> it(const_cast<CDBWrapper&>(dbw).NewIterator());
for (int c=0; c<2; ++c) { for (int seek_start : {0x00, 0x80}) {
int seek_start;
if (c == 0)
seek_start = 0x00;
else
seek_start = 0x80;
it->Seek((uint8_t)seek_start); it->Seek((uint8_t)seek_start);
for (int x=seek_start; x<256; ++x) { for (int x=seek_start; x<256; ++x) {
uint8_t key; uint8_t key;
@ -287,12 +279,7 @@ BOOST_AUTO_TEST_CASE(iterator_string_ordering)
} }
std::unique_ptr<CDBIterator> it(const_cast<CDBWrapper&>(dbw).NewIterator()); std::unique_ptr<CDBIterator> it(const_cast<CDBWrapper&>(dbw).NewIterator());
for (int c=0; c<2; ++c) { for (int seek_start : {0, 5}) {
int seek_start;
if (c == 0)
seek_start = 0;
else
seek_start = 5;
snprintf(buf, sizeof(buf), "%d", seek_start); snprintf(buf, sizeof(buf), "%d", seek_start);
StringContentsSerializer seek_key(buf); StringContentsSerializer seek_key(buf);
it->Seek(seek_key); it->Seek(seek_key);