Skip to content

test: add GTest for panels/dock classes - #1710

Draft
MyLeeJiEun wants to merge 1 commit into
linuxdeepin:masterfrom
MyLeeJiEun:test/panels-dock-gtest
Draft

test: add GTest for panels/dock classes#1710
MyLeeJiEun wants to merge 1 commit into
linuxdeepin:masterfrom
MyLeeJiEun:test/panels-dock-gtest

Conversation

@MyLeeJiEun

@MyLeeJiEun MyLeeJiEun commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds 111 GTest unit tests for the panels/dock classes of dde-shell, which previously had zero test coverage. This is the dock batch, separate from PR #1703 (frame batch) and PR #1707 (applets batch) — no frame or applets files are included here.

Test scope (5 classes, 111 tests)

Class Source Tests
DockItemInfo panels/dock/dockiteminfo.cpp 16
HoverPreviewProxyModel panels/dock/hoverpreviewproxymodel.cpp 14
Globals panels/dock/global.h 18
WindowManager panels/dock/windowmanager.cpp 42
TrayItemPositionManager panels/dock/trayitempositionmanager.cpp 21

All 111 tests pass (0 failed / 1 disabled). Sources under test are compiled into an independent OBJECT library dock_test_objects (separate from frame/applets test objects) to avoid symbol clashes. No DConfig / Wayland runtime required — stubs isolate build-time dependencies.

Build

cmake -B build -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=Debug
cmake --build build
ctest --test-dir build -R '^dock_' --output-on-failure   # 111/111 passed

Coverage

Enable coverage through the build-system target:

cmake -B build -DBUILD_TESTING=ON -DDOCK_BUILD_COVERAGE=ON -DCMAKE_BUILD_TYPE=Debug
cmake --build build --target dock_coverage
# report: build/dock_coverage/html/index.html

lcov results (generated code excluded):

Metric Coverage Target (≥70%)
Function 94.6%
Line 92.6%
Branch 57.4%

This PR does not modify src/ — tests only.

Notes


Tracking issue: DDE-107 补充 dde-shell 项目测试代码

Summary by Sourcery

Expand dock panel test coverage with isolated GoogleTest targets covering core dock classes and optional coverage reporting.

Enhancements:

  • Add comprehensive GoogleTest coverage for dock panel data models, filtering, window management, global path conversion, and tray item positioning behavior.

Build:

  • Add CMake configuration for dedicated dock test executables, isolated production test objects, dependency stubs, and optional coverage report generation.

Tests:

  • Register the new dock test suite with CTest and GoogleTest discovery, including DBus-aware DockItemInfo tests and event-loop-based tray manager tests.

1. Add docktests for dockiteminfo, hoverpreviewproxymodel,
   globals, windowmanager and trayitempositionmanager
2. Include 111 test cases (1 disabled, 0 failures)
3. Add independent dock_test_objects OBJECT library to avoid
   symbol clashes with frame/applets test objects
4. Add stubs/QQmlEngine and stubs/taskmanager.h for Qt6 Qml
   dev-package-missing and build-time dependency isolation
5. Wire add_subdirectory(docktests) and DOCK_BUILD_COVERAGE gate

Influence:
1. Run docktests with QT_QPA_PLATFORM=offscreen, verify 111
   cases pass (0 failures, 1 disabled)
2. Verify coverage meets thresholds (function 94.6%, line
   92.6%, branch 57.4%)
3. Confirm dock tests build independent of frame/applets
4. Verify dockiteminfo_tests under dbus-run-session

test: 为 panels/dock 多模块类补充 GTest 单元测试

1. 新增 docktests,覆盖 dockiteminfo、hoverpreviewproxymodel、
   globals、windowmanager 与 trayitempositionmanager
2. 包含 111 个测试用例(1 禁用、0 失败)
3. 新增独立 dock_test_objects OBJECT 库,避免与 frame/applets
   测试对象的符号冲突
4. 新增 stubs/QQmlEngine 与 stubs/taskmanager.h,解决 Qt6 Qml
   开发包缺失及编译期依赖隔离
5. 接入 add_subdirectory(docktests) 与 DOCK_BUILD_COVERAGE 门控

Influence:
1. 以 QT_QPA_PLATFORM=offscreen 运行 docktests,验证 111
   用例通过(0 失败、1 禁用)
2. 验证覆盖率达标(函数 94.6%、行 92.6%、分支 57.4%)
3. 确认 dock 测试独立于 frame/applets 构建
4. 在 dbus-run-session 下验证 dockiteminfo_tests
@MyLeeJiEun
MyLeeJiEun marked this pull request as draft August 21, 2026 12:14

@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 @MyLeeJiEun, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: MyLeeJiEun

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

@deepin-ci-robot

Copy link
Copy Markdown

Hi @MyLeeJiEun. Thanks for your PR.

I'm waiting for a linuxdeepin member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@sourcery-ai

sourcery-ai Bot commented Aug 21, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds a new docktests GTest suite and coverage target for dock panel classes, wiring it into the existing tests/panels/dock tree, with an OBJECT library for shared non-Q_OBJECT sources and multiple focused test executables for HoverPreviewProxyModel, Globals helpers, DockItemInfo DBus/Debug behavior, WindowManager runtime tracking, and TrayItemPositionManager layout logic, plus minimal Qt stubs to decouple build-time dependencies.

File-Level Changes

Change Details Files
Introduce dock panel GTest suite wired into CTest with coverage support and shared OBJECT library for non-Q_OBJECT sources.
  • Add docktests subdirectory under tests/panels/dock and find/link GTest and required Qt components.
  • Define dock_test_objects OBJECT library for dockiteminfo.cpp with visibility hacks and optional gcov instrumentation.
  • Create GTest executables for hoverpreviewproxymodel, globals inline helpers, DockItemInfo, WindowManager, and TrayItemPositionManager, each with appropriate include paths, Qt links, and gtest_discover_tests registration.
  • Add DOCK_BUILD_COVERAGE option and dock_coverage custom target using lcov/genhtml, filtering generated and third-party code.
tests/panels/dock/CMakeLists.txt
tests/panels/dock/docktests/CMakeLists.txt
Add high-coverage DockItemInfo tests, including QMetaType registration, QDebug formatting, and DBus round-trip of QDBusArgument operators.
  • Verify registerPluginInfoMetaType registers DockItemInfo and DockItemInfos and is idempotent.
  • Exercise struct field assignments, copy semantics, empty fields, and various visible values via QDebug output checks.
  • Create a QObject-based DBus echo service and perform session bus round-trips of DockItemInfo using QDBusInterface/QDBusReply, skipping when no session bus is available.
tests/panels/dock/docktests/dockiteminfotests.cpp
Test dock::escapeToObjectPath/unescapeFromObjectPath behavior, including edge cases and a known underscore-handling quirk.
  • Cover escaping for empty strings, alphanumerics, spaces, punctuation, and typical desktop IDs.
  • Cover unescaping of encoded sequences and round-trip behavior for multiple sample strings.
  • Add a disabled test documenting that literal underscores are left as-is when not followed by two hex digits.
tests/panels/dock/docktests/globalstests.cpp
Add HoverPreviewProxyModel tests using a minimal source model to validate filtering by app ID and window ID and dynamic updates.
  • Introduce TestSourceModel providing WinIdRole and DesktopIdRole for use by HoverPreviewProxyModel.
  • Verify constructor behavior (dynamicSortFilter), filter modes, clearing filters, and behavior with null or missing source models.
  • Test special cases such as winId==0 rows being rejected, switching filter modes, and reacting to late-added rows.
tests/panels/dock/docktests/hoverpreviewproxymodeltests.cpp
tests/panels/dock/docktests/sourcemodel.h
Stub Qt/QML and taskmanager dependencies to make dock tests self-contained without full DTK/QML dev packages.
  • Provide a minimal QQmlEngine header stub that defines QML macros and forward-declares QQmlEngine/QJSEngine.
  • Introduce a stub TaskManager class exposing the Roles enum used by HoverPreviewProxyModel, avoiding pulling in the full taskmanager implementation.
tests/panels/dock/docktests/stubs/QQmlEngine
tests/panels/dock/docktests/stubs/taskmanager.h
Add comprehensive TrayItemPositionManager tests, including singleton behavior, layout computations, signals, and known defects.
  • Reset singleton mutable state between tests and validate default spacing, padding, and item visual size.
  • Cover registerVisualItemSize/visualItemSize semantics, visualSize calculations for horizontal and vertical orientations, and itemIndexByPoint behavior including off-by-one vertical loop quirk.
  • Test clearRegisteredSizes, layoutHealthCheck/updateVisualSize via signals and timers, DropIndex defaults, and provide a custom main() with QCoreApplication for event-loop-based tests.
tests/panels/dock/docktests/trayitempositionmanagertests.cpp
Add WindowManager tests targeting row/data semantics, duplicate handling, active/inactive transitions, and AppRuntimeInfo equality.
  • Validate rowCount, data() for various roles and invalid indices, and roleNames mappings.
  • Exercise setWindowInfoForeground/background duplicate behavior and missing windowList implementation via enabled and disabled tests that document current limitations and defects.
  • Test WindowDestroyInfo and setWindowInfoActive/InActive interactions (where link-time constraints allow), and fully cover AppRuntimeInfo operator== semantics, including that startTime is ignored.
tests/panels/dock/docktests/windowmanagertests.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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants