Skip to content

refactor(test): unify struct create/destroy pattern in protocol tests - #1333

Draft
deepin-wm wants to merge 1 commit into
linuxdeepin:masterfrom
deepin-wm:agent/developer/7902ee1f
Draft

refactor(test): unify struct create/destroy pattern in protocol tests#1333
deepin-wm wants to merge 1 commit into
linuxdeepin:masterfrom
deepin-wm:agent/developer/7902ee1f

Conversation

@deepin-wm

@deepin-wm deepin-wm commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

概述

tests/protocols/ 目录下 15 个 treeland-protocol 基础测试文件的 struct 创建/销毁方式从栈分配 test_init(ctx) / test_destroy(ctx) 统一重构为堆分配 test_ctx_create() / test_destroy(ctx) 模式。

改动内容

  • test_ctx_create:使用 calloc(1, sizeof(*ctx)) 堆分配,分配失败时打印日志并返回 NULL;子资源(results 数组)分配失败时先 free(ctx) 再返回 NULL。
  • test_destroy:增加 NULL 守卫,依次释放内部资源(ctx->results)与自身(ctx)。
  • protocol_test_runstruct test_ctx ctxstruct test_ctx *ctx&ctxctxctx.ctx->,create 后增加 NULL 检查。
  • .h 声明同步更新void test_init(struct test_ctx *)struct test_ctx *test_ctx_create(void)

改动范围

30 个文件(15 .c + 15 .h),+485 / -260,全部位于 tests/protocols/

验证

  • 全部 15 个文件编译链接通过
  • 12 项测试通过
  • Code Review 审核通过 ✅

关联 Issue

WM-329

Summary by Sourcery

Unify protocol test context lifecycle management across the protocol test suite.

Enhancements:

  • Standardize the 15 protocol tests on heap-allocated test contexts with consistent creation, cleanup, and destruction semantics.
  • Improve test-context allocation failure handling and make destruction safe for null contexts.

Refactor 15 treeland-protocol base test files from stack-allocated
test_init(ctx)/test_destroy(ctx) to heap-allocated
test_ctx_create()/test_destroy(ctx) pattern:

- test_ctx_create: calloc(1, sizeof(*ctx)) with NULL check, error
  logging, and return NULL on failure; sub-resource (results array)
  calloc with NULL check + free parent + return NULL
- test_destroy: NULL guard, free internal resources (ctx->results),
  free self (ctx)
- protocol_test_run: struct test_ctx ctx -> struct test_ctx *ctx,
  &ctx -> ctx, ctx. -> ctx->
- .h declarations: void test_init(struct test_ctx *) ->
  struct test_ctx *test_ctx_create(void)

将 tests/protocols/ 下 15 个测试文件的 struct 创建/销毁方式从
栈分配 test_init 统一重构为堆分配 test_ctx_create 模式,含内存
失败日志与 NULL 返回;销毁统一为 test_destroy 含 NULL 守卫。

Log: 统一协议测试中 struct 创建与销毁方式
Influence: 测试代码结构更清晰,创建/销毁语义明确,内存分配失败有日志可查,便于后续维护。
@deepin-ci-robot

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: deepin-wm

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

@sourcery-ai

sourcery-ai Bot commented Aug 25, 2026

Copy link
Copy Markdown

Reviewer's Guide

Across 15 protocol test implementations and their headers, the PR standardizes test context ownership on calloc-based heap creation and NULL-safe destruction, updates all runner call sites to pointer semantics with allocation checks, and synchronizes the public declarations.

File-Level Changes

Change Details Files
Replace stack-based test context initialization with heap allocation and unified ownership semantics.
  • Add calloc-based context creation with initialization defaults and allocation-failure cleanup.
  • Make destruction NULL-safe and free both result storage and the context object.
  • Update all protocol runners to handle creation failure and use pointer member access through the full test lifecycle.
tests/protocols/treeland-app-id-resolver-v1/treeland-app-id-resolver-v1.c
tests/protocols/treeland-capture-unstable-v1/treeland-capture-unstable-v1.c
tests/protocols/treeland-dde-shell-v1/treeland-dde-shell-v1.c
tests/protocols/treeland-ddm-v1/treeland-ddm-v1.c
tests/protocols/treeland-foreign-toplevel-manager-v1/treeland-foreign-toplevel-manager-v1.c
tests/protocols/treeland-output-manager-v1/treeland-output-manager-v1.c
tests/protocols/treeland-personalization-manager-v1/treeland-personalization-manager-v1.c
tests/protocols/treeland-prelaunch-splash-v2/treeland-prelaunch-splash-v2.c
tests/protocols/treeland-screensaver-v1/treeland-screensaver-v1.c
tests/protocols/treeland-shortcut-manager-v2/treeland-shortcut-manager-v2.c
tests/protocols/treeland-virtual-output-manager-v1/treeland-virtual-output-manager-v1.c
tests/protocols/treeland-wallpaper-color-v1/treeland-wallpaper-color-v1.c
tests/protocols/treeland-wallpaper-manager-unstable-v1/treeland-wallpaper-manager-unstable-v1.c
tests/protocols/treeland-wallpaper-shell-unstable-v1/treeland-wallpaper-shell-unstable-v1.c
tests/protocols/treeland-window-management-v1/treeland-window-management-v1.c
Synchronize the test context API declarations with the new create/destroy lifecycle.
  • Replace test_init declarations with test_ctx_create declarations returning a context pointer.
  • Retain the shared test_destroy interface for heap-owned contexts.
tests/protocols/treeland-app-id-resolver-v1/treeland-app-id-resolver-v1.h
tests/protocols/treeland-capture-unstable-v1/treeland-capture-unstable-v1.h
tests/protocols/treeland-dde-shell-v1/treeland-dde-shell-v1.h
tests/protocols/treeland-ddm-v1/treeland-ddm-v1.h
tests/protocols/treeland-foreign-toplevel-manager-v1/treeland-foreign-toplevel-manager-v1.h
tests/protocols/treeland-output-manager-v1/treeland-output-manager-v1.h
tests/protocols/treeland-personalization-manager-v1/treeland-personalization-manager-v1.h
tests/protocols/treeland-prelaunch-splash-v2/treeland-prelaunch-splash-v2.h
tests/protocols/treeland-screensaver-v1/treeland-screensaver-v1.h
tests/protocols/treeland-shortcut-manager-v2/treeland-shortcut-manager-v2.h
tests/protocols/treeland-virtual-output-manager-v1/treeland-virtual-output-manager-v1.h
tests/protocols/treeland-wallpaper-color-v1/treeland-wallpaper-color-v1.h
tests/protocols/treeland-wallpaper-manager-unstable-v1/treeland-wallpaper-manager-unstable-v1.h
tests/protocols/treeland-wallpaper-shell-unstable-v1/treeland-wallpaper-shell-unstable-v1.h
tests/protocols/treeland-window-management-v1/treeland-window-management-v1.h

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

@zzxyb
zzxyb requested a review from zorowk August 26, 2026 06:23
@deepin-bot

deepin-bot Bot commented Aug 28, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 0.9.1
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1348

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