util: Change blob_test to use macro from mesa-gtest-extras.h
Reviewed-by: Dylan Baker <dylan@pnwbakers.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13672>
This commit is contained in:
parent
015383d1d7
commit
75161e6f3d
|
@ -35,60 +35,7 @@ typedef SSIZE_T ssize_t;
|
|||
#include "blob.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
static testing::AssertionResult
|
||||
bytes_equal_pred(const char *a_expr,
|
||||
const char *b_expr,
|
||||
const char *c_expr,
|
||||
const uint8_t *expected,
|
||||
const uint8_t *actual,
|
||||
size_t num_bytes)
|
||||
{
|
||||
if (memcmp(expected, actual, num_bytes)) {
|
||||
std::stringstream result;
|
||||
|
||||
result << a_expr << " and " << b_expr << " are different "
|
||||
<< "when comparing " << num_bytes << " bytes):\n";
|
||||
|
||||
for (size_t i = 0; i < num_bytes; i++) {
|
||||
if (actual[i] != expected[i]) {
|
||||
result << "Mismatch at index " << i << ": "
|
||||
<< "0x" << std::setfill('0') << std::setw(2) << std::right << std::hex << unsigned(actual[i])
|
||||
<< " != "
|
||||
<< "0x" << std::setfill('0') << std::setw(2) << std::right << std::hex << unsigned(expected[i])
|
||||
<< "\n";
|
||||
}
|
||||
}
|
||||
result << "\n";
|
||||
|
||||
result << " Actual: [";
|
||||
for (size_t i = 0; i < num_bytes; i++) {
|
||||
if (i % 16 == 0)
|
||||
result << "\n";
|
||||
unsigned v = actual[i];
|
||||
result << " 0x" << std::setfill('0') << std::setw(2)
|
||||
<< std::right << std::hex << v;
|
||||
}
|
||||
result << "]\n";
|
||||
|
||||
result << "Expected: [";
|
||||
for (size_t i = 0; i < num_bytes; i++) {
|
||||
if (i % 16 == 0)
|
||||
result << "\n";
|
||||
unsigned v = expected[i];
|
||||
result << " 0x" << std::setfill('0') << std::setw(2)
|
||||
<< std::right << std::hex << v;
|
||||
}
|
||||
result << "]\n";
|
||||
|
||||
return testing::AssertionFailure() << result.str();
|
||||
} else {
|
||||
return testing::AssertionSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
#define EXPECT_BYTES_EQUAL(expected, actual, num_bytes) \
|
||||
EXPECT_PRED_FORMAT3(bytes_equal_pred, expected, actual, num_bytes)
|
||||
#include "mesa-gtest-extras.h"
|
||||
|
||||
#define bytes_test_str "bytes_test"
|
||||
#define reserve_test_str "reserve_test"
|
||||
|
@ -220,8 +167,8 @@ TEST(BlobTest, Alignment)
|
|||
<< "read of initial, aligned intptr_t";
|
||||
|
||||
for (num_bytes = 1; num_bytes < sizeof(intptr_t); num_bytes++) {
|
||||
EXPECT_BYTES_EQUAL(bytes, (const uint8_t *) blob_read_bytes(&reader, num_bytes),
|
||||
num_bytes) << "unaligned read of bytes";
|
||||
EXPECT_U8_ARRAY_EQUAL(bytes, (const uint8_t *) blob_read_bytes(&reader, num_bytes),
|
||||
num_bytes) << "unaligned read of bytes";
|
||||
EXPECT_EQ((intptr_t) &blob, blob_read_intptr(&reader)) << "aligned read of intptr_t";
|
||||
}
|
||||
|
||||
|
@ -277,8 +224,8 @@ TEST(BlobTest, BigObjects)
|
|||
|
||||
// Read and verify it many times.
|
||||
for (int i = 0; i < count; i++) {
|
||||
EXPECT_BYTES_EQUAL((uint8_t *) buf,
|
||||
(const uint8_t *) blob_read_bytes(&reader, size), size)
|
||||
EXPECT_U8_ARRAY_EQUAL((uint8_t *) buf,
|
||||
(const uint8_t *) blob_read_bytes(&reader, size), size)
|
||||
<< "read of large objects, iteration " << i;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue