Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions tests/app/ut_dbusobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

#include "DBusObject.h"
#include "MainWindow.h"
#include "stub.h"

Check warning on line 8 in tests/app/ut_dbusobject.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "stub.h" not found.

#include <QWidget>

Check warning on line 10 in tests/app/ut_dbusobject.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QWidget> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QUrl>

Check warning on line 11 in tests/app/ut_dbusobject.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QUrl> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <gtest/gtest.h>

Check warning on line 13 in tests/app/ut_dbusobject.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <gtest/gtest.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

/********测试DBusObject***********/
class TestDBusObject : public ::testing::Test
Expand Down Expand Up @@ -164,3 +165,66 @@
delete g_mainWindow;
}


/* ========== PMS 回归用例(sev1/2 bug 补强,批次1) ========== */

// PMS: https://pms.uniontech.com/bug-view-312013.html commit: c44cc7a0
static QString g_lastAddFilePath;
// 成员函数桩经 ut-stub jmp 补丁以成员 ABI (this, path) 被调用,需双参接收
void addFileCapture_stub(MainWindow *self, const QString &path)
{
Q_UNUSED(self)
g_funcName = __FUNCTION__;
g_lastAddFilePath = path;
}

// PMS: https://pms.uniontech.com/bug-view-312013.html commit: c44cc7a0
TEST_F(TestDBusObject, BUG312013_handleFiles_urlConvertedToLocal)
{
// 双击 pdf 无法查看修复(DBus 支持 URL 入参):file:// URL 必须转换为本地路径后打开
Stub s;
s.set(ADDR(MainWindow, addFile), addFileCapture_stub);
s.set(ADDR(QWidget, show), show_stub);
s.set(static_cast<MainWindow*(*)(QStringList)>(ADDR(MainWindow, createWindow)), createWindow_stub);

m_tester->m_isBlockShutdown = true;
QString localPath = UTSOURCEDIR;
localPath += "/files/normal.pdf";
QStringList filePathList = {QUrl::fromLocalFile(localPath).toString()};
m_tester->handleFiles(filePathList);
EXPECT_EQ(g_lastAddFilePath, localPath);
delete g_mainWindow;
}

// PMS: https://pms.uniontech.com/bug-view-312013.html commit: c44cc7a0
TEST_F(TestDBusObject, BUG312013_handleFiles_alreadyOpenNoReadd)
{
// 已打开文件(activateSheetIfExist 命中)不得重复入窗
Stub s;
s.set(ADDR(MainWindow, addFile), addFileCapture_stub);
s.set(ADDR(QWidget, show), show_stub);
s.set(static_cast<MainWindow*(*)(QStringList)>(ADDR(MainWindow, createWindow)), createWindow_stub);
s.set(ADDR(MainWindow, activateSheetIfExist), registerService_stub); // 任意返回 true 的 bool(const QString&)

m_tester->m_isBlockShutdown = true;
QString localPath = UTSOURCEDIR;
localPath += "/files/normal.pdf";
QStringList filePathList = {QUrl::fromLocalFile(localPath).toString()};
g_lastAddFilePath.clear();
m_tester->handleFiles(filePathList);
EXPECT_FALSE(g_funcName == QString("addFileCapture_stub"));
delete g_mainWindow;
}

// PMS: https://pms.uniontech.com/bug-view-312013.html commit: c44cc7a0
TEST_F(TestDBusObject, BUG312013_unBlockShutdown_repeatNoCrash)
{
// DBus 入口修复涉及 unBlockShutdown:重复解除关机阻断不得崩溃
Stub s;
s.set(ADDR(QDBusAbstractInterface, callWithArgumentList), callWithArgumentList_stub);
m_tester->blockShutdown();
m_tester->unBlockShutdown();
EXPECT_FALSE(m_tester->m_isBlockShutdown);
m_tester->unBlockShutdown();
EXPECT_FALSE(m_tester->m_isBlockShutdown);
}
24 changes: 24 additions & 0 deletions tests/app/ut_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,27 @@ TEST_F(TestUtils, UT_Utils_setCurrentFilePath_001)
EXPECT_TRUE(Utils::m_currenFilePath == "/test/path/file.pdf");
Utils::setCurrentFilePath("");
}

/* ========== PMS 回归用例(sev1/2 bug 补强,批次1) ========== */

// PMS: https://pms.uniontech.com/bug-view-218701.html commit: bb8f3e92
TEST_F(TestUtils, BUG218701_roundQPixmap_nullInputGuard)
{
// 复制文本修复涉及 roundQPixmap:空图输入必须返回空图不崩溃
QPixmap in;
EXPECT_TRUE(Utils::roundQPixmap(in, 10).isNull());
}

// PMS: https://pms.uniontech.com/bug-view-218701.html commit: bb8f3e92
TEST_F(TestUtils, BUG218701_roundQPixmap_validInputKeepsSize)
{
// 有效图输入圆角处理:输出非空且保持原始尺寸,零半径退化场景不崩溃
QPixmap in(100, 80);
QPixmap out = Utils::roundQPixmap(in, 12);
EXPECT_FALSE(out.isNull());
EXPECT_EQ(out.size(), in.size());

QPixmap out0 = Utils::roundQPixmap(in, 0);
EXPECT_FALSE(out0.isNull());
EXPECT_EQ(out0.size(), in.size());
}
115 changes: 115 additions & 0 deletions tests/document/ut_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
#include "dpdfdoc.h"
#include "stub.h"

#include <QProcess>

Check warning on line 14 in tests/document/ut_model.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QProcess> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDir>

Check warning on line 15 in tests/document/ut_model.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDir> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QtGlobal>

Check warning on line 16 in tests/document/ut_model.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QtGlobal> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QStandardPaths>

Check warning on line 17 in tests/document/ut_model.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QStandardPaths> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QCoreApplication>

Check warning on line 18 in tests/document/ut_model.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QCoreApplication> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <gtest/gtest.h>

Check warning on line 20 in tests/document/ut_model.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <gtest/gtest.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
using namespace deepin_reader;

/***********桩函数**********/
Expand Down Expand Up @@ -305,3 +307,116 @@
delete annot;
delete dAnnot;
}

/* ========== PMS 回归用例(sev1/2 bug 补强,批次1) ========== */

/* 说明:calculateTimeout / getHtmlToPdfPath 为 Model.cpp 文件内 static 自由函数,
* 无法从测试侧直接调用,经公开入口 DocumentFactory::getDocument 的 DOCX 转换管线
* 间接驱动(管线内 calculateTimeout×3、getHtmlToPdfPath×1)。
*/

// PMS: https://pms.uniontech.com/bug-view-332133.html commit: b1746b32
TEST(UT_DocumentFactory_getDocument, BUG332133_docxTimeout_dynamicTimeoutNoHang)
{
// 大文件 docx 转换超时修复:动态超时(按 MB 计算)替代固定超时,
// 常规文件取基准超时且各阶段失败时优雅返回 ConvertFailed,不得挂起
Stub s;
s.set(static_cast<bool(QFile::*)(const QString &)>(ADDR(QFile, copy)), copy_stub);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
s.set(static_cast<void(QProcess::*)(const QString &, const QStringList &, QProcess::OpenMode)>(ADDR(QProcess, start)), start_stub_qt6);
#else
s.set(static_cast<void(QProcess::*)(const QString &, QProcess::OpenMode)>(ADDR(QProcess, start)), start_stub);
#endif
Stub s1;
s1.set(ADDR(QProcess, waitForStarted), waitForStarted_true_stub);
s1.set(ADDR(QProcess, waitForFinished), waitForFinished_true_stub);

int fileType = Dr::DOCX;
QString filePath = UTSOURCEDIR;
filePath += "/files/normal.docx";
QString convertedFileDir = QCoreApplication::applicationDirPath();
QString password;
QProcess p;
QProcess *process = &p;
Document::Error error = Document::NoError;

Document *pdocument = DocumentFactory::getDocument(fileType, filePath, convertedFileDir, password, &process, error);
EXPECT_EQ(pdocument, nullptr);
EXPECT_EQ(error, Document::ConvertFailed); // word/ 目录未生成(unzip 桩不落盘)
EXPECT_EQ(process, nullptr);
}

// PMS: https://pms.uniontech.com/bug-view-332133.html commit: b1746b32
TEST(UT_DocumentFactory_getDocument, BUG332133_docxTimeout_overflowGuard)
{
// 溢出保护:超大文件 sizeInMB 超过安全上限时超时取 MAX_TIMEOUT_MS,
// 不得整型溢出/崩溃(300MB 稀疏文件 > 各阶段 maxSafeSize:unzip 285/pandoc 108/htmltopdf 48)
QString bigPath = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/ut_big_sparse.docx";
QFile bigFile(bigPath);
if (bigFile.exists())
bigFile.remove();
ASSERT_TRUE(bigFile.open(QIODevice::WriteOnly));
ASSERT_TRUE(bigFile.resize(300LL * 1024 * 1024)); // 300MB 稀疏文件,瞬间创建
bigFile.close();

Stub s;
s.set(static_cast<bool(QFile::*)(const QString &)>(ADDR(QFile, copy)), copy_stub);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
s.set(static_cast<void(QProcess::*)(const QString &, const QStringList &, QProcess::OpenMode)>(ADDR(QProcess, start)), start_stub_qt6);
#else
s.set(static_cast<void(QProcess::*)(const QString &, QProcess::OpenMode)>(ADDR(QProcess, start)), start_stub);
#endif
Stub s1;
s1.set(ADDR(QProcess, waitForStarted), waitForStarted_true_stub);
s1.set(ADDR(QProcess, waitForFinished), waitForFinished_true_stub);

int fileType = Dr::DOCX;
QString convertedFileDir = QCoreApplication::applicationDirPath();
QString password;
QProcess p;
QProcess *process = &p;
Document::Error error = Document::NoError;

Document *pdocument = DocumentFactory::getDocument(fileType, bigPath, convertedFileDir, password, &process, error);
EXPECT_EQ(pdocument, nullptr);
EXPECT_EQ(error, Document::ConvertFailed);
EXPECT_EQ(process, nullptr);

bigFile.remove();
}

// PMS: https://pms.uniontech.com/bug-view-304083.html commit: f260a63f
TEST(UT_DocumentFactory_getDocument, BUG304083_docxPipeline_gracefulFailNoCrash)
{
// docx 打不开修复(getHtmlToPdfPath 多级路径查找):完整转换管线(unzip->pandoc->htmltopdf)
// 各阶段失败必须优雅返回不崩溃,getHtmlToPdfPath 真实路径查找正常执行
Stub s;
s.set(static_cast<bool(QFile::*)(const QString &)>(ADDR(QFile, copy)), copy_stub);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
s.set(static_cast<void(QProcess::*)(const QString &, const QStringList &, QProcess::OpenMode)>(ADDR(QProcess, start)), start_stub_qt6);
#else
s.set(static_cast<void(QProcess::*)(const QString &, QProcess::OpenMode)>(ADDR(QProcess, start)), start_stub);
#endif
Stub s1;
s1.set(ADDR(QProcess, waitForStarted), waitForStarted_true_stub);
s1.set(ADDR(QProcess, waitForFinished), waitForFinished_true_stub);
Stub s2;
s2.set(static_cast<bool(QDir::*)()const>(ADDR(QDir, exists)), exists_stub);
s2.set(static_cast<bool(QFile::*)()const>(ADDR(QFile, exists)), exists_stub);
Stub s3;
s3.set(ADDR(PDFDocument, loadDocument), loadpdfDocument_stub);

int fileType = Dr::DOCX;
QString filePath = UTSOURCEDIR;
filePath += "/files/normal.docx";
QString convertedFileDir = QCoreApplication::applicationDirPath();
QString password;
QProcess p;
QProcess *process = &p;
Document::Error error = Document::NoError;

Document *pdocument = DocumentFactory::getDocument(fileType, filePath, convertedFileDir, password, &process, error);
EXPECT_EQ(pdocument, nullptr);
EXPECT_EQ(error, Document::FileError); // 转换产物加载失败(stub FileError)
EXPECT_EQ(process, nullptr);
}
28 changes: 28 additions & 0 deletions tests/document/ut_xpsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,3 +492,31 @@ TEST_F(TestXpsTextExtractor, parseGlyphsMissingOrigin)
// Position is default-constructed QPointF.
EXPECT_TRUE(info.position.isNull());
}

/* ========== PMS 回归用例(sev1/2 bug 补强,批次1) ========== */

// PMS: https://pms.uniontech.com/bug-view-343541.html commit: a3cb6cff
TEST_F(TestXpsDocumentAdapter, BUG343541_renderPage_highDpiScaling)
{
// XPS 渲染慢修复(cairo_matrix 高DPI 缩放):目标尺寸大于逻辑页尺寸时
// 按 A4@300dpi 渲染不崩溃且尺寸精确
ASSERT_GT(m_doc->pageCount(), 0);
QImage img = m_doc->renderPage(0, 2480, 3508, QRect());
EXPECT_FALSE(img.isNull());
EXPECT_EQ(img.size(), QSize(2480, 3508));
}

// PMS: https://pms.uniontech.com/bug-view-343541.html commit: a3cb6cff
TEST_F(TestXpsDocumentAdapter, BUG343541_renderPage_fixedSizeAndGuard)
{
// 固定尺寸渲染与守卫补充:单维负值/负页码返回空图且不崩溃
QImage img = m_doc->renderPage(0, 100, 100, QRect());
EXPECT_FALSE(img.isNull());
EXPECT_EQ(img.size(), QSize(100, 100));

// 单维负值(既有用例仅覆盖双负值与零值)
EXPECT_TRUE(m_doc->renderPage(0, -1, 100, QRect()).isNull());
EXPECT_TRUE(m_doc->renderPage(0, 100, -1, QRect()).isNull());
// 负页码(既有用例仅覆盖越界正页码)
EXPECT_TRUE(m_doc->renderPage(-1, 100, 100, QRect()).isNull());
}
Loading
Loading