Files
oysteikt 40424da19f
Build and test / build (push) Successful in 1m2s
Build and test / test (push) Successful in 1m7s
Build and test / build-freebsd-cross (push) Successful in 1m54s
Run clang-format
2026-06-12 02:53:57 +09:00

58 lines
1.9 KiB
C

#include <cmocka.h>
#include <math.h>
#include "../src/minecraft.h"
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]";
assert_int_equal(parse_player_entity(response, &entity), 0);
assert_non_null(entity.name);
assert_string_equal(entity.name, "Steve");
assert_true(fabs(entity.x - (-1234.1234567891234)) < 1e-12);
assert_true(fabs(entity.y - 71.0) < 1e-12);
assert_true(fabs(entity.z - 113.0000000000001) < 1e-12);
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);
}