test/minecraft: test parse_multiple_player_entities

This commit is contained in:
2026-06-12 02:47:33 +09:00
parent 9a145b2939
commit 3c2c462710
2 changed files with 43 additions and 3 deletions
+3 -1
View File
@@ -1,6 +1,6 @@
#include <cmocka.h>
#include <stdarg.h>
#include <stddef.h>
#include <cmocka.h>
#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);
+40 -2
View File
@@ -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);
}