| 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 <QPrintDialog> |
| 25 | #include <QPrintPreviewDialog> |
| 26 | #include <QPrintPreviewWidget> |
| 27 | #include <QPrinter> |
| 28 | #include <QPainter> |
| 29 | #include <QToolBar> |
| 30 | #include <QCoreApplication> |
| 31 | #include <QImageReader> |
| 32 | #include <QDebug> |
| 33 | #include <QMap> |
| 34 | #include <QTestEventList> |
| 35 | #include <QObject> |
| 36 | #include <QDialog> |
| 37 | #include <QStringList> |
| 38 | |
| 39 | #include <DSearchEdit> |
| 40 | #include <DFileDialog> |
| 41 | |
| 42 | #include <dprintpreviewdialog.h> |
| 43 | #include <dprintpreviewwidget.h> |
| 44 | |
| 45 | #define private public |
| 46 | #define protected public |
| 47 | |
| 48 | #include "mainwindow.h" |
| 49 | #include "albumcreatedialog.h" |
| 50 | #include "test_qtestDefine.h" |
| 51 | #include "imginfodialog.h" |
| 52 | #include "printhelper.h" |
| 53 | #include "ac-desktop-define.h" |
| 54 | #include "utils/unionimage.h" |
| 55 | |
| 56 | #include <stub-tool/cpp-stub/stub.h> |
| 57 | #include <stub-tool/stub-ext/stubext.h> |
| 58 | |
| 59 | TEST(PrintHelper, PrintHelper_test) |
| 60 | { |
| 61 | TEST_CASE_NAME("PrintHelper_test") |
| 62 | MainWindow *w = dApp->getMainWindow(); |
| 63 | w->allPicBtnClicked(); |
| 64 | QTest::qWait(2000); |
| 65 | |
| 66 | int (*dlgexec)() = []() { |
| 67 | return 1; |
| 68 | }; |
| 69 | typedef int (*fptr)(QDialog *); |
| 70 | fptr fptrexec = reinterpret_cast<fptr>(&QDialog::exec); //obtaining an address |
| 71 | Stub stub; |
| 72 | stub.set(fptrexec, dlgexec); |
| 73 | |
| 74 | QStringList paths = DBManager::instance()->getAllPaths(); |
| 75 | QWidget *p = nullptr; |
| 76 | |
| 77 | PrintHelper *p1 = new PrintHelper; |
| 78 | if (paths.size() < 1) |
| 79 | paths << testPath_test + "2k9o1m.png"; |
| 80 | PrintHelper::getIntance()->showPrintDialog(paths, p); |
| 81 | |
| 82 | delete p1;//单元测试也要记得释放内存 |
| 83 | } |