Debian Codegraph @

tests/allpicview/test_allpicview.cpp

raw symbols SCIP
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
26 #define private public
27 #define protected public
28
29 #include "application.h"
30 #include "mainwindow.h"
31 #include "allpicview.h"
32 #include "imgdeletedialog.h"
33 #include "wallpapersetter.h"
34 #include "ttbcontent.h"
35 #include "viewpanel.h"
36 #include "mainwidget.h"
37 #include "signalmanager.h"
38 #include "../test_qtestDefine.h"
39 #include "ac-desktop-define.h"
40 #include "testtoolkits.h"
41 #include "batchoperatewidget.h"
42 #include "imagedataservice.h"
43
44 TEST(allpicview, test_ini)
45 {
46 TEST_CASE_NAME("test_ini")
47 MainWindow *w = dApp->getMainWindow();
48
49 QPoint pos(20, 20);
50 QTestEventList event;
51 event.addMouseClick(Qt::MouseButton::LeftButton, Qt::NoModifier, pos);
52 event.simulate(w->getButG()->button(0));
53 AllPicView *a = w->m_pAllPicView;
54
55 int width = a->m_pStatusBar->m_pSlider->slider()->width();
56 pos = QPoint(width / 10 * a->m_pStatusBar->m_pSlider->slider()->sliderPosition(), 10);
57 event.addMousePress(Qt::LeftButton, Qt::NoModifier, pos);
58 pos = pos - QPoint(200, 0);
59 event.addMouseMove(pos);
60 QTest::qWait(500);
61 event.simulate(a->m_pStatusBar->m_pSlider->slider());
62 pos = QPoint(width / 10 * a->m_pStatusBar->m_pSlider->slider()->sliderPosition(), 10);
63 for (int i = 0; i < 5; i++) {
64 event.addMousePress(Qt::LeftButton, Qt::NoModifier, pos);
65 pos = pos + QPoint(20, 0);
66 event.addMouseMove(pos);
67 event.simulate(a->m_pStatusBar->m_pSlider->slider());
68 event.clear();
69 QTest::qWait(500);
70 }
71 pos = QPoint(width / 10 * a->m_pStatusBar->m_pSlider->slider()->sliderPosition(), 10);
72 for (int i = 0; i < 5; i++) {
73 event.addMousePress(Qt::LeftButton, Qt::NoModifier, pos);
74 pos = pos - QPoint(20, 0);
75 event.addMouseMove(pos);
76 event.simulate(a->m_pStatusBar->m_pSlider->slider());
77 event.clear();
78 QTest::qWait(500);
79 }
80 event.addMousePress(Qt::LeftButton, Qt::NoModifier, pos);
81 pos = pos - QPoint(20, 0);
82 event.addMouseMove(pos);
83 event.addMouseRelease(Qt::LeftButton, Qt::NoModifier, pos);
84 event.simulate(a->m_pStatusBar->m_pSlider->slider());
85 event.clear();
86 }
87
88 TEST(allpicview, resize)
89 {
90 TEST_CASE_NAME("resize")
91 MainWindow *w = dApp->getMainWindow();
92
93 QTest::qWait(200);
94 w->resize(w->size() + QSize(300, 300));
95 QTest::qWait(200);
96 QResizeEvent resize2(w->size() - QSize(100, 100), w->size());
97 w->resize(w->size() - QSize(300, 300));
98 QTest::qWait(200);
99 }
100
101 TEST(allpicview, dragevent)
102 {
103 TEST_CASE_NAME("dragevent")
104 QTest::qWait(200);
105 MainWindow *w = dApp->getMainWindow();
106 AllPicView *a = w->m_pAllPicView;
107 w->show();
108
109 // 打开保存绘制的 ddf
110 QString jpgItemPath = testPath_test + "/2e5y8y.jpg";
111
112 QString text = "xxxxxxxxxxxxxx";
113 QIcon icon = QIcon(":/resources/images/other/deepin-album.svg");
114 QIcon icon_hover = QIcon(":/resources/images/other/deepin-album.svg");
115 QByteArray itemData;
116 QDataStream dataStream(&itemData, QIODevice::WriteOnly);
117 dataStream << text << icon << icon_hover;
118 // QMimeData *mimeData = new QMimeData;
119 QMimeData mimedata;
120 mimedata.setData(QStringLiteral("TestListView/text-icon-icon_hover"), itemData);
121 QList<QUrl> li;
122 li.append(QUrl::fromLocalFile(jpgItemPath));
123 mimedata.setUrls(li);
124
125 const QPoint pos = a->getThumbnailListView()->viewport()->rect().center();
126 QDragEnterEvent eEnter(pos, Qt::IgnoreAction, &mimedata, Qt::LeftButton, Qt::NoModifier);
127 dApp->getDAppNew()->sendEvent(a->getThumbnailListView()->viewport(), &eEnter);
128 QTest::qWait(200);
129
130 QDragMoveEvent eMove(pos + QPoint(100, 100), Qt::IgnoreAction, &mimedata, Qt::LeftButton, Qt::NoModifier);
131 dApp->getDAppNew()->sendEvent(a->getThumbnailListView()->viewport(), &eMove);
132 QTest::qWait(200);
133
134 QDropEvent e(pos, Qt::IgnoreAction, &mimedata, Qt::LeftButton, Qt::NoModifier);
135 dApp->getDAppNew()->sendEvent(a->getThumbnailListView()->viewport(), &e);
136 QTest::qWait(200);
137
138 dApp->getDAppNew()->sendEvent(a->getThumbnailListView()->viewport(), &eEnter);
139 QTest::qWait(200);
140
141 QDragLeaveEvent eLeave;
142 dApp->getDAppNew()->sendEvent(a->getThumbnailListView()->viewport(), &eLeave);
143 QTest::qWait(2000);
144 }
145
146 TEST(allpicview, mousePress)
147 {
148 TEST_CASE_NAME("mousePress")
149 MainWindow *w = dApp->getMainWindow();
150
151 QPoint pos(40, 60);
152 AllPicView *a = w->m_pAllPicView;
153 QTestEventList event;
154 event.addMousePress(Qt::LeftButton, Qt::NoModifier, pos);
155 event.addMouseMove(pos + QPoint(200, 200));
156 event.addMouseRelease(Qt::LeftButton, Qt::NoModifier, pos + QPoint(200, 200));
157 event.simulate(a->getThumbnailListView()->viewport());
158 event.clear();
159 QTest::qWait(500);
160 }
161
162 TEST(allpicview, test_select)
163 {
164 TEST_CASE_NAME("test_select")
165 MainWindow *w = dApp->getMainWindow();
166 AllPicView *a = w->m_pAllPicView;
167 QTestEventList e;
168 QPoint p = a->getThumbnailListView()->pos();
169 p.setX(p.x() + 10);
170 p.setY(p.y() + 10);
171 e.addMouseMove(p);
172 e.addKeyPress(Qt::LeftButton);
173 e.addMouseMove(QPoint(p.x() + 400, p.y() + 200));
174 e.clear();
175 e.simulate(a->getThumbnailListView());
176
177 dApp->signalM->sigShortcutKeyDelete();
178 QTest::qWait(100);
179 // a->getThumbnailListView()->sigLoad80ThumbnailsFinish();
180 QTest::qWait(100);
181 a->updateStackedWidget();
182 a->restorePicNum();
183 a->updatePicNum();
184 dApp->signalM->imagesRemoved();
185 QTest::qWait(100);
186 // emit a->getThumbnailListView()->openImage(0, ImageEngineApi::instance()->get_AllImagePath().first(), false);
187 // QTest::qWait(100);
188 }
189
190 TEST(allpicview, BatchOperateWidget)
191 {
192 TEST_CASE_NAME("BatchOperateWidget")
193
194 if (ImageEngineApi::instance()->getAllImageDataCount() <= 0) {
195 return;
196 }
197 //定位到所有图片
198 clickToAllPictureView();
199 //定位到第一张图片位置
200 QModelIndex index;
201 for (int i = 0; i < dApp->getMainWindow()->m_pAllPicView->getThumbnailListView()->m_model->rowCount(); i++) {
202 index = dApp->getMainWindow()->m_pAllPicView->getThumbnailListView()->m_model->index(i, 0);
203 DBImgInfo data = index.data(Qt::DisplayRole).value<DBImgInfo>();
204 if (data.itemType == ItemType::ItemTypePic) {
205 break;
206 }
207 }
208 QRect picItem = dApp->getMainWindow()->m_pAllPicView->getThumbnailListView()->visualRect(index);
209 //选中第一张图片
210 QTest::qWait(200);
211 QPoint p1(picItem.x() + 20, picItem.y() + 20);
212 QTestEventList e;
213 e.addMouseMove(p1);
214 e.addMouseClick(Qt::MouseButton::LeftButton, Qt::NoModifier, p1, 50);
215 e.simulate(dApp->getMainWindow()->m_pAllPicView->m_pThumbnailListView->viewport());
216 e.clear();
217 QTest::qWait(200);
218
219 BatchOperateWidget *batchOperateWidget = dApp->getMainWindow()->m_pAllPicView->findChild<BatchOperateWidget *>(All_Picture_BatchOperateWidget);
220 if (batchOperateWidget) {
221 batchOperateWidget->sltCollectSelect(true);
222 QTest::qWait(200);
223 batchOperateWidget->sltCollectSelect(true);
224 QTest::qWait(200);
225 batchOperateWidget->sltRightRotate(true);
226 QTest::qWait(200);
227 batchOperateWidget->sltLeftRotate(true);
228 QTest::qWait(200);
229 batchOperateWidget->sltSelectAll();
230 QTest::qWait(200);
231 batchOperateWidget->sltUnSelectAll();
232 }
233
234 dApp->getMainWindow()->m_pAllPicView->m_pThumbnailListView->clearSelection();
235 if (batchOperateWidget) {
236 ExpansionPanel::FilteData data;
237
238 data.type = ItemType::ItemTypeNull;
239 batchOperateWidget->sltCurrentFilterChanged(data);
240 QTest::qWait(200);
241
242 data.type = ItemType::ItemTypePic;
243 batchOperateWidget->sltCurrentFilterChanged(data);
244 QTest::qWait(200);
245
246 data.type = ItemType::ItemTypeVideo;
247 batchOperateWidget->sltCurrentFilterChanged(data);
248 QTest::qWait(200);
249 }
250 }
251
252 TEST(allpicview, test_showInFileManagerAndBackGrond)
253 {
254 // TEST_CASE_NAME("test_showInFileManagerAndBackGrond")
255 // using namespace utils::base;
256 // using namespace utils::image;
257 // MainWindow *w = dApp->getMainWindow();
258 // AllPicView *a = w->m_pAllPicView;
259 // QString testPath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) + QDir::separator() + "test";
260 // ImageEngineApi::instance()->ImportImagesFromFileList((QStringList() << testPath), "", a, false);
261 //// QTime t;
262 // QTest::qWait(500);
263 // QStringList paths = ImageEngineApi::instance()->get_AllImagePath();
264 // if (!paths.isEmpty()) {
265 // QString testImage = paths.first();
266 //// showInFileManager(testImage);//roc
267 //// imageSupportSave(testImage);
268 //// checkFileType(testImage);
269 // copyImageToClipboard(paths);
270 //// copyOneImageToClipboard(testImage);
271 // WallpaperSetter::instance()->setBackground(testImage);
272 // QTest::qWait(500);
273 // QMimeData *newMimeData = new QMimeData();
274 // QByteArray gnomeFormat = QByteArray("copy\n");
275 // QString text;
276 // QList<QUrl> dataUrls;
277
278 // for (QString path : paths) {
279 // if (!path.isEmpty())
280 // text += path + '\n';
281 // dataUrls << QUrl::fromLocalFile(path);
282 // gnomeFormat.append(QUrl::fromLocalFile(path).toEncoded()).append("\n");
283 // }
284 // newMimeData->setUrls(dataUrls);
285 // checkMimeData(newMimeData);
286 // QTest::qWait(500);
287 // }
288 }
289
290 TEST(allpicview, viewpaneltest)
291 {
292 TEST_CASE_NAME("viewpaneltest")
293 QString publicTestPath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) + QDir::separator() + "test";
294 QString testPath = publicTestPath;
295 MainWindow *w = dApp->getMainWindow();
296 AllPicView *a = w->m_pAllPicView;
297 QTestEventList tl;
298 tl.addMouseMove(QPoint(0, 0), 100);
299 tl.addMousePress(Qt::MouseButton::LeftButton, Qt::KeyboardModifier::NoModifier, QPoint(0, 0), 100);
300 tl.addMouseMove(a->m_pImportView->geometry().center());
301 tl.simulate(a->m_pImportView);
302 QTest::qWait(500);
303 // ImageEngineApi::instance()->ImportImagesFromFileList((QStringList() << testPath), "", a, false);
304 // QTest::qWait(500);
305
306 QStringList testPathlist = ImageEngineApi::instance()->get_AllImagePath();
307 if (!testPathlist.isEmpty()) {
308 qDebug() << "test ImageView Success ";
309 w->m_pSearchEdit->setText("1");
310 w->m_pSearchEdit->editingFinished();
311 QTest::qWait(300);
312
313 emit a->getThumbnailListView()->openImage(0, testPathlist.first(), false);
314 QTest::qWait(300);
315
316 QTestEventList e;
317 e.addKeyClick(Qt::Key_Minus, Qt::ControlModifier, 100);
318 e.addKeyClick(Qt::Key_Minus, Qt::ControlModifier, 100);
319 e.addKeyClick(Qt::Key_Plus, Qt::ControlModifier, 100);
320 e.addKeyClick(Qt::Key_Plus, Qt::ControlModifier, 100);
321 e.addKeyClick(Qt::Key_Plus, Qt::ControlModifier, 100);
322 e.addKeyClick(Qt::Key_Plus, Qt::ControlModifier, 100);
323 e.addKeyClick(Qt::Key_Plus, Qt::ControlModifier, 100);
324 e.simulate(w);
325 e.clear();
326
327 // emit dApp->signalM->showImageInfo(testPathlist.first());
328
329 QTest::qWait(500);
330 // ImgInfoDialog *dialog = w->findChild<ImgInfoDialog *>("ImgInfoDialog");
331 // dialog->height();
332 // dialog->setImagePath(testPath_test + "2k9o1m.png");
333 // dialog->updateInfo();
334 // QPoint p = dialog->pos();
335 // e.addMouseMove(p, 10);
336 // e.addKeyClick(Qt::Key_Escape, Qt::NoModifier, 10);
337 // e.simulate(dialog);
338 // e.clear();
339 // dialog->deleteLater();
340 // QTest::qWait(500);
341 // ViewPanel *viewPanel = w->findChild<ViewPanel *>("ViewPanel");
342
343 QList<QWidget *> widgets = w->findChildren<QWidget *>();
344 foreach (auto widget, widgets) {
345 if (!strcmp(widget->metaObject()->className(), "ViewPanel")) {
346 ViewPanel *viewPanel = dynamic_cast<ViewPanel *>(widget);
347
348 viewPanel->onDeleteByMenu();
349 QTest::qWait(100);
350 viewPanel->onShowExtensionPanel();
351 QTest::qWait(100);
352 viewPanel->onHideExtensionPanel();
353 QTest::qWait(100);
354 viewPanel->onResetTransform(false);
355 QTest::qWait(100);
356 viewPanel->onResetTransform(true);
357 QTest::qWait(100);
358 viewPanel->showNormal();
359 QTest::qWait(100);
360 viewPanel->onHideImageView();
361 QTest::qWait(500);
362 emit a->getThumbnailListView()->openImage(0, testPathlist.first(), false);
363 QTest::qWait(500);
364 // viewPanel->onESCKeyActivated();
365 // QTest::qWait(500);
366 break;
367 }
368 }
369
370 MainWidget *mw = CommandLine::instance()->findChild<MainWidget *>("MainWidget");
371 if (mw) {
372 TTBContent *t = mw->findChild<TTBContent *>("TTBContent");
373 if (t == nullptr) {
374 return;
375 }
376 t->onNextButton();
377 QTest::qWait(500);
378 t->onPreButton();
379 QTest::qWait(500);
380 t->updateFilenameLayout();
381 QTest::qWait(500);
382
383 //todo
384 // MyImageListWidget *imgListView = t->findChild<MyImageListWidget *>("MyImageListWidget");
385 // if (imgListView) {
386 // }
387 }
388 }
389
390 QTestEventList e;
391 e.addKeyClick(Qt::Key_Escape);
392 e.simulate(w);
393 }
394
395 TEST(allpicview, deleteTips)
396 {
397 TEST_CASE_NAME("deleteTips")
398 MainWindow *w = dApp->getMainWindow();
399 w->allPicBtnClicked();
400 QTest::qWait(500);
401 AllPicView *a = w->m_pAllPicView;
402 QStringList testPathlist = ImageEngineApi::instance()->get_AllImagePath();
403 if (testPathlist.count() > 0) {
404 QStringList tempDel;
405 tempDel << testPathlist.last();
406 // ImgDeleteDialog *delDlg = new ImgDeleteDialog(a->getThumbnailListView(), tempDel.length());
407 // delDlg->show();
408 // QTest::qWait(500);
409 ImageEngineApi::instance()->moveImagesToTrash(tempDel);
410 // delDlg->deleteLater();
411 QTest::qWait(500);
412 }
413 }
414
415 TEST(allpicview, allpicview_other_test)
416 {
417 TEST_CASE_NAME("allpicview_other_test")
418 MainWindow *w = dApp->getMainWindow();
419
420 // w->m_pAllPicView->onMenuOpenImage("", QStringList(), false, false);
421 // w->m_pAllPicView->onImportViewImportBtnClicked();
422
423
424 QMimeData mimedata;
425 QList<QUrl> li;
426 QString lastImportPath = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).first();
427 lastImportPath += "/test/4l6r5y.png";
428 li.append(QUrl(lastImportPath));
429 mimedata.setUrls(li);
430
431 QPoint pos = QPoint(20, 20);
432 QDragEnterEvent dee(pos, Qt::IgnoreAction, &mimedata, Qt::LeftButton, Qt::NoModifier);
433 w->m_pAllPicView->dragEnterEvent(&dee);
434
435 QDragMoveEvent dme(pos, Qt::IgnoreAction, &mimedata, Qt::LeftButton, Qt::NoModifier);
436 w->m_pAllPicView->dragMoveEvent(&dme);
437
438 QDropEvent de(pos, Qt::IgnoreAction, &mimedata, Qt::LeftButton, Qt::NoModifier);
439 w->m_pAllPicView->dropEvent(&de);
440 }