Skip to content

Commit

Permalink
Add additional test sets
Browse files Browse the repository at this point in the history
  • Loading branch information
mborland committed Oct 11, 2024
1 parent 5969bca commit d1ffa8e
Showing 1 changed file with 37 additions and 18 deletions.
55 changes: 37 additions & 18 deletions test/test_md5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,36 @@

#include <boost/crypt/hash/md5.hpp>
#include <boost/core/lightweight_test.hpp>
#include <iostream>
#include <string>
#include <array>
#include <tuple>

constexpr std::array<std::tuple<const char*, uint32_t, uint32_t, uint32_t, uint32_t>, 3> test_values =
constexpr std::array<std::tuple<const char*, uint32_t, uint32_t, uint32_t, uint32_t>, 9> test_values =
{
std::make_tuple("The quick brown fox jumps over the lazy dog", 0x9e107d9d, 0x372bb682, 0x6bd81d35, 0x42a419d6),
std::make_tuple("The quick brown fox jumps over the lazy dog.", 0xe4d909c2, 0x90d0fb1c, 0xa068ffad, 0xdf22cbd0),
std::make_tuple("", 0xd41d8cd9, 0x8f00b204, 0xe9800998, 0xecf8427e)
std::make_tuple("", 0xd41d8cd9, 0x8f00b204, 0xe9800998, 0xecf8427e),
std::make_tuple("ddcc8542894a27456bbeb43f51f38764c32f72ae", 0x3b340f00, 0x97312ec8, 0x2fa4da0d, 0x7da53002),
std::make_tuple("webmin1980", 0xb78aae35, 0x6709f8c3, 0x1118ea61, 0x3980954b),
std::make_tuple("$2y$10$EQAmcJw0cg.rt.6..SJ2bulFhDo0eWtuMhkfDMPGsNdap4xrOY61K", 0x40bbe664, 0x4efd9354, 0x078d8c70, 0xfb6c9f42),
std::make_tuple("pkirsanov", 0x8793ce04, 0xf0c5f1e8, 0xed1e0c78, 0xf249fe1b),
std::make_tuple("Eleanor", 0xd37e4317, 0x4905de70, 0xfbb5b038, 0xd7247f57),
std::make_tuple("The Whirlpool Galaxy is about 88% the size of the Milky Way, with a diameter of 76,900 light-years", 0xd5dfd7b4, 0x1235abc7, 0xa9a3205b, 0x6896f34d),
};

void basic_tests()
{
for (const auto& test_value : test_values)
{
const auto message_result {boost::crypt::md5(std::get<0>(test_value))};
BOOST_TEST_EQ(message_result[0], std::get<1>(test_value));
BOOST_TEST_EQ(message_result[1], std::get<2>(test_value));
BOOST_TEST_EQ(message_result[2], std::get<3>(test_value));
BOOST_TEST_EQ(message_result[3], std::get<4>(test_value));
if (!(BOOST_TEST_EQ(message_result[0], std::get<1>(test_value)) &&
BOOST_TEST_EQ(message_result[1], std::get<2>(test_value)) &&
BOOST_TEST_EQ(message_result[2], std::get<3>(test_value)) &&
BOOST_TEST_EQ(message_result[3], std::get<4>(test_value))))
{
std::cerr << "Failure with message: " << std::get<0>(test_value) << '\n';

Check warning on line 37 in test/test_md5.cpp

View check run for this annotation

Codecov / codecov/patch

test/test_md5.cpp#L37

Added line #L37 was not covered by tests
}
}
}

Expand All @@ -35,10 +45,13 @@ void string_test()
{
const std::string string_message {std::get<0>(test_value)};
const auto message_result {boost::crypt::md5(string_message)};
BOOST_TEST_EQ(message_result[0], std::get<1>(test_value));
BOOST_TEST_EQ(message_result[1], std::get<2>(test_value));
BOOST_TEST_EQ(message_result[2], std::get<3>(test_value));
BOOST_TEST_EQ(message_result[3], std::get<4>(test_value));
if (!(BOOST_TEST_EQ(message_result[0], std::get<1>(test_value)) &&
BOOST_TEST_EQ(message_result[1], std::get<2>(test_value)) &&
BOOST_TEST_EQ(message_result[2], std::get<3>(test_value)) &&
BOOST_TEST_EQ(message_result[3], std::get<4>(test_value))))
{
std::cerr << "Failure with message: " << std::get<0>(test_value) << '\n';

Check warning on line 53 in test/test_md5.cpp

View check run for this annotation

Codecov / codecov/patch

test/test_md5.cpp#L53

Added line #L53 was not covered by tests
}
}
}

Expand All @@ -50,10 +63,13 @@ void string_view_test()
const std::string string_message {std::get<0>(test_value)};
const std::string_view string_view_message {string_message};
const auto message_result {boost::crypt::md5(string_view_message)};
BOOST_TEST_EQ(message_result[0], std::get<1>(test_value));
BOOST_TEST_EQ(message_result[1], std::get<2>(test_value));
BOOST_TEST_EQ(message_result[2], std::get<3>(test_value));
BOOST_TEST_EQ(message_result[3], std::get<4>(test_value));
if (!(BOOST_TEST_EQ(message_result[0], std::get<1>(test_value)) &&
BOOST_TEST_EQ(message_result[1], std::get<2>(test_value)) &&
BOOST_TEST_EQ(message_result[2], std::get<3>(test_value)) &&
BOOST_TEST_EQ(message_result[3], std::get<4>(test_value))))
{
std::cerr << "Failure with message: " << std::get<0>(test_value) << '\n';

Check warning on line 71 in test/test_md5.cpp

View check run for this annotation

Codecov / codecov/patch

test/test_md5.cpp#L71

Added line #L71 was not covered by tests
}
}
#endif
}
Expand All @@ -78,10 +94,13 @@ void test_class()
std::array<std::uint32_t, 4> message_result {};
hasher.get_digest(message_result.begin(), message_result.size());

BOOST_TEST_EQ(message_result[0], std::get<1>(test_value));
BOOST_TEST_EQ(message_result[1], std::get<2>(test_value));
BOOST_TEST_EQ(message_result[2], std::get<3>(test_value));
BOOST_TEST_EQ(message_result[3], std::get<4>(test_value));
if (!(BOOST_TEST_EQ(message_result[0], std::get<1>(test_value)) &&
BOOST_TEST_EQ(message_result[1], std::get<2>(test_value)) &&
BOOST_TEST_EQ(message_result[2], std::get<3>(test_value)) &&
BOOST_TEST_EQ(message_result[3], std::get<4>(test_value))))
{
std::cerr << "Failure with message: " << std::get<0>(test_value) << '\n';

Check warning on line 102 in test/test_md5.cpp

View check run for this annotation

Codecov / codecov/patch

test/test_md5.cpp#L102

Added line #L102 was not covered by tests
}

hasher.init();
}
Expand Down

0 comments on commit d1ffa8e

Please sign in to comment.