Skip to content
Snippets Groups Projects
Commit 5cf33d2b authored by Le-Bao-Tin.Ha's avatar Le-Bao-Tin.Ha
Browse files

add test_map.h, fix cmakeliste.txt

parent 69461ec9
No related branches found
No related tags found
4 merge requests!8Modele,!7Modele,!6Modele,!5Modele Version 1
...@@ -14,11 +14,11 @@ if (WIN32) ...@@ -14,11 +14,11 @@ if (WIN32)
option(BUILD_TESTS OFF) option(BUILD_TESTS OFF)
set(BUILD_TESTS ON) set(BUILD_TESTS ON)
include_directories(include)
if(BUILD_TESTS) if(BUILD_TESTS)
project(INSAGAMETEST C CXX) project(INSAGAMETEST C CXX)
set(GTEST_INCLUDE_DIR /googletest/googletest/include) set(GTEST_INCLUDE_DIR /googletest/googletest/include)
include_directories(include) include_directories(test)
include_directories(${GTEST_INCLUDE_DIR}) include_directories(${GTEST_INCLUDE_DIR})
enable_testing() enable_testing()
...@@ -32,7 +32,7 @@ if (WIN32) ...@@ -32,7 +32,7 @@ if (WIN32)
COMMAND INSAGAMETEST COMMAND INSAGAMETEST
) )
else() else()
include_directories(include)
project(INSAGAME C) project(INSAGAME C)
file(GLOB_RECURSE SOURCES "src/*c" main.c) file(GLOB_RECURSE SOURCES "src/*c" main.c)
add_executable(INSAGAME ${SOURCES}) add_executable(INSAGAME ${SOURCES})
......
...@@ -40,7 +40,7 @@ typedef struct { ...@@ -40,7 +40,7 @@ typedef struct {
void init_prof(Prof * prof, int x, int y, int length, int width, int speed, char * path); void init_prof(Prof * prof, int x, int y, int length, int width, int speed, char * path);
void calculpointsprof(Prof * prof); void calcul_points_prof(Prof * prof);
#endif /*GAME_INSA_PROJECT_Prof_H*/ #endif /*GAME_INSA_PROJECT_Prof_H*/
......
...@@ -78,15 +78,11 @@ int **maptomatrix(MAP *map){ ...@@ -78,15 +78,11 @@ int **maptomatrix(MAP *map){
FILE *bin; FILE *bin;
if(!(bin=fopen(map->functional_path,"rb"))){ if(!(bin=fopen(map->functional_path,"rb"))){
puts("Error to open the map !");
return NULL; return NULL;
} }
FILE *outout; FILE *outout;
if(!(outout=fopen("map.log","w"))){ outout=fopen("map.log","w");
puts("Error to open the map !");
return NULL;
}
//Read Every Information of Map //Read Every Information of Map
fread(identity,sizeof(identity),1,bin); fread(identity,sizeof(identity),1,bin);
...@@ -121,7 +117,7 @@ int **maptomatrix(MAP *map){ ...@@ -121,7 +117,7 @@ int **maptomatrix(MAP *map){
map->height = image_height; map->height = image_height;
map->width = image_width; map->width = image_width;
//fill the functional matrix //fill the functional matrix
linematrix = image_height -1; linematrix = image_height -1;
colummatrix = 0; colummatrix = 0;
...@@ -129,14 +125,14 @@ int **maptomatrix(MAP *map){ ...@@ -129,14 +125,14 @@ int **maptomatrix(MAP *map){
fread(color,sizeof(color),1,bin); fread(color,sizeof(color),1,bin);
if(color[2] == 255 && color[1] == 0 && color[0] == 0) if(color[2] == 255 && color[1] == 0 && color[0] == 0)
{ {
fonc[linematrix][colummatrix] = 2; //Exam fonc[linematrix][colummatrix] = 2; //Exam = RED
} }
else if (color[2] == 0 && color[1] == 255 && color[0] == 0) else if (color[2] == 0 && color[1] == 255 && color[0] == 0)
{ {
fonc[linematrix][colummatrix] = 1; //wall fonc[linematrix][colummatrix] = 1; //wall = GREEN
} }
else { else {
fonc[linematrix][colummatrix] = 0; //road fonc[linematrix][colummatrix] = 0; //road = WHITE
} }
if(colummatrix<image_width-1) colummatrix ++; if(colummatrix<image_width-1) colummatrix ++;
else { else {
...@@ -149,7 +145,7 @@ int **maptomatrix(MAP *map){ ...@@ -149,7 +145,7 @@ int **maptomatrix(MAP *map){
for(linematrix = 0; linematrix <image_height; linematrix ++) for(linematrix = 0; linematrix <image_height; linematrix ++)
{ {
for(colummatrix=0; colummatrix<image_height;colummatrix++){ for(colummatrix=0; colummatrix<image_width;colummatrix++){
fprintf(outout,"%d",fonc[linematrix][colummatrix]); fprintf(outout,"%d",fonc[linematrix][colummatrix]);
} }
fprintf(outout,"\n"); fprintf(outout,"\n");
......
...@@ -107,7 +107,7 @@ void prof_move(Prof *prof, int * predirection, SDL_Rect * prof_rect, MAP * map, ...@@ -107,7 +107,7 @@ void prof_move(Prof *prof, int * predirection, SDL_Rect * prof_rect, MAP * map,
prof->x_prof += prof->speed_prof; prof->x_prof += prof->speed_prof;
break; break;
} }
calculpointsprof(prof); calcul_points_prof(prof);
// prof collision detection // prof collision detection
int collision = test_position_prof(prof,map,exam); // return 0 if nothing, 1 if wall or bounds int collision = test_position_prof(prof,map,exam); // return 0 if nothing, 1 if wall or bounds
// set the positions following collision variable // set the positions following collision variable
......
...@@ -53,7 +53,7 @@ void init_prof(Prof * prof, int x, int y, int length, int width, int speed, char ...@@ -53,7 +53,7 @@ void init_prof(Prof * prof, int x, int y, int length, int width, int speed, char
*/ */
void calculpointsprof(Prof * prof){ void calcul_points_prof(Prof * prof){
prof->x_hr = prof->x_prof + prof->larg_prof ; prof->x_hr = prof->x_prof + prof->larg_prof ;
prof->y_hr = prof->y_prof; prof->y_hr = prof->y_prof;
prof->x_ll = prof->x_prof; prof->x_ll = prof->x_prof;
......
...@@ -12,13 +12,15 @@ extern "C"{ ...@@ -12,13 +12,15 @@ extern "C"{
} }
TEST(test_init_DS,Door_3){ TEST(test_init_DS,Door_3){
DS exam; int times=500000000;
init_DS(&exam,3,"testimage"); DS exam;
EXPECT_STREQ("testimage",exam.image_DS); init_DS(&exam,3,"testimage");
EXPECT_EQ(369,exam.x_DS); EXPECT_STREQ("testimage",exam.image_DS);
EXPECT_EQ(41,exam.y_DS); EXPECT_EQ(369,exam.x_DS);
EXPECT_EQ(21,exam.larg_DS); EXPECT_EQ(41,exam.y_DS);
EXPECT_EQ(10,exam.long_DS); EXPECT_EQ(21,exam.larg_DS);
EXPECT_EQ(10,exam.long_DS);
while(times>0) times--;
} }
......
/*
// Created by Tiny on 3/18/2021.
*/
#ifndef MAIN_C_TEST_MAP_H
#define MAIN_C_TEST_MAP_H
#include <gtest/gtest.h>
#include <stdio.h>
extern "C"{
#include "map.h"
}
TEST(test_init_map,with_real_path){
int times=500000000;
MAP map;
init_map(&map, "ressource/colored.bmp", "ressoure/mapvis.bmp");
EXPECT_STREQ("ressource/colored.bmp",map.functional_path);
EXPECT_STREQ("ressoure/mapvis.bmp",map.visual_path);
EXPECT_TRUE(map.functional);
while(times>0) times--; //this do nothing but it looks cool ^^
}
TEST(test_init_map,with_false_path){
int times=500000000;
MAP map;
init_map(&map, "coloro.bmp", "mapvis.bmp");
EXPECT_FALSE(map.functional);
while(times>0) times--; //this do nothing but it looks cool ^^
}
TEST(test_map_to_matrix,with_ez_image){
int times=500000000;
int i ;
int y ;
MAP map;
init_map(&map, "ressource/func_test_map.bmp", "mapvis.bmp");
EXPECT_EQ(55,map.height);
EXPECT_EQ(116,map.width);
while(times>0) times--; //this do nothing but it looks cool ^^
}
#endif /*MAIN_C_TEST_PROF_H*/
...@@ -11,6 +11,7 @@ extern "C"{ ...@@ -11,6 +11,7 @@ extern "C"{
} }
TEST(test_init_personnage,values_3_3_3_3_3_testimage){ TEST(test_init_personnage,values_3_3_3_3_3_testimage){
int times=500000000;
Personnage person; Personnage person;
init_pers(&person,3,3,3,3,3,"testimage"); init_pers(&person,3,3,3,3,3,"testimage");
EXPECT_EQ(3,person.x_pers); EXPECT_EQ(3,person.x_pers);
...@@ -18,8 +19,10 @@ TEST(test_init_personnage,values_3_3_3_3_3_testimage){ ...@@ -18,8 +19,10 @@ TEST(test_init_personnage,values_3_3_3_3_3_testimage){
EXPECT_EQ(3,person.long_pers); EXPECT_EQ(3,person.long_pers);
EXPECT_EQ(3,person.larg_pers); EXPECT_EQ(3,person.larg_pers);
EXPECT_STREQ("testimage",person.image_pers); EXPECT_STREQ("testimage",person.image_pers);
while(times>0) times--; //this do nothing but it looks cool ^^
} }
TEST(test_calcul_point,values_3_3){ TEST(test_calcul_point,values_3_3){
int times=500000000;
Personnage person; Personnage person;
init_pers(&person,3,3,3,3,3,"testimage"); init_pers(&person,3,3,3,3,3,"testimage");
calcul_points_pers(&person); calcul_points_pers(&person);
...@@ -29,6 +32,7 @@ TEST(test_calcul_point,values_3_3){ ...@@ -29,6 +32,7 @@ TEST(test_calcul_point,values_3_3){
EXPECT_EQ(6,person.y_ll); EXPECT_EQ(6,person.y_ll);
EXPECT_EQ(6,person.x_lr); EXPECT_EQ(6,person.x_lr);
EXPECT_EQ(6,person.y_lr); EXPECT_EQ(6,person.y_lr);
while(times>0) times--;
} }
#endif /*INSAGAME_TEST_PERSONNAGE_H*/ #endif /*INSAGAME_TEST_PERSONNAGE_H*/
...@@ -11,6 +11,7 @@ extern "C"{ ...@@ -11,6 +11,7 @@ extern "C"{
} }
TEST(test_init_prof,values_3_3_3_3_3_testimage){ TEST(test_init_prof,values_3_3_3_3_3_testimage){
int times=500000000;
Prof prof; Prof prof;
init_prof(&prof,3,3,3,3,3,"testimage"); init_prof(&prof,3,3,3,3,3,"testimage");
EXPECT_EQ(3,prof.x_prof); EXPECT_EQ(3,prof.x_prof);
...@@ -18,7 +19,20 @@ TEST(test_init_prof,values_3_3_3_3_3_testimage){ ...@@ -18,7 +19,20 @@ TEST(test_init_prof,values_3_3_3_3_3_testimage){
EXPECT_EQ(3,prof.long_prof); EXPECT_EQ(3,prof.long_prof);
EXPECT_EQ(3,prof.larg_prof); EXPECT_EQ(3,prof.larg_prof);
EXPECT_STREQ("testimage",prof.image_prof); EXPECT_STREQ("testimage",prof.image_prof);
while(times>0) times--; //this do nothing but it looks cool ^^
}
TEST(test_calcul_point_prof,values_3_3){
int times=500000000;
Prof prof;
init_prof(&prof,3,3,3,3,3,"testimage");
calcul_points_prof(&prof);
EXPECT_EQ(6,prof.x_hr);
EXPECT_EQ(3,prof.y_hr);
EXPECT_EQ(3,prof.x_ll);
EXPECT_EQ(6,prof.y_ll);
EXPECT_EQ(6,prof.x_lr);
EXPECT_EQ(6,prof.y_lr);
while(times>0) times--;
} }
#endif /*MAIN_C_TEST_PROF_H*/ #endif /*MAIN_C_TEST_PROF_H*/
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "test_personnage.h" #include "test_personnage.h"
#include "test_prof.h"
#include "test_DS.h"
#include "test_map.h"
int main(int argc, char* args[]){ int main(int argc, char* args[]){
::testing::InitGoogleTest(&argc, args); ::testing::InitGoogleTest(&argc, args);
......
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