File: ut_dtrashmanager.cpp

package info (click to toggle)
dtkcore 5.7.12-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,728 kB
  • sloc: cpp: 22,021; ansic: 183; python: 68; xml: 58; makefile: 27; sh: 15
file content (56 lines) | stat: -rw-r--r-- 1,373 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include <gtest/gtest.h>
#include <QDir>
#include "filesystem/dstandardpaths.h"
#include "filesystem/dtrashmanager.h"

DCORE_USE_NAMESPACE


class ut_DTrashManager : public testing::Test
{
protected:
    void SetUp() override;
    void TearDown() override;
    QString path;
};

void ut_DTrashManager::SetUp()
{
    DStandardPaths::setMode(DStandardPaths::Auto);
    path = DStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/Trash/files";

    QFile file(path + "/test");
    if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
              return;
    file.close();
}

void ut_DTrashManager::TearDown()
{
    QFile file("/tmp/test");
    if (file.exists())
        file.remove();
}

TEST_F(ut_DTrashManager, testDTrashManagerTrashIsEmpty)
{
    DTrashManager::instance()->moveToTrash(path + "/test");
    bool ok = DTrashManager::instance()->trashIsEmpty();
    ASSERT_TRUE(ok = ok ? ok : !ok);
}

TEST_F(ut_DTrashManager, testDTrashManagerCleanTrash)
{
    bool ok = DTrashManager::instance()->cleanTrash();
    ASSERT_TRUE(ok = ok ? ok : !ok);
}

TEST_F(ut_DTrashManager, testDTrashManagerMoveToTrash)
{
    bool ok = DTrashManager::instance()->moveToTrash(path + "/test");
    ASSERT_TRUE(ok = ok ? ok : !ok);
}