DBUS プロキシ API を使用してcall_sync
DBUS からデータを読み込んでおり、今度は単体テストを追加し、そのモックを作成しました。
コードは次のとおりです。
class MockDBusProxy : public IDBusProxy {
public:
MOCK_METHOD(Glib::VariantContainerBase, callDBusMethod,
(const Glib::ustring& busName, const Glib::ustring& objectPath,
const Glib::ustring& interfaceName, const Glib::ustring& methodName,
Glib::VariantContainerBase& tuple, int timeout), (override));
};
class TestSystemOperationsTranslation : public ::testing::Test
{
public:
MockDBusProxy mockDBusProxy;
SystemOperationsTranslation testSysOperations;
TestSystemOperationsTranslation() : testSysOperations(mockDBusProxy) {}
};
bool compareVariantContainers(const Glib::VariantContainerBase& container1, const Glib::VariantContainerBase& container2) {
return container1.equal(container2);;
}
MATCHER_P(VariantContainerEq, expected, "") {
return arg.equal(expected);
}
TEST_F(TestSystemOperationsTranslation, testGetData)
{
Glib::ustring busName = "bus_name";
Glib::ustring objectPath = "object_path";
Glib::ustring interfaceName = "interface_name";
Glib::ustring methodName = "method_name";
Glib::VariantContainerBase tuple;
int timeout = 100; // Example timeout value
// Set expectations on the mock object
Glib::VariantContainerBase expectedReturnValue;
EXPECT_CALL(mockDBusProxy, callDBusMethod(busName, objectPath, interfaceName, methodName, tuple, timeout))
.WillOnce(testing::Invoke([&expectedReturnValue](const Glib::ustring&, const Glib::ustring&, const Glib::ustring&, const Glib::ustring&, const Glib::VariantContainerBase&, int) {
return expectedReturnValue;
}));
// Act
Glib::ustring result = testSysOperations.handleGetData();
std::cout << "result: " << result << std::endl;
// Validate the result using the custom comparison function
//ASSERT_TRUE(compareVariantContainers(tuple, expectedReturnValue));
EXPECT_THAT(tuple, VariantContainerEq(expectedReturnValue));
}
しかし、コンパイルエラーが表示されます。
unit/test/gtest/googletest-src/googletest/include/gtest/gtest-matchers.h:179:60:
error: no match for ‘operator==’ (operand types are ‘const
Glib::VariantContainerBase’ and ‘const VariantContainerEq’) 179 |
bool operator()(const A& a, const B& b) const { return a == b; }
This may be due to the comparison of Glib::VariantContainerBase
objects. The Glib::VariantBase::operator== is declared as private,
causing the compilation error when the compareVariantContainers
function is used for validation.
しかし、どのように解決するのかわかりません。このgiomm
DBUSプロキシAPIを実際にエミュレートできますか?