chore(CI): 单元测试

Description: 单元测试覆盖率提升

Log: 添加单元测试
Change-Id: Ia03c3bd2b7cd676dd32a5b4484d17876831e0124
This commit is contained in:
hemingyang 2021-12-28 20:27:01 +08:00
parent acf251fc11
commit c0961accf8
4 changed files with 159 additions and 19 deletions

View File

@ -280,9 +280,6 @@ RecognitionResult TessOcrUtils::getRecognizeResult(Pix * image,ResultType result
case ResultType::RESULT_HTML:
resultString = t_Tesseract->GetHOCRText(0);
break;
case ResultType::RESULT_STRING:
resultString = t_Tesseract->GetUTF8Text();
break;
default:
resultString = t_Tesseract->GetUTF8Text();
break;
@ -355,9 +352,6 @@ QString TessOcrUtils::getLangStr(Languages lang)
case Languages::CHI_TRA:
langStr = "chi_tra";
break;
case Languages::ENG:
langStr = "eng";
break;
default:
langStr = "eng";
break;

View File

@ -0,0 +1,59 @@
/*
* Copyright (C) 2020 ~ 2021 Uniontech Software Technology Co., Ltd.
*
* Author: ZhangYong <zhangyong@uniontech.com>
*
* Maintainer: ZhangYong <ZhangYong@uniontech.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gtest/gtest.h>
#include <gmock/gmock-matchers.h>
#include <QTestEventList>
#include <QObject>
#include <QStandardPaths>
#include <QDBusConnection>
#define private public
#define protected public
#include "ocrapplication.h"
#include "service/dbusocr_adaptor.h"
#include "service/ocrinterface.h"
//初始拉起主界面
TEST(OcrInterface, mainwindow)
{
OcrInterface *pOcr = new OcrInterface("com.deepin.Ocr", "/com/deepin/Ocr", QDBusConnection::sessionBus());
qDebug() << __FUNCTION__ << __LINE__;
QString imagePath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) + "/Wallpapers/marian-kroell-qElMHWePpok-unsplash.jpg";;
pOcr->openFile(imagePath);
QTest::qWait(2000);
QImage img = QImage(imagePath);
pOcr->openImage(img);
QTest::qWait(2000);
pOcr->openImageAndName(img, "TestName");
QTest::qWait(2000);
delete pOcr;
}
TEST(DbusOcrAdaptor, MainWidget_show)
{
//DbusOcrAdaptor *adaptor = new DbusOcrAdaptor(nullptr);
//delete adaptor;
}

View File

@ -72,13 +72,14 @@ TEST(MainWindow, mainwindow_openFile)
TEST(MainWidget, MainWidget_show)
{
MainWidget *a = new MainWidget();
DGuiApplicationHelper::ColorType themeType = DGuiApplicationHelper::LightType;
a->setIcons(themeType);
a->loadHtml("");
a->loadHtml("test");
a->loadString("");
a->loadString("test");
a->slotCopy();
DGuiApplicationHelper::ColorType themeType = DGuiApplicationHelper::LightType;
a->setIcons(themeType);
a->resultEmpty();
a->deleteLater();
a = nullptr;
QTest::qWait(2000);
@ -96,6 +97,12 @@ TEST(ImageView, ImageView_show)
imageView->setScaleValue(1.1);
imageView->setScaleValue(0.9);
imageView->RotateImage(90);
imageView->scaleAtPoint(QPoint(10, 10), 1.2);
QPinchGesture *gesture = new QPinchGesture;
imageView->pinchTriggered(gesture);
delete gesture;
QTest::qWait(2000);
delete imageView;
}

View File

@ -28,6 +28,7 @@
#include <QSize>
#include <QGesture>
#include <QTapAndHoldGesture>
#include <QMenu>
#define private public
#define protected public
@ -36,34 +37,63 @@
#include "mainwidget.h"
#include "view/imageview.h"
#include "resulttextview.h"
#include "stub.h"
#include "addr_pri.h"
//初始拉起主界面
Qt::GestureState state_stub(void* obj)
{
Q_UNUSED(obj);
return Qt::GestureStarted;
}
Qt::GestureState state_stub1(void* obj)
{
Q_UNUSED(obj);
return Qt::GestureUpdated;
}
Qt::GestureState state_stub2(void* obj)
{
Q_UNUSED(obj);
return Qt::GestureCanceled;
}
Qt::GestureState state_stub3(void* obj)
{
Q_UNUSED(obj);
return Qt::GestureFinished;
}
QAction *exec_stub(void* obj, const QPoint &pos, QAction *at)
{
Q_UNUSED(obj);
Q_UNUSED(pos);
Q_UNUSED(at);
return nullptr;
}
TEST(ResultTextView, mainwindow)
{
Stub stub;
ResultTextView* reTextView = new ResultTextView(nullptr);
QResizeEvent resizeEvent(QSize(500, 200), QSize(500, 400));
reTextView->resizeEvent(&resizeEvent);
//QMouseEvent mouseMoveEvent;
//e->type() == QEvent::MouseMove && e->source() == Qt::MouseEventSynthesizedByQt
QMouseEvent *ev = new QMouseEvent(QEvent::MouseMove, QPoint(15,36), QPoint(25,40), QPoint(60,80), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier, Qt::MouseEventSynthesizedByQt);
reTextView->m_gestureAction = ResultTextView::GA_slide;
reTextView->mouseMoveEvent(ev);
delete ev;
stub.set((QAction*(QMenu::*)(const QPoint &, QAction *))ADDR(QMenu, exec), exec_stub);
reTextView->contextMenuEvent(nullptr);
stub.reset((QAction*(QMenu::*)(const QPoint &, QAction *))ADDR(QMenu, exec));
//reTextView->contextMenuEvent(nullptr);
//QTest::mouseClick(reTextView, Qt::MouseButton::LeftButton);
//reTextView->m_Menu->activeAction()->trigger();
QMouseEvent *evPress = new QMouseEvent(QEvent::MouseButtonPress, QPoint(15,36), QPoint(25,40), QPoint(60,80), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier, Qt::MouseEventSynthesizedByQt);
reTextView->mousePressEvent(evPress);
delete evPress;
QMouseEvent *evRele = new QMouseEvent(QEvent::MouseButtonRelease, QPoint(15,36), QPoint(25,40), QPoint(60,80), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier, Qt::MouseEventSynthesizedByQt);
reTextView->mousePressEvent(evRele);
reTextView->mouseReleaseEvent(evRele);
delete evRele;
@ -72,6 +102,19 @@ TEST(ResultTextView, mainwindow)
list.append(tap);
QGestureEvent *gestureEvent = new QGestureEvent(list);
reTextView->event(gestureEvent);
stub.set(ADDR(QTapGesture,state), state_stub);
reTextView->event(gestureEvent);
stub.reset(ADDR(QTapGesture,state));
stub.set(ADDR(QTapGesture,state), state_stub1);
reTextView->event(gestureEvent);
stub.reset(ADDR(QTapGesture,state));
stub.set(ADDR(QTapGesture,state), state_stub2);
reTextView->event(gestureEvent);
stub.reset(ADDR(QTapGesture,state));
stub.set(ADDR(QTapGesture,state), state_stub3);
reTextView->event(gestureEvent);
stub.reset(ADDR(QTapGesture,state));
delete gestureEvent;
delete tap;
@ -81,6 +124,18 @@ TEST(ResultTextView, mainwindow)
list1.append(tapAndHold);
QGestureEvent *gestureEvent1 = new QGestureEvent(list1);
reTextView->event(gestureEvent1);
stub.set(ADDR(QTapAndHoldGesture,state), state_stub);
reTextView->event(gestureEvent1);
stub.reset(ADDR(QTapAndHoldGesture,state));
stub.set(ADDR(QTapAndHoldGesture,state), state_stub1);
reTextView->event(gestureEvent1);
stub.reset(ADDR(QTapAndHoldGesture,state));
stub.set(ADDR(QTapAndHoldGesture,state), state_stub2);
reTextView->event(gestureEvent1);
stub.reset(ADDR(QTapAndHoldGesture,state));
stub.set(ADDR(QTapAndHoldGesture,state), state_stub3);
reTextView->event(gestureEvent1);
stub.reset(ADDR(QTapAndHoldGesture,state));
delete gestureEvent1;
delete tapAndHold;
@ -89,6 +144,18 @@ TEST(ResultTextView, mainwindow)
list2.append(pan);
QGestureEvent *gestureEvent2 = new QGestureEvent(list2);
reTextView->event(gestureEvent2);
stub.set(ADDR(QPanGesture,state), state_stub);
reTextView->event(gestureEvent2);
stub.reset(ADDR(QPanGesture,state));
stub.set(ADDR(QPanGesture,state), state_stub1);
reTextView->event(gestureEvent2);
stub.reset(ADDR(QPanGesture,state));
stub.set(ADDR(QPanGesture,state), state_stub2);
reTextView->event(gestureEvent2);
stub.reset(ADDR(QPanGesture,state));
stub.set(ADDR(QPanGesture,state), state_stub3);
reTextView->event(gestureEvent2);
stub.reset(ADDR(QPanGesture,state));
delete gestureEvent2;
delete pan;
@ -97,10 +164,21 @@ TEST(ResultTextView, mainwindow)
list3.append(pinch);
QGestureEvent *gestureEvent3 = new QGestureEvent(list3);
reTextView->event(gestureEvent3);
stub.set(ADDR(QPinchGesture,state), state_stub);
reTextView->event(gestureEvent3);
stub.reset(ADDR(QPinchGesture,state));
stub.set(ADDR(QPinchGesture,state), state_stub1);
reTextView->event(gestureEvent3);
stub.reset(ADDR(QPinchGesture,state));
stub.set(ADDR(QPinchGesture,state), state_stub2);
reTextView->event(gestureEvent3);
stub.reset(ADDR(QPinchGesture,state));
stub.set(ADDR(QPinchGesture,state), state_stub3);
reTextView->event(gestureEvent3);
stub.reset(ADDR(QPinchGesture,state));
delete gestureEvent3;
delete pinch;
reTextView->slideGestureY(2.5);
reTextView->slideGestureX(2.5);
@ -108,3 +186,5 @@ TEST(ResultTextView, mainwindow)
}