Debian Codegraph @

tests/controller/test_exporter.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2020 ~ 2021 Uniontech Software Technology Co., Ltd.
3 *
4 * Author: ZhangYong <[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 #include <gtest/gtest.h>
22 #include <gmock/gmock-matchers.h>
23
24 #include <DFileDialog>
25 #include <DSearchEdit>
26
27 #include <QTestEventList>
28 #include <QMap>
29 #include <QObject>
30 #include <QDialog>
31 #include <QStringList>
32 #include <QFileDialog>
33 #include <QDir>
34 #include <QStandardPaths>
35 #include <QDebug>
36 #include <QMimeDatabase>
37 #include <QCommandLineParser>
38
39 #define private public
40 #define protected public
41
42 #include "mainwindow.h"
43 #include "albumcreatedialog.h"
44 #include "test_qtestDefine.h"
45 #include "imginfodialog.h"
46 #include "exporter.h"
47 #include "utils/imageutils.h"
48 #include "utils/unionimage.h"
49 #include "imageengine/imageengineapi.h"
50 #include "ac-desktop-define.h"
51
52 #include <stub-tool/cpp-stub/stub.h>
53 #include <stub-tool/stub-ext/stubext.h>
54
55 struct CMOption {
56 QString shortOption;
57 QString longOption;
58 QString description;
59 QString valueName;
60 };
61
62 TEST(Exporter, test_Exporter_init)
63 {
64 TEST_CASE_NAME("test_Exporter_init")
65 MainWindow *w = dApp->getMainWindow();
66 Q_UNUSED(w)
67 Exporter::instance();
68 }
69
70 TEST(Exporter, exportImage_test)
71 {
72 TEST_CASE_NAME("exportImage_test")
73
74 //根据UT报告,补充测试部分分支
75
76 //列表为空
77 Exporter::instance()->exportImage({});
78
79 //GIF
80 Exporter::instance()->exportImage({ testPath_test + "/9a0a4c97036f61.gif" });
81
82 //多个图片
83 {
84 int (*dlgexec)() = []() {
85 return 1;
86 };
87 typedef int (*fptr)(QDialog *);
88 fptr fptrexec = reinterpret_cast<fptr>(&QDialog::exec); //obtaining an address
89 Stub stub;
90 stub.set(fptrexec, dlgexec);
91 Exporter::instance()->exportImage({ testPath_test + "/9a0a4c97036f61.gif", testPath_test + "/2e5y8y.jpg" });
92 }
93 }
94
95
96 TEST(Exporter, exportAlbum_test)
97 {
98 TEST_CASE_NAME("exportAlbum_test")
99 MainWindow *w = dApp->getMainWindow();
100 QStringList paths;
101 if (DBManager::instance()->getAllPaths().length() > 0)
102 paths << DBManager::instance()->getAllPaths().first();
103 else
104 paths << testPath_test + "/2e5y8y.jpg";
105
106 AlbumView *a = w->m_pAlbumview;
107 // AlbumCreateDialog *ad = new AlbumCreateDialog;
108 // QTest::keyClicks(ad->getEdit(), "exportalbum");
109 // emit ad->buttonClicked(1, "");
110 // QTest::qWait(200);
111 // ImageEngineApi::instance()->ImportImagesFromFileList((paths), "exportalbum", a, true);
112 const QStringList albumPaths;
113 const QString albumnam;
114
115 int (*dlgexec)() = []() {
116 return 1;
117 };
118 typedef int (*fptr)(QDialog *);
119 fptr fptrexec = reinterpret_cast<fptr>(&QDialog::exec); //obtaining an address
120 Stub stub;
121 stub.set(fptrexec, dlgexec);
122
123 stub_ext::StubExt stu;
124 // stu.set_lamda(ADDR(QFileDialog, exec), [](){
125 // return QDialog::Accepted;
126 // });
127
128 QFileInfo fileinfo(paths.first());
129 QDir dir = fileinfo.dir();
130 stu.set_lamda(ADDR(QFileDialog, directory), [dir]() {
131 return dir;
132 });
133 stu.set_lamda(ADDR(QDir, absolutePath), [paths]() {
134 return paths.first();
135 });
136
137 QTestEventList event;
138 event.addMousePress(Qt::MouseButton::LeftButton, Qt::NoModifier, QPoint(10, 10));
139 event.addMouseRelease(Qt::MouseButton::LeftButton, Qt::NoModifier, QPoint(10, 10));
140 event.simulate(a->m_pLeftListView->m_pCustomizeListView->viewport());
141 QTest::qWait(500);
142
143 Exporter::instance()->exportAlbum(paths, "TestAlbum");
144 QTest::qWait(500);
145 }
146
147 TEST(Exporter, popupDialogSaveImage_test)
148 {
149 TEST_CASE_NAME("popupDialogSaveImage_test")
150 MainWindow *w = dApp->getMainWindow();
151 QStringList paths;
152 if (DBManager::instance()->getAllPaths().length() > 0)
153 paths << DBManager::instance()->getAllPaths().first();
154 else
155 paths << testPath_test + "/2e5y8y.jpg";
156
157 AlbumView *a = w->m_pAlbumview;
158
159 int (*dlgexec)() = []() {
160 return 1;
161 };
162 typedef int (*fptr)(QDialog *);
163 fptr fptrexec = reinterpret_cast<fptr>(&QDialog::exec); //obtaining an address
164 Stub stub;
165 stub.set(fptrexec, dlgexec);
166
167 stub_ext::StubExt stu;
168 QFileInfo fileinfo(paths.first());
169 QDir dir = fileinfo.dir();
170 stu.set_lamda(ADDR(QFileDialog, directory), [dir]() {
171 return dir;
172 });
173 stu.set_lamda(ADDR(QDir, absolutePath), [paths]() {
174 return paths.first();
175 });
176
177 Exporter::instance()->popupDialogSaveImage(paths);
178 QTest::qWait(500);
179 }
180
181 TEST(Exporter, initValidFormatMap_test)
182 {
183 TEST_CASE_NAME("initValidFormatMap_test")
184 MainWindow *w = dApp->getMainWindow();
185 w->albumBtnClicked();
186 Exporter::instance()->initValidFormatMap();
187 QTest::qWait(500);
188 }