2
0
mirror of https://github.com/boostorg/uuid.git synced 2026-01-19 04:42:16 +00:00

Update test_detail_random_provider.cpp

This commit is contained in:
Peter Dimov
2024-04-22 03:19:57 +03:00
parent b28350fe57
commit 2ba3eacba6

View File

@@ -8,8 +8,6 @@
// Positive and negative testing for detail::random_provider
//
// The mock needs to load first for posix system call redirection to work properly
#include "mock_random.hpp"
#include <boost/uuid/detail/random_provider.hpp>
#include <boost/uuid/entropy_error.hpp>
#include <boost/uuid/uuid.hpp>
@@ -20,11 +18,8 @@
#include <cstdint>
#include <string.h>
int main()
{
#if !defined(BOOST_UUID_TEST_RANDOM_MOCK) // Positive Testing
boost::uuids::detail::random_provider provider;
boost::array<unsigned int, 2> ints;
@@ -37,41 +32,12 @@ int main()
// test name()
BOOST_TEST_GT(strlen(provider.name()), 4u);
// test get_random_bytes()
// test the equivalent of get_random_bytes()
std::uint32_t buf1[16];
std::uint32_t buf2[16];
provider.generate(buf1, buf1 + 16);
provider.generate(buf2, buf2 + 16);
BOOST_TEST_NE(0, memcmp(buf1, buf2, 64));
#else // Negative Testing
if (expectations_capable())
{
// Test fail acquiring context if the provider supports it
if (provider_acquires_context())
{
expect_next_call_success(false);
BOOST_TEST_THROWS(boost::uuids::detail::random_provider(),
boost::uuids::entropy_error);
BOOST_TEST(expectations_met());
}
// Test fail acquiring entropy
if (provider_acquires_context())
{
expect_next_call_success(true);
}
expect_next_call_success(false);
// 4 is important for the posix negative test (partial read) to work properly
// as it sees a size of 4, returns 1, causing a 2nd loop to read 3 more bytes...
std::uint32_t buf[1];
BOOST_TEST_THROWS(boost::uuids::detail::random_provider().generate(buf, buf + 1),
boost::uuids::entropy_error);
BOOST_TEST(expectations_met());
}
#endif
return boost::report_errors();
}