File: ut_qdeepintheme.cpp

package info (click to toggle)
dde-qt5integration 5.7.12-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,528 kB
  • sloc: cpp: 12,089; xml: 154; sh: 13; makefile: 10
file content (92 lines) | stat: -rw-r--r-- 2,579 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
 * SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */
#include <gtest/gtest.h>
#include "qdeepintheme.h"
#include "filedialogmanagerservice.h"
#ifndef DIALOG_SERVICE
#define DIALOG_SERVICE "org.deepin.fakefilemanager.filedialog"
#endif

class EnvGuard {
public:
    EnvGuard(const char *name, const QByteArray &value) : m_name{name}
    {
        m_prev = qgetenv(name);
        qputenv(name, value);
    }
    ~EnvGuard()
    {
        qputenv(qPrintable(m_name), m_prev);
    }
private:
    QString m_name;
    QByteArray m_prev;
};

class TestQDeepinTheme : public testing::Test
{
public:
    static void SetUpTestSuite()
    {
        qputenv("_d_fileDialogServiceName", DIALOG_SERVICE);
        theme = new QDeepinTheme;
        managerService = new FileDialogManagerService(DIALOG_SERVICE, "/com/deepin/filemanager/filedialogmanager");
    }

    static void TearDownTestSuite()
    {
        qunsetenv("_d_fileDialogServiceName");
        delete theme;
        delete managerService;
    }

    static QDeepinTheme *theme;
    static FileDialogManagerService *managerService;
};

QDeepinTheme *TestQDeepinTheme::theme = nullptr;
FileDialogManagerService *TestQDeepinTheme::managerService = nullptr;

TEST_F(TestQDeepinTheme, usePlatformNativeDialog)
{
    managerService->m_useFileChooserDialog = true;
    {
        // Test if environment variable take effect
        EnvGuard guard{"_d_disableDBusFileDialog", "false"};
        EXPECT_TRUE(theme->usePlatformNativeDialog(QDeepinTheme::FileDialog));
    }
    {
        EnvGuard guard{"_d_disableDBusFileDialog", "true"};
        EXPECT_FALSE(theme->usePlatformNativeDialog(QDeepinTheme::FileDialog));
    }
    managerService->m_useFileChooserDialog = false;
    {
        EnvGuard guard{"_d_disableDBusFileDialog", "false"};
        EXPECT_FALSE(theme->usePlatformNativeDialog(QDeepinTheme::FileDialog));
    }
    {
        EnvGuard guard{"_d_disableDBusFileDialog", "true"};
        EXPECT_FALSE(theme->usePlatformNativeDialog(QDeepinTheme::FileDialog));
    }
}

TEST_F(TestQDeepinTheme, createPlatformDialogHelper)
{
    managerService->m_useFileChooserDialog = true;
    auto helper = theme->createPlatformDialogHelper(QPlatformTheme::FileDialog);
    EXPECT_NE(nullptr, helper);
}

// Test if right icon engine is choosed
TEST_F(TestQDeepinTheme, createIconEngine)
{
    auto engine = theme->createIconEngine("icon_Layout");
    ASSERT_NE(nullptr, engine);
}

TEST_F(TestQDeepinTheme, settings)
{
    ASSERT_NE(nullptr, theme->settings());
}