diff options
author | Jack Lloyd <[email protected]> | 2017-10-24 12:01:43 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-10-24 12:01:43 -0400 |
commit | 5c3470fee0d3e8a6c0eb702602364e9e5dd5d658 (patch) | |
tree | d40d1af9f123973447d7f56394b4eb16810ab603 /src | |
parent | da0a1124242e3a108819df58054e8dd909268a00 (diff) |
Avoid "using namespace" in test code
Diffstat (limited to 'src')
-rw-r--r-- | src/tests/test_mp.cpp | 58 | ||||
-rw-r--r-- | src/tests/test_pkcs11.cpp | 7 | ||||
-rw-r--r-- | src/tests/test_utils.cpp | 50 |
3 files changed, 51 insertions, 64 deletions
diff --git a/src/tests/test_mp.cpp b/src/tests/test_mp.cpp index 8372e7e5c..766ba476f 100644 --- a/src/tests/test_mp.cpp +++ b/src/tests/test_mp.cpp @@ -35,17 +35,15 @@ class MP_Unit_Tests final : public Test { Result result("bigint_cnd_add"); - using namespace Botan; + const Botan::word max = Botan::MP_WORD_MAX; - const word max = MP_WORD_MAX; - - word a = 2; - word c = bigint_cnd_add(0, &a, &max, 1); + Botan::word a = 2; + Botan::word c = Botan::bigint_cnd_add(0, &a, &max, 1); result.test_int_eq(a, 2, "No op"); result.test_int_eq(c, 0, "No op"); - c = bigint_cnd_add(1, &a, &max, 1); + c = Botan::bigint_cnd_add(1, &a, &max, 1); result.test_int_eq(a, 1, "Add"); result.test_int_eq(c, 1, "Carry"); @@ -59,18 +57,16 @@ class MP_Unit_Tests final : public Test { Result result("bigint_cnd_sub"); - using namespace Botan; - - word a = 2; - word b = 3; - word c = bigint_cnd_sub(0, &a, &b, 1); + Botan::word a = 2; + Botan::word b = 3; + Botan::word c = Botan::bigint_cnd_sub(0, &a, &b, 1); result.test_int_eq(a, 2, "No op"); result.test_int_eq(c, 0, "No op"); - c = bigint_cnd_sub(1, &a, &b, 1); + c = Botan::bigint_cnd_sub(1, &a, &b, 1); - result.test_int_eq(a, MP_WORD_MAX, "Sub"); + result.test_int_eq(a, Botan::MP_WORD_MAX, "Sub"); result.test_int_eq(c, 1, "Borrow"); return result; @@ -80,27 +76,25 @@ class MP_Unit_Tests final : public Test { Result result("bigint_cnd_abs"); - using namespace Botan; - - word x1 = MP_WORD_MAX; - bigint_cnd_abs(1, &x1, 1); + Botan::word x1 = Botan::MP_WORD_MAX; + Botan::bigint_cnd_abs(1, &x1, 1); result.test_int_eq(x1, 1, "Abs"); x1 = 0; - bigint_cnd_abs(1, &x1, 1); + Botan::bigint_cnd_abs(1, &x1, 1); result.test_int_eq(x1, 0, "Abs"); x1 = 1; - bigint_cnd_abs(1, &x1, 1); - result.test_int_eq(x1, MP_WORD_MAX, "Abs"); + Botan::bigint_cnd_abs(1, &x1, 1); + result.test_int_eq(x1, Botan::MP_WORD_MAX, "Abs"); x1 = 1; - bigint_cnd_abs(0, &x1, 1); + Botan::bigint_cnd_abs(0, &x1, 1); result.test_int_eq(x1, 1, "No change"); - word x2[2] = { MP_WORD_MAX, MP_WORD_MAX }; + Botan::word x2[2] = { Botan::MP_WORD_MAX, Botan::MP_WORD_MAX }; - bigint_cnd_abs(1, x2, 2); + Botan::bigint_cnd_abs(1, x2, 2); result.test_int_eq(x2[0], 1, "Abs"); result.test_int_eq(x2[1], 0, "Abs"); @@ -111,24 +105,22 @@ class MP_Unit_Tests final : public Test { Result result("bigint_cnd_swap"); - using namespace Botan; - // null with zero length is ok - bigint_cnd_swap(0, nullptr, nullptr, 0); - bigint_cnd_swap(1, nullptr, nullptr, 0); + Botan::bigint_cnd_swap(0, nullptr, nullptr, 0); + Botan::bigint_cnd_swap(1, nullptr, nullptr, 0); - word x1 = 5, y1 = 9; + Botan::word x1 = 5, y1 = 9; - bigint_cnd_swap(0, &x1, &y1, 1); + Botan::bigint_cnd_swap(0, &x1, &y1, 1); result.test_int_eq(x1, 5, "No swap"); - bigint_cnd_swap(1, &x1, &y1, 1); + Botan::bigint_cnd_swap(1, &x1, &y1, 1); result.test_int_eq(x1, 9, "Swap"); - word x5[5] = { 0, 1, 2, 3, 4 }; - word y5[5] = { 3, 2, 1, 0, 9 }; + Botan::word x5[5] = { 0, 1, 2, 3, 4 }; + Botan::word y5[5] = { 3, 2, 1, 0, 9 }; // Should only modify first four - bigint_cnd_swap(1, x5, y5, 4); + Botan::bigint_cnd_swap(1, x5, y5, 4); for(size_t i = 0; i != 4; ++i) { diff --git a/src/tests/test_pkcs11.cpp b/src/tests/test_pkcs11.cpp index 289e34466..70861cef7 100644 --- a/src/tests/test_pkcs11.cpp +++ b/src/tests/test_pkcs11.cpp @@ -10,9 +10,6 @@ namespace Botan_Tests { #if defined(BOTAN_HAS_PKCS11) -using namespace Botan; -using namespace PKCS11; - std::vector<Test::Result> PKCS11_Test::run_pkcs11_tests(const std::string& name, std::vector<std::function<Test::Result()>>& fns) { @@ -24,11 +21,11 @@ std::vector<Test::Result> PKCS11_Test::run_pkcs11_tests(const std::string& name, { results.push_back(fns[ i ]()); } - catch(PKCS11_ReturnError& e) + catch(Botan::PKCS11::PKCS11_ReturnError& e) { results.push_back(Test::Result::Failure(name + " test " + std::to_string(i), e.what())); - if(e.get_return_value() == ReturnValue::PinIncorrect) + if(e.get_return_value() == Botan::PKCS11::ReturnValue::PinIncorrect) { break; // Do not continue to not potentially lock the token } diff --git a/src/tests/test_utils.cpp b/src/tests/test_utils.cpp index 8d46d4a26..57cd3208c 100644 --- a/src/tests/test_utils.cpp +++ b/src/tests/test_utils.cpp @@ -404,8 +404,6 @@ class Charset_Tests final : public Text_Based_Test Test::Result run_one_test(const std::string& type, const VarMap& vars) override { - using namespace Botan; - Test::Result result("Charset"); const std::vector<uint8_t> in = get_req_bin(vars, "In"); @@ -414,18 +412,21 @@ class Charset_Tests final : public Text_Based_Test std::string converted; if(type == "UTF16-LATIN1") { - converted = Charset::transcode(std::string(in.begin(), in.end()), - Character_Set::LATIN1_CHARSET, Character_Set::UCS2_CHARSET); + converted = Botan::Charset::transcode(std::string(in.begin(), in.end()), + Botan::Character_Set::LATIN1_CHARSET, + Botan::Character_Set::UCS2_CHARSET); } else if(type == "UTF8-LATIN1") { - converted = Charset::transcode(std::string(in.begin(), in.end()), - Character_Set::LATIN1_CHARSET, Character_Set::UTF8_CHARSET); + converted = Botan::Charset::transcode(std::string(in.begin(), in.end()), + Botan::Character_Set::LATIN1_CHARSET, + Botan::Character_Set::UTF8_CHARSET); } else if(type == "LATIN1-UTF8") { - converted = Charset::transcode(std::string(in.begin(), in.end()), - Character_Set::UTF8_CHARSET, Character_Set::LATIN1_CHARSET); + converted = Botan::Charset::transcode(std::string(in.begin(), in.end()), + Botan::Character_Set::UTF8_CHARSET, + Botan::Character_Set::LATIN1_CHARSET); } else { @@ -439,8 +440,6 @@ class Charset_Tests final : public Text_Based_Test Test::Result utf16_to_latin1_negative_tests() { - using namespace Botan; - Test::Result result("Charset negative tests"); result.test_throws("conversion fails for non-Latin1 characters", []() @@ -450,16 +449,18 @@ class Charset_Tests final : public Text_Based_Test 0x78, 0x00, 0x61, 0x00, 0x62, 0x00, 0x63, 0x00, 0x64, 0x00, 0x65, 0x00, 0x66 }; - Charset::transcode(std::string(input.begin(), input.end()), - Character_Set::LATIN1_CHARSET, Character_Set::UCS2_CHARSET); + Botan::Charset::transcode(std::string(input.begin(), input.end()), + Botan::Character_Set::LATIN1_CHARSET, + Botan::Character_Set::UCS2_CHARSET); }); result.test_throws("conversion fails for UTF16 string with odd number of bytes", []() { std::vector<uint8_t> input = { 0x00, 0x61, 0x00 }; - Charset::transcode(std::string(input.begin(), input.end()), - Character_Set::LATIN1_CHARSET, Character_Set::UCS2_CHARSET); + Botan::Charset::transcode(std::string(input.begin(), input.end()), + Botan::Character_Set::LATIN1_CHARSET, + Botan::Character_Set::UCS2_CHARSET); }); return result; @@ -467,8 +468,6 @@ class Charset_Tests final : public Text_Based_Test Test::Result utf8_to_latin1_negative_tests() { - using namespace Botan; - Test::Result result("Charset negative tests"); result.test_throws("conversion fails for non-Latin1 characters", []() @@ -478,8 +477,9 @@ class Charset_Tests final : public Text_Based_Test 0xB8, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66 }; - Charset::transcode(std::string(input.begin(), input.end()), - Character_Set::LATIN1_CHARSET, Character_Set::UTF8_CHARSET); + Botan::Charset::transcode(std::string(input.begin(), input.end()), + Botan::Character_Set::LATIN1_CHARSET, + Botan::Character_Set::UTF8_CHARSET); }); result.test_throws("invalid utf-8 string", []() @@ -487,16 +487,18 @@ class Charset_Tests final : public Text_Based_Test // sequence truncated std::vector<uint8_t> input = { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0xC5 }; - Charset::transcode(std::string(input.begin(), input.end()), - Character_Set::LATIN1_CHARSET, Character_Set::UTF8_CHARSET); + Botan::Charset::transcode(std::string(input.begin(), input.end()), + Botan::Character_Set::LATIN1_CHARSET, + Botan::Character_Set::UTF8_CHARSET); }); result.test_throws("invalid utf-8 string", []() { std::vector<uint8_t> input = { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0xC8, 0xB8, 0x61 }; - Charset::transcode(std::string(input.begin(), input.end()), - Character_Set::LATIN1_CHARSET, Character_Set::UTF8_CHARSET); + Botan::Charset::transcode(std::string(input.begin(), input.end()), + Botan::Character_Set::LATIN1_CHARSET, + Botan::Character_Set::UTF8_CHARSET); }); return result; @@ -504,8 +506,6 @@ class Charset_Tests final : public Text_Based_Test std::vector<Test::Result> run_final_tests() override { - using namespace Botan; - Test::Result result("Charset negative tests"); result.merge(utf16_to_latin1_negative_tests()); @@ -526,8 +526,6 @@ class Hostname_Tests final : public Text_Based_Test Test::Result run_one_test(const std::string& type, const VarMap& vars) override { - using namespace Botan; - Test::Result result("Hostname"); const std::string issued = get_req_str(vars, "Issued"); |