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)
{
if (!img->isNull() && scene()) {
QPixmap pic = QPixmap::fromImage(*img);
if (!pic.isNull()) {
scene()->clear();
m_pixmapItem = new QGraphicsPixmapItem(pic);
m_pixmapItem->setTransformationMode(Qt::SmoothTransformation);
QRectF rect = m_pixmapItem->boundingRect();
setSceneRect(rect);
scene()->addItem(m_pixmapItem);
fitWindow();
}
}
}
//void ImageView::openImage(QImage *img)
//{
// if (!img->isNull() && scene()) {
// QPixmap pic = QPixmap::fromImage(*img);
// if (!pic.isNull()) {
// scene()->clear();
// m_pixmapItem = new QGraphicsPixmapItem(pic);
// m_pixmapItem->setTransformationMode(Qt::SmoothTransformation);
// QRectF rect = m_pixmapItem->boundingRect();
// setSceneRect(rect);
// scene()->addItem(m_pixmapItem);
// fitWindow();
// }
// }
//}
qreal ImageView::imageRelativeScale() const
{

View File

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

View File

@ -23,12 +23,14 @@
#include <QTestEventList>
#include <QObject>
#include <QStandardPaths>
#define private public
#define protected public
#include "ocrapplication.h"
#include "mainwidget.h"
#include "view/imageview.h"
//初始拉起主界面
TEST(MainWindow, mainwindow)
{
@ -38,3 +40,59 @@ TEST(MainWindow, mainwindow)
}
//其余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);
}