C64 Test files written in the same location as other test files

This commit is contained in:
Thomas Bernard 2020-01-04 10:35:02 +01:00
parent c8c53827e3
commit 22eddf1071
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C
3 changed files with 46 additions and 13 deletions

View File

@ -34,6 +34,7 @@
#include "../fileformats.h" #include "../fileformats.h"
#include "../gfx2log.h" #include "../gfx2log.h"
#include "../gfx2mem.h" #include "../gfx2mem.h"
#include "tests.h"
// Load_IFF/Save_IFF does for both LBM and PBM (and Load_IFF also loads ACBM format) // Load_IFF/Save_IFF does for both LBM and PBM (and Load_IFF also loads ACBM format)
#define Load_ACBM Load_IFF #define Load_ACBM Load_IFF
@ -232,7 +233,6 @@ int Test_Save(void)
{ {
T_IO_Context context; T_IO_Context context;
char path[256]; char path[256];
char tmpdir[40];
int i; int i;
int ok = 0; int ok = 0;
T_GFX2_Surface * testpic256 = NULL; T_GFX2_Surface * testpic256 = NULL;
@ -277,13 +277,6 @@ int Test_Save(void)
context.Surface = NULL; context.Surface = NULL;
memcpy(testpiccpco->palette, context.Palette, sizeof(T_Palette)); memcpy(testpiccpco->palette, context.Palette, sizeof(T_Palette));
snprintf(tmpdir, sizeof(tmpdir), "/tmp/grafx2-test.XXXXXX");
if (mkdtemp(tmpdir) == NULL)
{
perror("mkdtemp");
goto ret;
}
printf("temp dir : %s\n", tmpdir);
ok = 1; ok = 1;
for (i = 0; ok && formats[i].name != NULL; i++) for (i = 0; ok && formats[i].name != NULL; i++)
{ {
@ -388,8 +381,6 @@ int Test_Save(void)
} }
} }
} }
if (rmdir(tmpdir) < 0)
perror("rmdir");
ret: ret:
if (testpic16) if (testpic16)
Free_GFX2_Surface(testpic16); Free_GFX2_Surface(testpic16);
@ -458,7 +449,7 @@ int Test_C64_Formats(void)
ref = testpichires; ref = testpichires;
context.Ratio = PIXEL_SIMPLE; context.Ratio = PIXEL_SIMPLE;
} }
snprintf(path, sizeof(path), "/tmp/%s-%d.%s", "test", j, formats[i].name); snprintf(path, sizeof(path), "%s/%s-%d.%s", tmpdir, "test", j, formats[i].name);
context_set_file_path(&context, path); context_set_file_path(&context, path);
// save the reference picture // save the reference picture
@ -513,6 +504,11 @@ int Test_C64_Formats(void)
GFX2_Log(GFX2_ERROR, "Save_%s/Load_%s: Pixels mismatch\n", formats[i].name, formats[i].name); GFX2_Log(GFX2_ERROR, "Save_%s/Load_%s: Pixels mismatch\n", formats[i].name, formats[i].name);
ok = 0; ok = 0;
} }
else
{
if (unlink(path) < 0)
perror("unlink");
}
Free_GFX2_Surface(context.Surface); Free_GFX2_Surface(context.Surface);
context.Surface = NULL; context.Surface = NULL;
} }

View File

@ -29,6 +29,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include <time.h> #include <time.h>
#include "../struct.h" #include "../struct.h"
#include "../global.h" #include "../global.h"
@ -68,6 +69,8 @@ byte Windows_open;
dword Key; dword Key;
char tmpdir[40];
static const struct { static const struct {
int (*test_func)(void); int (*test_func)(void);
const char * test_name; const char * test_name;
@ -81,7 +84,7 @@ static const struct {
/** /**
* Initializations for test program * Initializations for test program
*/ */
void init(void) int init(void)
{ {
srandom(time(NULL)); srandom(time(NULL));
#ifdef ENABLE_FILENAMES_ICONV #ifdef ENABLE_FILENAMES_ICONV
@ -96,6 +99,29 @@ void init(void)
cd_utf16_inv = iconv_open(FROMCODE, "UTF-16LE"); // From UTF16 to UTF8 cd_utf16_inv = iconv_open(FROMCODE, "UTF-16LE"); // From UTF16 to UTF8
#endif #endif
#endif /* ENABLE_FILENAMES_ICONV */ #endif /* ENABLE_FILENAMES_ICONV */
snprintf(tmpdir, sizeof(tmpdir), "/tmp/grafx2-test.XXXXXX");
if (mkdtemp(tmpdir) == NULL)
{
perror("mkdtemp");
return -1;
}
printf("temp dir : %s\n", tmpdir);
return 0;
}
/**
* Releases resources
*/
void finish(void)
{
#ifdef ENABLE_FILENAMES_ICONV
iconv_close(cd);
iconv_close(cd_inv);
iconv_close(cd_utf16);
iconv_close(cd_utf16_inv);
#endif /* ENABLE_FILENAMES_ICONV */
if (rmdir(tmpdir) < 0)
fprintf(stderr, "Failed to rmdir(\"%s\"): %s\n", tmpdir, strerror(errno));
} }
#define ESC_GREEN "\033[32m" #define ESC_GREEN "\033[32m"
@ -113,7 +139,11 @@ int main(int argc, char * * argv)
(void)argv; (void)argv;
GFX2_verbosity_level = GFX2_DEBUG; GFX2_verbosity_level = GFX2_DEBUG;
init(); if (init() < 0)
{
fprintf(stderr, "Failed to init.\n");
return 1;
}
for (i = 0; tests[i].test_func != 0; i++) for (i = 0; tests[i].test_func != 0; i++)
{ {
@ -127,6 +157,8 @@ int main(int argc, char * * argv)
} }
} }
finish();
if (fail == 0) if (fail == 0)
{ {
printf(ESC_GREEN "All tests succesfull" ESC_RESET "\n"); printf(ESC_GREEN "All tests succesfull" ESC_RESET "\n");

View File

@ -26,4 +26,9 @@
#include "testlist.h" #include "testlist.h"
#undef TEST #undef TEST
/**
* path to directory where tests can write files
*/
extern char tmpdir[];
#endif #endif