| 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 "application.h" |
| 25 | #include "dbmanager.h" |
| 26 | #include "DBandImgOperate.h" |
| 27 | #include "utils/baseutils.h" |
| 28 | #include "utils/imageutils.h" |
| 29 | #include "../test_qtestDefine.h" |
| 30 | #include "ac-desktop-define.h" |
| 31 | #include "mainwindow.h" |
| 32 | |
| 33 | TEST(getImgsCount, db5) |
| 34 | { |
| 35 | TEST_CASE_NAME("db5") |
| 36 | QString testPath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) + QDir::separator() + "test"; |
| 37 | QStringList image_list; |
| 38 | auto finfos = utils::image::getImagesAndVideoInfo(testPath); |
| 39 | DBManager::instance()->getImgsCount(); |
| 40 | } |
| 41 | |
| 42 | TEST(removeTestImagesInfo, db6) |
| 43 | { |
| 44 | TEST_CASE_NAME("db6") |
| 45 | QStringList image_list; |
| 46 | auto finfos = utils::image::getImagesAndVideoInfo(testPath_test); |
| 47 | for (auto info : finfos) { |
| 48 | image_list << info.absoluteFilePath(); |
| 49 | } |
| 50 | DBManager::instance()->removeImgInfos(QStringList()); |
| 51 | DBManager::instance()->removeImgInfos(image_list); |
| 52 | image_list << QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) + "test.png"; |
| 53 | DBManager::instance()->removeImgInfosNoSignal(image_list); |
| 54 | DBManager::instance()->getAllPathAlbumNames(); |
| 55 | } |
| 56 | |
| 57 | TEST(getImageByKeyBoard, db8) |
| 58 | { |
| 59 | TEST_CASE_NAME("db8") |
| 60 | DBManager::instance()->getInfosForKeyword(""); |
| 61 | DBManager::instance()->getInfosForKeyword("1"); |
| 62 | DBManager::instance()->getInfosForKeyword("a"); |
| 63 | } |
| 64 | |
| 65 | TEST(getTrashImageCount, db10) |
| 66 | { |
| 67 | TEST_CASE_NAME("db10") |
| 68 | DBManager::instance()->getTrashImgsCount(); |
| 69 | DBManager::instance()->getAllTrashInfos(); |
| 70 | DBManager::instance()->getAllTrashPaths(); |
| 71 | DBManager::instance()->getTrashInfoByPath(""); |
| 72 | } |
| 73 | |
| 74 | TEST(AlbumForTest, db11) |
| 75 | { |
| 76 | TEST_CASE_NAME("db11") |
| 77 | QString testPath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) + QDir::separator() + "dbtest"; |
| 78 | QStringList image_list; |
| 79 | auto finfos = utils::image::getImagesAndVideoInfo(testPath); |
| 80 | for (auto info : finfos) { |
| 81 | image_list << info.absoluteFilePath(); |
| 82 | } |
| 83 | QStringList partList = image_list.mid(image_list.size() / 2); |
| 84 | DBManager::instance()->insertIntoAlbum("testAlbum", image_list); |
| 85 | DBManager::instance()->insertIntoAlbumNoSignal("testAlbum", image_list); |
| 86 | DBManager::instance()->getPathsByAlbum("testAlbum"); |
| 87 | DBManager::instance()->getInfosByAlbum("testAlbum"); |
| 88 | // DBManager::instance()->removeFromAlbum("testAlbum", partList); |
| 89 | DBManager::instance()->renameAlbum("testAlbum", "newTestAlbum"); |
| 90 | // DBManager::instance()->removeAlbum("newTestAlbum"); |
| 91 | DBManager::instance()->getTrashInfosForKeyword(""); |
| 92 | QStringList l; |
| 93 | l << "newTestAlbum"; |
| 94 | DBManager::instance()->removeTrashImgInfosNoSignal(l); |
| 95 | |
| 96 | DBImgInfo info, info1; |
| 97 | info.dirHash = "test"; |
| 98 | info1.dirHash = "test"; |
| 99 | if (info == info1) |
| 100 | qDebug() << "same"; |
| 101 | } |
| 102 | |
| 103 | TEST(DBandImgOperate, setThreadShouldStop) |
| 104 | { |
| 105 | TEST_CASE_NAME("setThreadShouldStop") |
| 106 | ImageEngineApi::instance()->setThreadShouldStop(); |
| 107 | } |