void tst_QFileSystemEntry::defaultCtor() { QFileSystemEntry entry; QVERIFY(entry.filePath().isNull()); QVERIFY(entry.nativeFilePath().isNull()); QVERIFY(entry.fileName().isNull()); QCOMPARE(entry.path(), QString(".")); QVERIFY(entry.baseName().isNull()); QVERIFY(entry.completeBaseName().isNull()); QVERIFY(entry.suffix().isNull()); QVERIFY(entry.completeSuffix().isNull()); QVERIFY(!entry.isAbsolute()); QVERIFY(entry.isRelative()); QVERIFY(entry.isClean()); #if defined(Q_OS_WIN) QVERIFY(!entry.isDriveRoot()); #endif QVERIFY(!entry.isRoot()); QVERIFY(entry.isEmpty()); }
//static QFileSystemEntry QFileSystemEngine::absoluteName(const QFileSystemEntry &entry) { if (entry.isAbsolute() && entry.isClean()) return entry; QByteArray orig = entry.nativeFilePath(); QByteArray result; if (orig.isEmpty() || !orig.startsWith('/')) { QFileSystemEntry cur(currentPath()); result = cur.nativeFilePath(); } if (!orig.isEmpty() && !(orig.length() == 1 && orig[0] == '.')) { if (!result.isEmpty() && !result.endsWith('/')) result.append('/'); result.append(orig); } if (result.length() == 1 && result[0] == '/') return QFileSystemEntry(result, QFileSystemEntry::FromNativePath()); const bool isDir = result.endsWith('/'); /* as long as QDir::cleanPath() operates on a QString we have to convert to a string here. * ideally we never convert to a string since that loses information. Please fix after * we get a QByteArray version of QDir::cleanPath() */ QFileSystemEntry resultingEntry(result, QFileSystemEntry::FromNativePath()); QString stringVersion = QDir::cleanPath(resultingEntry.filePath()); if (isDir) stringVersion.append(QLatin1Char('/')); return QFileSystemEntry(stringVersion); }
//static QFileSystemEntry QFileSystemEngine::absoluteName(const QFileSystemEntry &entry) { QString orig = entry.filePath(); const bool isAbsolute = entry.isAbsolute(); const bool isDirty = !entry.isClean(); if (isAbsolute && !isDirty) return entry; const bool isRelative = entry.isRelative(); const bool needsDrive = (!orig.isEmpty() && orig.at(0).unicode() == '/'); const bool isDriveLetter = !needsDrive && !isAbsolute && !isRelative && orig.length() == 2; const bool isDriveRelative = !needsDrive && !isAbsolute && !isRelative && orig.length() > 2; QString result; if (needsDrive || isDriveLetter || isDriveRelative || !isAbsolute || orig.isEmpty()) { QFileSystemEntry cur(currentPath()); if(needsDrive) result = cur.filePath().left(2); else if(isDriveRelative && cur.filePath().at(0) != orig.at(0)) result = orig.left(2); // for BC, see tst_QFileInfo::absolutePath(<not current drive>:my.dll) else result = cur.filePath(); if(isDriveLetter) { result[0] = orig.at(0); //copy drive letter orig.clear(); } if(isDriveRelative) { orig = orig.mid(2); //discard the drive specifier from orig } } if (!orig.isEmpty() && !(orig.length() == 1 && orig.at(0).unicode() == '.')) { if (!result.isEmpty() && !result.endsWith(QLatin1Char('/'))) result.append(QLatin1Char('/')); result.append(orig); } return QFileSystemEntry(symbianCleanAbsolutePath(result), QFileSystemEntry::FromInternalPath()); }