refactor(test): unify struct create/destroy pattern in protocol tests - #1333
refactor(test): unify struct create/destroy pattern in protocol tests#1333deepin-wm wants to merge 1 commit into
Conversation
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: 测试代码结构更清晰,创建/销毁语义明确,内存分配失败有日志可查,便于后续维护。
|
Skipping CI for Draft Pull Request. |
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's GuideAcross 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
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
TAG Bot New tag: 0.9.1 |
概述
将
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_run:struct test_ctx ctx→struct test_ctx *ctx,&ctx→ctx,ctx.→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/。验证
关联 Issue
WM-329
Summary by Sourcery
Unify protocol test context lifecycle management across the protocol test suite.
Enhancements: