From 3c2c462710dc558ce0f2b42f78c40b7302155eae Mon Sep 17 00:00:00 2001 From: h7x4 Date: Fri, 12 Jun 2026 02:47:33 +0900 Subject: [PATCH] test/minecraft: test `parse_multiple_player_entities` --- test/test.c | 4 +++- test/test_minecraft.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/test/test.c b/test/test.c index a8672b8..69392f6 100644 --- a/test/test.c +++ b/test/test.c @@ -1,6 +1,6 @@ +#include #include #include -#include #include "test_minecraft.c" #include "test_rcon.c" @@ -20,6 +20,8 @@ int main(void) { // Minecraft tests cmocka_unit_test(test_parse_player_entity), + cmocka_unit_test(test_parse_multiple_player_entities), + cmocka_unit_test(test_parse_multiple_player_entities_empty_response), }; return cmocka_run_group_tests(tests, NULL, NULL); diff --git a/test/test_minecraft.c b/test/test_minecraft.c index a0c6779..3f1a47d 100644 --- a/test/test_minecraft.c +++ b/test/test_minecraft.c @@ -7,8 +7,8 @@ static void test_parse_player_entity(void **state) { (void)state; player_entity_t entity = {0}; - const char *response = - "Steve has the following entity data: [-1234.1234567891234d, 71.0d, 113.0000000000001d]"; + const char *response = "Steve has the following entity data: " + "[-1234.1234567891234d, 71.0d, 113.0000000000001d]"; assert_int_equal(parse_player_entity(response, &entity), 0); assert_non_null(entity.name); @@ -19,3 +19,41 @@ static void test_parse_player_entity(void **state) { free_player_entity(&entity); } + +static void test_parse_multiple_player_entities(void **state) { + (void)state; + + player_entity_t entities[2] = {0}; + char response[] = + "Steve has the following entity data: [-1234.1234567891234d, 71.0d, " + "113.0000000000001d]\n" + "Alex has the following entity data: [100.0d, 64.0d, -50.5d]"; + + assert_int_equal(parse_multiple_player_entities(response, 2, entities), 0); + + // Check Steve + assert_non_null(entities[0].name); + assert_string_equal(entities[0].name, "Steve"); + assert_true(fabs(entities[0].x - (-1234.1234567891234)) < 1e-12); + assert_true(fabs(entities[0].y - 71.0) < 1e-12); + assert_true(fabs(entities[0].z - 113.0000000000001) < 1e-12); + + // Check Alex + assert_non_null(entities[1].name); + assert_string_equal(entities[1].name, "Alex"); + assert_true(fabs(entities[1].x - 100.0) < 1e-12); + assert_true(fabs(entities[1].y - 64.0) < 1e-12); + assert_true(fabs(entities[1].z - (-50.5)) < 1e-12); + + free_player_entity(&entities[0]); + free_player_entity(&entities[1]); +} + +static void test_parse_multiple_player_entities_empty_response(void **state) { + (void)state; + + player_entity_t entities[2] = {0}; + char response[] = "\n"; + + assert_int_equal(parse_multiple_player_entities(response, 2, entities), 0); +}