| 1 |
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-3.0-or-later |
| 4 |
|
| 5 |
#include <gtest/gtest.h> |
| 6 |
#include <ddbusinterface.h> |
| 7 |
|
| 8 |
#include "fakedbus/fakedbusservice.h" |
| 9 |
#include <QTest> |
| 10 |
#include <QSignalSpy> |
| 11 |
|
| 12 |
using Dtk::Core::DDBusInterface; |
| 13 |
|
| 14 |
class ut_DDBusInterface : public testing::Test |
| 15 |
{ |
| 16 |
public: |
| 17 |
void SetUp() override |
| 18 |
{ |
| 19 |
m_testservice = new FakeDBusService(); |
| 20 |
m_testDBusInterfaceParent = new FakeDBusServiceParent(); |
| 21 |
// if parent is nullptr |
| 22 |
m_testInterface = new DDBusInterface(FakeDBusService::get_service(), |
| 23 |
FakeDBusService::get_path(), |
| 24 |
FakeDBusService::get_interface(), |
| 25 |
QDBusConnection::sessionBus()); |
| 26 |
} |
| 27 |
void TearDown() override |
| 28 |
{ |
| 29 |
delete m_testDBusInterfaceParent; |
| 30 |
delete m_testInterface; |
| 31 |
delete m_testservice; |
| 32 |
} |
| 33 |
DDBusInterface *m_testInterface; |
| 34 |
FakeDBusService *m_testservice; |
| 35 |
FakeDBusServiceParent *m_testDBusInterfaceParent; |
| 36 |
}; |
| 37 |
|
| 38 |
TEST_F(ut_DDBusInterface, TestProperty) |
| 39 |
{ |
| 40 |
auto objectpaths = m_testservice->objectpaths(); |
| 41 |
EXPECT_EQ(m_testDBusInterfaceParent->objectpaths().length(), objectpaths.length()); |
| 42 |
|
| 43 |
auto strproperty = qvariant_cast<QString>(m_testInterface->property("strProperty")); |
| 44 |
EXPECT_EQ(strproperty, m_testservice->strproperty()); |
| 45 |
} |
| 46 |
|
| 47 |
TEST_F(ut_DDBusInterface, suffix) |
| 48 |
{ |
| 49 |
EXPECT_EQ(m_testInterface->suffix(), ""); |
| 50 |
m_testInterface->setSuffix("-suffix"); |
| 51 |
EXPECT_EQ(m_testInterface->suffix(), "-suffix"); |
| 52 |
} |