| 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 <QScrollBar> |
| 26 | |
| 27 | #include "application.h" |
| 28 | #include "mainwindow.h" |
| 29 | #include "timelineview.h" |
| 30 | #include "../test_qtestDefine.h" |
| 31 | #include "ac-desktop-define.h" |
| 32 | #include "utils/baseutils.h" |
| 33 | |
| 34 | |
| 35 | TEST(TimeLineView, T1) |
| 36 | { |
| 37 | TEST_CASE_NAME("T1") |
| 38 | MainWindow *w = dApp->getMainWindow(); |
| 39 | w->showEvent(nullptr); |
| 40 | QTestEventList event; |
| 41 | event.addMouseClick(Qt::MouseButton::LeftButton); |
| 42 | event.simulate(w->getButG()->button(1)); |
| 43 | event.clear(); |
| 44 | QTest::qWait(500); |
| 45 | TimeLineView *t = w->m_pTimeLineView; |
| 46 | t->m_pStatusBar->m_pSlider->setValue(1); |
| 47 | t->m_pStatusBar->m_pSlider->setValue(2); |
| 48 | t->m_pStatusBar->m_pSlider->setValue(3); |
| 49 | t->m_pStatusBar->m_pSlider->setValue(4); |
| 50 | t->m_pStatusBar->m_pSlider->setValue(5); |
| 51 | t->m_pStatusBar->m_pSlider->setValue(6); |
| 52 | t->m_pStatusBar->m_pSlider->setValue(7); |
| 53 | t->m_pStatusBar->m_pSlider->setValue(8); |
| 54 | t->m_pStatusBar->m_pSlider->setValue(9); |
| 55 | t->m_pStatusBar->m_pSlider->setValue(10); |
| 56 | t->m_pStatusBar->m_pSlider->setValue(4); |
| 57 | |
| 58 | dApp->viewerTheme->setCurrentTheme(ViewerThemeManager::Light); |
| 59 | QTest::qWait(500); |
| 60 | dApp->viewerTheme->setCurrentTheme(ViewerThemeManager::Dark); |
| 61 | QStringList list; |
| 62 | list << testPath_test + "2k9o1m.png"; |
| 63 | t->updataLayout(list); |
| 64 | t->on_DCommandLinkButton(); |
| 65 | //todo |
| 66 | // t->on_GetSelectedPaths(&list); |
| 67 | // t->on_KeyEvent(Qt::Key_PageDown); |
| 68 | // t->on_KeyEvent(Qt::Key_PageUp); |
| 69 | // t->updateChoseText(); |
| 70 | |
| 71 | QString jpgItemPath = testPath_test + "/2k9o1m.png"; |
| 72 | QString text = "xxxxxxxxxxxxxx"; |
| 73 | QIcon icon = QIcon(":/resources/images/other/deepin-album.svg"); |
| 74 | QIcon icon_hover = QIcon(":/resources/images/other/deepin-album.svg"); |
| 75 | QByteArray itemData; |
| 76 | QDataStream dataStream(&itemData, QIODevice::WriteOnly); |
| 77 | dataStream << text << icon << icon_hover; |
| 78 | QMimeData mimedata; |
| 79 | mimedata.setData(QStringLiteral("TestListView/text-icon-icon_hover"), itemData); |
| 80 | QList<QUrl> li; |
| 81 | li.append(QUrl::fromLocalFile(jpgItemPath)); |
| 82 | mimedata.setUrls(li); |
| 83 | |
| 84 | QPoint pos1 = t->pos(); |
| 85 | QDropEvent ed(pos1, Qt::IgnoreAction, &mimedata, Qt::LeftButton, Qt::NoModifier); |
| 86 | dApp->getDAppNew()->sendEvent(t, &ed); |
| 87 | QTest::qWait(100); |
| 88 | |
| 89 | QTestEventList e; |
| 90 | e.addMousePress(Qt::MouseButton::LeftButton, Qt::NoModifier, pos1, 10); |
| 91 | e.simulate(t); |
| 92 | e.clear(); |
| 93 | |
| 94 | // ASSERT_TRUE(t->getIBaseHeight()); |
| 95 | } |
| 96 | |
| 97 | TEST(TimeLineView, dragPhotoToAnAlbum) |
| 98 | { |
| 99 | TEST_CASE_NAME("dragPhotoToAnAlbum") |
| 100 | MainWindow *w = dApp->getMainWindow(); |
| 101 | |
| 102 | w->timeLineBtnClicked(); |
| 103 | QTest::qWait(100); |
| 104 | TimeLineView *a = w->m_pTimeLineView; |
| 105 | QList<QWidget *> widgets = a->findChildren<QWidget *>(""); |
| 106 | for (int index = 0; index < widgets.count(); index++) { |
| 107 | if (!strcmp(widgets.at(index)->metaObject()->className(), ("TimelineList"))) { |
| 108 | //todo |
| 109 | // TimelineListWidget *li = static_cast<TimelineListWidget *>(widgets.at(index)); |
| 110 | // if (li) { |
| 111 | // QScrollBar *bar = li->verticalScrollBar(); |
| 112 | // bar->setRange(1, 100); |
| 113 | // QPoint pos1 = li->rect().center(); |
| 114 | // QString text = "xxxxxxxxxxxxxx"; |
| 115 | // QIcon icon = QIcon(":/resources/images/other/deepin-album.svg"); |
| 116 | // QIcon icon_hover = QIcon(":/resources/images/other/deepin-album.svg"); |
| 117 | // QByteArray itemData; |
| 118 | // QDataStream dataStream(&itemData, QIODevice::WriteOnly); |
| 119 | // dataStream << text << icon << icon_hover; |
| 120 | // QMimeData mimedata; |
| 121 | // mimedata.setData(QStringLiteral("TestListView/text-icon-icon_hover"), itemData); |
| 122 | // QDragMoveEvent eMove(pos1, Qt::IgnoreAction, &mimedata, Qt::LeftButton, Qt::NoModifier); |
| 123 | // dApp->getDAppNew()->sendEvent(a, &eMove); |
| 124 | // QTest::qWait(200); |
| 125 | |
| 126 | // QTestEventList e; |
| 127 | // e.addMouseMove(pos1); |
| 128 | // e.addMouseMove(pos1 + QPoint(1, 1)); |
| 129 | // e.simulate(li); |
| 130 | // } |
| 131 | } |
| 132 | if (!strcmp(widgets.at(index)->metaObject()->className(), ("ThumbnailListView"))) { |
| 133 | QString jpgItemPath = testPath_test + "/2k9o1m.png"; |
| 134 | QString text = "xxxxxxxxxxxxxx"; |
| 135 | QIcon icon = QIcon(":/resources/images/other/deepin-album.svg"); |
| 136 | QIcon icon_hover = QIcon(":/resources/images/other/deepin-album.svg"); |
| 137 | QByteArray itemData; |
| 138 | QDataStream dataStream(&itemData, QIODevice::WriteOnly); |
| 139 | dataStream << text << icon << icon_hover; |
| 140 | QMimeData mimedata; |
| 141 | mimedata.setData(QStringLiteral("TestListView/text-icon-icon_hover"), itemData); |
| 142 | QList<QUrl> li; |
| 143 | li.append(QUrl::fromLocalFile(jpgItemPath)); |
| 144 | mimedata.setUrls(li); |
| 145 | QTest::qWait(200); |
| 146 | |
| 147 | const QPoint pos1 = a->rect().center(); |
| 148 | QDragEnterEvent eEnter(pos1, Qt::IgnoreAction, &mimedata, Qt::LeftButton, Qt::NoModifier); |
| 149 | dApp->getDAppNew()->sendEvent(a, &eEnter); |
| 150 | QTest::qWait(200); |
| 151 | |
| 152 | QDragMoveEvent eMove(pos1, Qt::IgnoreAction, &mimedata, Qt::LeftButton, Qt::NoModifier); |
| 153 | dApp->getDAppNew()->sendEvent(a, &eMove); |
| 154 | QTest::qWait(200); |
| 155 | |
| 156 | QDropEvent e(pos1, Qt::IgnoreAction, &mimedata, Qt::LeftButton, Qt::NoModifier); |
| 157 | // dApp->getDAppNew()->sendEvent(a, &e); |
| 158 | QTest::qWait(200); |
| 159 | |
| 160 | dApp->getDAppNew()->sendEvent(a, &eEnter); |
| 161 | QTest::qWait(200); |
| 162 | |
| 163 | QDragLeaveEvent eLeave; |
| 164 | dApp->getDAppNew()->sendEvent(a, &eLeave); |
| 165 | QTest::qWait(500); |
| 166 | break; |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | TEST(TimeLineView, SelectTimeLinesBtn) |
| 171 | { |
| 172 | TEST_CASE_NAME("SelectTimeLinesBtn") |
| 173 | MainWindow *w = dApp->getMainWindow(); |
| 174 | QTestEventList event; |
| 175 | w->timeLineBtnClicked(); |
| 176 | QTest::qWait(500); |
| 177 | TimeLineView *t = w->m_pTimeLineView; |
| 178 | QList<QWidget *> widgets = t->findChildren<QWidget *>(""); |
| 179 | foreach (auto widget, widgets) { |
| 180 | if (widget->objectName() == "TimeLineChooseButton") { |
| 181 | DCommandLinkButton *temp = static_cast<DCommandLinkButton *>(widget); |
| 182 | QPoint pos(10, 10); |
| 183 | event.addMouseMove(pos); |
| 184 | event.addMouseClick(Qt::MouseButton::LeftButton, Qt::NoModifier, pos); |
| 185 | event.simulate(temp); |
| 186 | event.clear(); |
| 187 | QTest::qWait(500); |
| 188 | |
| 189 | event.addMouseMove(pos); |
| 190 | event.addMouseClick(Qt::MouseButton::LeftButton, Qt::NoModifier, pos); |
| 191 | event.simulate(temp); |
| 192 | event.clear(); |
| 193 | QTest::qWait(500); |
| 194 | break; |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | TEST(TimeLineView, selectBtn) |
| 200 | { |
| 201 | TEST_CASE_NAME("selectBtn") |
| 202 | MainWindow *w = dApp->getMainWindow(); |
| 203 | w->timeLineBtnClicked(); |
| 204 | QTest::qWait(500); |
| 205 | |
| 206 | TimeLineView *t = w->m_pTimeLineView; |
| 207 | QList<QWidget *> widgets = t->findChildren<QWidget *>(""); |
| 208 | for (int i = 0; i < widgets.count(); i++) { |
| 209 | if (!strcmp(widgets.at(i)->metaObject()->className(), ("Dtk::Widget::DCommandLinkButton"))) { |
| 210 | DCommandLinkButton *pDCmdBtnSelect = dynamic_cast<DCommandLinkButton *>(widgets.at(i)); |
| 211 | if (pDCmdBtnSelect->text() == QObject::tr("Select")) { |
| 212 | QTestEventList event; |
| 213 | event.addMouseClick(Qt::MouseButton::LeftButton, Qt::NoModifier, QPoint(10, 10)); |
| 214 | event.simulate(widgets.at(i)); |
| 215 | event.clear(); |
| 216 | break; |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | QTest::qWait(500); |
| 221 | for (int i = 0; i < widgets.count(); i++) { |
| 222 | if (!strcmp(widgets.at(i)->metaObject()->className(), ("Dtk::Widget::DCommandLinkButton"))) { |
| 223 | DCommandLinkButton *pDCmdBtnUnselect = dynamic_cast<DCommandLinkButton *>(widgets.at(i)); |
| 224 | if (pDCmdBtnUnselect->text() == QObject::tr("Unselect")) { |
| 225 | QTestEventList event; |
| 226 | event.addMouseClick(Qt::MouseButton::LeftButton, Qt::NoModifier, QPoint(10, 10)); |
| 227 | event.simulate(widgets.at(i)); |
| 228 | event.clear(); |
| 229 | break; |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | QTest::qWait(500); |
| 234 | } |
| 235 | |
| 236 | TEST(TimeLineView, changeTheme) |
| 237 | { |
| 238 | TEST_CASE_NAME("changeTheme") |
| 239 | MainWindow *w = dApp->getMainWindow(); |
| 240 | w->timeLineBtnClicked(); |
| 241 | QTest::qWait(500); |
| 242 | TimeLineView *t = w->m_pTimeLineView; |
| 243 | t->setFocus(); |
| 244 | dApp->viewerTheme->setCurrentTheme(ViewerThemeManager::Dark); |
| 245 | QTest::qWait(500); |
| 246 | } |
| 247 | |
| 248 | TEST(TimeLineView, oneThumblistview_test) |
| 249 | { |
| 250 | TEST_CASE_NAME("oneThumblistview_test") |
| 251 | MainWindow *w = dApp->getMainWindow(); |
| 252 | w->showEvent(nullptr); |
| 253 | QTestEventList event; |
| 254 | event.addMouseClick(Qt::MouseButton::LeftButton); |
| 255 | event.simulate(w->getButG()->button(1)); |
| 256 | event.clear(); |
| 257 | QTest::qWait(500); |
| 258 | |
| 259 | |
| 260 | TimeLineView *tlView = w->m_pTimeLineView; |
| 261 | QList<QWidget *> widgets = tlView->findChildren<QWidget *>(); |
| 262 | foreach (auto wgt, widgets) { |
| 263 | if (!strcmp(wgt->metaObject()->className(), "ThumbnailListView")) { |
| 264 | |
| 265 | QPoint pos(60, 60); |
| 266 | event.addMouseClick(Qt::MouseButton::LeftButton, Qt::NoModifier, pos); |
| 267 | event.simulate(wgt); |
| 268 | event.clear(); |
| 269 | QTest::qWait(500); |
| 270 | |
| 271 | event.addMousePress(Qt::MouseButton::LeftButton, Qt::NoModifier, pos); |
| 272 | event.simulate(wgt); |
| 273 | event.clear(); |
| 274 | QTest::qWait(500); |
| 275 | |
| 276 | event.addMousePress(Qt::MouseButton::LeftButton, Qt::ControlModifier, pos); |
| 277 | event.simulate(wgt); |
| 278 | event.clear(); |
| 279 | QTest::qWait(500); |
| 280 | |
| 281 | event.addMousePress(Qt::MouseButton::LeftButton, Qt::ShiftModifier, pos); |
| 282 | event.simulate(wgt); |
| 283 | event.clear(); |
| 284 | QTest::qWait(500); |
| 285 | |
| 286 | event.addMousePress(Qt::MouseButton::LeftButton, Qt::NoModifier, pos); |
| 287 | event.addMouseRelease(Qt::MouseButton::LeftButton, Qt::NoModifier, pos); |
| 288 | event.simulate(wgt); |
| 289 | event.clear(); |
| 290 | QTest::qWait(500); |
| 291 | } |
| 292 | } |
| 293 | } |
| 294 | |
| 295 |