| 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 <QTestEventList> |
| 25 | #include <QString> |
| 26 | |
| 27 | #define private public |
| 28 | #define protected public |
| 29 | |
| 30 | #include "leftlistview.h" |
| 31 | #include "application.h" |
| 32 | #include "mainwindow.h" |
| 33 | #include "albumview.h" |
| 34 | #include "baseutils.h" |
| 35 | #include "dbmanager.h" |
| 36 | #include "albumcreatedialog.h" |
| 37 | #include "../test_qtestDefine.h" |
| 38 | #include "thumbnaillistview.h" |
| 39 | #include "ac-desktop-define.h" |
| 40 | |
| 41 | #include <stub-tool/cpp-stub/stub.h> |
| 42 | #include <stub-tool/stub-ext/stubext.h> |
| 43 | |
| 44 | TEST(ThumbnailListView, initThumbnailListView) |
| 45 | { |
| 46 | TEST_CASE_NAME("initThumbnailListView") |
| 47 | MainWindow *w = dApp->getMainWindow(); |
| 48 | w->timeLineBtnClicked(); |
| 49 | w->allPicBtnClicked(); |
| 50 | // w->m_pAllPicView->m_pThumbnailListView-> |
| 51 | QStringList paths; |
| 52 | if (DBManager::instance()->getAllPaths().length() > 0) |
| 53 | paths << DBManager::instance()->getAllPaths().first(); |
| 54 | else |
| 55 | paths << testPath_test + "/2e5y8y.jpg"; |
| 56 | QStringList files; |
| 57 | files << paths.first(); |
| 58 | bool needcache = true; |
| 59 | bool needcheck = true;; |
| 60 | // w->m_pAllPicView->m_pThumbnailListView->loadFilesFromLocal(files, needcache, needcheck); |
| 61 | QTest::qWait(200); |
| 62 | DBImgInfoList infolist; |
| 63 | DBImgInfo temp; |
| 64 | temp.fileName = testPath_test + "/2k9o1m.png"; |
| 65 | if (DBManager::instance()->getAllInfos().size() > 0) |
| 66 | infolist = DBManager::instance()->getAllInfos(); |
| 67 | else |
| 68 | infolist << temp; |
| 69 | DBImgInfoList info; |
| 70 | info << infolist.first(); |
| 71 | w->m_pAllPicView->m_pThumbnailListView->insertThumbnailByImgInfos(info); |
| 72 | QTest::qWait(200); |
| 73 | //todo |
| 74 | // w->m_pAllPicView->m_pThumbnailListView->isLoading(); |
| 75 | // w->m_pAllPicView->m_pThumbnailListView->isAllPicSeleted(); |
| 76 | w->m_pAllPicView->m_pThumbnailListView->getDagItemPath(); |
| 77 | // w->m_pAllPicView->m_pThumbnailListView->getSelectedIndexes(); |
| 78 | QPoint point(10, 10); |
| 79 | w->m_pAllPicView->m_pThumbnailListView->getRow(point); |
| 80 | int row = 1; |
| 81 | int start = 1; |
| 82 | int end = 2; |
| 83 | //todo |
| 84 | // w->m_pAllPicView->m_pThumbnailListView->selectRear(row); |
| 85 | // w->m_pAllPicView->m_pThumbnailListView->selectFront(row); |
| 86 | // w->m_pAllPicView->m_pThumbnailListView->selectExtent(start, end); |
| 87 | // w->m_pAllPicView->m_pThumbnailListView->resizeHand(); |
| 88 | w->m_pAllPicView->m_pThumbnailListView->onShowMenu(point); |
| 89 | QList<int> ilist; |
| 90 | ilist << 0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 10; |
| 91 | foreach (auto i, ilist) { |
| 92 | w->m_pAllPicView->m_pThumbnailListView->onPixMapScale(i); |
| 93 | } |
| 94 | |
| 95 | w->m_pAllPicView->m_pThumbnailListView->getListViewHeight(); |
| 96 | w->m_pAllPicView->m_pThumbnailListView->initMenuAction(); |
| 97 | w->m_pAllPicView->m_pThumbnailListView->createAlbumMenu(); |
| 98 | // w->m_pAllPicView->m_pThumbnailListView->updateThumbnaillistview(); |
| 99 | w->m_pAllPicView->m_pThumbnailListView->startDrag(Qt::DropAction::CopyAction); |
| 100 | |
| 101 | QPoint pointbtn = w->m_pAllPicView->m_pThumbnailListView->pos(); |
| 102 | QTestEventList event; |
| 103 | event.addMousePress(Qt::LeftButton, Qt::NoModifier, pointbtn + QPoint(1, 1), 600); |
| 104 | event.addMouseMove(pointbtn + QPoint(200, 200), 10); |
| 105 | event.addMouseRelease(Qt::LeftButton, Qt::NoModifier, pointbtn + QPoint(200, 200), 600); |
| 106 | event.simulate(w->m_pAllPicView->m_pThumbnailListView); |
| 107 | event.clear(); |
| 108 | QTest::qWait(500); |
| 109 | } |
| 110 | |
| 111 | TEST(ThumbnailListView, createNewAlbumFromDialog1) |
| 112 | { |
| 113 | TEST_CASE_NAME("createNewAlbumFromDialog1") |
| 114 | MainWindow *w = dApp->getMainWindow(); |
| 115 | w->albumBtnClicked(); |
| 116 | |
| 117 | QList<QAction *> actions = w->actions(); |
| 118 | |
| 119 | AlbumImageButton *btn = w->m_pAlbumview->m_pLeftListView->m_pAddListBtn; |
| 120 | QPoint pointbtn = btn->pos(); |
| 121 | QTestEventList event; |
| 122 | event.addMouseMove(pointbtn + QPoint(1, 1), 10); |
| 123 | event.addMouseMove(pointbtn + QPoint(2, 2), 10); |
| 124 | event.addMouseClick(Qt::LeftButton, Qt::NoModifier); |
| 125 | event.addMousePress(Qt::LeftButton, Qt::NoModifier); |
| 126 | event.addMouseMove(pointbtn + QPoint(200, 200), 10); |
| 127 | event.addMouseRelease(Qt::LeftButton, Qt::NoModifier, pointbtn + QPoint(200, 200), 10); |
| 128 | event.simulate(btn); |
| 129 | event.clear(); |
| 130 | QTest::qWait(500); |
| 131 | QList<QWidget *> widgets = w->findChildren<QWidget *>(""); |
| 132 | foreach (auto widget, widgets) { |
| 133 | if (!strcmp(widget->metaObject()->className(), "AlbumCreateDialog")) { |
| 134 | AlbumCreateDialog *temp = static_cast<AlbumCreateDialog *>(widget); |
| 135 | QPoint pos(10, 10); |
| 136 | event.addMouseMove(pos); |
| 137 | event.addMouseClick(Qt::MouseButton::LeftButton, Qt::NoModifier, pos); |
| 138 | event.simulate(temp->getButton(1)); |
| 139 | event.clear(); |
| 140 | break; |
| 141 | } |
| 142 | } |
| 143 | QTest::qWait(200); |
| 144 | emit dApp->signalM->sigCreateNewAlbumFromDialog("test-album1"); |
| 145 | } |