Test_* functions return error message for report.xml
This commit is contained in:
		
							parent
							
								
									4eee27953c
								
							
						
					
					
						commit
						0a3c608059
					
				@ -130,7 +130,7 @@ static void context_set_file_path(T_IO_Context * context, const char * filepath)
 | 
			
		||||
/**
 | 
			
		||||
 * test the Test_* functions
 | 
			
		||||
 */
 | 
			
		||||
int Test_Formats(void)
 | 
			
		||||
int Test_Formats(char * errmsg)
 | 
			
		||||
{
 | 
			
		||||
  T_IO_Context context;
 | 
			
		||||
  char path[256];
 | 
			
		||||
@ -146,7 +146,7 @@ int Test_Formats(void)
 | 
			
		||||
    f = fopen(path, "rb");
 | 
			
		||||
    if (f == NULL)
 | 
			
		||||
    {
 | 
			
		||||
      GFX2_Log(GFX2_ERROR, "error opening %s\n", path);
 | 
			
		||||
      snprintf(errmsg, ERRMSG_LENGTH, "error opening %s", path);
 | 
			
		||||
      return 0;
 | 
			
		||||
    }
 | 
			
		||||
    context_set_file_path(&context, path);
 | 
			
		||||
@ -155,7 +155,7 @@ int Test_Formats(void)
 | 
			
		||||
    fclose(f);
 | 
			
		||||
    if (File_error != 0)
 | 
			
		||||
    {
 | 
			
		||||
      GFX2_Log(GFX2_ERROR, "Test_%s failed for file %s\n", formats[i].name, formats[i].sample);
 | 
			
		||||
      snprintf(errmsg, ERRMSG_LENGTH, "Test_%s failed for file %s", formats[i].name, formats[i].sample);
 | 
			
		||||
      return 0;
 | 
			
		||||
    }
 | 
			
		||||
    // now check that all other samples are not recognized
 | 
			
		||||
@ -170,7 +170,7 @@ int Test_Formats(void)
 | 
			
		||||
      f = fopen(path, "rb");
 | 
			
		||||
      if (f == NULL)
 | 
			
		||||
      {
 | 
			
		||||
        GFX2_Log(GFX2_ERROR, "error opening %s\n", path);
 | 
			
		||||
        snprintf(errmsg, ERRMSG_LENGTH, "error opening %s", path);
 | 
			
		||||
        return 0;
 | 
			
		||||
      }
 | 
			
		||||
      context_set_file_path(&context, path);
 | 
			
		||||
@ -179,7 +179,7 @@ int Test_Formats(void)
 | 
			
		||||
      fclose(f);
 | 
			
		||||
      if (File_error == 0)
 | 
			
		||||
      {
 | 
			
		||||
        GFX2_Log(GFX2_ERROR, "Test_%s failed for file %s\n", formats[i].name, formats[j].sample);
 | 
			
		||||
        snprintf(errmsg, ERRMSG_LENGTH, "Test_%s failed for file %s", formats[i].name, formats[j].sample);
 | 
			
		||||
        return 0;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
@ -193,7 +193,7 @@ int Test_Formats(void)
 | 
			
		||||
/**
 | 
			
		||||
 * test the Load_* functions
 | 
			
		||||
 */
 | 
			
		||||
int Test_Load(void)
 | 
			
		||||
int Test_Load(char * errmsg)
 | 
			
		||||
{
 | 
			
		||||
  T_IO_Context context;
 | 
			
		||||
  char path[256];
 | 
			
		||||
@ -211,7 +211,7 @@ int Test_Load(void)
 | 
			
		||||
    formats[i].Load(&context);
 | 
			
		||||
    if (File_error != 0)
 | 
			
		||||
    {
 | 
			
		||||
      GFX2_Log(GFX2_ERROR, "Load_%s failed for file %s\n", formats[i].name, formats[i].sample);
 | 
			
		||||
      snprintf(errmsg, ERRMSG_LENGTH, "Load_%s failed for file %s", formats[i].name, formats[i].sample);
 | 
			
		||||
      return 0;
 | 
			
		||||
    }
 | 
			
		||||
    if (context.Surface)
 | 
			
		||||
@ -230,7 +230,7 @@ int Test_Load(void)
 | 
			
		||||
/**
 | 
			
		||||
 * Test the Save_* functions
 | 
			
		||||
 */
 | 
			
		||||
int Test_Save(void)
 | 
			
		||||
int Test_Save(char * errmsg)
 | 
			
		||||
{
 | 
			
		||||
  T_IO_Context context;
 | 
			
		||||
  char path[256];
 | 
			
		||||
@ -394,7 +394,7 @@ ret:
 | 
			
		||||
  return ok;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Test_C64_Formats(void)
 | 
			
		||||
int Test_C64_Formats(char * errmsg)
 | 
			
		||||
{
 | 
			
		||||
  int i, j;
 | 
			
		||||
  int ok = 0;
 | 
			
		||||
 | 
			
		||||
@ -41,7 +41,7 @@
 | 
			
		||||
#define random (long)rand
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
int Test_Read_Write_byte(void)
 | 
			
		||||
int Test_Read_Write_byte(char * errmsg)
 | 
			
		||||
{
 | 
			
		||||
  char path[256];
 | 
			
		||||
  FILE * f;
 | 
			
		||||
@ -51,25 +51,25 @@ int Test_Read_Write_byte(void)
 | 
			
		||||
  f = fopen(path, "w+b");
 | 
			
		||||
  if (f == NULL)
 | 
			
		||||
  {
 | 
			
		||||
    GFX2_Log(GFX2_ERROR, "error opening %s\n", path);
 | 
			
		||||
    snprintf(errmsg, ERRMSG_LENGTH, "error opening %s", path);
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
  if (!Write_byte(f, 42))
 | 
			
		||||
  {
 | 
			
		||||
    GFX2_Log(GFX2_ERROR, "error writing\n");
 | 
			
		||||
    snprintf(errmsg, ERRMSG_LENGTH, "error writing");
 | 
			
		||||
    fclose(f);
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
  rewind(f);
 | 
			
		||||
  if (!Read_byte(f, &b))
 | 
			
		||||
  {
 | 
			
		||||
    GFX2_Log(GFX2_ERROR, "error reading\n");
 | 
			
		||||
    snprintf(errmsg, ERRMSG_LENGTH, "error reading");
 | 
			
		||||
    fclose(f);
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
  if (b != 42)
 | 
			
		||||
  {
 | 
			
		||||
    GFX2_Log(GFX2_ERROR, "Byte value mismatch\n");
 | 
			
		||||
    snprintf(errmsg, ERRMSG_LENGTH, "Byte value mismatch 0x%02x != 0x%02x", b, 42);
 | 
			
		||||
    fclose(f);
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
@ -78,7 +78,7 @@ int Test_Read_Write_byte(void)
 | 
			
		||||
  return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Test_Read_Write_word(void)
 | 
			
		||||
int Test_Read_Write_word(char * errmsg)
 | 
			
		||||
{
 | 
			
		||||
  char path[256];
 | 
			
		||||
  FILE * f;
 | 
			
		||||
@ -89,26 +89,26 @@ int Test_Read_Write_word(void)
 | 
			
		||||
  f = fopen(path, "w+b");
 | 
			
		||||
  if (f == NULL)
 | 
			
		||||
  {
 | 
			
		||||
    GFX2_Log(GFX2_ERROR, "error opening %s\n", path);
 | 
			
		||||
    snprintf(errmsg, ERRMSG_LENGTH, "error opening %s", path);
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
  // write bytes 12 34 56 78 90
 | 
			
		||||
  if (!Write_word_le(f, 0x3412) || !Write_word_be(f, 0x5678) || !Write_byte(f, 0x90))
 | 
			
		||||
  {
 | 
			
		||||
    GFX2_Log(GFX2_ERROR, "error writing\n");
 | 
			
		||||
    snprintf(errmsg, ERRMSG_LENGTH, "error writing");
 | 
			
		||||
    fclose(f);
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
  rewind(f);
 | 
			
		||||
  if (!Read_byte(f, &b) || !Read_word_be(f, &w1) || !Read_word_le(f, &w2))
 | 
			
		||||
  {
 | 
			
		||||
    GFX2_Log(GFX2_ERROR, "error reading\n");
 | 
			
		||||
    snprintf(errmsg, ERRMSG_LENGTH, "error reading");
 | 
			
		||||
    fclose(f);
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
  if ((b != 0x12) || (w1 != 0x3456) || (w2 != 0x9078))
 | 
			
		||||
  {
 | 
			
		||||
    GFX2_Log(GFX2_ERROR, "word values mismatch\n");
 | 
			
		||||
    snprintf(errmsg, ERRMSG_LENGTH, "word values mismatch b=0x%02x w1=0x%04x w2=0x%04x", b, w1, w2);
 | 
			
		||||
    fclose(f);
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
@ -117,7 +117,7 @@ int Test_Read_Write_word(void)
 | 
			
		||||
  return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Test_Read_Write_dword(void)
 | 
			
		||||
int Test_Read_Write_dword(char * errmsg)
 | 
			
		||||
{
 | 
			
		||||
  char path[256];
 | 
			
		||||
  FILE * f;
 | 
			
		||||
@ -128,26 +128,26 @@ int Test_Read_Write_dword(void)
 | 
			
		||||
  f = fopen(path, "w+b");
 | 
			
		||||
  if (f == NULL)
 | 
			
		||||
  {
 | 
			
		||||
    GFX2_Log(GFX2_ERROR, "error opening %s\n", path);
 | 
			
		||||
    snprintf(errmsg, ERRMSG_LENGTH, "error opening %s", path);
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
  // write bytes 01 02 03 04 05 06 07 08 09
 | 
			
		||||
  if (!Write_dword_le(f, 0x04030201) || !Write_dword_be(f, 0x05060708) || !Write_byte(f, 9))
 | 
			
		||||
  {
 | 
			
		||||
    GFX2_Log(GFX2_ERROR, "error writing\n");
 | 
			
		||||
    snprintf(errmsg, ERRMSG_LENGTH, "error writing");
 | 
			
		||||
    fclose(f);
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
  rewind(f);
 | 
			
		||||
  if (!Read_byte(f, &b) || !Read_dword_be(f, &dw1) || !Read_dword_le(f, &dw2))
 | 
			
		||||
  {
 | 
			
		||||
    GFX2_Log(GFX2_ERROR, "error reading\n");
 | 
			
		||||
    snprintf(errmsg, ERRMSG_LENGTH, "error reading");
 | 
			
		||||
    fclose(f);
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
  if ((b != 0x1) || (dw1 != 0x02030405) || (dw2 != 0x09080706))
 | 
			
		||||
  {
 | 
			
		||||
    GFX2_Log(GFX2_ERROR, "word values mismatch\n");
 | 
			
		||||
    snprintf(errmsg, ERRMSG_LENGTH, "word values mismatch");
 | 
			
		||||
    fclose(f);
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
@ -156,7 +156,7 @@ int Test_Read_Write_dword(void)
 | 
			
		||||
  return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Test_Read_Write_bytes(void)
 | 
			
		||||
int Test_Read_Write_bytes(char * errmsg)
 | 
			
		||||
{
 | 
			
		||||
  char path[256];
 | 
			
		||||
  FILE * f;
 | 
			
		||||
@ -168,7 +168,7 @@ int Test_Read_Write_bytes(void)
 | 
			
		||||
  f = fopen(path, "w+b");
 | 
			
		||||
  if (f == NULL)
 | 
			
		||||
  {
 | 
			
		||||
    GFX2_Log(GFX2_ERROR, "error opening %s\n", path);
 | 
			
		||||
    snprintf(errmsg, ERRMSG_LENGTH, "error opening %s", path);
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
  b = (byte)random();
 | 
			
		||||
@ -184,7 +184,7 @@ int Test_Read_Write_bytes(void)
 | 
			
		||||
  // write bytes
 | 
			
		||||
  if (!Write_bytes(f, buffer, len))
 | 
			
		||||
  {
 | 
			
		||||
    GFX2_Log(GFX2_ERROR, "error writing\n");
 | 
			
		||||
    snprintf(errmsg, ERRMSG_LENGTH, "error writing");
 | 
			
		||||
    free(buffer);
 | 
			
		||||
    fclose(f);
 | 
			
		||||
    return 0;
 | 
			
		||||
@ -193,14 +193,14 @@ int Test_Read_Write_bytes(void)
 | 
			
		||||
  memset(buffer, 0, len);
 | 
			
		||||
  if (!Read_bytes(f, buffer, len))
 | 
			
		||||
  {
 | 
			
		||||
    GFX2_Log(GFX2_ERROR, "error reading\n");
 | 
			
		||||
    snprintf(errmsg, ERRMSG_LENGTH, "error reading");
 | 
			
		||||
    free(buffer);
 | 
			
		||||
    fclose(f);
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
  if (!GFX2_is_mem_filled_with(buffer, b, len))
 | 
			
		||||
  {
 | 
			
		||||
    GFX2_Log(GFX2_ERROR, "byte values mismatch\n");
 | 
			
		||||
    snprintf(errmsg, ERRMSG_LENGTH, "byte values mismatch");
 | 
			
		||||
    free(buffer);
 | 
			
		||||
    fclose(f);
 | 
			
		||||
    return 0;
 | 
			
		||||
@ -208,7 +208,7 @@ int Test_Read_Write_bytes(void)
 | 
			
		||||
  free(buffer);
 | 
			
		||||
  if (File_length_file(f) != len)
 | 
			
		||||
  {
 | 
			
		||||
    GFX2_Log(GFX2_ERROR, "File_length_file() returned %lu (should be %lu)\n",
 | 
			
		||||
    snprintf(errmsg, ERRMSG_LENGTH, "File_length_file() returned %lu (should be %lu)",
 | 
			
		||||
             File_length_file(f), len);
 | 
			
		||||
    fclose(f);
 | 
			
		||||
    return 0;
 | 
			
		||||
@ -216,7 +216,7 @@ int Test_Read_Write_bytes(void)
 | 
			
		||||
  fclose(f);
 | 
			
		||||
  if (File_length(path) != len)
 | 
			
		||||
  {
 | 
			
		||||
    GFX2_Log(GFX2_ERROR, "File_length() returned %lu (should be %lu)\n",
 | 
			
		||||
    snprintf(errmsg, ERRMSG_LENGTH, "File_length() returned %lu (should be %lu)",
 | 
			
		||||
             File_length(path), len);
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
@ -249,7 +249,7 @@ static void directory_callback(void * pdata, const char * filename, const word *
 | 
			
		||||
    data->result = 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Test_File_exists(void)
 | 
			
		||||
int Test_File_exists(char * errmsg)
 | 
			
		||||
{
 | 
			
		||||
  struct dir_callback_data data;
 | 
			
		||||
  char path[256];
 | 
			
		||||
@ -257,40 +257,40 @@ int Test_File_exists(void)
 | 
			
		||||
 | 
			
		||||
  if (!Directory_exists(tmpdir))
 | 
			
		||||
  {
 | 
			
		||||
    GFX2_Log(GFX2_ERROR, "Directory_exists(\"%s\") FALSE\n", tmpdir);
 | 
			
		||||
    snprintf(errmsg, ERRMSG_LENGTH, "Directory_exists(\"%s\") FALSE", tmpdir);
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
  snprintf(path, sizeof(path), "%s%sX%07x.tmp", tmpdir, PATH_SEPARATOR, (unsigned)(random() & 0x0fffffff));
 | 
			
		||||
  if (File_exists(path))
 | 
			
		||||
  {
 | 
			
		||||
    GFX2_Log(GFX2_ERROR, "File_exists(\"%s\") TRUE before creation\n", path);
 | 
			
		||||
    snprintf(errmsg, ERRMSG_LENGTH, "File_exists(\"%s\") TRUE before creation", path);
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
  f = fopen(path, "w");
 | 
			
		||||
  if (f == NULL)
 | 
			
		||||
  {
 | 
			
		||||
    GFX2_Log(GFX2_ERROR, "fopen(\"%s\", \"wb\") FAILED\n", path);
 | 
			
		||||
    snprintf(errmsg, ERRMSG_LENGTH, "fopen(\"%s\", \"wb\") FAILED", path);
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
  fputs("test\n", f);
 | 
			
		||||
  fclose(f);
 | 
			
		||||
  if (!File_exists(path))
 | 
			
		||||
  {
 | 
			
		||||
    GFX2_Log(GFX2_ERROR, "File_exists(\"%s\") FALSE after create\n", path);
 | 
			
		||||
    snprintf(errmsg, ERRMSG_LENGTH, "File_exists(\"%s\") FALSE after create", path);
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
  data.result = 0;
 | 
			
		||||
  data.filename = Extract_filename(NULL, path);
 | 
			
		||||
  if (data.filename == NULL)
 | 
			
		||||
  {
 | 
			
		||||
    GFX2_Log(GFX2_ERROR, "Extract_filename(NULL, \"%s\") FAILED\n", path);
 | 
			
		||||
    snprintf(errmsg, ERRMSG_LENGTH, "Extract_filename(NULL, \"%s\") FAILED", path);
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
  GFX2_Log(GFX2_DEBUG, "Listing directory with For_each_directory_entry(\"%s\"):\n", tmpdir);
 | 
			
		||||
  For_each_directory_entry(tmpdir, &data, directory_callback);
 | 
			
		||||
  if (!data.result)
 | 
			
		||||
  {
 | 
			
		||||
    GFX2_Log(GFX2_ERROR, "Failed to find file \"%s\" in directory \"%s\"\n", data.filename, tmpdir);
 | 
			
		||||
    snprintf(errmsg, ERRMSG_LENGTH, "Failed to find file \"%s\" in directory \"%s\"", data.filename, tmpdir);
 | 
			
		||||
    free(data.filename);
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
@ -298,20 +298,20 @@ int Test_File_exists(void)
 | 
			
		||||
  Remove_path(path);
 | 
			
		||||
  if (File_exists(path))
 | 
			
		||||
  {
 | 
			
		||||
    GFX2_Log(GFX2_ERROR, "File_exists(\"%s\") TRUE after Remove\n", path);
 | 
			
		||||
    snprintf(errmsg, ERRMSG_LENGTH, "File_exists(\"%s\") TRUE after Remove", path);
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
  return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Test_Realpath(void)
 | 
			
		||||
int Test_Realpath(char * errmsg)
 | 
			
		||||
{
 | 
			
		||||
  char * path;
 | 
			
		||||
 | 
			
		||||
  path = Realpath(tmpdir, NULL);
 | 
			
		||||
  if (path == NULL)
 | 
			
		||||
  {
 | 
			
		||||
    GFX2_Log(GFX2_ERROR, "Realpath(\"%s\") returned NULL\n", tmpdir);
 | 
			
		||||
    snprintf(errmsg, ERRMSG_LENGTH, "Realpath(\"%s\") returned NULL", tmpdir);
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
  GFX2_Log(GFX2_DEBUG, "Realpath(\"%s\") returned \"%s\"\n", tmpdir, path);
 | 
			
		||||
 | 
			
		||||
@ -99,7 +99,7 @@ dword Key;
 | 
			
		||||
char tmpdir[256];
 | 
			
		||||
 | 
			
		||||
static const struct {
 | 
			
		||||
  int (*test_func)(void);
 | 
			
		||||
  int (*test_func)(char * errmsg);
 | 
			
		||||
  const char * test_name;
 | 
			
		||||
} tests[] = {
 | 
			
		||||
#define TEST(func) { Test_ ## func, # func },
 | 
			
		||||
@ -174,6 +174,7 @@ int main(int argc, char * * argv)
 | 
			
		||||
  int fail_early = 0;
 | 
			
		||||
  const char * xml_path = "test-report.xml";
 | 
			
		||||
  FILE * xml; // see https://llg.cubic.org/docs/junit/
 | 
			
		||||
  char errmsg[ERRMSG_LENGTH];
 | 
			
		||||
 | 
			
		||||
  for (i = 1; i < argc; i++)
 | 
			
		||||
  {
 | 
			
		||||
@ -209,17 +210,26 @@ int main(int argc, char * * argv)
 | 
			
		||||
  }
 | 
			
		||||
  fprintf(xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
 | 
			
		||||
  fprintf(xml, "<testsuite name=\"GrafX2\" tests=\"%lu\">\n", TEST_COUNT);
 | 
			
		||||
  for (i = 0; i < (int)TEST_COUNT && !(fail_early && fail > 0) ; i++)
 | 
			
		||||
  for (i = 0; i < (int)TEST_COUNT; i++)
 | 
			
		||||
  {
 | 
			
		||||
    fprintf(xml, "  <testcase name=\"%s\" classname=\"%s\">\n", tests[i].test_name, "GrafX2");
 | 
			
		||||
    if (fail_early && fail > 0)
 | 
			
		||||
      fprintf(xml, "    <skipped />\n");
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
      printf("Testing %s :\n", tests[i].test_name);
 | 
			
		||||
    fprintf(xml, "  <testcase name=\"%s\" classname=\"%s\">\n", tests[i].test_name, "GrafX2");
 | 
			
		||||
    r[i] = tests[i].test_func();
 | 
			
		||||
      errmsg[0] = '\0';
 | 
			
		||||
      r[i] = tests[i].test_func(errmsg);
 | 
			
		||||
      if (r[i])
 | 
			
		||||
        printf(ESC_GREEN "OK" ESC_RESET "\n");
 | 
			
		||||
    else {
 | 
			
		||||
      else
 | 
			
		||||
      {
 | 
			
		||||
        fprintf(stderr, ESC_RED "%s" ESC_RESET "\n", errmsg);
 | 
			
		||||
        printf(ESC_RED "FAILED" ESC_RESET "\n");
 | 
			
		||||
        fail++;
 | 
			
		||||
      fprintf(xml, "    <failure message=\"test failure\">failure details</failure>\n");
 | 
			
		||||
        fprintf(xml, "    <failure message='%s'><!-- failure details --></failure>\n",
 | 
			
		||||
                errmsg);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    fprintf(xml, "  </testcase>\n");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -28,10 +28,11 @@
 | 
			
		||||
///
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include "tests.h"
 | 
			
		||||
#include "../op_c.h"
 | 
			
		||||
#include "../gfx2log.h"
 | 
			
		||||
 | 
			
		||||
int Test_Convert_24b_bitmap_to_256(void)
 | 
			
		||||
int Test_Convert_24b_bitmap_to_256(char * msg)
 | 
			
		||||
{
 | 
			
		||||
  T_Palette palette;
 | 
			
		||||
  byte dest[256];
 | 
			
		||||
 | 
			
		||||
@ -48,7 +48,7 @@ unsigned int MOTO_MAP_pack(byte * packed, const byte * unpacked, unsigned int un
 | 
			
		||||
/**
 | 
			
		||||
 * Tests for MOTO_MAP_pack()
 | 
			
		||||
 */
 | 
			
		||||
int Test_MOTO_MAP_pack(void)
 | 
			
		||||
int Test_MOTO_MAP_pack(char * errmsg)
 | 
			
		||||
{
 | 
			
		||||
  unsigned int i, j;
 | 
			
		||||
  byte buffer[1024];
 | 
			
		||||
@ -89,7 +89,8 @@ int Test_MOTO_MAP_pack(void)
 | 
			
		||||
    }
 | 
			
		||||
    if (unpacked_len != original_len || 0 != memcmp(tests[i], buffer2, original_len))
 | 
			
		||||
    {
 | 
			
		||||
      GFX2_Log(GFX2_ERROR, "*** %u %s != %u %s ***\n", original_len, tests[i], unpacked_len, buffer2);
 | 
			
		||||
      snprintf(errmsg, ERRMSG_LENGTH, "(un)pack error : %u %s != %u %s",
 | 
			
		||||
               original_len, tests[i], unpacked_len, buffer2);
 | 
			
		||||
      return 0;  // test failed
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
@ -99,7 +100,7 @@ int Test_MOTO_MAP_pack(void)
 | 
			
		||||
/**
 | 
			
		||||
 * Test for Test_CPC_compare_colors()
 | 
			
		||||
 */
 | 
			
		||||
int Test_CPC_compare_colors(void)
 | 
			
		||||
int Test_CPC_compare_colors(char * errmsg)
 | 
			
		||||
{
 | 
			
		||||
  unsigned int r, g, b;
 | 
			
		||||
  T_Components c1, c2;
 | 
			
		||||
@ -113,13 +114,16 @@ int Test_CPC_compare_colors(void)
 | 
			
		||||
        c1.G = g * 0x11;
 | 
			
		||||
        c1.B = b * 0x11;
 | 
			
		||||
        if (!CPC_compare_colors(&c1, &c1))
 | 
			
		||||
          return 0; // same colors should be recognized as identical !!!
 | 
			
		||||
        {
 | 
			
		||||
          snprintf(errmsg, ERRMSG_LENGTH, "same colors should be recognized as identical");
 | 
			
		||||
          return 0;
 | 
			
		||||
        }
 | 
			
		||||
        c2.R = ((r + 6) & 15) * 0x11;
 | 
			
		||||
        c2.G = c1.G;
 | 
			
		||||
        c2.B = c1.B;
 | 
			
		||||
        if (CPC_compare_colors(&c1, &c2))
 | 
			
		||||
        {
 | 
			
		||||
          GFX2_Log(GFX2_ERROR, "#%02x%02x%02x <> #%02x%02x%02x\n",
 | 
			
		||||
          snprintf(errmsg, ERRMSG_LENGTH, "#%02x%02x%02x <> #%02x%02x%02x",
 | 
			
		||||
                   c1.R, c1.G, c1.B, c2.R, c2.G, c2.B);
 | 
			
		||||
          return 0; // Should be differents !
 | 
			
		||||
        }
 | 
			
		||||
@ -127,7 +131,7 @@ int Test_CPC_compare_colors(void)
 | 
			
		||||
        c2.G = ((g + 6) & 15) * 0x11;
 | 
			
		||||
        if (CPC_compare_colors(&c1, &c2))
 | 
			
		||||
        {
 | 
			
		||||
          GFX2_Log(GFX2_ERROR, "#%02x%02x%02x <> #%02x%02x%02x\n",
 | 
			
		||||
          snprintf(errmsg, ERRMSG_LENGTH, "#%02x%02x%02x <> #%02x%02x%02x",
 | 
			
		||||
                   c1.R, c1.G, c1.B, c2.R, c2.G, c2.B);
 | 
			
		||||
          return 0; // Should be differents !
 | 
			
		||||
        }
 | 
			
		||||
@ -135,7 +139,7 @@ int Test_CPC_compare_colors(void)
 | 
			
		||||
        c2.B = ((b + 6) & 15) * 0x11;
 | 
			
		||||
        if (CPC_compare_colors(&c1, &c2))
 | 
			
		||||
        {
 | 
			
		||||
          GFX2_Log(GFX2_ERROR, "#%02x%02x%02x <> #%02x%02x%02x\n",
 | 
			
		||||
          snprintf(errmsg, ERRMSG_LENGTH, "#%02x%02x%02x <> #%02x%02x%02x",
 | 
			
		||||
                   c1.R, c1.G, c1.B, c2.R, c2.G, c2.B);
 | 
			
		||||
          return 0; // Should be differents !
 | 
			
		||||
        }
 | 
			
		||||
@ -149,7 +153,7 @@ int Test_CPC_compare_colors(void)
 | 
			
		||||
 * Tests for the packbits compression used in IFF ILBM, etc.
 | 
			
		||||
 * see http://fileformats.archiveteam.org/wiki/PackBits
 | 
			
		||||
 */
 | 
			
		||||
int Test_Packbits(void)
 | 
			
		||||
int Test_Packbits(char * errmsg)
 | 
			
		||||
{
 | 
			
		||||
  char tempfilename[256];
 | 
			
		||||
  FILE * f;
 | 
			
		||||
@ -187,7 +191,7 @@ int Test_Packbits(void)
 | 
			
		||||
  f = fopen(tempfilename, "wb");
 | 
			
		||||
  if (f == NULL)
 | 
			
		||||
  {
 | 
			
		||||
    GFX2_Log(GFX2_ERROR, "Failed to open %s for writing\n", tempfilename);
 | 
			
		||||
    snprintf(errmsg, ERRMSG_LENGTH, "Failed to open %s for writing", tempfilename);
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -199,14 +203,14 @@ int Test_Packbits(void)
 | 
			
		||||
    {
 | 
			
		||||
      if (PackBits_pack_add(&pb_data, (byte)tests[i][j]) < 0)
 | 
			
		||||
      {
 | 
			
		||||
        GFX2_Log(GFX2_ERROR, "PackBits_pack_add() failed\n");
 | 
			
		||||
        snprintf(errmsg, ERRMSG_LENGTH, "PackBits_pack_add() failed");
 | 
			
		||||
        return 0;
 | 
			
		||||
      }
 | 
			
		||||
      unpacked++;
 | 
			
		||||
    }
 | 
			
		||||
    if (PackBits_pack_flush(&pb_data) < 0)
 | 
			
		||||
    {
 | 
			
		||||
      GFX2_Log(GFX2_ERROR, "PackBits_pack_flush() failed\n");
 | 
			
		||||
      snprintf(errmsg, ERRMSG_LENGTH, "PackBits_pack_flush() failed");
 | 
			
		||||
      return 0;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
@ -214,7 +218,7 @@ int Test_Packbits(void)
 | 
			
		||||
  fclose(f);
 | 
			
		||||
  GFX2_Log(GFX2_DEBUG, "Compressed %ld bytes to %ld\n", unpacked, packed);
 | 
			
		||||
  if (packed > best_packed) {
 | 
			
		||||
    GFX2_Log(GFX2_ERROR, "*** Packbits less efficient as expected (%ld > %ld bytes) ***\n",
 | 
			
		||||
    snprintf(errmsg, ERRMSG_LENGTH, "Packbits less efficient than expected (%ld > %ld bytes)",
 | 
			
		||||
             packed, best_packed);
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
@ -223,7 +227,7 @@ int Test_Packbits(void)
 | 
			
		||||
  f = fopen(tempfilename, "rb");
 | 
			
		||||
  if (f == NULL)
 | 
			
		||||
  {
 | 
			
		||||
    GFX2_Log(GFX2_ERROR, "Failed to open %s for reading\n", tempfilename);
 | 
			
		||||
    snprintf(errmsg, ERRMSG_LENGTH, "Failed to open %s for reading", tempfilename);
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
  for (i = 0; tests[i]; i++)
 | 
			
		||||
@ -232,7 +236,7 @@ int Test_Packbits(void)
 | 
			
		||||
    memset(buffer, 0x80, len);
 | 
			
		||||
    if (PackBits_unpack_from_file(f, buffer, len) != PACKBITS_UNPACK_OK)
 | 
			
		||||
    {
 | 
			
		||||
      GFX2_Log(GFX2_ERROR, "PackBits_unpack_from_file() failed\n");
 | 
			
		||||
      snprintf(errmsg, ERRMSG_LENGTH, "PackBits_unpack_from_file() failed");
 | 
			
		||||
      return 0;
 | 
			
		||||
    }
 | 
			
		||||
    if (memcmp(buffer, tests[i], len) != 0)
 | 
			
		||||
@ -240,6 +244,7 @@ int Test_Packbits(void)
 | 
			
		||||
      GFX2_Log(GFX2_ERROR, "uncompressed stream mismatch !\n");
 | 
			
		||||
      GFX2_LogHexDump(GFX2_ERROR, "original ", (const byte *)tests[i], 0, len);
 | 
			
		||||
      GFX2_LogHexDump(GFX2_ERROR, "unpacked ", buffer, 0, len);
 | 
			
		||||
      snprintf(errmsg, ERRMSG_LENGTH, "uncompressed stream mismatch");
 | 
			
		||||
      return 0;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -22,7 +22,9 @@
 | 
			
		||||
#ifndef TESTS_H_INCLUDED
 | 
			
		||||
#define TESTS_H_INCLUDED
 | 
			
		||||
 | 
			
		||||
#define TEST(func) int Test_ ## func (void);
 | 
			
		||||
#define ERRMSG_LENGTH (256)
 | 
			
		||||
 | 
			
		||||
#define TEST(func) int Test_ ## func (char *);
 | 
			
		||||
#include "testlist.h"
 | 
			
		||||
#undef TEST
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user