Debian Codegraph @

tests/ut_dtrashmanager.cpp

raw
1 // SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd.
2 //
3 // SPDX-License-Identifier: LGPL-3.0-or-later
4
5 #include <gtest/gtest.h>
6 #include <QDir>
7 #include "filesystem/dstandardpaths.h"
8 #include "filesystem/dtrashmanager.h"
9
10 DCORE_USE_NAMESPACE
11
12
13 class ut_DTrashManager : public testing::Test
14 {
15 protected:
16 void SetUp() override;
17 void TearDown() override;
18 QString path;
19 };
20
21 void ut_DTrashManager::SetUp()
22 {
23 DStandardPaths::setMode(DStandardPaths::Auto);
24 path = DStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/Trash/files";
25
26 QFile file(path + "/test");
27 if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
28 return;
29 file.close();
30 }
31
32 void ut_DTrashManager::TearDown()
33 {
34 QFile file("/tmp/test");
35 if (file.exists())
36 file.remove();
37 }
38
39 TEST_F(ut_DTrashManager, testDTrashManagerTrashIsEmpty)
40 {
41 DTrashManager::instance()->moveToTrash(path + "/test");
42 bool ok = DTrashManager::instance()->trashIsEmpty();
43 ASSERT_TRUE(ok = ok ? ok : !ok);
44 }
45
46 TEST_F(ut_DTrashManager, testDTrashManagerCleanTrash)
47 {
48 bool ok = DTrashManager::instance()->cleanTrash();
49 ASSERT_TRUE(ok = ok ? ok : !ok);
50 }
51
52 TEST_F(ut_DTrashManager, testDTrashManagerMoveToTrash)
53 {
54 bool ok = DTrashManager::instance()->moveToTrash(path + "/test");
55 ASSERT_TRUE(ok = ok ? ok : !ok);
56 }