Skip to content

Commit c0ce0ee

Browse files
committed
Add string array equality test assert
1 parent 64d1fd8 commit c0ce0ee

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

src/json_encode.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,7 @@ GG_TEST_DEFINE(json_encode_null_ok) {
225225
GgBuffer buf = GG_BUF((uint8_t[4]) { 0 });
226226
GgByteVec vec = gg_byte_vec_init(buf);
227227
GG_TEST_ASSERT_OK(gg_json_encode(null, gg_byte_vec_writer(&vec)));
228-
TEST_ASSERT_EQUAL_UINT(4, vec.buf.len);
229-
TEST_ASSERT_EQUAL_CHAR_ARRAY("null", (char *) vec.buf.data, vec.buf.len);
228+
GG_TEST_ASSERT_BUF_EQUAL_STR(GG_STR("null"), vec.buf);
230229
}
231230

232231
GG_TEST_DEFINE(json_encode_bool_ok) {
@@ -235,15 +234,15 @@ GG_TEST_DEFINE(json_encode_bool_ok) {
235234
GgBuffer buf = GG_BUF((uint8_t[5]) { 0 });
236235
GgByteVec vec = gg_byte_vec_init(buf);
237236
GG_TEST_ASSERT_OK(gg_json_encode(obj_false, gg_byte_vec_writer(&vec)));
238-
GG_TEST_ASSERT_BUF_EQUAL(GG_STR("false"), vec.buf);
237+
GG_TEST_ASSERT_BUF_EQUAL_STR(GG_STR("false"), vec.buf);
239238
}
240239

241240
{
242241
GgObject obj_true = gg_obj_bool(true);
243242
GgBuffer buf = GG_BUF((uint8_t[4]) { 0 });
244243
GgByteVec vec = gg_byte_vec_init(buf);
245244
GG_TEST_ASSERT_OK(gg_json_encode(obj_true, gg_byte_vec_writer(&vec)));
246-
GG_TEST_ASSERT_BUF_EQUAL(GG_STR("true"), vec.buf);
245+
GG_TEST_ASSERT_BUF_EQUAL_STR(GG_STR("true"), vec.buf);
247246
}
248247
}
249248

@@ -252,7 +251,7 @@ GG_TEST_DEFINE(json_encode_i64_ok) {
252251
GgBuffer buf = GG_BUF((uint8_t[3]) { 0 });
253252
GgByteVec vec = gg_byte_vec_init(buf);
254253
GG_TEST_ASSERT_OK(gg_json_encode(obj, gg_byte_vec_writer(&vec)));
255-
GG_TEST_ASSERT_BUF_EQUAL(GG_STR("123"), vec.buf);
254+
GG_TEST_ASSERT_BUF_EQUAL_STR(GG_STR("123"), vec.buf);
256255
}
257256

258257
GG_TEST_DEFINE(json_encode_f64_ok) {
@@ -272,23 +271,23 @@ GG_TEST_DEFINE(json_encode_buf_ok) {
272271
GgBuffer buf = GG_BUF((uint8_t[8]) { 0 });
273272
GgByteVec vec = gg_byte_vec_init(buf);
274273
GG_TEST_ASSERT_OK(gg_json_encode(obj, gg_byte_vec_writer(&vec)));
275-
GG_TEST_ASSERT_BUF_EQUAL(GG_STR("\"\\u001F\""), vec.buf);
274+
GG_TEST_ASSERT_BUF_EQUAL_STR(GG_STR("\"\\u001F\""), vec.buf);
276275
}
277276

278277
{
279278
GgObject obj = gg_obj_buf(GG_STR("Hello, world!"));
280279
GgBuffer buf = GG_BUF((uint8_t[15]) { 0 });
281280
GgByteVec vec = gg_byte_vec_init(buf);
282281
GG_TEST_ASSERT_OK(gg_json_encode(obj, gg_byte_vec_writer(&vec)));
283-
GG_TEST_ASSERT_BUF_EQUAL(GG_STR("\"Hello, world!\""), vec.buf);
282+
GG_TEST_ASSERT_BUF_EQUAL_STR(GG_STR("\"Hello, world!\""), vec.buf);
284283
}
285284

286285
{
287286
GgObject obj = gg_obj_buf(GG_STR("\"escape \\ me \" \0"));
288287
GgBuffer buf = GG_BUF((uint8_t[26]) { 0 });
289288
GgByteVec vec = gg_byte_vec_init(buf);
290289
GG_TEST_ASSERT_OK(gg_json_encode(obj, gg_byte_vec_writer(&vec)));
291-
GG_TEST_ASSERT_BUF_EQUAL(
290+
GG_TEST_ASSERT_BUF_EQUAL_STR(
292291
GG_STR("\"\\\"escape \\\\ me \\\" \\u0000\""), vec.buf
293292
);
294293
}
@@ -304,7 +303,9 @@ GG_TEST_DEFINE(json_encode_map_ok) {
304303
GgBuffer buf = GG_BUF((uint8_t[20]) { 0 });
305304
GgByteVec vec = gg_byte_vec_init(buf);
306305
GG_TEST_ASSERT_OK(gg_json_encode(obj, gg_byte_vec_writer(&vec)));
307-
GG_TEST_ASSERT_BUF_EQUAL(GG_STR("{\"a\":1,\"b\":2,\"c\":3}"), vec.buf);
306+
GG_TEST_ASSERT_BUF_EQUAL_STR(
307+
GG_STR("{\"a\":1,\"b\":2,\"c\":3}"), vec.buf
308+
);
308309
}
309310
}
310311

@@ -315,7 +316,7 @@ GG_TEST_DEFINE(json_encode_list_ok) {
315316
GgBuffer buf = GG_BUF((uint8_t[7]) { 0 });
316317
GgByteVec vec = gg_byte_vec_init(buf);
317318
GG_TEST_ASSERT_OK(gg_json_encode(obj, gg_byte_vec_writer(&vec)));
318-
GG_TEST_ASSERT_BUF_EQUAL(GG_STR("[1,2,3]"), vec.buf);
319+
GG_TEST_ASSERT_BUF_EQUAL_STR(GG_STR("[1,2,3]"), vec.buf);
319320
}
320321
}
321322

test/client/mqtt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ static void subscribe_to_iot_core_okay_subscription_response(
219219
) {
220220
SubscribeOkayContext *context = ctx;
221221
TEST_ASSERT_EQUAL_PTR(&subscribe_okay_context, context);
222-
GG_TEST_ASSERT_BUF_EQUAL(GG_STR("my/topic"), topic);
222+
GG_TEST_ASSERT_BUF_EQUAL_STR(GG_STR("my/topic"), topic);
223223

224224
GG_TEST_ASSERT_BUF_EQUAL(payloads[0].payload, payload);
225225

unity/gg_test/include/gg/test.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,14 @@ int gg_test_run_suite(void);
5252
); \
5353
} while (0)
5454

55+
#define GG_TEST_ASSERT_BUF_EQUAL_STR(expected, actual) \
56+
do { \
57+
TEST_ASSERT_EQUAL_size_t_MESSAGE( \
58+
(expected).len, (actual).len, "Size mismatch" \
59+
); \
60+
TEST_ASSERT_EQUAL_STRING_LEN( \
61+
(expected).data, (actual).data, (expected).len \
62+
); \
63+
} while (0)
64+
5565
#endif

0 commit comments

Comments
 (0)