Skip to content

test: add unit tests for markdown and theme modules - #564

Merged
pengfeixx merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:test/ut-markdown-theme
Sep 4, 2026
Merged

test: add unit tests for markdown and theme modules#564
pengfeixx merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:test/ut-markdown-theme

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

内容

新增 markdown 与主题模块的 GTest 单元测试:markdown 渲染/桥接/视图、滚动同步、主题序列化、视图模式状态机及主题面板组件,共 16 个文件。

说明

  • 基于 master 独立拉出,可独立评审与合并
  • 仅新增单元测试代码,不改动编辑器本体功能

Summary by Sourcery

Expand automated unit-test coverage across the Markdown and theme modules without changing editor functionality.

Enhancements:

  • Add comprehensive GoogleTest coverage for Markdown rendering, bridging, image handling, view state, scrolling, throttling, and theme serialization behavior.
  • Add unit coverage for theme models, views, delegates, and panels, including theme loading, selection, rendering, and UI state transitions.

Build:

  • Add CMake targets and test discovery configuration for Markdown and theme module test suites, including Qt Test and coverage dependencies.

Tests:

  • Introduce isolated offscreen GTest executables covering 16 Markdown and theme module test files with controlled stubs and parameterized edge-case tests.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry @pengfeixx, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 6 days and 6 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Sep 4, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds a standalone, offscreen GTest suite covering Markdown rendering/bridging, image and WebEngine behavior, scroll synchronization, throttling, theme serialization, view-mode transitions, and theme-panel UI components without changing production functionality.

File-Level Changes

Change Details Files
Added standalone CMake targets for markdown-focused unit tests with Qt/GTest integration, AUTOMOC support, offscreen discovery, and debug coverage linking.
  • Introduced a reusable test-target helper and separate executables for renderer, bridge, logic, scroll synchronization, serialization, view state, WebEngine view/image handling, and render throttling.
  • Added Qt6 Test linkage for signal-spy-based tests and included production headers or implementation files where required for Q_OBJECT and internal-class coverage.
tests/editor_markdown/CMakeLists.txt
Added comprehensive tests for markdown utility and protocol behavior.
  • Tested polymorphic renderer dispatch, virtual destruction, readiness, and payload forwarding.
  • Tested bridge signal forwarding, ratio boundaries, empty payloads, translations, UI text properties, and QObject ownership.
  • Tested markdown classification and image-path rewriting across extensions, schemes, empty inputs, titles, multiple images, and whitespace.
  • Tested scroll ratio clamping and degenerate scrollbar ranges.
  • Tested theme darkness detection, CSS-variable serialization, fallback chains, malformed input, and compact JSON output.
  • Tested view-mode availability and transitions for Markdown/non-Markdown files, including reserved modes.
tests/editor_markdown/test_imarkdownrenderer.cpp
tests/editor_markdown/test_markdownbridge.cpp
tests/editor_markdown/test_markdownlogic.cpp
tests/editor_markdown/test_scrollsync.cpp
tests/editor_markdown/test_themeserializer.cpp
tests/editor_markdown/test_viewmodefsm.cpp
Added integration-style unit tests for the Markdown WebEngine view and image resource handling.
  • Verified MarkdownView construction, bridge forwarding, pre-ready caching/replay, mode mapping, theme/layout/scroll requests, scroll calculations, link filtering, URL navigation, initialization idempotence, and render-process recovery.
  • Exercised MarkdownImageHandler with real temporary files and symlinks, covering image replies, missing or directory resources, MIME denial, URL host reconstruction, and path normalization.
  • Added RenderThrottle timing tests for leading-edge rendering, trailing-edge emission, continuous input renewal, cooldown stopping, and the default interval.
tests/editor_markdown/test_markdownview.cpp
tests/editor_markdown/test_markdownimagehandler.cpp
tests/editor_markdown/test_renderthrottle.cpp
Added a dedicated theme-module test executable and shared controlled test environment.
  • Configured offscreen Qt/GTest execution, Qt Test support, coverage linking, source-library linkage, private-access compilation, and symbol export for stubbing.
  • Created shared QApplication setup, fake theme data construction, and stubs for theme directory enumeration and theme-map loading.
tests/thememodule/CMakeLists.txt
tests/thememodule/test_env.h
Added tests for theme model, view, delegate, and panel components.
  • Verified ThemeListModel empty and sorted data loading, role values, frame colors, selection signaling, and unknown-path behavior.
  • Verified ThemeListView scroll policies, visible/hidden scrollbar margin handling, focus filtering, and single/multi/empty selection signaling.
  • Verified ThemeItemDelegate size hints and selected/unselected offscreen painting behavior.
  • Verified ThemePanel hierarchy, dimensions, lightness-based frame colors, popup/hide animations, model forwarding, selection changes, and paint output.
tests/thememodule/test_themelistmodel.cpp
tests/thememodule/test_themelistview.cpp
tests/thememodule/test_themeitemdelegate.cpp
tests/thememodule/test_themepanel.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 99 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 99 分,大于 70 分通过阈值,代码质量符合要求。本次提交为纯单元测试代码,测试覆盖全面,文档详尽,无安全问题。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 语法正确,逻辑清晰。所有测试文件正确使用 Google Test 框架,CMake 配置正确,Arrange-Act-Assert 模式一致遵循,内存管理正确(无泄漏、无双重释放)。


2. 代码质量 ✅

评价: 优秀 ✅ 通过

潜在问题:

  1. tests/editor_markdown/test_markdownimagehandler.cpp:486 - 直接 #include "markdownview.cpp" 包含实现文件(测试匿名命名空间类的已知模式,注释已说明原因,但属于代码异味)

建议: 代码结构清晰,注释完整。建议将 MarkdownImageHandler 从匿名命名空间提取为内部头文件,避免直接包含 .cpp 文件。


3. 代码性能 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 性能良好,资源使用合理。测试使用 offscreen Qt 平台高效运行,QTest::qWait 超时设置合理,QTemporaryDir 文件隔离正确清理。


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: 存在0个安全漏洞。测试代码正确验证了安全相关行为:MarkdownImageHandler 拒绝非图片文件、URL scheme 验证;MarkdownView 链接 scheme 验证(仅允许 http/https,拦截 javascript: 协议)。无硬编码凭据,QTemporaryDir 文件隔离,stub_ext 正确隔离外部依赖。


💡 改进建议代码示例

// 建议将 MarkdownImageHandler 从匿名命名空间提取为内部头文件
// markdownimagehandler.h (新增内部头文件)
#pragma once
#include <QWebEngineUrlSchemeHandler>

class MarkdownImageHandler : public QWebEngineUrlSchemeHandler {
protected:
    void requestStarted(QWebEngineUrlRequestJob *job) override;
};

// 测试文件改为:
// #include "markdownimagehandler.h"  // 替代 #include "markdownview.cpp"

本报告由 AI 代码审查工具自动生成

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, pengfeixx

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Add GTest suites for markdown rendering/bridge/logic/view, scroll
sync, theme serializer, view mode FSM and theme panel widgets.

新增 markdown 渲染/桥接/视图、滚动同步、主题序列化、视图模式状态机
及主题面板组件的 GTest 单元测试。

Log: 新增 markdown 与主题模块单元测试
Influence: 仅新增单元测试代码,不影响编辑器本体功能。
@pengfeixx
pengfeixx force-pushed the test/ut-markdown-theme branch from 738f802 to 4443153 Compare September 4, 2026 09:07
@pengfeixx
pengfeixx merged commit 36ccb67 into linuxdeepin:master Sep 4, 2026
8 of 14 checks passed
@pengfeixx
pengfeixx deleted the test/ut-markdown-theme branch September 4, 2026 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants