Skip to content

Commit c5e9fc2

Browse files
committed
style: format code for consistency and readability in test files
1 parent 125cbcd commit c5e9fc2

File tree

4 files changed

+37
-19
lines changed

4 files changed

+37
-19
lines changed

test/arry_test.c

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
21
#include "unity.h"
32
#include "mjsonrpc.h"
3+
44
#include <stdlib.h>
55
#include <string.h>
66

77
void setUp(void) {}
88
void tearDown(void) {}
99

1010
// 简单加法方法
11-
static cJSON* add_func(mjrpc_func_ctx_t* ctx, cJSON* params, cJSON* id) {
11+
static cJSON* add_func(mjrpc_func_ctx_t* ctx, cJSON* params, cJSON* id)
12+
{
1213
int a = 0, b = 0;
13-
if (params && cJSON_IsArray(params) && cJSON_GetArraySize(params) == 2) {
14+
if (params && cJSON_IsArray(params) && cJSON_GetArraySize(params) == 2)
15+
{
1416
cJSON* a_item = cJSON_GetArrayItem(params, 0);
1517
cJSON* b_item = cJSON_GetArrayItem(params, 1);
16-
if (cJSON_IsNumber(a_item) && cJSON_IsNumber(b_item)) {
18+
if (cJSON_IsNumber(a_item) && cJSON_IsNumber(b_item))
19+
{
1720
a = a_item->valueint;
1821
b = b_item->valueint;
1922
}
@@ -22,13 +25,15 @@ static cJSON* add_func(mjrpc_func_ctx_t* ctx, cJSON* params, cJSON* id) {
2225
}
2326

2427
// 批量请求正常
25-
void test_batch_request_normal(void) {
28+
void test_batch_request_normal(void)
29+
{
2630
mjrpc_handle_t* h = mjrpc_create_handle(8);
2731
mjrpc_add_method(h, add_func, "add", NULL);
2832
cJSON* arr = cJSON_CreateArray();
29-
for (int i = 0; i < 3; ++i) {
30-
cJSON* params = cJSON_CreateIntArray((int[]){i, i+1}, 2);
31-
cJSON* id = cJSON_CreateNumber(i+1);
33+
for (int i = 0; i < 3; ++i)
34+
{
35+
cJSON* params = cJSON_CreateIntArray((int[]) {i, i + 1}, 2);
36+
cJSON* id = cJSON_CreateNumber(i + 1);
3237
cJSON* req = mjrpc_request_cjson("add", params, id);
3338
cJSON_AddItemToArray(arr, req);
3439
}
@@ -37,27 +42,31 @@ void test_batch_request_normal(void) {
3742
TEST_ASSERT_NOT_NULL(resp);
3843
TEST_ASSERT_TRUE(cJSON_IsArray(resp));
3944
TEST_ASSERT_EQUAL_INT(3, cJSON_GetArraySize(resp));
40-
for (int i = 0; i < 3; ++i) {
45+
for (int i = 0; i < 3; ++i)
46+
{
4147
cJSON* item = cJSON_GetArrayItem(resp, i);
4248
cJSON* result = cJSON_GetObjectItem(item, "result");
4349
TEST_ASSERT_TRUE(cJSON_IsNumber(result));
44-
TEST_ASSERT_EQUAL_INT(i + (i+1), result->valueint);
50+
TEST_ASSERT_EQUAL_INT(i + (i + 1), result->valueint);
4551
}
4652
cJSON_Delete(resp);
4753
mjrpc_destroy_handle(h);
4854
}
4955

5056
// 批量请求部分错误
51-
void test_batch_request_partial_error(void) {
57+
void test_batch_request_partial_error(void)
58+
{
5259
mjrpc_handle_t* h = mjrpc_create_handle(8);
5360
mjrpc_add_method(h, add_func, "add", NULL);
5461
cJSON* arr = cJSON_CreateArray();
5562
// 正常
56-
cJSON* req1 = mjrpc_request_cjson("add", cJSON_CreateIntArray((int[]){1,2},2), cJSON_CreateNumber(1));
63+
cJSON* req1 =
64+
mjrpc_request_cjson("add", cJSON_CreateIntArray((int[]) {1, 2}, 2), cJSON_CreateNumber(1));
5765
// 错误方法
5866
cJSON* req2 = mjrpc_request_cjson("no_such", NULL, cJSON_CreateNumber(2));
5967
// 正常
60-
cJSON* req3 = mjrpc_request_cjson("add", cJSON_CreateIntArray((int[]){3,4},2), cJSON_CreateNumber(3));
68+
cJSON* req3 =
69+
mjrpc_request_cjson("add", cJSON_CreateIntArray((int[]) {3, 4}, 2), cJSON_CreateNumber(3));
6170
cJSON_AddItemToArray(arr, req1);
6271
cJSON_AddItemToArray(arr, req2);
6372
cJSON_AddItemToArray(arr, req3);
@@ -77,7 +86,8 @@ void test_batch_request_partial_error(void) {
7786
}
7887

7988
// 空数组请求
80-
void test_batch_request_empty_array(void) {
89+
void test_batch_request_empty_array(void)
90+
{
8191
mjrpc_handle_t* h = mjrpc_create_handle(8);
8292
cJSON* arr = cJSON_CreateArray();
8393
int code = -1;

test/err_test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "unity.h"
22
#include "mjsonrpc.h"
3+
34
#include <stdlib.h>
45
#include <string.h>
56

test/mem_test.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
11
#include "unity.h"
22
#include "mjsonrpc.h"
3+
34
#include <stdlib.h>
45
#include <string.h>
56

67
void setUp(void) {}
78
void tearDown(void) {}
89

910
// 用于测试自动扩容的空方法
10-
static cJSON* dummy_func(mjrpc_func_ctx_t* ctx, cJSON* params, cJSON* id) {
11+
static cJSON* dummy_func(mjrpc_func_ctx_t* ctx, cJSON* params, cJSON* id)
12+
{
1113
return cJSON_CreateString("ok");
1214
}
1315

14-
void test_auto_resize(void) {
16+
void test_auto_resize(void)
17+
{
1518
size_t initial_capacity = 4;
1619
mjrpc_handle_t* h = mjrpc_create_handle(initial_capacity);
1720
// 注册比初始容量多的方法,触发扩容
1821
int method_count = 20;
1922
char name[32];
20-
for (int i = 0; i < method_count; ++i) {
23+
for (int i = 0; i < method_count; ++i)
24+
{
2125
snprintf(name, sizeof(name), "m%d", i);
2226
int ret = mjrpc_add_method(h, dummy_func, name, NULL);
2327
TEST_ASSERT_EQUAL_INT(MJRPC_RET_OK, ret);
2428
}
2529
// 检查所有方法都能被正确调用
26-
for (int i = 0; i < method_count; ++i) {
30+
for (int i = 0; i < method_count; ++i)
31+
{
2732
snprintf(name, sizeof(name), "m%d", i);
2833
cJSON* id = cJSON_CreateNumber(i);
2934
cJSON* req = mjrpc_request_cjson(name, NULL, id);
@@ -38,7 +43,8 @@ void test_auto_resize(void) {
3843
mjrpc_destroy_handle(h);
3944
}
4045

41-
int main(void) {
46+
int main(void)
47+
{
4248
UNITY_BEGIN();
4349
RUN_TEST(test_auto_resize);
4450
return UNITY_END();

test/obj_test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "unity.h"
22
#include "mjsonrpc.h"
3+
34
#include <stdlib.h>
45
#include <string.h>
56

0 commit comments

Comments
 (0)