ajout d'un systeme de test unitaires

This commit is contained in:
Thomas Bernard
2019-10-28 20:57:59 +01:00
parent a76aa44f4d
commit 1810cdfb61
8 changed files with 381 additions and 8 deletions

59
src/tests/mockloadsave.c Normal file
View File

@@ -0,0 +1,59 @@
/* vim:expandtab:ts=2 sw=2:
*/
/* Grafx2 - The Ultimate 256-color bitmap paint program
Copyright 2019 Thomas Bernard
Copyright 2007-2018 Adrien Destugues
Copyright 1996-2001 Sunset Design (Guillaume Dorme & Karl Maritaud)
Grafx2 is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2
of the License.
Grafx2 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Grafx2; if not, see <http://www.gnu.org/licenses/>
*/
#include <stdio.h>
#include "../loadsave.h"
void Pre_load(T_IO_Context *context, short width, short height, long file_size, int format, enum PIXEL_RATIO ratio, byte bpp)
{
printf("Pre_load()\n");
}
byte Get_pixel(T_IO_Context *context, short x, short y)
{
return 0;
}
void Pixel_in_layer(int layer, word x, word y, byte color)
{
}
void Set_pixel(T_IO_Context *context, short x, short y, byte c)
{
}
void Set_saving_layer(T_IO_Context *context, int layer)
{
}
void Set_loading_layer(T_IO_Context *context, int layer)
{
}
void Set_image_mode(T_IO_Context *context, enum IMAGE_MODES mode)
{
}
void Set_frame_duration(T_IO_Context *context, int duration)
{
}

125
src/tests/mockui.c Normal file
View File

@@ -0,0 +1,125 @@
/* vim:expandtab:ts=2 sw=2:
*/
/* Grafx2 - The Ultimate 256-color bitmap paint program
Copyright 2019 Thomas Bernard
Copyright 2007-2018 Adrien Destugues
Copyright 1996-2001 Sunset Design (Guillaume Dorme & Karl Maritaud)
Grafx2 is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2
of the License.
Grafx2 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Grafx2; if not, see <http://www.gnu.org/licenses/>
*/
#include <stdio.h>
#include <stdarg.h>
#include "../struct.h"
void Warning_message(const char * message)
{
puts(message);
}
void Warning_with_format(const char *template, ...)
{
va_list arg_ptr;
va_start(arg_ptr, template);
vprintf(template, arg_ptr);
va_end(arg_ptr);
}
void Error_function(int error_code, const char *filename, int line_number, const char *function_name)
{
printf("%s:%d %s(): Error %d\n", filename, line_number, function_name, error_code);
}
void Warning_function(const char *message, const char *filename, int line_number, const char *function_name)
{
printf("%s:%d %s(): Warning: %s\n", filename, line_number, function_name, message);
}
void Window_help(int section, const char * sub_section)
{
printf("Window_help(%d, %s)\n", section, sub_section);
}
void Open_window(word width, word height, const char * title)
{
printf("Open_window() %hux%hu : %s\n", width, height, title);
}
void Close_window()
{
}
void Print_in_window(short x,short y,const char * str,byte text_color,byte background_color)
{
}
void Window_dropdown_add_item(T_Dropdown_button * dropdown, word btn_number, const char *label)
{
printf("Window_dropdown_add_item(%p, %hu, %s)\n", dropdown, btn_number, label);
}
void Window_dropdown_clear_items(T_Dropdown_button * dropdown)
{
}
T_Dropdown_button * Window_set_dropdown_button(word x_pos, word y_pos,
word width, word height, word dropdown_width, const char *label,
byte display_choice, byte display_centered, byte display_arrow,
byte active_button,byte bottom_up)
{
return NULL;
}
T_Normal_button * Window_set_normal_button(word x_pos, word y_pos,
word width, word height, const char * title, byte undersc_letter,
byte clickable, word shortcut)
{
return NULL;
}
short Window_clicked_button(void)
{
return 0;
}
int Is_shortcut(word key, word function)
{
printf("Is_shortcut(%04x, %04x)\n", key, function);
return 0;
}
void Update_rect(short x, short y, unsigned short width, unsigned short height)
{
}
void Display_cursor(void)
{
}
void Hide_cursor(void)
{
}
word Count_used_colors(dword * usage)
{
return 256;
}
word Count_used_colors_area(dword* usage, word start_x, word start_y, word width, word height)
{
return 256;
}

5
src/tests/testlist.h Normal file
View File

@@ -0,0 +1,5 @@
/* list of tests
* TEST(function_to_test) */
TEST(MOTO_MAP_pack)

127
src/tests/testmain.c Normal file
View File

@@ -0,0 +1,127 @@
/* vim:expandtab:ts=2 sw=2:
*/
/* Grafx2 - The Ultimate 256-color bitmap paint program
Copyright 2018-2019 Thomas Bernard
Copyright 2011 Pawel Góralski
Copyright 2009 Petter Lindquist
Copyright 2008 Yves Rizoud
Copyright 2008 Franck Charlet
Copyright 2007-2011 Adrien Destugues
Copyright 1996-2001 Sunset Design (Guillaume Dorme & Karl Maritaud)
Grafx2 is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2
of the License.
Grafx2 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Grafx2; if not, see <http://www.gnu.org/licenses/>
*/
///@file testmain.c
/// Unit tests.
#include <stdio.h>
#include <string.h>
#include "../struct.h"
#include "../global.h"
#include "../gfx2log.h"
#include "tests.h"
#ifdef ENABLE_FILENAMES_ICONV
iconv_t cd; // FROMCODE => TOCODE
iconv_t cd_inv; // TOCODE => FROMCODE
iconv_t cd_utf16; // FROMCODE => UTF16
iconv_t cd_utf16_inv; // UTF16 => FROMCODE
#endif
signed char File_error;
T_Config Config;
T_Document Main;
T_Document Spare;
byte * Screen_backup;
byte * Main_Screen;
short Screen_width;
short Screen_height;
short Original_screen_X;
short Original_screen_Y;
byte Menu_factor_X;
byte Menu_factor_Y;
int Pixel_ratio;
byte First_color_in_palette;
byte Back_color;
byte MC_Dark;
byte MC_Light;
T_Window Window_stack[8];
byte Windows_open;
dword Key;
static const struct {
int (*test_func)(void);
const char * test_name;
} tests[] = {
#define TEST(func) { Test_ ## func, # func },
#include "testlist.h"
#undef TEST
{ NULL, NULL}
};
void init(void)
{
#ifdef ENABLE_FILENAMES_ICONV
// iconv is used to convert filenames
cd = iconv_open(TOCODE, FROMCODE); // From UTF8 to ANSI
cd_inv = iconv_open(FROMCODE, TOCODE); // From ANSI to UTF8
#if (defined(SDL_BYTEORDER) && (SDL_BYTEORDER == SDL_BIG_ENDIAN)) || (defined(BYTE_ORDER) && (BYTE_ORDER == BIG_ENDIAN))
cd_utf16 = iconv_open("UTF-16BE", FROMCODE); // From UTF8 to UTF16
cd_utf16_inv = iconv_open(FROMCODE, "UTF-16BE"); // From UTF16 to UTF8
#else
cd_utf16 = iconv_open("UTF-16LE", FROMCODE); // From UTF8 to UTF16
cd_utf16_inv = iconv_open(FROMCODE, "UTF-16LE"); // From UTF16 to UTF8
#endif
#endif /* ENABLE_FILENAMES_ICONV */
}
/**
* Test program entry point
*/
int main(int argc, char * * argv)
{
int i, r;
int fail = 0;
GFX2_verbosity_level = GFX2_DEBUG;
for (i = 0; tests[i].test_func != 0; i++)
{
printf("Testing %s :\n", tests[i].test_name);
r = tests[i].test_func();
if (r)
printf("OK\n");
else {
printf("FAILED\n");
fail++;
}
}
if (fail == 0)
{
printf("All tests succesfull\n");
return 0;
}
else
{
printf("%d tests failed\n", fail);
return 1;
}
}

View File

@@ -28,6 +28,11 @@
///
/// TODO : make a test binary and include the tests to the constant-integration
#include <stdio.h>
#include <string.h>
#include "../struct.h"
#include "../gfx2log.h"
/**
* Tests for MOTO_MAP_pack()
*/

29
src/tests/tests.h Normal file
View File

@@ -0,0 +1,29 @@
/* vim:expandtab:ts=2 sw=2:
*/
/* Grafx2 - The Ultimate 256-color bitmap paint program
Copyright 2019 Thomas Bernard
Copyright 2007-2011 Adrien Destugues
Copyright 1996-2001 Sunset Design (Guillaume Dorme & Karl Maritaud)
Grafx2 is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2
of the License.
Grafx2 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Grafx2; if not, see <http://www.gnu.org/licenses/>
*/
#ifndef TESTS_H_INCLUDED
#define TESTS_H_INCLUDED
#define TEST(func) int Test_ ## func (void);
#include "testlist.h"
#undef TEST
#endif