Debian Codegraph @

tests/albumview/mock_mount.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2020 ~ 2021 Uniontech Software Technology Co., Ltd.
3 *
4 * Author: WangZhengYang <[email protected]>
5 *
6 * Maintainer: ZhangYong <[email protected]>
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include "mock_mount.h"
23 #include "stub-tool/cpp-stub/stub.h"
24 #include "stub-tool/cpp-stub/addr_any.h"
25
26 #include <dgiomount.h>
27 #include <dgiofile.h>
28 #include <dgiovolumemanager.h>
29
30 QString Mock_Mount::mountPoint;
31
32 Mock_Mount::Mock_Mount(const QString &mountPoint)
33 {
34 this->mountPoint = mountPoint;
35
36 //以下代码顺序不能调换
37 stub = new Stub;
38 initMountMock();
39 }
40
41 Mock_Mount::~Mock_Mount()
42 {
43 delete stub;
44 }
45
46 void Mock_Mount::initMountMock()
47 {
48 //基础函数替换
49 stub->set(&DGioMount::name, &Mock_Mount::stub_DGioMount_name);
50 stub->set(&DGioMount::getRootFile, &Mock_Mount::stub_DGioMount_getRootFile);
51 stub->set(&DGioMount::getDefaultLocationFile, &Mock_Mount::stub_DGioMount_getDefaultLocationFile);
52 stub->set(&DGioMount::canEject, &Mock_Mount::stub_DGioMount_canEject);
53 stub->set(&DGioFile::uri, &Mock_Mount::stub_DGioFile_uri);
54 stub->set(&DGioFile::path, &Mock_Mount::stub_DGioFile_path);
55 stub->set(&DGioVolumeManager::getMounts, &Mock_Mount::stub_DGioVolumeManager_getMounts);
56 }
57
58 void Mock_Mount::setToUmountDevice()
59 {
60 stub->reset(&DGioVolumeManager::getMounts);
61 }
62
63 QString Mock_Mount::stub_DGioMount_name()
64 {
65 return "Journey";
66 }
67
68 QExplicitlySharedDataPointer<DGioFile> Mock_Mount::stub_DGioMount_getRootFile()
69 {
70 return QExplicitlySharedDataPointer<DGioFile>(nullptr);
71 }
72
73 bool Mock_Mount::stub_DGioMount_canEject() const
74 {
75 return true;
76 }
77
78 QExplicitlySharedDataPointer<DGioFile> Mock_Mount::stub_DGioMount_getDefaultLocationFile()
79 {
80 return QExplicitlySharedDataPointer<DGioFile>(nullptr);
81 }
82
83 QString Mock_Mount::stub_DGioFile_uri()
84 {
85 return "file:///" + mountPoint;
86 }
87
88 QString Mock_Mount::stub_DGioFile_path()
89 {
90 return mountPoint;
91 }
92
93 const QList<QExplicitlySharedDataPointer<DGioMount>> Mock_Mount::stub_DGioVolumeManager_getMounts() //这个是静态函数
94 {
95 return QList<QExplicitlySharedDataPointer<DGioMount>> {QExplicitlySharedDataPointer<DGioMount>(nullptr)};
96 }