Fixes to get unit tests to compile
There are 2 CI failures that started showing up at the same time:
1) sdbusplus recenty had a commit that started checking the return code
on sd_bus_add_object_vtable and now 2 tests are getting those fails
in CI, so used the mocked bus objects instead.
2) pel_values_test.cpp fails with:
Expected equality of these values:
"cec_service_network"
Which is: 0x563efae570fc
std::get<registryNamePos>(*s)
Which is: 0x563efae57a64
because it is using EXPECT_EQ to compare to char* values instead of
EXPECT_STREQ. I'm not sure what changed that uncovered this.
Fix them both at the same time as CI won't pass when doing them
separately because of the other error.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I937bd6d6965be5c8aab26f6c539cf30537439e0b
diff --git a/test/extensions_test.cpp b/test/extensions_test.cpp
index d210115..6dfe9be 100644
--- a/test/extensions_test.cpp
+++ b/test/extensions_test.cpp
@@ -1,6 +1,8 @@
#include "elog_entry.hpp"
#include "extensions.hpp"
+#include <sdbusplus/test/sdbus_mock.hpp>
+
#include <gtest/gtest.h>
using namespace phosphor::logging;
@@ -63,7 +65,8 @@
TEST(ExtensionsTest, FunctionCallTest)
{
- auto bus = sdbusplus::bus::new_default();
+ sdbusplus::SdBusMock sdbusMock;
+ sdbusplus::bus::bus bus = sdbusplus::get_mocked_new(&sdbusMock);
internal::Manager manager(bus, "testpath");
EXPECT_EQ(Extensions::getStartupFunctions().size(), 2);
diff --git a/test/openpower-pels/pel_values_test.cpp b/test/openpower-pels/pel_values_test.cpp
index a62e6c5..c71526b 100644
--- a/test/openpower-pels/pel_values_test.cpp
+++ b/test/openpower-pels/pel_values_test.cpp
@@ -24,18 +24,18 @@
{
auto s = findByValue(0x5D, subsystemValues);
ASSERT_NE(s, subsystemValues.end());
- ASSERT_EQ(0x5D, std::get<fieldValuePos>(*s));
- ASSERT_EQ("cec_service_network", std::get<registryNamePos>(*s));
+ EXPECT_EQ(0x5D, std::get<fieldValuePos>(*s));
+ EXPECT_STREQ("cec_service_network", std::get<registryNamePos>(*s));
s = findByName("cec_clocks", subsystemValues);
ASSERT_NE(s, subsystemValues.end());
- ASSERT_EQ(0x58, std::get<fieldValuePos>(*s));
- ASSERT_EQ("cec_clocks", std::get<registryNamePos>(*s));
- ASSERT_EQ("CEC Hardware: Clock", std::get<descriptionPos>(*s));
+ EXPECT_EQ(0x58, std::get<fieldValuePos>(*s));
+ EXPECT_STREQ("cec_clocks", std::get<registryNamePos>(*s));
+ EXPECT_STREQ("CEC Hardware: Clock", std::get<descriptionPos>(*s));
s = findByValue(0xFF, subsystemValues);
- ASSERT_EQ(s, subsystemValues.end());
+ EXPECT_EQ(s, subsystemValues.end());
s = findByName("foo", subsystemValues);
- ASSERT_EQ(s, subsystemValues.end());
+ EXPECT_EQ(s, subsystemValues.end());
}
diff --git a/test/serialization_tests.hpp b/test/serialization_tests.hpp
index 6e41379..7831ce2 100644
--- a/test/serialization_tests.hpp
+++ b/test/serialization_tests.hpp
@@ -6,6 +6,7 @@
#include <experimental/filesystem>
#include <sdbusplus/bus.hpp>
+#include <sdbusplus/test/sdbus_mock.hpp>
#include <gtest/gtest.h>
@@ -19,7 +20,8 @@
namespace fs = std::experimental::filesystem;
char tmplt[] = "/tmp/logging_test.XXXXXX";
-auto bus = sdbusplus::bus::new_default();
+sdbusplus::SdBusMock sdbusMock;
+sdbusplus::bus::bus bus = sdbusplus::get_mocked_new(&sdbusMock);
phosphor::logging::internal::Manager manager(bus, OBJ_INTERNAL);
class TestSerialization : public testing::Test