From aec6ba3b71bf039dd2f5cb8506207b8d4be13743 Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Wed, 23 Oct 2019 15:57:44 +0200 Subject: [PATCH] [test/misc] Convert hashstr to unit test Signed-off-by: Arne Schwabe --- test/misc/hashstr.cpp | 37 -------------------------- test/unittests/input/1984.txt | 7 +++++ test/unittests/test_crypto_hashstr.cpp | 19 +++++++++++++ 3 files changed, 26 insertions(+), 37 deletions(-) delete mode 100644 test/misc/hashstr.cpp create mode 100644 test/unittests/input/1984.txt create mode 100644 test/unittests/test_crypto_hashstr.cpp diff --git a/test/misc/hashstr.cpp b/test/misc/hashstr.cpp deleted file mode 100644 index 33c9f9ad..00000000 --- a/test/misc/hashstr.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// TEST : {"cmd": "./go hashstr"} - -#include - -#include -#include -#include - -#define OPENVPN_LOG_SSL(x) OPENVPN_LOG(x) - -#include -#include -#include -#include - -using namespace openvpn; - -int main(int /*argc*/, char* /*argv*/[]) -{ - try { - const std::string content = read_text_utf8("1984.txt"); - - DigestFactory::Ptr digest_factory(new CryptoDigestFactory()); - HashString hash(*digest_factory, CryptoAlgs::MD5); - hash.update(content); - const std::string actual = hash.final_hex(); - const std::string expected = "2bea7a83bf94971af26372126ebba7e3"; - if (actual != expected) - throw Exception("actual does not match expected"); - } - catch (const std::exception& e) - { - std::cerr << "Exception: " << e.what() << std::endl; - return 1; - } - return 0; -} diff --git a/test/unittests/input/1984.txt b/test/unittests/input/1984.txt new file mode 100644 index 00000000..4f4f6db6 --- /dev/null +++ b/test/unittests/input/1984.txt @@ -0,0 +1,7 @@ +It was a bright cold day in April, and the clocks +were striking thirteen. Winston Smith, his chin nuzzled +into his breast in an effort to escape the vile wind, +slipped quickly through the glass doors of Victory +Mansions, though not quickly enough to prevent a +swirl of gritty dust from entering along with him. +----------------------------------------------------- diff --git a/test/unittests/test_crypto_hashstr.cpp b/test/unittests/test_crypto_hashstr.cpp new file mode 100644 index 00000000..ad32d680 --- /dev/null +++ b/test/unittests/test_crypto_hashstr.cpp @@ -0,0 +1,19 @@ +#include "test_common.h" + +#include +#include +#include +#include + +using namespace openvpn; + +TEST(crypto, hashstr) { + const std::string content = read_text_utf8(UNITTEST_SOURCE_DIR "/input/1984.txt"); + + DigestFactory::Ptr digest_factory(new CryptoDigestFactory()); + HashString hash(*digest_factory, CryptoAlgs::MD5); + hash.update(content); + const std::string actual = hash.final_hex(); + const std::string expected = "2bea7a83bf94971af26372126ebba7e3"; + ASSERT_EQ (actual, expected); +}