| 1 | // SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. |
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-only |
| 4 | |
| 5 | #include "filesystemtest.h" |
| 6 | #include <QFile> |
| 7 | #include <QDir> |
| 8 | #include <QDebug> |
| 9 | |
| 10 | // Sets up the test fixture. |
| 11 | void FileSystemTest::SetUp() |
| 12 | { |
| 13 | m_fileA = "/tmp/lls.txt"; |
| 14 | m_fileB = "/tmp/llls.txt"; |
| 15 | m_dir = "/tmp/testDir"; |
| 16 | QStringList list; |
| 17 | list << m_fileA << m_fileB; |
| 18 | for (int i = 0; i < list.size(); ++i) { |
| 19 | QFile f(list[i]); |
| 20 | if (!f.open(QIODevice::ReadWrite)) { |
| 21 | return; |
| 22 | } |
| 23 | f.write("test"); |
| 24 | f.close(); |
| 25 | } |
| 26 | |
| 27 | QDir dir; |
| 28 | dir.mkdir(m_dir); |
| 29 | |
| 30 | } |
| 31 | |
| 32 | // Tears down the test fixture. |
| 33 | void FileSystemTest::TearDown() |
| 34 | { |
| 35 | QFile fileA(m_fileA); |
| 36 | QFile fileB(m_fileB); |
| 37 | if (fileA.exists() || fileB.exists()) { |
| 38 | QFile::remove(m_fileA); |
| 39 | QFile::remove(m_fileB); |
| 40 | } |
| 41 | QDir dir(m_dir); |
| 42 | if (dir.exists()) { |
| 43 | dir.rmdir(m_dir); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | TEST_F(FileSystemTest,fileTest) |
| 48 | { |
| 49 | QFile fileA(m_fileA); |
| 50 | QFile fileB(m_fileB); |
| 51 | |
| 52 | |
| 53 | if (fileA.exists() || fileB.exists()) { |
| 54 | QByteArray bateArray = "hhhhh"; |
| 55 | EXPECT_TRUE(XSys::FS::InsertFileData(m_fileA,bateArray)); |
| 56 | EXPECT_TRUE(XSys::FS::InsertFile(m_fileA,m_fileB)); |
| 57 | |
| 58 | EXPECT_TRUE(XSys::FS::CpFile(m_fileA,m_fileB)); |
| 59 | |
| 60 | QStringList fileList; |
| 61 | fileList << "/tmp/a.txt" << "/tmp/b.txt"; |
| 62 | QString ret = XSys::FS::PathSearch(m_fileA,fileList); |
| 63 | qInfo() << "ret = " << ret; |
| 64 | ret = XSys::FS::SearchBin(m_fileB); |
| 65 | |
| 66 | EXPECT_TRUE(XSys::FS::RmFile(m_fileA)); |
| 67 | EXPECT_TRUE(XSys::FS::RmFile(fileB)); |
| 68 | |
| 69 | QString newDir = "/tmp/dirTest"; |
| 70 | EXPECT_TRUE(XSys::FS::MoveDir(m_dir,newDir)); |
| 71 | |
| 72 | EXPECT_TRUE(XSys::FS::RmDir(newDir)); |
| 73 | |
| 74 | |
| 75 | } |
| 76 | |
| 77 | |
| 78 | } |
| 79 | |
| 80 | //TEST_F(FileSystemTest,RmFile) |
| 81 | //{ |
| 82 | // EXPECT_TRUE(XSys::FS::RmFile("~/ls.txt")); |
| 83 | //} |
| 84 | |
| 85 | //TEST_F(FileSystemTest,RmFileQFile) |
| 86 | //{ |
| 87 | // QFile f("~/hello.txt"); |
| 88 | // EXPECT_TRUE(XSys::FS::RmFile(f)); |
| 89 | //} |
| 90 | |
| 91 | //// 文件复制 需要两个文件都存在 才能复制 |
| 92 | //TEST_F(FileSystemTest,CpFile) |
| 93 | //{ |
| 94 | // QString fileA = "~/hello.txt"; |
| 95 | // QString fileB = "~/test/fileB/hi.txt"; |
| 96 | // EXPECT_TRUE(XSys::FS::CpFile(fileA,fileB)); |
| 97 | //} |
| 98 | |
| 99 | //TEST_F(FileSystemTest,RmDir) |
| 100 | //{ |
| 101 | // QString dirPath = "~/test/testDir"; |
| 102 | // EXPECT_TRUE(XSys::FS::RmDir(dirPath)); |
| 103 | //} |
| 104 | |
| 105 | |
| 106 | //TEST_F(FileSystemTest,MoveDir) |
| 107 | //{ |
| 108 | // QString oldName = "~/test/oldname"; |
| 109 | // QString newName = "~/test/newname/dir"; |
| 110 | // EXPECT_TRUE(XSys::FS::MoveDir(oldName,newName)); |
| 111 | //} |
| 112 | |
| 113 | //TEST_F(FileSystemTest,PathSearch) |
| 114 | //{ |
| 115 | //#define TESTDIR "~/test/" |
| 116 | //#define DIR "~/" |
| 117 | // QString file = TESTDIR"a.txt"; |
| 118 | // QStringList fileList; |
| 119 | // fileList << DIR << TESTDIR; |
| 120 | // QString ret = XSys::FS::PathSearch(file,fileList); |
| 121 | // qInfo() << "ret = " << ret; |
| 122 | //} |
| 123 | |
| 124 | //TEST_F(FileSystemTest,SearchBin) |
| 125 | //{ |
| 126 | // QString bin = TESTDIR"z.txt"; |
| 127 | // QString ret = XSys::FS::SearchBin(bin); |
| 128 | // qInfo() << "ret = " << ret; |
| 129 | //} |
| 130 | |
| 131 | //TEST_F(FileSystemTest,InsertFileData) |
| 132 | //{ |
| 133 | // QString file = TESTDIR"a.txt"; |
| 134 | // QByteArray bateArray = "hhhhh"; |
| 135 | // EXPECT_TRUE(XSys::FS::InsertFileData(file,bateArray)); |
| 136 | //} |
| 137 | |
| 138 | //TEST_F(FileSystemTest,InsertFile) |
| 139 | //{ |
| 140 | // QString fileA = TESTDIR"a.txt"; |
| 141 | // QString fileB = TESTDIR"c.txt"; |
| 142 | // EXPECT_TRUE(XSys::FS::InsertFile(fileA,fileB)); |
| 143 | //} |
| 144 | |
| 145 | //TEST_F(FileSystemTest,TmpFilePath) |
| 146 | //{ |
| 147 | // QString file = TESTDIR"a.txt"; |
| 148 | // QString ret = XSys::FS::TmpFilePath(file); |
| 149 | // qInfo() << "ret = " << ret; |
| 150 | //} |
| 151 | |
| 152 | //TEST_F(FileSystemTest,InsertTmpFile) |
| 153 | //{ |
| 154 | // QString file = TESTDIR"a.txt"; |
| 155 | // QString ret = XSys::FS::InsertTmpFile(file); |
| 156 | // qInfo() << "ret = " << ret; |
| 157 | //} |
| 158 |