test: use comparison assertions that print both values

- EXPECT_EQ/EXPECT_NE instead of EXPECT_TRUE(a == b) in the parts,
  memory resource and plugin manager tests; split the && checks
- ASSERT_NE on the message pointer before it is dereferenced
- ASSERT_TRUE/ASSERT_FALSE instead of ASSERT_EQ(x, true/false)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Claude
2026-11-03 14:43:51 +00:00
committed by Dennis Klein
parent 8ff2214f9c
commit f1ae05b45c
7 changed files with 58 additions and 53 deletions

View File

@@ -88,9 +88,10 @@ TEST(MemoryResources, transportAllocatorMap)
auto allocZMQ = factoryZMQ->GetMemoryResource();
auto allocSHM = factorySHM->GetMemoryResource();
EXPECT_TRUE(allocZMQ != nullptr && allocSHM != allocZMQ);
EXPECT_NE(allocZMQ, nullptr);
EXPECT_NE(allocSHM, allocZMQ);
auto _tmp = factoryZMQ->GetMemoryResource();
EXPECT_TRUE(_tmp == allocZMQ);
EXPECT_EQ(_tmp, allocZMQ);
}
using namespace fair::mq::pmr;
@@ -110,16 +111,16 @@ TEST(MemoryResources, allocator)
{
std::vector<TestData, polymorphic_allocator<TestData>> v(polymorphic_allocator<TestData>{allocZMQ});
v.reserve(3);
EXPECT_TRUE(v.capacity() == 3);
EXPECT_TRUE(allocZMQ->getNumberOfMessages() == 1);
EXPECT_EQ(v.capacity(), 3U);
EXPECT_EQ(allocZMQ->getNumberOfMessages(), 1U);
v.emplace_back(1);
v.emplace_back(2);
v.emplace_back(3);
EXPECT_EQ(reinterpret_cast<fair::mq::byte*>(v.data() + v.size()) - reinterpret_cast<fair::mq::byte*>(v.data()), static_cast<std::ptrdiff_t>(3 * sizeof(TestData)));
EXPECT_TRUE(TestData::nallocated == 3);
EXPECT_EQ(TestData::nallocated, 3);
}
EXPECT_TRUE(TestData::nallocated == 0);
EXPECT_TRUE(TestData::nallocations == TestData::ndeallocations);
EXPECT_EQ(TestData::nallocated, 0);
EXPECT_EQ(TestData::nallocations, TestData::ndeallocations);
}
TEST(MemoryResources, getMessage)
@@ -147,12 +148,14 @@ TEST(MemoryResources, getMessage)
v.emplace_back(3);
void* vectorBeginPtr = &v[0];
message = getMessage(std::move(v));
EXPECT_TRUE(message != nullptr);
EXPECT_TRUE(message->GetData() == vectorBeginPtr);
ASSERT_NE(message, nullptr);
EXPECT_EQ(message->GetData(), vectorBeginPtr);
}
EXPECT_TRUE(message->GetSize() == 3 * sizeof(TestData));
EXPECT_EQ(message->GetSize(), 3 * sizeof(TestData));
messageArray = static_cast<int*>(message->GetData());
EXPECT_TRUE(messageArray[0] == 1 && messageArray[1] == 2 && messageArray[2] == 3);
EXPECT_EQ(messageArray[0], 1);
EXPECT_EQ(messageArray[1], 2);
EXPECT_EQ(messageArray[2], 3);
// test message creation on a different channel than it was allocated with
{
@@ -162,13 +165,15 @@ TEST(MemoryResources, getMessage)
v.emplace_back(6);
void* vectorBeginPtr = &v[0];
message = getMessage(std::move(v), *factorySHM);
EXPECT_TRUE(message != nullptr);
EXPECT_TRUE(message->GetData() != vectorBeginPtr);
ASSERT_NE(message, nullptr);
EXPECT_NE(message->GetData(), vectorBeginPtr);
}
EXPECT_TRUE(message->GetSize() == 3 * sizeof(TestData));
EXPECT_EQ(message->GetSize(), 3 * sizeof(TestData));
messageArray = static_cast<int*>(message->GetData());
EXPECT_TRUE(messageArray[0] == 4 && messageArray[1] == 5 && messageArray[2] == 6);
EXPECT_EQ(messageArray[0], 4);
EXPECT_EQ(messageArray[1], 5);
EXPECT_EQ(messageArray[2], 6);
}
} // namespace