summaryrefslogtreecommitdiff
path: root/Tests
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2023-04-02 13:08:43 -0400
committerAndreas Kling <kling@serenityos.org>2023-04-03 15:53:49 +0200
commit15532df83da6a8bd91db1b28431e0c14d5cbce05 (patch)
tree38811376618fee5a1fa8ae4d824db02853f3b5fe /Tests
parent5c045b693427f35b13b40f586fa63bd1d08e06ed (diff)
downloadserenity-15532df83da6a8bd91db1b28431e0c14d5cbce05.zip
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.
Diffstat (limited to 'Tests')
-rw-r--r--Tests/LibC/TestSnprintf.cpp2
-rw-r--r--Tests/LibC/TestStrlcpy.cpp2
-rw-r--r--Tests/LibCompress/TestDeflate.cpp6
-rw-r--r--Tests/LibCompress/TestGzip.cpp2
-rw-r--r--Tests/LibCrypto/TestBigInteger.cpp2
5 files changed, 7 insertions, 7 deletions
diff --git a/Tests/LibC/TestSnprintf.cpp b/Tests/LibC/TestSnprintf.cpp
index c7535db722..5f2bf01551 100644
--- a/Tests/LibC/TestSnprintf.cpp
+++ b/Tests/LibC/TestSnprintf.cpp
@@ -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);
diff --git a/Tests/LibC/TestStrlcpy.cpp b/Tests/LibC/TestStrlcpy.cpp
index 01d97e45c0..98317e13a3 100644
--- a/Tests/LibC/TestStrlcpy.cpp
+++ b/Tests/LibC/TestStrlcpy.cpp
@@ -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);
diff --git a/Tests/LibCompress/TestDeflate.cpp b/Tests/LibCompress/TestDeflate.cpp
index e51092e5b3..c4bd045182 100644
--- a/Tests/LibCompress/TestDeflate.cpp
+++ b/Tests/LibCompress/TestDeflate.cpp
@@ -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());
diff --git a/Tests/LibCompress/TestGzip.cpp b/Tests/LibCompress/TestGzip.cpp
index 2f90725aea..39082ca357 100644
--- a/Tests/LibCompress/TestGzip.cpp
+++ b/Tests/LibCompress/TestGzip.cpp
@@ -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());
diff --git a/Tests/LibCrypto/TestBigInteger.cpp b/Tests/LibCrypto/TestBigInteger.cpp
index 91f82e6f92..92e3e03194 100644
--- a/Tests/LibCrypto/TestBigInteger.cpp
+++ b/Tests/LibCrypto/TestBigInteger.cpp
@@ -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);