if (m_lastSeparator == -1) {
#if defined(Q_OS_WIN)
if (m_filePath.length() >= 2 && m_filePath.at(1) == QLatin1Char(':'))
- return m_filePath.left(2);
+ return QFSFileEngine::currentPath(m_filePath.left(2));
#endif
return QString(QLatin1Char('.'));
}
QString QFileSystemEntry::baseName() const
{
findFileNameSeparators();
-#if defined(Q_OS_WIN)
- if (m_lastSeparator == -1 && m_filePath.length() >= 2 && m_filePath.at(1) == QLatin1Char(':'))
- return m_filePath.mid(2);
-#endif
int length = -1;
if (m_firstDotInFileName >= 0) {
length = m_firstDotInFileName;
if (m_lastSeparator != -1) // avoid off by one
length--;
}
+#if defined(Q_OS_WIN)
+ if (m_lastSeparator == -1 && m_filePath.length() >= 2 && m_filePath.at(1) == QLatin1Char(':'))
+ return m_filePath.mid(2, length - 2);
+#endif
return m_filePath.mid(m_lastSeparator + 1, length);
}
QString QFileSystemEntry::completeBaseName() const
{
findFileNameSeparators();
-#if defined(Q_OS_WIN)
- if (m_lastSeparator == -1 && m_filePath.length() >= 2 && m_filePath.at(1) == QLatin1Char(':'))
- return m_filePath.mid(2);
-#endif
int length = -1;
if (m_firstDotInFileName >= 0) {
length = m_firstDotInFileName + m_lastDotInFileName;
if (m_lastSeparator != -1) // avoid off by one
length--;
}
+#if defined(Q_OS_WIN)
+ if (m_lastSeparator == -1 && m_filePath.length() >= 2 && m_filePath.at(1) == QLatin1Char(':'))
+ return m_filePath.mid(2, length - 2);
+#endif
return m_filePath.mid(m_lastSeparator + 1, length);
}
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
QTest::newRow("c:\\autoexec.bat") << "c:\\autoexec.bat" << "C:/"
<< "autoexec.bat";
+ QTest::newRow("c:autoexec.bat") << QDir::currentPath().left(2) + "autoexec.bat" << QDir::currentPath()
+ << "autoexec.bat";
#endif
QTest::newRow("QTBUG-19995.1") << drivePrefix + "/System/Library/StartupItems/../Frameworks"
<< drivePrefix + "/System/Library"
QString nonCurrentDrivePrefix =
drivePrefix.left(1).compare("X", Qt::CaseInsensitive) == 0 ? QString("Y:") : QString("X:");
+ QTest::newRow("absFilePathWithoutSlash") << drivePrefix + "tmp.txt" << QDir::currentPath() + "/tmp.txt";
QTest::newRow("<current drive>:my.dll") << drivePrefix + "temp/my.dll" << QDir::currentPath() + "/temp/my.dll";
QTest::newRow("<not current drive>:my.dll") << nonCurrentDrivePrefix + "temp/my.dll"
<< nonCurrentDrivePrefix + "/temp/my.dll";
QTest::newRow("relativeFileInSubDir") << "temp/tmp.txt" << "tmp.txt";
#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE))
QTest::newRow("absFilePath") << "c:\\home\\andy\\tmp.txt" << "tmp.txt";
+ QTest::newRow("driveWithNoSlash") << "c:tmp.txt" << "tmp.txt";
#else
QTest::newRow("absFilePath") << "/home/andy/tmp.txt" << "tmp.txt";
#endif
QTest::newRow("absFilePath") << QDir::currentPath() + "/tmp.txt" << false << QDir::currentPath();
QTest::newRow("absFilePathAbsPath") << QDir::currentPath() + "/tmp.txt" << true << QDir::currentPath();
QTest::newRow("resource1") << ":/tst_qfileinfo/resources/file1.ext1" << true << ":/tst_qfileinfo/resources";
+#ifdef Q_OS_WIN
+ QTest::newRow("driveWithSlash") << "C:/file1.ext1.ext2" << true << "C:/";
+ QTest::newRow("driveWithoutSlash") << QDir::currentPath().left(2) + "file1.ext1.ext2" << false << QDir::currentPath();
+#endif
}
void tst_QFileInfo::dir()
QTest::newRow("hidden2") << ".ex.ext2" << "ext2";
QTest::newRow("hidden2") << ".e.ext2" << "ext2";
QTest::newRow("hidden2") << "..ext2" << "ext2";
+#ifdef Q_OS_WIN
+ QTest::newRow("driveWithSlash") << "c:/file1.ext1.ext2" << "ext2";
+ QTest::newRow("driveWithoutSlash") << "c:file1.ext1.ext2" << "ext2";
+#endif
}
void tst_QFileInfo::suffix()
QTest::newRow("data3") << "/path/file.tar" << "tar";
QTest::newRow("resource1") << ":/tst_qfileinfo/resources/file1.ext1" << "ext1";
QTest::newRow("resource2") << ":/tst_qfileinfo/resources/file1.ext1.ext2" << "ext1.ext2";
+#ifdef Q_OS_WIN
+ QTest::newRow("driveWithSlash") << "c:/file1.ext1.ext2" << "ext1.ext2";
+ QTest::newRow("driveWithoutSlash") << "c:file1.ext1.ext2" << "ext1.ext2";
+#endif
}
void tst_QFileInfo::completeSuffix()
QTest::newRow("data4") << "/path/file" << "file";
QTest::newRow("resource1") << ":/tst_qfileinfo/resources/file1.ext1" << "file1";
QTest::newRow("resource2") << ":/tst_qfileinfo/resources/file1.ext1.ext2" << "file1";
+#ifdef Q_OS_WIN
+ QTest::newRow("driveWithSlash") << "c:/file1.ext1.ext2" << "file1";
+ QTest::newRow("driveWithoutSlash") << "c:file1.ext1.ext2" << "file1";
+#endif
}
void tst_QFileInfo::baseName()
QTest::newRow("data4") << "/path/file" << "file";
QTest::newRow("resource1") << ":/tst_qfileinfo/resources/file1.ext1" << "file1";
QTest::newRow("resource2") << ":/tst_qfileinfo/resources/file1.ext1.ext2" << "file1.ext1";
+#ifdef Q_OS_WIN
+ QTest::newRow("driveWithSlash") << "c:/file1.ext1.ext2" << "file1.ext1";
+ QTest::newRow("driveWithoutSlash") << "c:file1.ext1.ext2" << "file1.ext1";
+#endif
}
void tst_QFileInfo::completeBaseName()
dwPrefMaxLen, &dwEntriesRead, &dwTotalEntries);
// Check if the current user is a member of Administrators group
if (nStatus == NERR_Success && pBuf){
- for (int i = 0; i < dwEntriesRead; i++) {
+ for (int i = 0; i < (int)dwEntriesRead; i++) {
QString groupName = QString::fromWCharArray(pBuf[i].lgrui0_name);
if (!groupName.compare(QLatin1String("Administrators")))
userName = groupName;