mirror of
https://github.com/OpenVPN/openvpn3.git
synced 2024-09-20 04:02:15 +02:00
[test/misc] Convert hashstr to unit test
Signed-off-by: Arne Schwabe <arne@openvpn.net>
This commit is contained in:
parent
ce9bd51f72
commit
aec6ba3b71
@ -1,37 +0,0 @@
|
||||
// TEST : {"cmd": "./go hashstr"}
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <openvpn/log/logsimple.hpp>
|
||||
#include <openvpn/common/size.hpp>
|
||||
#include <openvpn/common/exception.hpp>
|
||||
|
||||
#define OPENVPN_LOG_SSL(x) OPENVPN_LOG(x)
|
||||
|
||||
#include <openvpn/common/file.hpp>
|
||||
#include <openvpn/ssl/sslchoose.hpp>
|
||||
#include <openvpn/crypto/cryptoalgs.hpp>
|
||||
#include <openvpn/crypto/hashstr.hpp>
|
||||
|
||||
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<SSLLib::CryptoAPI>());
|
||||
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;
|
||||
}
|
7
test/unittests/input/1984.txt
Normal file
7
test/unittests/input/1984.txt
Normal file
@ -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.
|
||||
-----------------------------------------------------
|
19
test/unittests/test_crypto_hashstr.cpp
Normal file
19
test/unittests/test_crypto_hashstr.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
#include "test_common.h"
|
||||
|
||||
#include <openvpn/common/file.hpp>
|
||||
#include <openvpn/ssl/sslchoose.hpp>
|
||||
#include <openvpn/crypto/cryptoalgs.hpp>
|
||||
#include <openvpn/crypto/hashstr.hpp>
|
||||
|
||||
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<SSLLib::CryptoAPI>());
|
||||
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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user