Mesa (main): util: Change blob_test to use macro from mesa-gtest-extras.h
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Nov 8 18:09:38 UTC 2021
Module: Mesa
Branch: main
Commit: 75161e6f3d8909a5804f0d1490549c146d5cceeb
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=75161e6f3d8909a5804f0d1490549c146d5cceeb
Author: Caio Oliveira <caio.oliveira at intel.com>
Date: Wed Nov 3 23:22:50 2021 -0700
util: Change blob_test to use macro from mesa-gtest-extras.h
Reviewed-by: Dylan Baker <dylan at pnwbakers.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13672>
---
src/util/tests/blob_test.cpp | 63 ++++----------------------------------------
1 file changed, 5 insertions(+), 58 deletions(-)
diff --git a/src/util/tests/blob_test.cpp b/src/util/tests/blob_test.cpp
index a3b88378fe9..3bcfeb4fd70 100644
--- a/src/util/tests/blob_test.cpp
+++ b/src/util/tests/blob_test.cpp
@@ -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;
}
More information about the mesa-commit
mailing list