Debian Codegraph @

tests/importview/test_importview.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 <QObject>
29 #include <QDialog>
30 #include <QStringList>
31 #include <QMap>
32
33 #define private public
34 #define protected public
35
36 #include "mainwindow.h"
37 #include "albumcreatedialog.h"
38 #include "test_qtestDefine.h"
39 #include "imginfodialog.h"
40 #include "imageengine/imageengineapi.h"
41 #include "ac-desktop-define.h"
42
43 #include <stub-tool/cpp-stub/stub.h>
44 #include <stub-tool/stub-ext/stubext.h>
45
46
47 TEST(ImportView, test_onImprotBtnClicked)
48 {
49 TEST_CASE_NAME("test_onImprotBtnClicked")
50 MainWindow *w = dApp->getMainWindow();
51 w->allPicBtnClicked();
52 QTest::qWait(2000);
53
54 int (*dlgexec)() = []() {return 1;};
55 typedef int (*fptr)(QDialog *);
56 fptr fptrexec = reinterpret_cast<fptr>(&QDialog::exec); //obtaining an address
57 Stub stub;
58 stub.set(fptrexec, dlgexec);
59
60 stub_ext::StubExt stu;
61 stu.set_lamda(ADDR(DFileDialog, selectedFiles), []() {
62 QStringList filelist;
63 filelist << ":/2e5y8y.jpg" << ":/2ejqyx.jpg" << ":/2k9o1m.png";
64 return filelist;
65 });
66 stu.set_lamda(ADDR(ImageEngineApi, ImportImagesFromFileList), []() {
67 QStringList filelist;
68 filelist << ":/2e5y8y.jpg" << ":/2ejqyx.jpg" << ":/2k9o1m.png";
69 return true;
70 });
71
72 QStringList paths;
73 paths << ":/3kp6yv.jpg";
74 w->m_pAllPicView->m_pImportView->onImprotBtnClicked(true, paths);
75 QTest::qWait(500);
76 }
77
78
79 TEST(ImportView, test_onImprotBtnClicked_empty)
80 {
81 TEST_CASE_NAME("test_onImprotBtnClicked_empty")
82 MainWindow *w = dApp->getMainWindow();
83 w->allPicBtnClicked();
84 QTest::qWait(2000);
85
86 int (*dlgexec)() = []() {return 1;};
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
92 stub_ext::StubExt stu;
93 stu.set_lamda(ADDR(DFileDialog, selectedFiles), []() {
94 QStringList filelist;
95 return filelist;
96 });
97 stu.set_lamda(ADDR(ImageEngineApi, ImportImagesFromFileList), []() {
98 QStringList filelist;
99 filelist << ":/2e5y8y.jpg" << ":/2ejqyx.jpg" << ":/2k9o1m.png";
100 return true;
101 });
102
103 QStringList paths;
104 w->m_pAllPicView->m_pImportView->onImprotBtnClicked(false, paths);
105 QTest::qWait(500);
106 }