File indexing completed on 2024-09-15 11:46:59
0001 /* GCompris - DirectoryTest.cpp 0002 * 0003 * SPDX-FileCopyrightText: 2018 Himanshu Vishwakarma <himvish997@gmail.com> 0004 * GCompris (C) 2018 GCompris Developers <gcompris-devel@kde.org> 0005 * 0006 * Authors: 0007 * Himanshu Vishwakarma <himvish997@gmail.com> 0008 * 0009 * SPDX-License-Identifier: GPL-3.0-or-later 0010 */ 0011 0012 #include <QObject> 0013 #include <QTest> 0014 #include <QDir> 0015 0016 #include "src/core/File.h" 0017 #include "src/core/Directory.h" 0018 0019 class DirectoryTest : public QObject 0020 { 0021 public: 0022 Q_OBJECT 0023 private Q_SLOTS: 0024 void GetFilesTest(); 0025 }; 0026 0027 0028 void DirectoryTest::GetFilesTest() 0029 { 0030 // Removing the directory. 0031 // It is required as it may already be present in memory because of unsuccessful test/ interruption 0032 QDir dir("./dummy_directory"); 0033 dir.removeRecursively(); 0034 0035 File file; 0036 QVERIFY(File::mkpath("./dummy_directory")); 0037 0038 Directory directory; 0039 QStringList filelist = directory.getFiles("./dummy_directory"); 0040 // We do not count './' & '../' in directory. 0041 QCOMPARE(filelist.count(), 0); 0042 0043 // Creating the empty file of name file1. 0044 file.write("", "./dummy_directory/file1"); 0045 // Creating the empty directory of name dir1. 0046 File::mkpath("./dummy_directory/dir1"); 0047 filelist = directory.getFiles("./dummy_directory", {"*"}); 0048 QCOMPARE(filelist.count(), 2); 0049 0050 file.write("", "./dummy_directory/file2"); 0051 file.write("", "./dummy_directory/file3"); 0052 File::mkpath("./dummy_directory/dir2"); 0053 File::mkpath("./dummy_directory/dir3"); 0054 filelist = directory.getFiles("./dummy_directory"); 0055 QCOMPARE(filelist.count(), 6); 0056 0057 // Removing the directory. 0058 QVERIFY(File::rmpath("./dummy_directory/file3")); 0059 QVERIFY(File::rmpath("./dummy_directory/file2")); 0060 QVERIFY(!File::rmpath("./dummy_directory/dir3")); 0061 filelist = directory.getFiles("./dummy_directory"); 0062 QCOMPARE(filelist.count(), 4); 0063 dir.removeRecursively(); 0064 } 0065 0066 QTEST_MAIN(DirectoryTest) 0067 #include "DirectoryTest.moc"