Skip to content

test(applets): add GTest unit tests for dde-apps classes (54 tests) - #1707

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

test(applets): add GTest unit tests for dde-apps classes (54 tests)#1707
MyLeeJiEun wants to merge 1 commit into
linuxdeepin:masterfrom
MyLeeJiEun:test/applets-gtest

Conversation

@MyLeeJiEun

@MyLeeJiEun MyLeeJiEun commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds 54 GTest unit tests for the applets/dde-apps pure-logic classes of dde-shell, which previously had zero test coverage. This is the applets batch, separate from PR #1703 (frame batch) — no frame files are included here.

Test scope (2 classes, 54 tests)

Class Source Tests
CategoryUtils applets/dde-apps/categoryutils.cpp 16
ItemsPage applets/dde-apps/itemspage.cpp 38

All 54 tests pass (0 failed / 0 skipped / 0 crash). Sources under test are compiled into a single OBJECT library applets_test_objects, linked into 2 test executables. No DConfig / DBus / Wayland runtime required — only pure-logic classes with no external singletons are included.

Build

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

Coverage

Enable coverage through the build-system target:

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

lcov results (generated code excluded):

Metric Coverage Target (≥70%)
Function 100% (28/28)
Line 100% (filtered)
Branch 91.0% (no-throw)

This PR does not modify src/ — tests only.

Notes

  • Tests follow the existing tests/panels/dock/taskmanager pattern (BUILD_TESTING gate + gtest_discover_tests), registered with an applets_ ctest prefix so ctest -R '^applets_' runs only this batch.
  • The remaining applets/dde-apps sources (appslaunchtimes, appsdockedhelper, appitem, appgroup, appgroupmanager, amappitemmodel, etc.) require DConfig / DBus mocks or Wayland runtime and are deferred.

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

Summary by Sourcery

Add unit-test coverage for the pure-logic dde-apps applet classes and integrate the tests into the project build.

Enhancements:

  • Add comprehensive GTest coverage for the pure-logic CategoryUtils and ItemsPage classes in applets/dde-apps.
  • Register applet tests through CMake with dedicated discovery, filtering, and optional coverage-report support.

Build:

  • Add the applets test build configuration, including shared test objects and separate test executables.

Tests:

  • Add 54 unit tests covering category parsing, pagination, item manipulation, signals, and edge cases.

1. Add unit tests for CategoryUtils namespace functions
2. Add unit tests for ItemsPage pagination manager
3. Include 54 test cases covering all public API branches
4. Add CMake build integration with coverage support

Influence:
1. Test category parsing with DDE and XDG format strings
2. Test page operations including insert, move, and remove
3. Verify edge cases like empty input and page overflow

test: 添加 applets dde-apps 类的单元测试

1. 添加 CategoryUtils 命名空间函数的单元测试
2. 添加 ItemsPage 分页管理器的单元测试
3. 包含 54 个测试用例覆盖所有公共 API 分支
4. 添加 CMake 构建集成及覆盖率支持

Influence:
1. 测试 DDE 和 XDG 格式字符串的分类解析
2. 测试页面操作包括插入、移动和删除
3. 验证空输入和页面溢出等边界情况
@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 20, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds a new GTest-based unit test suite and coverage target for the pure-logic dde-apps applets classes (CategoryUtils and ItemsPage), wiring them into the existing tests build and ctest infrastructure without touching production src/ code.

File-Level Changes

Change Details Files
Introduce applets test subtree in CMake and hook it into the global tests build.
  • Add tests/applets as a subdirectory of the main tests/CMakeLists.txt so applets tests are built when BUILD_TESTING is enabled.
  • Create tests/applets/CMakeLists.txt that discovers GTest and Qt Core/Gui/Test, defines an OBJECT library with selected applets sources, and provides a helper function to declare applets test executables with gtest_discover_tests and an applets_ ctest prefix.
tests/CMakeLists.txt
tests/applets/CMakeLists.txt
Define an OBJECT library for pure-logic applets sources and two GTest executables that exercise CategoryUtils and ItemsPage.
  • Create applets_test_objects OBJECT library containing only categoryutils and itemspage sources, with appropriate include directories and Qt Core/Gui linkage, explicitly excluding applets that depend on DConfig/DBus/Wayland/frame singletons.
  • Add a reusable applets_add_test() CMake function that wires GTest, Qt, and applets_test_objects into per-class test executables and registers tests via gtest_discover_tests.
  • Instantiate two test binaries, categoryutils_tests and itemspage_tests, each pointing at its respective test cpp file.
tests/applets/CMakeLists.txt
Add an optional lcov-based coverage instrumentation and reporting pipeline for applets tests.
  • Introduce APPLETS_BUILD_COVERAGE CMake option that, when enabled, adds gcov compiler and linker flags to applets_test_objects and all applets test targets.
  • Define an applets_coverage custom target that runs only applets_ ctest tests, collects coverage with lcov, filters out system/third-party/generated/tests paths, generates an HTML branch-coverage report with genhtml, and prints the report location.
  • Emit a warning when lcov or genhtml are missing and skip creating the coverage target.
tests/applets/CMakeLists.txt
Implement focused GTest coverage for CategoryUtils category parsing logic.
  • Add tests that validate parseDDECategoryString against all known DDE category names and ensure unknown or empty strings yield CategoryErr, including case-sensitivity behavior.
  • Add tests for parseXdgCategoryString covering single and multi-match mappings, x-prefixed categories, and unknown/empty input returning an empty list.
  • Add tests for parseBestMatchedCategory covering empty input handling, DDE vs XDG inputs, voting behavior, special music/video tie-break, ignoring unknown categories, case-insensitive handling, and generic tie resolution behavior.
tests/applets/categoryutilstests.cpp
Implement comprehensive GTest coverage for ItemsPage pagination and item-management behavior, including signals and edge cases.
  • Add construction and basic property tests for ItemsPage with and without a name, verifying maxItemCountPerPage, pageCount, and name behavior.
  • Exercise appendEmptyPage, appendPage, and appendItem in normal, remainder, empty, and signal-emitting scenarios, including automatic page creation when needed.
  • Test insertItem and insertItemToPage, including clamping of indices, spillover into subsequent pages (existing and new), and multi-page spill behavior.
  • Cover findItem, contains, and removeItem (with and without removing empty pages), removeEmptyPages, and removeItemsNotIn (including keeping internal/ items and fully clearing pages).
  • Exercise moveItemPosition across same-page (including append/no-op adjacency cases) and cross-page moves, including removal of empty source pages and resulting pagination changes.
  • Validate allArrangedItems, allPagedItems, itemCount (global and per-page with out-of-range handling), and firstNItems—including observed src defect behavior when requesting 0 items and when requesting more than exist.
tests/applets/itemspagetests.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