chore(CI): 单元测试
Description: 单元测试补充 Log: 提高单元测试覆盖率 Change-Id: Ifa161aa07ccbf500077b7606d0f5c7a42d73a866
This commit is contained in:
parent
e91314a9d9
commit
acf251fc11
|
@ -30,6 +30,13 @@ ImageView::ImageView(QWidget *parent):
|
||||||
viewport()->setCursor(Qt::ArrowCursor);
|
viewport()->setCursor(Qt::ArrowCursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImageView::~ImageView()
|
||||||
|
{
|
||||||
|
if (m_currentImage) {
|
||||||
|
delete m_currentImage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ImageView::openImage(const QString &path)
|
void ImageView::openImage(const QString &path)
|
||||||
{
|
{
|
||||||
if (scene()) {
|
if (scene()) {
|
||||||
|
|
|
@ -15,6 +15,7 @@ class ImageView : public QGraphicsView
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ImageView(QWidget *parent = nullptr);
|
ImageView(QWidget *parent = nullptr);
|
||||||
|
~ImageView();
|
||||||
//通过路径打开图片
|
//通过路径打开图片
|
||||||
void openImage(const QString &path);
|
void openImage(const QString &path);
|
||||||
|
|
||||||
|
|
|
@ -129,7 +129,21 @@ TEST_F(TessOcrUtilsTest, getRecogitionResultImage)
|
||||||
//EXPECT_NE("", recognitionResult.result);
|
//EXPECT_NE("", recognitionResult.result);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
TEST_F(TessOcrUtilsTest, getRecogitionResultImageError)
|
||||||
|
{
|
||||||
|
QString imagePath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
|
||||||
|
QString path = "";
|
||||||
|
RecognitionResult recognitionResult = TessOcrUtils::instance()->getRecogitionResult(path);
|
||||||
|
EXPECT_EQ(ErrorCode::OCR_P_NULL, recognitionResult.errorCode);
|
||||||
|
recognitionResult = TessOcrUtils::instance()->getRecogitionResult(imagePath);
|
||||||
|
EXPECT_EQ(ErrorCode::OCR_P_NULL, recognitionResult.errorCode);
|
||||||
|
|
||||||
|
QImage* p_image = new QImage;
|
||||||
|
recognitionResult = TessOcrUtils::instance()->getRecogitionResult(p_image);
|
||||||
|
EXPECT_EQ(ErrorCode::OCR_P_NULL, recognitionResult.errorCode);
|
||||||
|
delete p_image;
|
||||||
|
|
||||||
|
}
|
||||||
TEST_F(TessOcrUtilsTest, isRunning)
|
TEST_F(TessOcrUtilsTest, isRunning)
|
||||||
{
|
{
|
||||||
EXPECT_EQ(false, m_tessOCrUtils->isRunning());
|
EXPECT_EQ(false, m_tessOCrUtils->isRunning());
|
||||||
|
@ -160,6 +174,8 @@ TEST_F(TessOcrUtilsTest, getRecognizeResult)
|
||||||
p_image->colormap = nullptr;
|
p_image->colormap = nullptr;
|
||||||
//p_image->data = reinterpret_cast<l_uint32*>(image->bits());
|
//p_image->data = reinterpret_cast<l_uint32*>(image->bits());
|
||||||
memcpy(reinterpret_cast<void*>(pixGetData(p_image)), reinterpret_cast<void*>(image->bits()), p_image->wpl * p_image->h * 4);
|
memcpy(reinterpret_cast<void*>(pixGetData(p_image)), reinterpret_cast<void*>(image->bits()), p_image->wpl * p_image->h * 4);
|
||||||
|
|
||||||
|
call_private_fun::TessOcrUtilsgetRecognizeResult(*m_tessOCrUtils,p_image,ResultType::UNKNOWN_TYPE);
|
||||||
RecognitionResult recognitionResult = call_private_fun::TessOcrUtilsgetRecognizeResult(*m_tessOCrUtils,p_image,resultType);
|
RecognitionResult recognitionResult = call_private_fun::TessOcrUtilsgetRecognizeResult(*m_tessOCrUtils,p_image,resultType);
|
||||||
EXPECT_EQ(true, recognitionResult.flag);
|
EXPECT_EQ(true, recognitionResult.flag);
|
||||||
EXPECT_EQ("", recognitionResult.message);
|
EXPECT_EQ("", recognitionResult.message);
|
||||||
|
@ -167,6 +183,35 @@ TEST_F(TessOcrUtilsTest, getRecognizeResult)
|
||||||
EXPECT_EQ(ResultType::RESULT_STRING, recognitionResult.resultType);
|
EXPECT_EQ(ResultType::RESULT_STRING, recognitionResult.resultType);
|
||||||
delete image;
|
delete image;
|
||||||
}
|
}
|
||||||
|
TEST_F(TessOcrUtilsTest, getRecognizeResultHTML)
|
||||||
|
{
|
||||||
|
QString imagePath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) + testImgPath;
|
||||||
|
QImage* image = new QImage(imagePath);
|
||||||
|
ResultType resultType = ResultType::RESULT_HTML;
|
||||||
|
Pix *p_image;
|
||||||
|
p_image = pixCreate(image->width(), image->height(), image->depth());
|
||||||
|
p_image->w = static_cast<l_uint32>(image->width());
|
||||||
|
p_image->h = static_cast<l_uint32>(image->height());
|
||||||
|
p_image->d = static_cast<l_uint32>(image->depth());
|
||||||
|
p_image->spp = 3;
|
||||||
|
p_image->wpl = static_cast<l_uint32>(image->width());
|
||||||
|
p_image->refcount = 1;
|
||||||
|
p_image->xres = 0;
|
||||||
|
p_image->yres = 0;
|
||||||
|
p_image->informat = 0;
|
||||||
|
p_image->special = 0;
|
||||||
|
p_image->text = nullptr;
|
||||||
|
p_image->colormap = nullptr;
|
||||||
|
//p_image->data = reinterpret_cast<l_uint32*>(image->bits());
|
||||||
|
memcpy(reinterpret_cast<void*>(pixGetData(p_image)), reinterpret_cast<void*>(image->bits()), p_image->wpl * p_image->h * 4);
|
||||||
|
RecognitionResult recognitionResult = call_private_fun::TessOcrUtilsgetRecognizeResult(*m_tessOCrUtils,p_image,resultType);
|
||||||
|
EXPECT_EQ(true, recognitionResult.flag);
|
||||||
|
EXPECT_EQ("", recognitionResult.message);
|
||||||
|
EXPECT_EQ(ErrorCode::OK, recognitionResult.errorCode);
|
||||||
|
EXPECT_EQ(ResultType::RESULT_HTML, recognitionResult.resultType);
|
||||||
|
delete image;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST_F(TessOcrUtilsTest, setLanguagesPath)
|
TEST_F(TessOcrUtilsTest, setLanguagesPath)
|
||||||
{
|
{
|
||||||
|
|
|
@ -77,6 +77,8 @@ TEST(MainWidget, MainWidget_show)
|
||||||
a->loadString("");
|
a->loadString("");
|
||||||
a->loadString("test");
|
a->loadString("test");
|
||||||
a->slotCopy();
|
a->slotCopy();
|
||||||
|
DGuiApplicationHelper::ColorType themeType = DGuiApplicationHelper::LightType;
|
||||||
|
a->setIcons(themeType);
|
||||||
a->deleteLater();
|
a->deleteLater();
|
||||||
a = nullptr;
|
a = nullptr;
|
||||||
QTest::qWait(2000);
|
QTest::qWait(2000);
|
||||||
|
@ -95,4 +97,5 @@ TEST(ImageView, ImageView_show)
|
||||||
imageView->setScaleValue(0.9);
|
imageView->setScaleValue(0.9);
|
||||||
imageView->RotateImage(90);
|
imageView->RotateImage(90);
|
||||||
QTest::qWait(2000);
|
QTest::qWait(2000);
|
||||||
|
delete imageView;
|
||||||
}
|
}
|
||||||
|
|
110
tests/test_resulttextview.cpp
Normal file
110
tests/test_resulttextview.cpp
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
/*
|
||||||
|
* 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 <QResizeEvent>
|
||||||
|
#include <QSize>
|
||||||
|
#include <QGesture>
|
||||||
|
#include <QTapAndHoldGesture>
|
||||||
|
|
||||||
|
#define private public
|
||||||
|
#define protected public
|
||||||
|
|
||||||
|
#include "ocrapplication.h"
|
||||||
|
#include "mainwidget.h"
|
||||||
|
#include "view/imageview.h"
|
||||||
|
#include "resulttextview.h"
|
||||||
|
//初始拉起主界面
|
||||||
|
TEST(ResultTextView, mainwindow)
|
||||||
|
{
|
||||||
|
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->mouseMoveEvent(ev);
|
||||||
|
delete ev;
|
||||||
|
|
||||||
|
|
||||||
|
//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);
|
||||||
|
delete evRele;
|
||||||
|
|
||||||
|
|
||||||
|
QList<QGesture*> list;
|
||||||
|
QTapGesture* tap = new QTapGesture();
|
||||||
|
list.append(tap);
|
||||||
|
QGestureEvent *gestureEvent = new QGestureEvent(list);
|
||||||
|
reTextView->event(gestureEvent);
|
||||||
|
delete gestureEvent;
|
||||||
|
delete tap;
|
||||||
|
|
||||||
|
|
||||||
|
QList<QGesture*> list1;
|
||||||
|
QTapAndHoldGesture* tapAndHold = new QTapAndHoldGesture();
|
||||||
|
list1.append(tapAndHold);
|
||||||
|
QGestureEvent *gestureEvent1 = new QGestureEvent(list1);
|
||||||
|
reTextView->event(gestureEvent1);
|
||||||
|
delete gestureEvent1;
|
||||||
|
delete tapAndHold;
|
||||||
|
|
||||||
|
QList<QGesture*> list2;
|
||||||
|
QPanGesture* pan = new QPanGesture();
|
||||||
|
list2.append(pan);
|
||||||
|
QGestureEvent *gestureEvent2 = new QGestureEvent(list2);
|
||||||
|
reTextView->event(gestureEvent2);
|
||||||
|
delete gestureEvent2;
|
||||||
|
delete pan;
|
||||||
|
|
||||||
|
QList<QGesture*> list3;
|
||||||
|
QPinchGesture* pinch = new QPinchGesture();
|
||||||
|
list3.append(pinch);
|
||||||
|
QGestureEvent *gestureEvent3 = new QGestureEvent(list3);
|
||||||
|
reTextView->event(gestureEvent3);
|
||||||
|
delete gestureEvent3;
|
||||||
|
delete pinch;
|
||||||
|
|
||||||
|
|
||||||
|
reTextView->slideGestureY(2.5);
|
||||||
|
reTextView->slideGestureX(2.5);
|
||||||
|
|
||||||
|
delete reTextView;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user