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
34 changes: 27 additions & 7 deletions tests/browser/ut_browserpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "BrowserPage.h"

Check warning on line 6 in tests/browser/ut_browserpage.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "BrowserPage.h" not found.
#include "NightFilter.h"

Check warning on line 7 in tests/browser/ut_browserpage.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "NightFilter.h" not found.
#include "PageRenderThread.h"

Check warning on line 8 in tests/browser/ut_browserpage.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "PageRenderThread.h" not found.
#include "BrowserAnnotation.h"

Check warning on line 9 in tests/browser/ut_browserpage.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "BrowserAnnotation.h" not found.
#include "PDFModel.h"

Check warning on line 10 in tests/browser/ut_browserpage.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "PDFModel.h" not found.
#include "dpdfannot.h"
#include "SheetRenderer.h"
#include "BrowserWord.h"
Expand Down Expand Up @@ -837,11 +838,30 @@

TEST_F(TestBrowserPage, UT_BrowserPage_applyNightMode_001)
{
QPixmap nullPix;
EXPECT_TRUE(m_tester->applyNightMode(nullPix).isNull());

QPixmap src(16, 16);
src.fill(Qt::white);
QPixmap dst = m_tester->applyNightMode(src);
EXPECT_FALSE(dst.isNull());
// applyNightMode 已重构为异步实现(NightFilter + 后台线程),
// 此处直接测试 NightFilter::apply 纯滤镜逻辑的输入/输出断言

// 空图像输入返回空图像
QImage nullImg;
EXPECT_TRUE(NightFilter::apply(nullImg).isNull());

// 白色图像经夜间滤镜反色后应为深色背景
QImage whiteImg(16, 16, QImage::Format_ARGB32);
whiteImg.fill(Qt::white);
QImage nightImg = NightFilter::apply(whiteImg);
EXPECT_FALSE(nightImg.isNull());
QRgb pixel = nightImg.pixel(0, 0);
EXPECT_LT(qRed(pixel), 128);
EXPECT_LT(qGreen(pixel), 128);
EXPECT_LT(qBlue(pixel), 128);
Comment on lines +854 to +856

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick (testing): The white-image assertions only require each RGB channel to be below 128, so an incorrect implementation that turns white pixels completely black still passes even though the documented filter clamps the inverted lightness to a non-black minimum.

Triggers: When the filter regresses to producing black output for white input.

Suggested fix: Assert the expected dark-gray range or exact/reference pixel values, including the alpha channel, rather than only checking that the channels are below 128.


// 深色像素(boostSourceBelow 以下)反色后应提纯白
QImage darkImg(16, 16, QImage::Format_ARGB32);
darkImg.fill(Qt::black);
QImage darkNight = NightFilter::apply(darkImg);
EXPECT_FALSE(darkNight.isNull());
QRgb darkPixel = darkNight.pixel(0, 0);
EXPECT_EQ(qRed(darkPixel), 255);
EXPECT_EQ(qGreen(darkPixel), 255);
EXPECT_EQ(qBlue(darkPixel), 255);
}
9 changes: 9 additions & 0 deletions tests/browser/ut_pagerenderthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ static void handleRenderFinished_stub(const int &, const QPixmap &, const QRect
g_funcName = __FUNCTION__;
}

// setImageObjectRects stub: night mode refactoring added this call before
// handleRenderFinished in onDocPageNormalImageTaskFinished / onDocPageBigImageTaskFinished.
// Stub prevents null-pointer dereference when task.page is nullptr.
static void setImageObjectRects_stub(const QVector<QRectF> &, int, int)
{
}

static void handleWordLoaded_stub(const QList<deepin_reader::Word> &)
{
g_funcName = __FUNCTION__;
Expand Down Expand Up @@ -228,6 +235,7 @@ TEST_F(TestPageRenderThread, UT_PageRenderThread_onDocPageNormalImageTaskFinishe
Stub s;
s.set(ADDR(DocSheet, existSheet), existSheet_true_stub);
s.set(ADDR(BrowserPage, handleRenderFinished), handleRenderFinished_stub);
s.set(ADDR(BrowserPage, setImageObjectRects), setImageObjectRects_stub);

DocPageNormalImageTask task;
task.sheet = nullptr; // existSheet is stubbed to return true anyway
Expand Down Expand Up @@ -263,6 +271,7 @@ TEST_F(TestPageRenderThread, UT_PageRenderThread_onDocPageBigImageTaskFinished_0
Stub s;
s.set(ADDR(DocSheet, existSheet), existSheet_true_stub);
s.set(ADDR(BrowserPage, handleRenderFinished), handleRenderFinished_stub);
s.set(ADDR(BrowserPage, setImageObjectRects), setImageObjectRects_stub);

DocPageBigImageTask task;
task.sheet = nullptr;
Expand Down
Loading