Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 84902824 authored by PRATS Tommy's avatar PRATS Tommy
Browse files

all test pass

parent 4b821965
No related branches found
No related tags found
2 merge requests!131Testing merge against main, to verify CI,!97Engines have test and no leak of memory
......@@ -31,7 +31,7 @@ Ils ont tous des tests unitaires et certains sont utilisés dans des niveaux.
XX CONFIG_FILE
- Note: disabled, ne vois pas l'intérêt de cette version.
- ajout d'un fichier de config avec la taille de la map la position du joueur
- ajout d'un fichier de config avec la taille de la map la position du joueur
pour init_game
** READ_MAP_STR
......@@ -66,10 +66,6 @@ XX CONFIG_FILE
** MAP_GRAPH
- map comme graph
* Engines à travailler/retravailler
Ces engines sont générés mais non testés complètement ou à revoir.
** EVENTS
- events
- interraction avec les objets dans le moteur et pas dans le niveau
......@@ -79,5 +75,9 @@ Ces engines sont générés mais non testés complètement ou à revoir.
- void * pour pointeur de fonction
- void * pour les arguments aussi
* Engines à travailler/retravailler
Ces engines sont générés mais non testés complètement ou à revoir.
** READ_MAP_TMX
- lire la carte dans un tmx
......@@ -21,7 +21,7 @@ entity create_entity(char symbol) {
if (symbol == ' ') {
return NULL;
}
entity e = malloc(sizeof(entity));
entity e = malloc(sizeof(struct entity_s));
e->id = -1;
#ifdef CUSTOM_ENTITY
e->category = category;
......
......@@ -24,16 +24,12 @@
#include "events.h"
#ifdef EVENT_ARGS
event* create_event(void (* event_to_add) (game_instance *game, void*), void* params) {
event_struct* create_event(void (* event_to_add) (game_instance *game, void*), void* params) {
#else
event* create_event(void (* event_to_add) (game_instance *game)) {
event_struct* create_event(void (* event_to_add) (game_instance *game)) {
#endif
printf("malloc tenté\n");
printf("malloc réussi\n");
event *new_event;
size_t siz = sizeof(*new_event);
new_event = (event*) malloc(sizeof(event));
printf("event a été ajouté\n");
event_struct *new_event;
new_event = malloc(sizeof(event_struct));
new_event->event = event_to_add;
#ifdef EVENT_ARGS
new_event->params = params;
......@@ -52,15 +48,12 @@ void add_event(game_instance *game, void (* event_to_add) (game_instance *game))
#ifdef EVENT_ARGS
game->event_list = create_event(event_to_add, params);
#else
printf("c'est bien vide au début\n");
game->event_list = create_event(event_to_add);
printf("c'est bien vide au début mais on a crée la tête\n");
#endif
return;
}
event * cur = game->event_list;
event_struct * cur = game->event_list;
while (cur->next){
cur = cur->next;
......@@ -81,8 +74,8 @@ void remove_event(game_instance *game, void (* event_to_remove) (game_instance *
if (!game->event_list)
return;
event * cur = game->event_list;
event * pred = NULL;
event_struct * cur = game->event_list;
event_struct * pred = NULL;
while (cur->event != event_to_remove && cur) {
pred = cur;
......@@ -102,7 +95,7 @@ void remove_event(game_instance *game, void (* event_to_remove) (game_instance *
}
void remove_all_events(game_instance* game) {
event * to_free;
event_struct * to_free;
while (game->event_list) {
to_free = game->event_list;
......@@ -113,7 +106,7 @@ void remove_all_events(game_instance* game) {
#ifdef EVENT_ARGS
void change_params(game_instance* game, void (*event_to_change)(game_instance *game, void *), void *params) {
event * cur = game->event_list;
event_struct * cur = game->event_list;
while (cur != NULL) {
if (cur->event == event_to_change) {
cur->params = params;
......@@ -124,7 +117,7 @@ void change_params(game_instance* game, void (*event_to_change)(game_instance *g
#endif
void apply_events(game_instance* game) {
event * cur = game->event_list;
event_struct * cur = game->event_list;
while (cur != NULL) {
#ifdef EVENT_ARGS
cur->event(game, cur->params);
......
......@@ -15,14 +15,14 @@ typedef struct event_s {
void (*event)(game_instance *game);
#endif
struct event_s *next;
} event;
} event_struct;
#ifdef EVENT_ARGS
event* create_event(void (* event_to_add) (game_instance *game, void*), void* params);
event_struct* create_event(void (* event_to_add) (game_instance *game, void*), void* params);
#else
event* create_event(void (* event_to_add) (game_instance *game));
event_struct* create_event(void (* event_to_add) (game_instance *game));
#endif
#ifdef EVENT_ARGS
......
......@@ -21,34 +21,21 @@ Test(events, test_event) {
game_instance *game = init_game();
game->current_map = init_map("map", 5, 6);
place_player(game->current_map, 1,1);
printf("coucou \n");
add_event(game, salut);
printf("un évent ajouté réussi\n");
cr_assert_eq(game->current_map->player_y, 1);
cr_assert_eq(game->current_map->player_x, 1);
printf("player n'a pas bougé mais est bien placé\n");
apply_events(game);
printf("on vient d'appliquer l'event\n");
cr_assert_eq(game->current_map->player_y, 0);
cr_assert_eq(game->current_map->player_x, 1);
cr_assert_eq(game->event_list->next, NULL);
printf("player a bougé et est bien placé\n");
remove_event(game, (salut) );
printf("on tente de remove l'event de la liste\n");
cr_assert_eq(game->event_list, NULL);
printf("on tente ajout de l'évent 1\n");
add_event(game, (salut2));
printf("un évent ajouté réussi\n");
printf("on tente ajout de l'évent 2\n");
add_event(game, (salut));
printf("second évent ajouté réussi\n");
apply_events(game);
printf("on vient d'appliquer les deux events\n");
cr_assert_eq(game->current_map->player_y, 2);
cr_assert_eq(game->current_map->player_x, 1);
printf("on tente de remove les deux events\n");
remove_all_events(game);
printf("on a bien remove les deux events\n");
cr_assert_eq(game->event_list, NULL);
free_game(game);
}
......@@ -21,13 +21,15 @@ Test(read_input, read_command)
command *c = get_next_command();
cr_assert_eq(c->buffer_size, 3);
cr_assert_str_eq(c->command_buffer, "UP");
command *c2 = get_next_command();
cr_assert_eq(c2->buffer_size, 5);
cr_assert_str_eq(c2->command_buffer, "DOWN");
// check that old buffer is not destroyed
cr_assert_str_eq(c->command_buffer, "UP");
free(c);
free(c2);
}
Test(read_input, apply_input)
......@@ -45,34 +47,44 @@ Test(read_input, apply_input)
int res;
// left
res = apply_input(m, get_next_command());
command *c = get_next_command();
res = apply_input(m, c);
cr_assert_eq(res, 1);
cr_assert_eq(m->player_x, 2);
cr_assert_eq(m->player_y, 3);
free(c);
// down
res = apply_input(m, get_next_command());
c = get_next_command();
res = apply_input(m, c);
cr_assert_eq(res, 1);
cr_assert_eq(m->player_x, 2);
cr_assert_eq(m->player_y, 4);
free(c);
// wrong
res = apply_input(m, get_next_command());
c = get_next_command();
res = apply_input(m, c);
cr_assert_eq(res, 0);
cr_assert_eq(m->player_x, 2);
cr_assert_eq(m->player_y, 4);
free(c);
// right
res = apply_input(m, get_next_command());
c = get_next_command();
res = apply_input(m, c);
cr_assert_eq(res, 1);
cr_assert_eq(m->player_x, 3);
cr_assert_eq(m->player_y, 4);
free(c);
// up
res = apply_input(m, get_next_command());
c = get_next_command();
res = apply_input(m, c);
cr_assert_eq(res, 1);
cr_assert_eq(m->player_x, 3);
cr_assert_eq(m->player_y, 3);
free(c);
}
Test(read_input, handle_problems, .exit_code = 2)
......@@ -85,12 +97,15 @@ Test(read_input, handle_problems, .exit_code = 2)
place_player(m, 3, 3);
int res;
res = apply_input(m, get_next_command());
cr_expect(res == 0, "unknown command");
command *c = get_next_command();
res = apply_input(m, c);
res = apply_input(m, get_next_command());
cr_expect(res == 0, "unknown command");
free(c);
c = get_next_command();
res = apply_input(m, c);
cr_expect(res == 0, "empty command");
free(c);
// Next one should make read fail with unavailable resource
fclose(f_stdin);
res = apply_input(m, get_next_command());
......@@ -106,6 +121,8 @@ Test(read_input, handle_EOF, .exit_code = 2)
map *m = init_map(5, 6);
apply_input(m, get_next_command());
command *c = get_next_command();
apply_input(m, c);
cr_fail("Should not continue after reading when received EOF");
free(c);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment