From f1ae05b45c7b1f9f00a1e623afd7db738dcde8fb Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 3 Nov 2026 14:43:51 +0000 Subject: [PATCH] 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 --- test/channel/_channel.cxx | 38 ++++++++++----------- test/device/_multiple_devices.cxx | 4 +-- test/memory_resources/_memory_resources.cxx | 35 +++++++++++-------- test/parts/_add_part.cxx | 8 ++--- test/plugin_services/_config.cxx | 14 ++++---- test/plugins/_plugin_manager.cxx | 6 ++-- test/region/_region.cxx | 6 ++-- 7 files changed, 58 insertions(+), 53 deletions(-) diff --git a/test/channel/_channel.cxx b/test/channel/_channel.cxx index e1e503b1..97f73970 100644 --- a/test/channel/_channel.cxx +++ b/test/channel/_channel.cxx @@ -28,35 +28,35 @@ TEST(Channel, Validation) ASSERT_THROW(channel.Validate(), Channel::ChannelConfigurationError); channel.UpdateType("pair"); - ASSERT_EQ(channel.Validate(), false); - ASSERT_EQ(channel.IsValid(), false); + ASSERT_FALSE(channel.Validate()); + ASSERT_FALSE(channel.IsValid()); channel.UpdateAddress("bla"); ASSERT_THROW(channel.Validate(), Channel::ChannelConfigurationError); channel.UpdateMethod("connect"); - ASSERT_EQ(channel.Validate(), false); - ASSERT_EQ(channel.IsValid(), false); + ASSERT_FALSE(channel.Validate()); + ASSERT_FALSE(channel.IsValid()); channel.UpdateAddress("ipc://"); - ASSERT_EQ(channel.Validate(), false); - ASSERT_EQ(channel.IsValid(), false); + ASSERT_FALSE(channel.Validate()); + ASSERT_FALSE(channel.IsValid()); channel.UpdateAddress("verbs://"); - ASSERT_EQ(channel.Validate(), false); - ASSERT_EQ(channel.IsValid(), false); + ASSERT_FALSE(channel.Validate()); + ASSERT_FALSE(channel.IsValid()); channel.UpdateAddress("inproc://"); - ASSERT_EQ(channel.Validate(), false); - ASSERT_EQ(channel.IsValid(), false); + ASSERT_FALSE(channel.Validate()); + ASSERT_FALSE(channel.IsValid()); channel.UpdateAddress("tcp://"); - ASSERT_EQ(channel.Validate(), false); - ASSERT_EQ(channel.IsValid(), false); + ASSERT_FALSE(channel.Validate()); + ASSERT_FALSE(channel.IsValid()); channel.UpdateAddress("tcp://localhost:5555"); - ASSERT_EQ(channel.Validate(), true); - ASSERT_EQ(channel.IsValid(), true); + ASSERT_TRUE(channel.Validate()); + ASSERT_TRUE(channel.IsValid()); channel.UpdateSndBufSize(-1); ASSERT_THROW(channel.Validate(), Channel::ChannelConfigurationError); @@ -85,16 +85,16 @@ TEST(Channel, Validation) Channel channel2 = channel; ASSERT_NO_THROW(channel2.Validate()); - ASSERT_EQ(channel2.Validate(), true); - ASSERT_EQ(channel2.IsValid(), true); - ASSERT_EQ(channel2.Validate(), true); + ASSERT_TRUE(channel2.Validate()); + ASSERT_TRUE(channel2.IsValid()); + ASSERT_TRUE(channel2.Validate()); channel2.UpdateName("Kanal"); ASSERT_EQ(channel2.GetName(), "Kanal"); channel2.Invalidate(); - ASSERT_EQ(channel2.IsValid(), false); - ASSERT_EQ(channel2.Validate(), true); + ASSERT_FALSE(channel2.IsValid()); + ASSERT_TRUE(channel2.Validate()); } auto testConnectedPeers(std::string const& transport) diff --git a/test/device/_multiple_devices.cxx b/test/device/_multiple_devices.cxx index 3c00b17d..23dcd3e4 100644 --- a/test/device/_multiple_devices.cxx +++ b/test/device/_multiple_devices.cxx @@ -74,8 +74,8 @@ TEST_F(MultipleDevices, TwoInSameProcess) bool first = fut1.get(); bool second = fut2.get(); - ASSERT_EQ(first, true); - ASSERT_EQ(second, true); + ASSERT_TRUE(first); + ASSERT_TRUE(second); } } // namespace diff --git a/test/memory_resources/_memory_resources.cxx b/test/memory_resources/_memory_resources.cxx index 6d355cd3..7c9a87c1 100644 --- a/test/memory_resources/_memory_resources.cxx +++ b/test/memory_resources/_memory_resources.cxx @@ -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> v(polymorphic_allocator{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(v.data() + v.size()) - reinterpret_cast(v.data()), static_cast(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(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(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 diff --git a/test/parts/_add_part.cxx b/test/parts/_add_part.cxx index 9cb723e4..891b09c5 100644 --- a/test/parts/_add_part.cxx +++ b/test/parts/_add_part.cxx @@ -42,14 +42,14 @@ TEST_F(AddPart, AnotherParts) auto const newSize = oldSize + addedSize; mParts.AddPart(std::move(anotherParts)); - ASSERT_TRUE(mParts.Size() == newSize); + ASSERT_EQ(mParts.Size(), newSize); } TEST_F(AddPart, SinglePart) { auto const oldSize = mParts.Size(); mParts.AddPart(mFactory->NewSimpleMessage("asdf")); - ASSERT_TRUE(mParts.Size() == oldSize + 1); + ASSERT_EQ(mParts.Size(), oldSize + 1); } TEST_F(AddPart, MultipleParts) @@ -58,7 +58,7 @@ TEST_F(AddPart, MultipleParts) mParts.AddPart(mFactory->NewSimpleMessage("1"), mFactory->NewSimpleMessage("2"), mFactory->NewSimpleMessage("3")); - ASSERT_TRUE(mParts.Size() == oldSize + 3); + ASSERT_EQ(mParts.Size(), oldSize + 3); } TEST(Construction, AppendMultipleParts) @@ -67,7 +67,7 @@ TEST(Construction, AppendMultipleParts) fair::mq::Parts newParts(factory->NewSimpleMessage("1"), factory->NewSimpleMessage("2"), factory->NewSimpleMessage("3")); - ASSERT_TRUE(newParts.Size() == 3); + ASSERT_EQ(newParts.Size(), 3U); } } // namespace diff --git a/test/plugin_services/_config.cxx b/test/plugin_services/_config.cxx index 9ece549b..f2ce695a 100644 --- a/test/plugin_services/_config.cxx +++ b/test/plugin_services/_config.cxx @@ -108,14 +108,14 @@ TEST_F(PluginServices, Accessors) mServices.SetProperties(properties); // an existing property should exist - ASSERT_EQ(mServices.PropertyExists("custom1"), true); + ASSERT_TRUE(mServices.PropertyExists("custom1")); // a not existing property should not exists - ASSERT_EQ(mServices.PropertyExists("custom3"), false); + ASSERT_FALSE(mServices.PropertyExists("custom3")); // updating a not existing property should fail - ASSERT_EQ(mServices.UpdateProperty("custom3", 12345), false); + ASSERT_FALSE(mServices.UpdateProperty("custom3", 12345)); mServices.SetProperty("custom3", 12345); // updating an existing existing property should succeed - ASSERT_EQ(mServices.UpdateProperty("custom3", 67890), true); + ASSERT_TRUE(mServices.UpdateProperty("custom3", 67890)); // updated property should return the correct value ASSERT_EQ(mServices.GetProperty("custom3"), 67890); // asking for non existing property should return the fallback if it is provided @@ -137,19 +137,19 @@ TEST_F(PluginServices, Accessors) properties.at("custom3") = 11111; // bulk update should update values of all properties, but only if all of them exist - ASSERT_EQ(mServices.UpdateProperties(properties), true); + ASSERT_TRUE(mServices.UpdateProperties(properties)); ASSERT_EQ(mServices.GetProperty("custom3"), 11111); properties.at("custom3") = 22222; properties.emplace("custom4", 17); // bulk update should fail if any of the properties do not exist in the container ... - ASSERT_EQ(mServices.UpdateProperties(properties), false); + ASSERT_FALSE(mServices.UpdateProperties(properties)); // ... all the values should remain unchanged ASSERT_EQ(mServices.GetProperty("custom3"), 11111); mServices.DeleteProperty("custom3"); // property should no longer exist after deletion - ASSERT_EQ(mServices.PropertyExists("custom3"), false); + ASSERT_FALSE(mServices.PropertyExists("custom3")); // accessing this property should throw an exception ASSERT_THROW(mServices.GetProperty("custom3"), fair::mq::PropertyNotFoundError); diff --git a/test/plugins/_plugin_manager.cxx b/test/plugins/_plugin_manager.cxx index 506d5274..ee27cf62 100644 --- a/test/plugins/_plugin_manager.cxx +++ b/test/plugins/_plugin_manager.cxx @@ -55,7 +55,7 @@ TEST(PluginManager, LoadPluginDynamic) const auto expected = vector{"test_dummy", "test_dummy2"}; auto actual = vector(); mgr.ForEachPlugin([&](Plugin& plugin){ actual.push_back(plugin.GetName()); }); - ASSERT_TRUE(actual == expected); + ASSERT_EQ(actual, expected); // program options auto count = 0; @@ -88,7 +88,7 @@ TEST(PluginManager, LoadPluginStatic) const auto expected = vector{"control"}; auto actual = vector(); mgr.ForEachPlugin([&](Plugin& plugin){ actual.push_back(plugin.GetName()); }); - ASSERT_TRUE(actual == expected); + ASSERT_EQ(actual, expected); // program options auto count = 0; @@ -110,7 +110,7 @@ TEST(PluginManager, Factory) const auto path4 = path{"/lib"}; const auto expected = vector{path1, path2, path3, path4}; // ASSERT_TRUE(static_cast(mgr)); - ASSERT_TRUE(mgr.SearchPaths() == expected); + ASSERT_EQ(mgr.SearchPaths(), expected); } TEST(PluginManager, SearchPathValidation) diff --git a/test/region/_region.cxx b/test/region/_region.cxx index 929aaffb..04fa3d2f 100644 --- a/test/region/_region.cxx +++ b/test/region/_region.cxx @@ -212,7 +212,7 @@ void RegionEventSubscriptions(const string& transport, bool external) } ASSERT_EQ(region2->GetSize(), r2Size); - ASSERT_EQ(factory->SubscribedToRegionEvents(), false); + ASSERT_FALSE(factory->SubscribedToRegionEvents()); factory->SubscribeToRegionEvents([&, id1, id2, ptr1, ptr2](RegionInfo info) { LOG(info) << ">>> " << info.event << ": " << (info.managed ? "managed" : "unmanaged") @@ -241,7 +241,7 @@ void RegionEventSubscriptions(const string& transport, bool external) } } }); - ASSERT_EQ(factory->SubscribedToRegionEvents(), true); + ASSERT_TRUE(factory->SubscribedToRegionEvents()); LOG(info) << "waiting for blockers..."; ASSERT_TRUE(blocker.Wait()); @@ -259,7 +259,7 @@ void RegionEventSubscriptions(const string& transport, bool external) LOG(info) << "All done."; factory->UnsubscribeFromRegionEvents(); - ASSERT_EQ(factory->SubscribedToRegionEvents(), false); + ASSERT_FALSE(factory->SubscribedToRegionEvents()); } void RegionCallbacks(const string& transport, const string& name)