| 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 | #include <QMap> |
| 24 | #include <DFileDialog> |
| 25 | #include <DSearchEdit> |
| 26 | |
| 27 | #include <QObject> |
| 28 | #include <QDialog> |
| 29 | #include <QStringList> |
| 30 | #include <QTestEventList> |
| 31 | #include <QCommandLineParser> |
| 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 "ac-desktop-define.h" |
| 41 | |
| 42 | #include <stub-tool/cpp-stub/stub.h> |
| 43 | #include <stub-tool/stub-ext/stubext.h> |
| 44 | |
| 45 | struct CMOption { |
| 46 | QString shortOption; |
| 47 | QString longOption; |
| 48 | QString description; |
| 49 | QString valueName; |
| 50 | }; |
| 51 | |
| 52 | TEST(CommandLine, test_CommandLine) |
| 53 | { |
| 54 | TEST_CASE_NAME("test_CommandLine") |
| 55 | // MainWindow *w = dApp->getMainWindow(); |
| 56 | CommandLine::instance(); |
| 57 | QStringList image_list; |
| 58 | auto finfos = utils::image::getImagesAndVideoInfo(testPath_test); |
| 59 | for (auto info : finfos) { |
| 60 | image_list << info.absoluteFilePath(); |
| 61 | } |
| 62 | DBManager::instance()->removeImgInfos(QStringList()); |
| 63 | |
| 64 | QStringList paths; |
| 65 | if (DBManager::instance()->getAllPaths().length() > 0) |
| 66 | paths << DBManager::instance()->getAllPaths().first(); |
| 67 | else |
| 68 | paths << testPath_test + "/2e5y8y.jpg"; |
| 69 | } |
| 70 | |
| 71 | TEST(CommandLine, urltest) |
| 72 | { |
| 73 | TEST_CASE_NAME("urltest") |
| 74 | stub_ext::StubExt stu; |
| 75 | stu.set_lamda(ADDR(QCommandLineParser, addOption), []() { |
| 76 | return false; |
| 77 | }); |
| 78 | CMOption option; |
| 79 | CommandLine::instance()->addOption(&option); |
| 80 | } |
| 81 | |
| 82 | TEST(CommandLine, viewImage_test) |
| 83 | { |
| 84 | TEST_CASE_NAME("viewImage_test") |
| 85 | MainWindow *w = dApp->getMainWindow(); |
| 86 | QStringList paths; |
| 87 | paths << testPath_test + "/2e5y8y.jpg"; |
| 88 | CommandLine::instance()->viewImage(paths.first(), paths); |
| 89 | QTest::qWait(500); |
| 90 | w->allPicBtnClicked(); |
| 91 | QTest::qWait(500); |
| 92 | } |
| 93 | |
| 94 | TEST(CommandLine, processOption_test) |
| 95 | { |
| 96 | TEST_CASE_NAME("processOption_test") |
| 97 | MainWindow *w = dApp->getMainWindow(); |
| 98 | QStringList paths; |
| 99 | |
| 100 | paths << testPath_test + "/2e5y8y.jpg"; |
| 101 | CommandLine::instance()->processOption(paths); |
| 102 | QTest::qWait(500); |
| 103 | w->allPicBtnClicked(); |
| 104 | QTest::qWait(500); |
| 105 | |
| 106 | paths.clear(); |
| 107 | CommandLine::instance()->processOption(paths); |
| 108 | QTest::qWait(500); |
| 109 | } |