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

@@ -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)

View File

@@ -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

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

View File

@@ -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

View File

@@ -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<int>("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<int>("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<int>("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<int>("custom3"), fair::mq::PropertyNotFoundError);

View File

@@ -55,7 +55,7 @@ TEST(PluginManager, LoadPluginDynamic)
const auto expected = vector<string>{"test_dummy", "test_dummy2"};
auto actual = vector<string>();
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<string>{"control"};
auto actual = vector<string>();
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<path>{path1, path2, path3, path4};
// ASSERT_TRUE(static_cast<bool>(mgr));
ASSERT_TRUE(mgr.SearchPaths() == expected);
ASSERT_EQ(mgr.SearchPaths(), expected);
}
TEST(PluginManager, SearchPathValidation)

View File

@@ -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)