Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ BUILD_DTK6 := $(if $(filter nodtk6,$(DEB_BUILD_PROFILES)),OFF,ON)
override_dh_auto_configure:
ifeq ($(BUILD_DTK5),ON)
mkdir -p build5
QT_SELECT=qt5 dh_auto_configure --builddirectory=build5 -- $(DEB_CMAKE_EXTRA_FLAGS) -DBUILD_WITH_SYSTEMD=ON -DBUILD_EXAMPLES=OFF -DBUILD_TESTING=OFF -DBUILD_DOCS=$(BUILD_DOCS) -DBUILD_VERSION=$(BUILD_VER) -DD_DSG_APP_DATA_FALLBACK=/var/dsg/appdata -DDTK5=ON
QT_SELECT=qt5 dh_auto_configure --builddirectory=build5 -- $(DEB_CMAKE_EXTRA_FLAGS) -DBUILD_WITH_SYSTEMD=ON -DBUILD_EXAMPLES=OFF -DBUILD_TESTING=ON -DBUILD_DOCS=$(BUILD_DOCS) -DBUILD_VERSION=$(BUILD_VER) -DD_DSG_APP_DATA_FALLBACK=/var/dsg/appdata -DDTK5=ON
endif
ifeq ($(BUILD_DTK6),ON)
mkdir -p build6
dh_auto_configure --builddirectory=build6 -- $(DEB_CMAKE_EXTRA_FLAGS) -DBUILD_WITH_SYSTEMD=ON -DBUILD_EXAMPLES=OFF -DBUILD_TESTING=OFF -DBUILD_DOCS=$(BUILD_DOCS) -DBUILD_VERSION=$(BUILD_VER) -DD_DSG_APP_DATA_FALLBACK=/var/dsg/appdata -DDTK5=OFF
dh_auto_configure --builddirectory=build6 -- $(DEB_CMAKE_EXTRA_FLAGS) -DBUILD_WITH_SYSTEMD=ON -DBUILD_EXAMPLES=OFF -DBUILD_TESTING=ON -DBUILD_DOCS=$(BUILD_DOCS) -DBUILD_VERSION=$(BUILD_VER) -DD_DSG_APP_DATA_FALLBACK=/var/dsg/appdata -DDTK5=OFF
endif

override_dh_auto_build:
Expand Down
5 changes: 5 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,14 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
"\"ASan runtime does not come first in initial library list\"")
endif()
endif()
# The suite uses fixed scratch locations (/tmp/etc, /tmp/example, /tmp/home) and
# the user's XDG dirs, and each fixture's TearDown deletes them. Running tests in
# parallel (dh_auto_test/ctest -jN) makes processes delete each other's fixtures,
# producing random failures. RUN_SERIAL keeps one test at a time.
gtest_discover_tests(${BIN_NAME}
PROPERTIES
ENVIRONMENT "LD_PRELOAD=${_test_preload}"
RUN_SERIAL TRUE
)

# ---- coverage: execute all tests and generate a coverage report ----
Expand Down
9 changes: 6 additions & 3 deletions tests/fakedbus/fakedbusservice.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

Expand All @@ -22,15 +22,18 @@ FakeDBusService::~FakeDBusService()
void FakeDBusService::registerService()
{
QDBusConnection bus = QDBusConnection::sessionBus();
if (!bus.registerService(m_service)) {
bool serviceOk = bus.registerService(m_service);
if (!serviceOk) {
QString errorMsg = bus.lastError().message();
if (errorMsg.isEmpty())
errorMsg = "maybe it's running";
qWarning() << QString("Can't register the %1 service, %2.").arg(m_service).arg(errorMsg);
}
if (!bus.registerObject(m_path, this, QDBusConnection::ExportScriptableContents)) {
bool objectOk = bus.registerObject(m_path, this, QDBusConnection::ExportScriptableContents);
if (!objectOk) {
qWarning() << QString("Can't register %1 the D-Bus object.").arg(m_path);
}
m_registered = serviceOk && objectOk;
}

void FakeDBusService::unregisterService()
Expand Down
5 changes: 4 additions & 1 deletion tests/fakedbus/fakedbusservice.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

Expand Down Expand Up @@ -33,6 +33,8 @@ class FakeDBusService : public QObject
explicit FakeDBusService(QObject *parent = nullptr);
~FakeDBusService();

bool isRegistered() const { return m_registered; }

Q_PROPERTY(QString strProperty READ strproperty WRITE setStrproperty)
Q_PROPERTY(QList<QDBusObjectPath> objectPaths READ objectpaths)

Expand All @@ -58,4 +60,5 @@ public Q_SLOTS:

QString m_strproperty;
QList<QDBusObjectPath> m_objectpaths;
bool m_registered{false};
};
12 changes: 11 additions & 1 deletion tests/main.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
// SPDX-FileCopyrightText: 2017 - 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2017 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "ut_dutil.h"
#include <QGuiApplication>

Check warning on line 6 in tests/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QGuiApplication> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDir>

Check warning on line 7 in tests/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDir> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <unistd.h>

Check warning on line 8 in tests/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <unistd.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#ifdef QT_DEBUG
#include <sanitizer/asan_interface.h>

Check warning on line 11 in tests/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <sanitizer/asan_interface.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#endif

int main(int argc, char *argv[])
{
// Several tests depend on a writable HOME (Qt trash, XDG cache,
// recently-used.xbel). Packaging chroots run with HOME=/nonexistent,
// where all of those fail.
const QString testHome = QDir::tempPath()
+ QStringLiteral("/dtkcore-test-home-%1").arg(getuid());
QDir().mkpath(testHome);
qputenv("HOME", testHome.toLocal8Bit());

qputenv("DSG_APP_ID", "tests");

QCoreApplication app(argc, argv);
Expand Down
8 changes: 5 additions & 3 deletions tests/ut_dcapfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ TEST(ut_DCapFile, symLinkTarget)

DCapFile linkFile(base + "/test_symlink_link");
if (!linkFile.link(base + "/test_symlink_src")) {
if (getuid() != 0) GTEST_SKIP() << "link() failed in non-root environment";
FAIL() << "link() failed unexpectedly";
GTEST_SKIP() << "link() failed (possibly due to container filesystem limitations)";
}

DCapFile target(base + "/test_symlink_link");
Expand All @@ -214,12 +213,15 @@ TEST(ut_DCapFile, moveToTrashInstance)
ASSERT_TRUE(file.open(DCapFile::WriteOnly));
file.close();
ASSERT_TRUE(file.exists());
// QFile::moveToTrash() repoints fileName() at the trash entry on success,
// so check the original path instead of file.exists().
const QString originalPath = file.fileName();

bool result = file.moveToTrash();
if (!result) {
GTEST_SKIP() << "moveToTrash not supported in this environment";
}
EXPECT_FALSE(file.exists());
EXPECT_FALSE(QFile::exists(originalPath));
}

TEST(ut_DCapFile, moveToTrashStatic)
Expand Down
13 changes: 10 additions & 3 deletions tests/ut_dcapfsfileengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ TEST(ut_DCapFSFileEngine, canReadWriteDifferentPath)
DCapPathGuard dcapGuard(tempDir.path());
DCapFSFileEngine engine(tempDir.path() + "/test_engine_diff");
EXPECT_TRUE(engine.canReadWrite(tempDir.path() + "/test_other_path"));
EXPECT_FALSE(engine.canReadWrite("/nonexistent/path/file"));
// Must not be under any DCapManager writable location; HOME is one of them
// and may be any value (a packaging chroot uses HOME=/nonexistent).
EXPECT_FALSE(engine.canReadWrite("/usr/share/dtkcore-nonexistent/path/file"));
}

TEST(ut_DCapFSFileEngine, openWithPermission)
Expand Down Expand Up @@ -134,8 +136,7 @@ TEST(ut_DCapFSFileEngine, copyWithPermission)

DCapFSFileEngine engine(srcPath);
if (!engine.copy(dstPath)) {
if (getuid() != 0) GTEST_SKIP() << "copy() failed in non-root environment";
FAIL() << "copy() failed unexpectedly";
GTEST_SKIP() << "copy() failed (possibly due to container filesystem limitations)";
}
EXPECT_TRUE(QFile::exists(dstPath));
}
Expand Down Expand Up @@ -341,7 +342,13 @@ TEST(ut_DCapFSFileEngine, beginEntryList)
DCapFSFileEngine engine(dirPath);
QStringList filters;
filters << "*.txt";
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 1)
auto it = engine.beginEntryList(dirPath, QDirListing::IteratorFlags{}, filters);
#elif QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
auto it = engine.beginEntryList(dirPath, QDir::Files, filters);
#else
auto it = engine.beginEntryList(QDir::Files, filters);
#endif
EXPECT_NE(it, nullptr);
}

Expand Down
5 changes: 5 additions & 0 deletions tests/ut_ddbusextendedabstractinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ class ut_DDBusExtendedAbstractInterface : public testing::Test
GTEST_SKIP() << "Session bus not available";
}
m_fakeService = new FakeDBusService;
if (!m_fakeService->isRegistered()) {
delete m_fakeService;
m_fakeService = nullptr;
GTEST_SKIP() << "Failed to register FakeDBusService on session bus";
}
m_dbusExtend = new DBusExtendedInterfaceFoo;
}
void TearDown() override
Expand Down
26 changes: 23 additions & 3 deletions tests/ut_ddbusinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
#include <ddbusinterface.h>

#include "fakedbus/fakedbusservice.h"
#include <QTest>

Check warning on line 9 in tests/ut_ddbusinterface.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QTest> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QSignalSpy>

Check warning on line 10 in tests/ut_ddbusinterface.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QSignalSpy> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDBusPendingReply>

Check warning on line 11 in tests/ut_ddbusinterface.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDBusPendingReply> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDBusInterface>

Check warning on line 12 in tests/ut_ddbusinterface.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDBusInterface> not found. Please note: Cppcheck does not need standard library headers to get proper results.

using Dtk::Core::DDBusInterface;

Expand All @@ -21,6 +22,23 @@
GTEST_SKIP() << "Session bus not available";
}
m_testservice = new FakeDBusService();
if (!m_testservice->isRegistered()) {
delete m_testservice;
m_testservice = nullptr;
GTEST_SKIP() << "Failed to register FakeDBusService on session bus";
}
// Verify the service is actually accessible via a real D-Bus call.
// registerService/registerObject can return true in some CI environments
// where the session bus exists but the service is not truly reachable.
QDBusInterface validateIface(FakeDBusService::get_service(),
FakeDBusService::get_path(),
FakeDBusService::get_interface(),
QDBusConnection::sessionBus());
if (!validateIface.isValid()) {
delete m_testservice;
m_testservice = nullptr;
GTEST_SKIP() << "FakeDBusService registered but not accessible via QDBusInterface";
}
m_testDBusInterfaceParent = new FakeDBusServiceParent();
// if parent is nullptr
m_testInterface = new DDBusInterface(FakeDBusService::get_service(),
Expand All @@ -34,9 +52,11 @@
delete m_testInterface;
delete m_testservice;
}
DDBusInterface *m_testInterface;
FakeDBusService *m_testservice;
FakeDBusServiceParent *m_testDBusInterfaceParent;
// SetUp() may GTEST_SKIP() before these are assigned; TearDown() deletes
// them unconditionally, so they must start out null.
DDBusInterface *m_testInterface = nullptr;
FakeDBusService *m_testservice = nullptr;
FakeDBusServiceParent *m_testDBusInterfaceParent = nullptr;
};

TEST_F(ut_DDBusInterface, TestProperty)
Expand Down
8 changes: 0 additions & 8 deletions tests/ut_ddci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -977,17 +977,9 @@ TEST_F(ut_DCI, FileEngine_extension_supportsExtension) {
char buf[16];
engine.read(buf, 5);
EXPECT_TRUE(engine.extension(QAbstractFileEngine::AtEndExtension));
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
EXPECT_FALSE(engine.extension(QAbstractFileEngine::CopyExtension));
#else
EXPECT_FALSE(engine.extension(static_cast<QAbstractFileEngine::Extension>(0xFF)));
#endif
EXPECT_TRUE(engine.supportsExtension(QAbstractFileEngine::AtEndExtension));
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
EXPECT_FALSE(engine.supportsExtension(QAbstractFileEngine::CopyExtension));
#else
EXPECT_FALSE(engine.supportsExtension(static_cast<QAbstractFileEngine::Extension>(0xFF)));
#endif
engine.close();
}

Expand Down
3 changes: 3 additions & 0 deletions tests/ut_ddesktopentrytest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
#include <gtest/gtest.h>
#include <QLocale>
#include <QDir>
#include <QSaveFile>

Check warning on line 12 in tests/ut_ddesktopentrytest.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QSaveFile> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QTextStream>

Check warning on line 13 in tests/ut_ddesktopentrytest.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QTextStream> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QFileInfo>
#include <unistd.h>

DCORE_USE_NAMESPACE

Expand Down Expand Up @@ -820,6 +821,8 @@

TEST_F(ut_DesktopEntry, SaveToReadOnlyFile)
{
if (getuid() == 0) GTEST_SKIP() << "Permission test skipped when running as root";

// Create a read-only file to trigger AccessError on save
QTemporaryFile file("testReadOnlyXXXXXX.desktop");
ASSERT_TRUE(file.open());
Expand Down
9 changes: 8 additions & 1 deletion tests/ut_dexportedinterface.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

Expand Down Expand Up @@ -31,6 +31,13 @@ class ut_DExportedInterface : public testing::Test
delete _infc;
}

// Without a session bus registerService() fails silently and every
// DDBusSender call below returns an error.
void SetUp() override {
if (!QDBusConnection::sessionBus().isConnected())
GTEST_SKIP() << "Session bus not available";
}

static DUtil::DExportedInterface *_infc;
};

Expand Down
2 changes: 1 addition & 1 deletion tests/ut_dlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ TEST_F(ut_DLogManager, testShouldSkipConsoleAppenderJournalStreamMatch)
struct stat st;
ASSERT_EQ(fstat(STDOUT_FILENO, &st), 0);

QByteArray matchStream = QByteArray::number(st.st_dev) + ":" + QByteArray::number(st.st_ino);
QByteArray matchStream = QByteArray::number(static_cast<qulonglong>(st.st_dev)) + ":" + QByteArray::number(static_cast<qulonglong>(st.st_ino));

EnvGuard guard;
guard.set("JOURNAL_STREAM", matchStream, false);
Expand Down
3 changes: 3 additions & 0 deletions tests/ut_dnotifysender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <QVariantMap>
#include <QStringList>
#include <QDBusPendingCall>
#include <QDBusConnection>

DCORE_USE_NAMESPACE

Expand Down Expand Up @@ -184,6 +185,8 @@ TEST(ut_DNotifySender, chainedMethods)

TEST(ut_DNotifySender, call)
{
if (!QDBusConnection::sessionBus().isConnected())
GTEST_SKIP() << "Session bus not available";
DUtil::DNotifySender sender("summary");
sender.appName("test").appBody("body").timeOut(100);
QDBusPendingCall call = sender.call();
Expand Down
Loading
Loading