/**************************************************************************** ** ** Copyright (C) 2014 Ivan Komissarov ** Contact: http://www.qt-project.org/legal ** ** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and Digia. For licensing terms and ** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Digia gives you certain additional ** rights. These rights are described in the Digia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3.0 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU General Public License version 3.0 requirements will be ** met: http://www.gnu.org/copyleft/gpl.html. ** ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include #include class tst_QStorageInfo : public QObject { Q_OBJECT private slots: void defaultValues(); void operatorEqual(); #ifndef Q_OS_WINRT void operatorNotEqual(); void root(); void currentStorage(); void storageList(); void tempFile(); void caching(); #endif }; void tst_QStorageInfo::defaultValues() { QStorageInfo storage; QVERIFY(!storage.isValid()); QVERIFY(!storage.isReady()); QVERIFY(storage.rootPath().isEmpty()); QVERIFY(!storage.isRoot()); QVERIFY(storage.device().isEmpty()); QVERIFY(storage.fileSystemType().isEmpty()); QVERIFY(storage.bytesTotal() == 0); QVERIFY(storage.bytesFree() == 0); QVERIFY(storage.bytesAvailable() == 0); } void tst_QStorageInfo::operatorEqual() { { QStorageInfo storage1 = QStorageInfo::root(); QStorageInfo storage2(QDir::rootPath()); QVERIFY(storage1 == storage2); } { QStorageInfo storage1(QCoreApplication::applicationDirPath()); QStorageInfo storage2(QCoreApplication::applicationFilePath()); QVERIFY(storage1 == storage2); } { QStorageInfo storage1; QStorageInfo storage2; QVERIFY(storage1 == storage2); } } #ifndef Q_OS_WINRT void tst_QStorageInfo::operatorNotEqual() { QStorageInfo storage1 = QStorageInfo::root(); QStorageInfo storage2; QVERIFY(storage1 != storage2); } void tst_QStorageInfo::root() { QStorageInfo storage = QStorageInfo::root(); QVERIFY(storage.isValid()); QVERIFY(storage.isReady()); QCOMPARE(storage.rootPath(), QDir::rootPath()); QVERIFY(storage.isRoot()); QVERIFY(!storage.device().isEmpty()); QVERIFY(!storage.fileSystemType().isEmpty()); QVERIFY(storage.bytesTotal() > 0); QVERIFY(storage.bytesFree() > 0); QVERIFY(storage.bytesAvailable() > 0); } void tst_QStorageInfo::currentStorage() { QString appPath = QCoreApplication::applicationFilePath(); QStorageInfo storage(appPath); QVERIFY(storage.isValid()); QVERIFY(storage.isReady()); QVERIFY(appPath.startsWith(storage.rootPath(), Qt::CaseInsensitive)); QVERIFY(!storage.device().isEmpty()); QVERIFY(!storage.fileSystemType().isEmpty()); QVERIFY(storage.bytesTotal() > 0); QVERIFY(storage.bytesFree() > 0); QVERIFY(storage.bytesAvailable() > 0); } void tst_QStorageInfo::storageList() { QStorageInfo root = QStorageInfo::root(); QList volumes = QStorageInfo::mountedVolumes(); // at least, root storage should be present QVERIFY(volumes.contains(root)); volumes.removeOne(root); QVERIFY(!volumes.contains(root)); foreach (const QStorageInfo &storage, volumes) { if (!storage.isReady()) continue; QVERIFY(storage.isValid()); QVERIFY(!storage.isRoot()); #ifndef Q_OS_WIN QVERIFY(!storage.device().isEmpty()); QVERIFY(!storage.fileSystemType().isEmpty()); #endif } } void tst_QStorageInfo::tempFile() { QTemporaryFile file; QVERIFY(file.open()); QStorageInfo storage1(file.fileName()); qint64 free = storage1.bytesFree(); file.write(QByteArray(1024*1024, '1')); file.flush(); file.close(); QStorageInfo storage2(file.fileName()); QVERIFY(free != storage2.bytesFree()); } void tst_QStorageInfo::caching() { QTemporaryFile file; QVERIFY(file.open()); QStorageInfo storage1(file.fileName()); qint64 free = storage1.bytesFree(); QStorageInfo storage2(storage1); QVERIFY(free == storage2.bytesFree()); file.write(QByteArray(1024*1024, '\0')); file.flush(); QVERIFY(free == storage1.bytesFree()); QVERIFY(free == storage2.bytesFree()); storage2.refresh(); QVERIFY(storage1 == storage2); QVERIFY(free != storage2.bytesFree()); } #endif QTEST_MAIN(tst_QStorageInfo) #include "tst_qstorageinfo.moc"