test/testtypes.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 20 Feb 2006 10:19:47 +0000
changeset 1387 835c1831f903
parent 1154 d93862a3d821
permissions -rw-r--r--
Tests require SDL 1.2.10
     1 
     2 #include <stdio.h>
     3 #include "SDL_main.h"
     4 #include "SDL_stdinc.h"
     5 
     6 /*
     7  * Watcom C flags these as Warning 201: "Unreachable code" if you just
     8  *  compare them directly, so we push it through a function to keep the
     9  *  compiler quiet.  --ryan.
    10  */
    11 static int badsize(size_t sizeoftype, size_t hardcodetype)
    12 {
    13     return sizeoftype != hardcodetype;
    14 }
    15 
    16 int main(int argc, char *argv[])
    17 {
    18 	int error = 0;
    19 	int verbose = 1;
    20 
    21 	if ( argv[1] && (strcmp(argv[1], "-q") == 0) )
    22 		verbose = 0;
    23 
    24 	if ( badsize(sizeof(Uint8), 1) ) {
    25 		if ( verbose )
    26 			printf("sizeof(Uint8) != 1, instead = %d\n",
    27 								sizeof(Uint8));
    28 		++error;
    29 	}
    30 	if ( badsize(sizeof(Uint16), 2) ) {
    31 		if ( verbose )
    32 			printf("sizeof(Uint16) != 2, instead = %d\n",
    33 								sizeof(Uint16));
    34 		++error;
    35 	}
    36 	if ( badsize(sizeof(Uint32), 4) ) {
    37 		if ( verbose )
    38 			printf("sizeof(Uint32) != 4, instead = %d\n",
    39 								sizeof(Uint32));
    40 		++error;
    41 	}
    42 #ifdef SDL_HAS_64BIT_TYPE
    43 	if ( badsize(sizeof(Uint64), 8) ) {
    44 		if ( verbose )
    45 			printf("sizeof(Uint64) != 8, instead = %d\n",
    46 								sizeof(Uint64));
    47 		++error;
    48 	}
    49 #else
    50 	if ( verbose ) {
    51 		printf("WARNING: No 64-bit datatype on this platform\n");
    52 	}
    53 #endif
    54 	if ( verbose && ! error )
    55 		printf("All data types are the expected size.\n");
    56 
    57 	return( error ? 1 : 0 );
    58 }