1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 14:27:34 +00:00

AK+Everywhere: Change AK::fill_with_random to accept a Bytes object

Rather than the very C-like API we currently have, accepting a void* and
a length, let's take a Bytes object instead. In almost all existing
cases, the compiler figures out the length.
This commit is contained in:
Timothy Flynn 2023-04-02 13:08:43 -04:00 committed by Andreas Kling
parent 5c045b6934
commit 15532df83d
20 changed files with 37 additions and 39 deletions

View file

@ -59,7 +59,7 @@ static bool test_single(Testcase<TArg> const& testcase)
// Setup
ByteBuffer actual = ByteBuffer::create_uninitialized(SANDBOX_CANARY_SIZE + testcase.dest_n + SANDBOX_CANARY_SIZE).release_value();
fill_with_random(actual.data(), actual.size());
fill_with_random(actual);
ByteBuffer expected = actual;
VERIFY(actual.offset_pointer(0) != expected.offset_pointer(0));
actual.overwrite(SANDBOX_CANARY_SIZE, testcase.dest, testcase.dest_n);

View file

@ -56,7 +56,7 @@ static bool test_single(Testcase const& testcase)
// Setup
ByteBuffer actual = ByteBuffer::create_uninitialized(SANDBOX_CANARY_SIZE + testcase.dest_n + SANDBOX_CANARY_SIZE).release_value();
fill_with_random(actual.data(), actual.size());
fill_with_random(actual);
ByteBuffer expected = actual;
VERIFY(actual.offset_pointer(0) != expected.offset_pointer(0));
actual.overwrite(SANDBOX_CANARY_SIZE, testcase.dest, testcase.dest_n);

View file

@ -115,7 +115,7 @@ TEST_CASE(deflate_decompress_zeroes)
TEST_CASE(deflate_round_trip_store)
{
auto original = ByteBuffer::create_uninitialized(1024).release_value();
fill_with_random(original.data(), 1024);
fill_with_random(original);
auto compressed = Compress::DeflateCompressor::compress_all(original, Compress::DeflateCompressor::CompressionLevel::STORE);
EXPECT(!compressed.is_error());
auto uncompressed = Compress::DeflateDecompressor::decompress_all(compressed.value());
@ -126,7 +126,7 @@ TEST_CASE(deflate_round_trip_store)
TEST_CASE(deflate_round_trip_compress)
{
auto original = ByteBuffer::create_zeroed(2048).release_value();
fill_with_random(original.data(), 1024); // we pre-filled the second half with 0s to make sure we test back references as well
fill_with_random(original.bytes().trim(1024)); // we pre-filled the second half with 0s to make sure we test back references as well
// Since the different levels just change how much time is spent looking for better matches, just use fast here to reduce test time
auto compressed = Compress::DeflateCompressor::compress_all(original, Compress::DeflateCompressor::CompressionLevel::FAST);
EXPECT(!compressed.is_error());
@ -139,7 +139,7 @@ TEST_CASE(deflate_round_trip_compress_large)
{
auto size = Compress::DeflateCompressor::block_size * 2;
auto original = ByteBuffer::create_uninitialized(size).release_value(); // Compress a buffer larger than the maximum block size to test the sliding window mechanism
fill_with_random(original.data(), size);
fill_with_random(original);
// Since the different levels just change how much time is spent looking for better matches, just use fast here to reduce test time
auto compressed = Compress::DeflateCompressor::compress_all(original, Compress::DeflateCompressor::CompressionLevel::FAST);
EXPECT(!compressed.is_error());

View file

@ -88,7 +88,7 @@ TEST_CASE(gzip_decompress_repeat_around_buffer)
TEST_CASE(gzip_round_trip)
{
auto original = ByteBuffer::create_uninitialized(1024).release_value();
fill_with_random(original.data(), 1024);
fill_with_random(original);
auto compressed = Compress::GzipCompressor::compress_all(original);
EXPECT(!compressed.is_error());
auto uncompressed = Compress::GzipDecompressor::decompress_all(compressed.value());

View file

@ -398,7 +398,7 @@ TEST_CASE(test_bigint_import_big_endian_decode_encode_roundtrip)
{
u8 random_bytes[128];
u8 target_buffer[128];
fill_with_random(random_bytes, 128);
fill_with_random(random_bytes);
auto encoded = Crypto::UnsignedBigInteger::import_data(random_bytes, 128);
encoded.export_data({ target_buffer, 128 });
EXPECT(memcmp(target_buffer, random_bytes, 128) == 0);