diff options
Diffstat (limited to 'tests/auto/corelib/io/qlockfile')
4 files changed, 33 insertions, 23 deletions
diff --git a/tests/auto/corelib/io/qlockfile/CMakeLists.txt b/tests/auto/corelib/io/qlockfile/CMakeLists.txt index b10b32b88a..1dda272d52 100644 --- a/tests/auto/corelib/io/qlockfile/CMakeLists.txt +++ b/tests/auto/corelib/io/qlockfile/CMakeLists.txt @@ -1,10 +1,16 @@ # Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qlockfile Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qlockfile LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qlockfile SOURCES tst_qlockfile.cpp diff --git a/tests/auto/corelib/io/qlockfile/qlockfiletesthelper/CMakeLists.txt b/tests/auto/corelib/io/qlockfile/qlockfiletesthelper/CMakeLists.txt index f70aae94b3..c8bde9d606 100644 --- a/tests/auto/corelib/io/qlockfile/qlockfiletesthelper/CMakeLists.txt +++ b/tests/auto/corelib/io/qlockfile/qlockfiletesthelper/CMakeLists.txt @@ -1,14 +1,12 @@ # Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - -# Generated from qlockfile_test_helper.pro. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## qlockfile_test_helper Binary: ##################################################################### -qt_internal_add_test_helper(qlockfile_test_helper # special case - OVERRIDE_OUTPUT_DIRECTORY # special case +qt_internal_add_test_helper(qlockfile_test_helper + OVERRIDE_OUTPUT_DIRECTORY OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/" SOURCES qlockfile_test_helper.cpp diff --git a/tests/auto/corelib/io/qlockfile/qlockfiletesthelper/qlockfile_test_helper.cpp b/tests/auto/corelib/io/qlockfile/qlockfiletesthelper/qlockfile_test_helper.cpp index c8a1f5a447..b990209f32 100644 --- a/tests/auto/corelib/io/qlockfile/qlockfiletesthelper/qlockfile_test_helper.cpp +++ b/tests/auto/corelib/io/qlockfile/qlockfiletesthelper/qlockfile_test_helper.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2013 David Faure <faure+bluesystems@kde.org> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QDebug> #include <QCoreApplication> diff --git a/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp b/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp index f36334db02..b7056e20c9 100644 --- a/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp +++ b/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp @@ -1,7 +1,8 @@ // Copyright (C) 2021 The Qt Company Ltd. // Copyright (C) 2013 David Faure <faure+bluesystems@kde.org> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only +#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses #include <QTest> #include <QtConcurrentRun> @@ -16,6 +17,8 @@ #include <qsysinfo.h> #if defined(Q_OS_UNIX) && !defined(Q_OS_VXWORKS) #include <unistd.h> + +#include <sys/stat.h> // utimensat #include <sys/time.h> #elif defined(Q_OS_WIN) # include <qt_windows.h> @@ -24,6 +27,8 @@ #include <private/qlockfile_p.h> // for getLockFileHandle() +using namespace std::chrono_literals; + class tst_QLockFile : public QObject { Q_OBJECT @@ -94,7 +99,7 @@ void tst_QLockFile::lockUnlock() QVERIFY(lockFile.getLockInfo(&pid, &hostname, &appname)); QCOMPARE(pid, QCoreApplication::applicationPid()); QCOMPARE(appname, qAppName()); - QVERIFY(!lockFile.tryLock(200)); + QVERIFY(!lockFile.tryLock(200ms)); QCOMPARE(int(lockFile.error()), int(QLockFile::LockFailedError)); // Unlock deletes the lock file @@ -339,8 +344,8 @@ void tst_QLockFile::staleLongLockFromBusyProcess() QTRY_VERIFY(QFile::exists(fileName)); QLockFile secondLock(fileName); - secondLock.setStaleLockTime(0); - QVERIFY(!secondLock.tryLock(100)); // never stale + secondLock.setStaleLockTime(0ms); + QVERIFY(!secondLock.tryLock(100ms)); // never stale QCOMPARE(int(secondLock.error()), int(QLockFile::LockFailedError)); qint64 pid; QTRY_VERIFY(secondLock.getLockInfo(&pid, NULL, NULL)); @@ -508,15 +513,15 @@ void tst_QLockFile::corruptedLockFile() } QLockFile secondLock(fileName); - secondLock.setStaleLockTime(100); - QVERIFY(secondLock.tryLock(10000)); + secondLock.setStaleLockTime(100ms); + QVERIFY(secondLock.tryLock(10s)); QCOMPARE(int(secondLock.error()), int(QLockFile::NoError)); } void tst_QLockFile::corruptedLockFileInTheFuture() { -#if !defined(Q_OS_UNIX) - QSKIP("This tests needs utimes"); +#if !defined(Q_OS_UNIX) || defined(Q_OS_VXWORKS) + QSKIP("This test needs utimensat"); #else // This test is the same as the previous one, but the corruption was so there is a corrupted // .rmlock whose timestamp is in the future @@ -528,11 +533,12 @@ void tst_QLockFile::corruptedLockFileInTheFuture() QVERIFY(file.open(QFile::WriteOnly)); } - struct timeval times[2]; - gettimeofday(times, 0); - times[1].tv_sec = (times[0].tv_sec += 600); - times[1].tv_usec = times[0].tv_usec; - utimes(fileName.toLocal8Bit(), times); + struct timespec times[2]; + clock_gettime(CLOCK_REALTIME, times); + times[0].tv_sec += 600; + times[1].tv_sec = times[0].tv_sec; + times[1].tv_nsec = times[0].tv_nsec; + utimensat(0 /* ignored */, fileName.toLocal8Bit(), times, 0); QTest::ignoreMessage(QtInfoMsg, "QLockFile: Lock file '" + fileName.toUtf8() + "' has a modification time in the future"); corruptedLockFile(); @@ -561,7 +567,7 @@ void tst_QLockFile::hostnameChange() { // we should fail to lock QLockFile lock2(lockFile); - QVERIFY(!lock2.tryLock(1000)); + QVERIFY(!lock2.tryLock(1s)); } } @@ -588,7 +594,7 @@ void tst_QLockFile::differentMachines() { // we should fail to lock QLockFile lock2(lockFile); - QVERIFY(!lock2.tryLock(1000)); + QVERIFY(!lock2.tryLock(1s)); } } @@ -617,7 +623,7 @@ void tst_QLockFile::reboot() f.close(); // we should succeed in locking - QVERIFY(lock1.tryLock(0)); + QVERIFY(lock1.tryLock(0ms)); } bool tst_QLockFile::overwritePidInLockFile(const QString &filePath, qint64 pid) |