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
20 changes: 10 additions & 10 deletions reader/browser/PageRenderThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -916,8 +916,8 @@ void PageRenderThread::onDocPageNormalImageTaskFinished(DocPageNormalImageTask t
{
// qCDebug(appLog) << "PageRenderThread::onDocPageNormalImageTaskFinished() - Starting on doc page normal image task finished";
if (DocSheet::existSheet(task.sheet)) {
if (nullptr != task.page && !BrowserPage::existPage(task.page))
return; // 页面已析构,丢弃残留回包(task.page 非空时必须存活才可解引用)
if (nullptr == task.page || !BrowserPage::existPage(task.page))
return; // 页面为空或已析构,丢弃残留回包
task.page->setImageObjectRects(task.imageRects, task.rect.width(), task.rect.height());
task.page->handleRenderFinished(task.pixmapId, pixmap);
}
Expand All @@ -928,8 +928,8 @@ void PageRenderThread::onDocPageSliceImageTaskFinished(DocPageSliceImageTask tas
{
// qCDebug(appLog) << "PageRenderThread::onDocPageSliceImageTaskFinished() - Starting on doc page slice image task finished";
if (DocSheet::existSheet(task.sheet)) {
if (nullptr != task.page && !BrowserPage::existPage(task.page))
return; // 页面已析构,丢弃残留回包
if (nullptr == task.page || !BrowserPage::existPage(task.page))
return; // 页面为空或已析构,丢弃残留回包
task.page->handleRenderFinished(task.pixmapId, pixmap, task.slice);
}
// qCDebug(appLog) << "PageRenderThread::onDocPageSliceImageTaskFinished() - On doc page slice image task finished completed";
Expand All @@ -939,8 +939,8 @@ void PageRenderThread::onDocPageBigImageTaskFinished(DocPageBigImageTask task, Q
{
// qCDebug(appLog) << "PageRenderThread::onDocPageBigImageTaskFinished() - Starting on doc page big image task finished";
if (DocSheet::existSheet(task.sheet)) {
if (nullptr != task.page && !BrowserPage::existPage(task.page))
return; // 页面已析构,丢弃残留回包
if (nullptr == task.page || !BrowserPage::existPage(task.page))
return; // 页面为空或已析构,丢弃残留回包
task.page->setImageObjectRects(task.imageRects, task.rect.width(), task.rect.height());
task.page->handleRenderFinished(task.pixmapId, pixmap);
}
Expand All @@ -951,8 +951,8 @@ void PageRenderThread::onDocPageWordTaskFinished(DocPageWordTask task, QList<dee
{
// qCDebug(appLog) << "PageRenderThread::onDocPageWordTaskFinished() - Starting on doc page word task finished";
if (DocSheet::existSheet(task.sheet)) {
if (nullptr != task.page && !BrowserPage::existPage(task.page))
return; // 页面已析构,丢弃残留回包(测试场景中 page 为空且 handler 已被 stub,直接放行)
if (nullptr == task.page || !BrowserPage::existPage(task.page))
return; // 页面为空或已析构,丢弃残留回包
task.page->handleWordLoaded(words);
}
// qCDebug(appLog) << "PageRenderThread::onDocPageWordTaskFinished() - On doc page word task finished completed";
Expand All @@ -962,8 +962,8 @@ void PageRenderThread::onDocPageAnnotationTaskFinished(DocPageAnnotationTask tas
{
// qCDebug(appLog) << "PageRenderThread::onDocPageAnnotationTaskFinished() - Starting on doc page annotation task finished";
if (DocSheet::existSheet(task.sheet)) {
if (nullptr != task.page && !BrowserPage::existPage(task.page))
return; // 页面已析构,丢弃残留回包
if (nullptr == task.page || !BrowserPage::existPage(task.page))
return; // 页面为空或已析构,丢弃残留回包
task.page->handleAnnotationLoaded(annots);
}
// qCDebug(appLog) << "PageRenderThread::onDocPageAnnotationTaskFinished() - On doc page annotation task finished completed";
Expand Down
23 changes: 18 additions & 5 deletions tests/browser/ut_pagerenderthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ static bool existSheet_true_stub(DocSheet *)
return true;
}

// Makes BrowserPage::existPage() return true so the onDoc*Finished guard
// (nullptr == task.page || !existPage(task.page)) passes with a non-null
// placeholder page whose handler methods are already stubbed.
static bool existPage_true_stub(const BrowserPage *)
{
return true;
}

/*********测试用例**********/
//TEST_F(TestPageRenderThread, UT_PageRenderThread_clearImageTasks_001)
//{
Expand Down Expand Up @@ -234,12 +242,13 @@ TEST_F(TestPageRenderThread, UT_PageRenderThread_onDocPageNormalImageTaskFinishe
{
Stub s;
s.set(ADDR(DocSheet, existSheet), existSheet_true_stub);
s.set(ADDR(BrowserPage, existPage), existPage_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
task.page = nullptr; // stub will be invoked, nullptr this is ignored
task.page = reinterpret_cast<BrowserPage *>(0x1); // non-null placeholder; handler methods are stubbed
task.pixmapId = 1;
QPixmap pix;
m_tester->onDocPageNormalImageTaskFinished(task, pix);
Expand All @@ -252,11 +261,12 @@ TEST_F(TestPageRenderThread, UT_PageRenderThread_onDocPageSliceImageTaskFinished
{
Stub s;
s.set(ADDR(DocSheet, existSheet), existSheet_true_stub);
s.set(ADDR(BrowserPage, existPage), existPage_true_stub);
s.set(ADDR(BrowserPage, handleRenderFinished), handleRenderFinished_stub);

DocPageSliceImageTask task;
task.sheet = nullptr;
task.page = nullptr;
task.page = reinterpret_cast<BrowserPage *>(0x1);
task.pixmapId = 2;
task.slice = QRect(0, 0, 10, 10);
QPixmap pix;
Expand All @@ -270,12 +280,13 @@ TEST_F(TestPageRenderThread, UT_PageRenderThread_onDocPageBigImageTaskFinished_0
{
Stub s;
s.set(ADDR(DocSheet, existSheet), existSheet_true_stub);
s.set(ADDR(BrowserPage, existPage), existPage_true_stub);
s.set(ADDR(BrowserPage, handleRenderFinished), handleRenderFinished_stub);
s.set(ADDR(BrowserPage, setImageObjectRects), setImageObjectRects_stub);

DocPageBigImageTask task;
task.sheet = nullptr;
task.page = nullptr;
task.page = reinterpret_cast<BrowserPage *>(0x1);
task.pixmapId = 3;
QPixmap pix;
m_tester->onDocPageBigImageTaskFinished(task, pix);
Expand All @@ -288,11 +299,12 @@ TEST_F(TestPageRenderThread, UT_PageRenderThread_onDocPageWordTaskFinished_002)
{
Stub s;
s.set(ADDR(DocSheet, existSheet), existSheet_true_stub);
s.set(ADDR(BrowserPage, existPage), existPage_true_stub);
s.set(ADDR(BrowserPage, handleWordLoaded), handleWordLoaded_stub);

DocPageWordTask task;
task.sheet = nullptr;
task.page = nullptr;
task.page = reinterpret_cast<BrowserPage *>(0x1);
QList<deepin_reader::Word> words;
m_tester->onDocPageWordTaskFinished(task, words);
EXPECT_TRUE(g_funcName == "handleWordLoaded_stub");
Expand All @@ -304,11 +316,12 @@ TEST_F(TestPageRenderThread, UT_PageRenderThread_onDocPageAnnotationTaskFinished
{
Stub s;
s.set(ADDR(DocSheet, existSheet), existSheet_true_stub);
s.set(ADDR(BrowserPage, existPage), existPage_true_stub);
s.set(ADDR(BrowserPage, handleAnnotationLoaded), handleAnnotationLoaded_stub);

DocPageAnnotationTask task;
task.sheet = nullptr;
task.page = nullptr;
task.page = reinterpret_cast<BrowserPage *>(0x1);
QList<deepin_reader::Annotation *> annots;
m_tester->onDocPageAnnotationTaskFinished(task, annots);
EXPECT_TRUE(g_funcName == "handleAnnotationLoaded_stub");
Expand Down
Loading