| 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 <QMap> |
| 25 | #include <QTestEventList> |
| 26 | #include <QObject> |
| 27 | #include <QDialog> |
| 28 | #include <QStringList> |
| 29 | #include <QFileInfo> |
| 30 | |
| 31 | #include <DSearchEdit> |
| 32 | #include <DFileDialog> |
| 33 | |
| 34 | #define private public |
| 35 | #define protected public |
| 36 | |
| 37 | #include "mainwindow.h" |
| 38 | #include "albumcreatedialog.h" |
| 39 | #include "test_qtestDefine.h" |
| 40 | #include "imginfodialog.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 | TEST(CExportImageDialog, showQuestionDialog_test) |
| 47 | { |
| 48 | TEST_CASE_NAME("showQuestionDialog_test") |
| 49 | MainWindow *w = dApp->getMainWindow(); |
| 50 | w->allPicBtnClicked(); |
| 51 | QTest::qWait(2000); |
| 52 | |
| 53 | CExportImageDialog *expdlg0 = new CExportImageDialog; |
| 54 | |
| 55 | int (*dlgexec)() = []() {return 1;}; |
| 56 | typedef int (*fptr)(QDialog *); |
| 57 | fptr fptrexec = reinterpret_cast<fptr>(&QDialog::exec); //obtaining an address |
| 58 | Stub stub; |
| 59 | stub.set(fptrexec, dlgexec); |
| 60 | |
| 61 | QString path; |
| 62 | if (DBManager::instance()->getAllPaths().length() > 0) |
| 63 | path = DBManager::instance()->getAllPaths().first(); |
| 64 | else |
| 65 | path = testPath_test + "/2e5y8y.jpg"; |
| 66 | QString srcpath = path; |
| 67 | expdlg0->showQuestionDialog(path, srcpath); |
| 68 | } |
| 69 | |
| 70 | // |
| 71 | TEST(CExportImageDialog, showDirChoseDialog_test) |
| 72 | { |
| 73 | TEST_CASE_NAME("showDirChoseDialog_test") |
| 74 | MainWindow *w = dApp->getMainWindow(); |
| 75 | w->allPicBtnClicked(); |
| 76 | QTest::qWait(2000); |
| 77 | |
| 78 | int (*dlgexec)() = []() {return 1;}; |
| 79 | typedef int (*fptr)(QDialog *); |
| 80 | fptr fptrexec = reinterpret_cast<fptr>(&QDialog::exec); //obtaining an address |
| 81 | Stub stub; |
| 82 | stub.set(fptrexec, dlgexec); |
| 83 | |
| 84 | stub_ext::StubExt stu; |
| 85 | stu.set_lamda(ADDR(DFileDialog, selectedFiles), []() { |
| 86 | QStringList filelist; |
| 87 | filelist << ":/2e5y8y.jpg" << ":/2ejqyx.jpg" << ":/2k9o1m.png"; |
| 88 | return filelist; |
| 89 | }); |
| 90 | |
| 91 | CExportImageDialog *expdlg1 = new CExportImageDialog; |
| 92 | |
| 93 | expdlg1->showDirChoseDialog(); |
| 94 | } |
| 95 | |
| 96 | TEST(CExportImageDialog, showEmptyWarningDialog_test) |
| 97 | { |
| 98 | TEST_CASE_NAME("showEmptyWarningDialog_test") |
| 99 | MainWindow *w = dApp->getMainWindow(); |
| 100 | w->allPicBtnClicked(); |
| 101 | QTest::qWait(500); |
| 102 | |
| 103 | CExportImageDialog *expdlg2 = new CExportImageDialog; |
| 104 | |
| 105 | expdlg2->showEmptyWarningDialog(); |
| 106 | } |
| 107 | TEST(CExportImageDialog, CExportImageDialog_func) |
| 108 | { |
| 109 | TEST_CASE_NAME("CExportImageDialog_func") |
| 110 | MainWindow *w = dApp->getMainWindow(); |
| 111 | w->allPicBtnClicked(); |
| 112 | QTest::qWait(500); |
| 113 | |
| 114 | CExportImageDialog *expdlg3 = new CExportImageDialog; |
| 115 | |
| 116 | expdlg3->slotOnQualityChanged(1); |
| 117 | |
| 118 | int index = 0; |
| 119 | QString text = "hello"; |
| 120 | stub_ext::StubExt stu; |
| 121 | stu.set_lamda(ADDR(CExportImageDialog, doSave), []() { |
| 122 | return true; |
| 123 | }); |
| 124 | |
| 125 | expdlg3->slotOnQuestionDialogButtonClick(index, text); |
| 126 | } |
| 127 | |
| 128 | TEST(CExportImageDialog, slotOnDialogButtonClick_test) |
| 129 | { |
| 130 | TEST_CASE_NAME("slotOnDialogButtonClick_test") |
| 131 | MainWindow *w = dApp->getMainWindow(); |
| 132 | w->allPicBtnClicked(); |
| 133 | QTest::qWait(500); |
| 134 | |
| 135 | CExportImageDialog *expdlg4 = new CExportImageDialog; |
| 136 | |
| 137 | int index = 1; |
| 138 | QString text = "hello"; |
| 139 | stub_ext::StubExt stu; |
| 140 | stu.set_lamda(ADDR(CExportImageDialog, showDirChoseDialog), []() { |
| 141 | return; |
| 142 | }); |
| 143 | |
| 144 | expdlg4->slotOnDialogButtonClick(index, text); |
| 145 | QTest::qWait(50); |
| 146 | expdlg4->setGifType(text); |
| 147 | QTest::qWait(50); |
| 148 | expdlg4->removeGifType(); |
| 149 | QTest::qWait(50); |
| 150 | |
| 151 | for (int i = 0; i < 8; i++) { |
| 152 | expdlg4->slotOnSavePathChange(i); |
| 153 | } |
| 154 | QTest::qWait(500); |
| 155 | } |
| 156 | |
| 157 | TEST(CExportImageDialog, doSave_test) |
| 158 | { |
| 159 | TEST_CASE_NAME("doSave_test") |
| 160 | MainWindow *w = dApp->getMainWindow(); |
| 161 | w->allPicBtnClicked(); |
| 162 | QTest::qWait(500); |
| 163 | |
| 164 | CExportImageDialog *expdlg = new CExportImageDialog; |
| 165 | |
| 166 | stub_ext::StubExt stu; |
| 167 | stu.set_lamda(ADDR(QComboBox, currentText), []() { |
| 168 | return "gif"; |
| 169 | }); |
| 170 | |
| 171 | expdlg->doSave(); |
| 172 | } |