fix: 单元测试更新

Description: 单元测试更新,当前覆盖率67%

Log: 单元测试更新,当前覆盖率67%
Change-Id: I2b56f415c9d98f8efe40c507edd7f23f18c6e36a
This commit is contained in:
liuminghang 2021-06-28 14:38:59 +08:00
parent 10093812cc
commit cb69768a9f
3 changed files with 77 additions and 42 deletions

View File

@ -132,43 +132,24 @@ void ImageView::RotateImage(const int &index)
} }
void ImageView::savecurrentPic()
{
QString filename = QFileDialog::getSaveFileName(this, tr("Save Image"), "", tr("Images (*.png *.bmp *.jpg)")); //选择路径
image().save(filename);
}
void ImageView::savecurrentPicAs()
{
QFileDialog fileDialog;
QString fileName = fileDialog.getSaveFileName(this, tr("Open File"), "/home", tr("png"));
if (fileName == "") {
return;
}
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
QMessageBox::warning(this, tr("error"), tr("open file error"));
return;
} else {
image().save(fileName, "png");
}
}
void ImageView::openImage(QImage *img)
{ //void ImageView::openImage(QImage *img)
if (!img->isNull() && scene()) { //{
QPixmap pic = QPixmap::fromImage(*img); // if (!img->isNull() && scene()) {
if (!pic.isNull()) { // QPixmap pic = QPixmap::fromImage(*img);
scene()->clear(); // if (!pic.isNull()) {
m_pixmapItem = new QGraphicsPixmapItem(pic); // scene()->clear();
m_pixmapItem->setTransformationMode(Qt::SmoothTransformation); // m_pixmapItem = new QGraphicsPixmapItem(pic);
QRectF rect = m_pixmapItem->boundingRect(); // m_pixmapItem->setTransformationMode(Qt::SmoothTransformation);
setSceneRect(rect); // QRectF rect = m_pixmapItem->boundingRect();
scene()->addItem(m_pixmapItem); // setSceneRect(rect);
fitWindow(); // scene()->addItem(m_pixmapItem);
} // fitWindow();
} // }
} // }
//}
qreal ImageView::imageRelativeScale() const qreal ImageView::imageRelativeScale() const
{ {

View File

@ -42,12 +42,8 @@ public slots:
void fitImage(); void fitImage();
//旋转图片感觉index角度-为左,+为右 //旋转图片感觉index角度-为左,+为右
void RotateImage(const int &index); void RotateImage(const int &index);
//保存图片 // //打开该图片
void savecurrentPic(); // void openImage(QImage *img);
//另存为
void savecurrentPicAs();
//打开该图片
void openImage(QImage *img);
//窗口大小改变事件 //窗口大小改变事件
void resizeEvent(QResizeEvent *event) override; void resizeEvent(QResizeEvent *event) override;

View File

@ -23,12 +23,14 @@
#include <QTestEventList> #include <QTestEventList>
#include <QObject> #include <QObject>
#include <QStandardPaths>
#define private public #define private public
#define protected public #define protected public
#include "ocrapplication.h" #include "ocrapplication.h"
#include "mainwidget.h"
#include "view/imageview.h"
//初始拉起主界面 //初始拉起主界面
TEST(MainWindow, mainwindow) TEST(MainWindow, mainwindow)
{ {
@ -38,3 +40,59 @@ TEST(MainWindow, mainwindow)
} }
//其余case //其余case
//初始拉起主界面,带有参数的
TEST(MainWindow, mainwindow_openFile)
{
QString picPath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) + "/Wallpapers/luca-micheli-ruWkmt3nU58-unsplash.jpg";
OcrApplication instance;
instance.openFile(picPath);
bool bRet = false;
while (!bRet) {
if (!TessOcrUtils::instance()->isRunning()) {
bRet = true;
QTest::qWait(1000);
}
}
instance.openImage(QImage(picPath).scaled(200, 200));
bRet = false;
while (!bRet) {
if (!TessOcrUtils::instance()->isRunning()) {
bRet = true;
QTest::qWait(1000);
}
}
instance.openImageAndName(QImage(picPath).scaled(10, 10), picPath);
QTest::qWait(2000);
}
//初始拉起主界面,带有参数的
TEST(MainWidget, MainWidget_show)
{
MainWidget *a = new MainWidget();
a->loadHtml("");
a->loadHtml("test");
a->loadString("");
a->loadString("test");
a->slotCopy();
a->deleteLater();
a = nullptr;
QTest::qWait(2000);
}
TEST(ImageView, ImageView_show)
{
QString picPath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) + "/Wallpapers/luca-micheli-ruWkmt3nU58-unsplash.jpg";
ImageView *imageView = new ImageView();
imageView->openImage(picPath);
imageView->fitImage();
imageView->fitWindow();
imageView->autoFit();
imageView->imageRelativeScale();
imageView->setScaleValue(1.1);
imageView->setScaleValue(0.9);
imageView->RotateImage(90);
QTest::qWait(2000);
}