From: Ivailo Monev Date: Thu, 3 Nov 2022 13:22:23 +0000 (+0200) Subject: fetch the owner and group from the QFile file descriptor in QFileInof tests X-Git-Tag: 4.12.0~232 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=7f04979b7e9e6d1d033a2615d574a65378bef26c;p=kde%2FKatie.git fetch the owner and group from the QFile file descriptor in QFileInof tests much more reliable comparison Signed-off-by: Ivailo Monev --- diff --git a/tests/auto/qfileinfo/tst_qfileinfo.cpp b/tests/auto/qfileinfo/tst_qfileinfo.cpp index 1fa8fea35..2f022b10a 100644 --- a/tests/auto/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/qfileinfo/tst_qfileinfo.cpp @@ -974,10 +974,7 @@ void tst_QFileInfo::detachingOperations() void tst_QFileInfo::owner() { - struct passwd *pw = ::getpwuid(::geteuid()); - QVERIFY(pw); - QString expected = QString::fromLocal8Bit(pw->pw_name); - QVERIFY(!expected.isEmpty()); + QString expected; QString fileName("ownertest.txt"); QVERIFY(!QFile::exists(fileName) || QFile::remove(fileName)); @@ -986,6 +983,13 @@ void tst_QFileInfo::owner() QVERIFY(testFile.open(QIODevice::WriteOnly | QIODevice::Text)); QByteArray testData("testfile"); QVERIFY(testFile.write(testData) != -1); + + QT_STATBUF statbuf; + QVERIFY(QT_FSTAT(testFile.handle(), &statbuf) == 0); + struct passwd *pw = ::getpwuid(statbuf.st_uid); + QVERIFY(pw); + expected = QString::fromLocal8Bit(pw->pw_name); + QVERIFY(!expected.isEmpty()); } QFileInfo fi(fileName); QVERIFY(fi.exists()); @@ -996,20 +1000,25 @@ void tst_QFileInfo::owner() void tst_QFileInfo::group() { - struct group *gr = ::getgrgid(::getegid()); - QVERIFY(gr); - QString expected = QString::fromLocal8Bit(gr->gr_name); - QVERIFY(!expected.isEmpty()); + QString expected; QString fileName("ownertest.txt"); - QFile testFile(fileName); - QVERIFY(testFile.open(QIODevice::WriteOnly | QIODevice::Text)); - QByteArray testData("testfile"); - QVERIFY(testFile.write(testData) != -1); - testFile.close(); + QVERIFY(!QFile::exists(fileName) || QFile::remove(fileName)); + { + QFile testFile(fileName); + QVERIFY(testFile.open(QIODevice::WriteOnly | QIODevice::Text)); + QByteArray testData("testfile"); + QVERIFY(testFile.write(testData) != -1); + + QT_STATBUF statbuf; + QVERIFY(QT_FSTAT(testFile.handle(), &statbuf) == 0); + struct group *gr = ::getgrgid(statbuf.st_gid); + QVERIFY(gr); + expected = QString::fromLocal8Bit(gr->gr_name); + QVERIFY(!expected.isEmpty()); + } QFileInfo fi(fileName); QVERIFY(fi.exists()); - QCOMPARE(fi.group(), expected); QFile::remove(fileName);