diff options
author | Jack Lloyd <[email protected]> | 2015-11-28 11:50:44 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2015-11-28 11:50:44 -0500 |
commit | 62cad8095bdf68a339e219d3d78ab7a977e87e91 (patch) | |
tree | 08e8e7d53210a33da16ad4cd0f267a94c293b456 /src | |
parent | 466cc0fb0b1a072584c26f0949d377510c440d0d (diff) |
Convert const char* arguments on Test:: to std::strings
unless they are actually optional
Diffstat (limited to 'src')
-rw-r--r-- | src/tests/test_block.cpp | 8 | ||||
-rw-r--r-- | src/tests/test_hash.cpp | 2 | ||||
-rw-r--r-- | src/tests/test_mac.cpp | 2 | ||||
-rw-r--r-- | src/tests/test_stream.cpp | 2 | ||||
-rw-r--r-- | src/tests/test_utils.cpp | 8 | ||||
-rw-r--r-- | src/tests/tests.cpp | 53 | ||||
-rw-r--r-- | src/tests/tests.h | 52 | ||||
-rw-r--r-- | src/tests/unit_ecc.cpp | 2 |
8 files changed, 57 insertions, 72 deletions
diff --git a/src/tests/test_block.cpp b/src/tests/test_block.cpp index 224735e22..7831b99a3 100644 --- a/src/tests/test_block.cpp +++ b/src/tests/test_block.cpp @@ -40,10 +40,10 @@ class Block_Cipher_Tests : public Text_Based_Test continue; } - result.test_eq(provider.c_str(), cipher->name(), algo); - result.test_gte(provider.c_str(), cipher->parallelism(), 1); - result.test_gte(provider.c_str(), cipher->block_size(), 8); - result.test_gte(provider.c_str(), cipher->parallel_bytes(), cipher->block_size() * cipher->parallelism()); + result.test_eq(provider, cipher->name(), algo); + result.test_gte(provider, cipher->parallelism(), 1); + result.test_gte(provider, cipher->block_size(), 8); + result.test_gte(provider, cipher->parallel_bytes(), cipher->block_size() * cipher->parallelism()); cipher->set_key(key); std::vector<uint8_t> buf = input; diff --git a/src/tests/test_hash.cpp b/src/tests/test_hash.cpp index 6c0dfb1c6..bdfe70a6a 100644 --- a/src/tests/test_hash.cpp +++ b/src/tests/test_hash.cpp @@ -42,7 +42,7 @@ class Hash_Function_Tests : public Text_Based_Test continue; } - result.test_eq(provider.c_str(), hash->name(), algo); + result.test_eq(provider, hash->name(), algo); hash->update(input); diff --git a/src/tests/test_mac.cpp b/src/tests/test_mac.cpp index a5b2b49ca..e7341f443 100644 --- a/src/tests/test_mac.cpp +++ b/src/tests/test_mac.cpp @@ -48,7 +48,7 @@ class Message_Auth_Tests : public Text_Based_Test continue; } - result.test_eq(provider.c_str(), mac->name(), algo); + result.test_eq(provider, mac->name(), algo); mac->set_key(key); diff --git a/src/tests/test_stream.cpp b/src/tests/test_stream.cpp index ed86b3d84..618d34755 100644 --- a/src/tests/test_stream.cpp +++ b/src/tests/test_stream.cpp @@ -46,7 +46,7 @@ class Stream_Cipher_Tests : public Text_Based_Test continue; } - result.test_eq(provider.c_str(), cipher->name(), algo); + result.test_eq(provider, cipher->name(), algo); cipher->set_key(key); if(nonce.size()) diff --git a/src/tests/test_utils.cpp b/src/tests/test_utils.cpp index dfe0b19d3..9ee799519 100644 --- a/src/tests/test_utils.cpp +++ b/src/tests/test_utils.cpp @@ -34,7 +34,7 @@ class Utility_Function_Tests : public Text_Based_Test const size_t x = get_req_sz(vars, "In1"); const size_t to = get_req_sz(vars, "In2"); - result.test_eq(algo.c_str(), Botan::round_up(x, to), get_req_sz(vars, "Out")); + result.test_eq(algo, Botan::round_up(x, to), get_req_sz(vars, "Out")); try { @@ -48,8 +48,8 @@ class Utility_Function_Tests : public Text_Based_Test const size_t x = get_req_sz(vars, "In1"); const size_t to = get_req_sz(vars, "In2"); - result.test_eq(algo.c_str(), Botan::round_down<size_t>(x, to), get_req_sz(vars, "Out")); - result.test_eq(algo.c_str(), Botan::round_down<size_t>(x, 0), x); + result.test_eq(algo, Botan::round_down<size_t>(x, to), get_req_sz(vars, "Out")); + result.test_eq(algo, Botan::round_down<size_t>(x, 0), x); } return result; @@ -313,7 +313,7 @@ class Base64_Tests : public Text_Based_Test } catch(std::exception& e) { - result.test_failure(b64_ws.c_str(), e.what()); + result.test_failure(b64_ws, e.what()); } } } diff --git a/src/tests/tests.cpp b/src/tests/tests.cpp index e421d245c..4db24dcc7 100644 --- a/src/tests/tests.cpp +++ b/src/tests/tests.cpp @@ -106,12 +106,12 @@ bool Test::Result::test_success(const std::string& note) return true; } -bool Test::Result::test_failure(const char* what, const char* error) +bool Test::Result::test_failure(const std::string& what, const std::string& error) { return test_failure(who() + " " + what + " with error " + error); } -void Test::Result::test_failure(const char* what, const uint8_t buf[], size_t buf_len) +void Test::Result::test_failure(const std::string& what, const uint8_t buf[], size_t buf_len) { test_failure(who() + ": " + what + " buf len " + std::to_string(buf_len) + @@ -124,7 +124,7 @@ bool Test::Result::test_failure(const std::string& err) return false; } -bool Test::Result::test_ne(const char* what, +bool Test::Result::test_ne(const std::string& what, const uint8_t produced[], size_t produced_len, const uint8_t expected[], size_t expected_len) { @@ -133,7 +133,7 @@ bool Test::Result::test_ne(const char* what, return test_success(); } -bool Test::Result::test_eq(const char* producer, const char* what, +bool Test::Result::test_eq(const char* producer, const std::string& what, const uint8_t produced[], size_t produced_size, const uint8_t expected[], size_t expected_size) { @@ -149,12 +149,7 @@ bool Test::Result::test_eq(const char* producer, const char* what, err << " producer '" << producer << "'"; } - err << " unexpected result"; - - if(what) - { - err << " for " << what; - } + err << " unexpected result for " << what; if(produced_size != expected_size) { @@ -182,29 +177,27 @@ bool Test::Result::test_eq(const char* producer, const char* what, return test_failure(err.str()); } -bool Test::Result::test_eq(const char* what, const std::string& produced, const std::string& expected) +bool Test::Result::test_eq(const std::string& what, const std::string& produced, const std::string& expected) { return test_is_eq(what, produced, expected); } -bool Test::Result::test_eq(const char* what, const char* produced, const char* expected) +bool Test::Result::test_eq(const std::string& what, const char* produced, const char* expected) { return test_is_eq(what, std::string(produced), std::string(expected)); } -bool Test::Result::test_eq(const char* what, size_t produced, size_t expected) +bool Test::Result::test_eq(const std::string& what, size_t produced, size_t expected) { return test_is_eq(what, produced, expected); } -bool Test::Result::test_lt(const char* what, size_t produced, size_t expected) +bool Test::Result::test_lt(const std::string& what, size_t produced, size_t expected) { if(produced >= expected) { std::ostringstream err; - err << m_who; - if(what) - err << " " << what; + err << m_who << " " << what; err << " unexpected result " << produced << " >= " << expected; return test_failure(err.str()); } @@ -212,14 +205,13 @@ bool Test::Result::test_lt(const char* what, size_t produced, size_t expected) return test_success(); } -bool Test::Result::test_gte(const char* what, size_t produced, size_t expected) +bool Test::Result::test_gte(const std::string& what, size_t produced, size_t expected) { if(produced < expected) { std::ostringstream err; err << m_who; - if(what) - err << " " << what; + err << " " << what; err << " unexpected result " << produced << " < " << expected; return test_failure(err.str()); } @@ -228,12 +220,12 @@ bool Test::Result::test_gte(const char* what, size_t produced, size_t expected) } #if defined(BOTAN_HAS_BIGINT) -bool Test::Result::test_eq(const char* what, const BigInt& produced, const BigInt& expected) +bool Test::Result::test_eq(const std::string& what, const BigInt& produced, const BigInt& expected) { return test_is_eq(what, produced, expected); } -bool Test::Result::test_ne(const char* what, const BigInt& produced, const BigInt& expected) +bool Test::Result::test_ne(const std::string& what, const BigInt& produced, const BigInt& expected) { if(produced != expected) return test_success(); @@ -245,7 +237,7 @@ bool Test::Result::test_ne(const char* what, const BigInt& produced, const BigIn #endif #if defined(BOTAN_HAS_EC_CURVE_GFP) -bool Test::Result::test_eq(const char* what, const Botan::PointGFp& a, const Botan::PointGFp& b) +bool Test::Result::test_eq(const std::string& what, const Botan::PointGFp& a, const Botan::PointGFp& b) { //return test_is_eq(what, a, b); if(a == b) @@ -258,19 +250,18 @@ bool Test::Result::test_eq(const char* what, const Botan::PointGFp& a, const Bot } #endif -bool Test::Result::test_eq(const char* what, bool produced, bool expected) +bool Test::Result::test_eq(const std::string& what, bool produced, bool expected) { return test_is_eq(what, produced, expected); } -bool Test::Result::test_rc_ok(const char* what, int rc) +bool Test::Result::test_rc_ok(const std::string& what, int rc) { if(rc != 0) { std::ostringstream err; err << m_who; - if(what) - err << " " << what; + err << " " << what; err << " unexpectedly failed with error code " << rc; return test_failure(err.str()); } @@ -278,16 +269,14 @@ bool Test::Result::test_rc_ok(const char* what, int rc) return test_success(); } -bool Test::Result::test_rc_fail(const char* func, const char* why, int rc) +bool Test::Result::test_rc_fail(const std::string& func, const std::string& why, int rc) { if(rc == 0) { std::ostringstream err; err << m_who; - if(func) - err << " call to " << func << " unexpectedly succeeded"; - if(why) - err << " expecting failure because " << why; + err << " call to " << func << " unexpectedly succeeded"; + err << " expecting failure because " << why; return test_failure(err.str()); } diff --git a/src/tests/tests.h b/src/tests/tests.h index 1af278cce..fddf44aaf 100644 --- a/src/tests/tests.h +++ b/src/tests/tests.h @@ -121,17 +121,17 @@ class Test bool test_failure(const std::string& err); - bool test_failure(const char* what, const char* error); + bool test_failure(const std::string& what, const std::string& error); - void test_failure(const char* what, const uint8_t buf[], size_t buf_len); + void test_failure(const std::string& what, const uint8_t buf[], size_t buf_len); template<typename Alloc> - void test_failure(const char* what, const std::vector<uint8_t, Alloc>& buf) + void test_failure(const std::string& what, const std::vector<uint8_t, Alloc>& buf) { test_failure(what, buf.data(), buf.size()); } - bool confirm(const char* what, bool expr) + bool confirm(const std::string& what, bool expr) { return test_eq(what, expr, true); } @@ -139,18 +139,14 @@ class Test template<typename T> bool test_is_eq(const T& produced, const T& expected) { - return test_is_eq(nullptr, produced, expected); + return test_is_eq("comparison", produced, expected); } template<typename T> - bool test_is_eq(const char* what, const T& produced, const T& expected) + bool test_is_eq(const std::string& what, const T& produced, const T& expected) { std::ostringstream out; - out << m_who; - if(what) - { - out << " " << what; - } + out << m_who << " " << what; if(produced == expected) { @@ -164,36 +160,36 @@ class Test } } - bool test_eq(const char* what, const char* produced, const char* expected); - bool test_eq(const char* what, const std::string& produced, const std::string& expected); - bool test_eq(const char* what, bool produced, bool expected); + bool test_eq(const std::string& what, const char* produced, const char* expected); + bool test_eq(const std::string& what, const std::string& produced, const std::string& expected); + bool test_eq(const std::string& what, bool produced, bool expected); - bool test_eq(const char* what, size_t produced, size_t expected); - bool test_lt(const char* what, size_t produced, size_t expected); - bool test_gte(const char* what, size_t produced, size_t expected); + bool test_eq(const std::string& what, size_t produced, size_t expected); + bool test_lt(const std::string& what, size_t produced, size_t expected); + bool test_gte(const std::string& what, size_t produced, size_t expected); - bool test_rc_ok(const char* func, int rc); - bool test_rc_fail(const char* func, const char* why, int rc); + bool test_rc_ok(const std::string& func, int rc); + bool test_rc_fail(const std::string& func, const std::string& why, int rc); #if defined(BOTAN_HAS_BIGINT) - bool test_eq(const char* what, const BigInt& produced, const BigInt& expected); - bool test_ne(const char* what, const BigInt& produced, const BigInt& expected); + bool test_eq(const std::string& what, const BigInt& produced, const BigInt& expected); + bool test_ne(const std::string& what, const BigInt& produced, const BigInt& expected); #endif #if defined(BOTAN_HAS_EC_CURVE_GFP) - bool test_eq(const char* what, const Botan::PointGFp& a, const Botan::PointGFp& b); + bool test_eq(const std::string& what, const Botan::PointGFp& a, const Botan::PointGFp& b); #endif - bool test_eq(const char* producer, const char* what, + bool test_eq(const char* producer, const std::string& what, const uint8_t produced[], size_t produced_len, const uint8_t expected[], size_t expected_len); - bool test_ne(const char* what, + bool test_ne(const std::string& what, const uint8_t produced[], size_t produced_len, const uint8_t expected[], size_t expected_len); template<typename Alloc1, typename Alloc2> - bool test_eq(const char* what, + bool test_eq(const std::string& what, const std::vector<uint8_t, Alloc1>& produced, const std::vector<uint8_t, Alloc2>& expected) { @@ -203,7 +199,7 @@ class Test } template<typename Alloc1, typename Alloc2> - bool test_eq(const std::string& producer, const char* what, + bool test_eq(const std::string& producer, const std::string& what, const std::vector<uint8_t, Alloc1>& produced, const std::vector<uint8_t, Alloc2>& expected) { @@ -213,7 +209,7 @@ class Test } template<typename Alloc> - bool test_eq(const char* what, + bool test_eq(const std::string& what, const std::vector<uint8_t, Alloc>& produced, const char* expected_hex) { @@ -224,7 +220,7 @@ class Test } template<typename Alloc1, typename Alloc2> - bool test_ne(const char* what, + bool test_ne(const std::string& what, const std::vector<uint8_t, Alloc1>& produced, const std::vector<uint8_t, Alloc2>& expected) { diff --git a/src/tests/unit_ecc.cpp b/src/tests/unit_ecc.cpp index 65187a428..0d6c34213 100644 --- a/src/tests/unit_ecc.cpp +++ b/src/tests/unit_ecc.cpp @@ -183,7 +183,7 @@ std::vector<Test::Result> ECC_Randomized_Tests::run() } catch(std::exception& e) { - result.test_failure(group_name.c_str(), e.what()); + result.test_failure(group_name, e.what()); } results.push_back(result); } |