test/testplatform.c
changeset 1421 638da75f9ab8
child 1424 7a610f25c12f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/testplatform.c	Fri Feb 24 06:49:31 2006 +0000
     1.3 @@ -0,0 +1,205 @@
     1.4 +
     1.5 +#include <stdio.h>
     1.6 +
     1.7 +#include "SDL.h"
     1.8 +#include "SDL_endian.h"
     1.9 +#include "SDL_cpuinfo.h"
    1.10 +
    1.11 +/*
    1.12 + * Watcom C flags these as Warning 201: "Unreachable code" if you just
    1.13 + *  compare them directly, so we push it through a function to keep the
    1.14 + *  compiler quiet.  --ryan.
    1.15 + */
    1.16 +static int badsize(size_t sizeoftype, size_t hardcodetype)
    1.17 +{
    1.18 +    return sizeoftype != hardcodetype;
    1.19 +}
    1.20 +
    1.21 +int TestTypes(SDL_bool verbose)
    1.22 +{
    1.23 +	int error = 0;
    1.24 +
    1.25 +	if ( badsize(sizeof(Uint8), 1) ) {
    1.26 +		if ( verbose )
    1.27 +			printf("sizeof(Uint8) != 1, instead = %d\n",
    1.28 +								sizeof(Uint8));
    1.29 +		++error;
    1.30 +	}
    1.31 +	if ( badsize(sizeof(Uint16), 2) ) {
    1.32 +		if ( verbose )
    1.33 +			printf("sizeof(Uint16) != 2, instead = %d\n",
    1.34 +								sizeof(Uint16));
    1.35 +		++error;
    1.36 +	}
    1.37 +	if ( badsize(sizeof(Uint32), 4) ) {
    1.38 +		if ( verbose )
    1.39 +			printf("sizeof(Uint32) != 4, instead = %d\n",
    1.40 +								sizeof(Uint32));
    1.41 +		++error;
    1.42 +	}
    1.43 +#ifdef SDL_HAS_64BIT_TYPE
    1.44 +	if ( badsize(sizeof(Uint64), 8) ) {
    1.45 +		if ( verbose )
    1.46 +			printf("sizeof(Uint64) != 8, instead = %d\n",
    1.47 +								sizeof(Uint64));
    1.48 +		++error;
    1.49 +	}
    1.50 +#else
    1.51 +	if ( verbose ) {
    1.52 +		printf("WARNING: No 64-bit datatype on this platform\n");
    1.53 +	}
    1.54 +#endif
    1.55 +	if ( verbose && !error )
    1.56 +		printf("All data types are the expected size.\n");
    1.57 +
    1.58 +	return( error ? 1 : 0 );
    1.59 +}
    1.60 +
    1.61 +int TestEndian(SDL_bool verbose)
    1.62 +{
    1.63 +	int error = 0;
    1.64 +	Uint16 value = 0x1234;
    1.65 +	int real_byteorder;
    1.66 +	Uint16 value16 = 0xCDAB;
    1.67 +	Uint16 swapped16 = 0xABCD;
    1.68 +	Uint32 value32 = 0xEFBEADDE;
    1.69 +	Uint32 swapped32 = 0xDEADBEEF;
    1.70 +#ifdef SDL_HAS_64BIT_TYPE
    1.71 +	Uint64 value64, swapped64;
    1.72 +	value64 = 0xEFBEADDE;
    1.73 +	value64 <<= 32;
    1.74 +	value64 |= 0xCDAB3412;
    1.75 +	swapped64 = 0x1234ABCD;
    1.76 +	swapped64 <<= 32;
    1.77 +	swapped64 |= 0xDEADBEEF;
    1.78 +#endif
    1.79 +
    1.80 +	if ( verbose ) {
    1.81 +		printf("Detected a %s endian machine.\n",
    1.82 +			(SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big");
    1.83 +	}
    1.84 +	if ( *((char *)&value) == '1' ) {
    1.85 +		real_byteorder = SDL_BIG_ENDIAN;
    1.86 +	} else {
    1.87 +		real_byteorder = SDL_LIL_ENDIAN;
    1.88 +	}
    1.89 +	if ( real_byteorder != SDL_BYTEORDER ) {
    1.90 +		if ( verbose ) {
    1.91 +			printf("Actually a %s endian machine!\n",
    1.92 +				(real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big");
    1.93 +		}
    1.94 +		++error;
    1.95 +	}
    1.96 +	if ( verbose ) {
    1.97 +		printf("Value 16 = 0x%X, swapped = 0x%X\n", value16, SDL_Swap16(value16));
    1.98 +	}
    1.99 +	if ( SDL_Swap16(value16) != swapped16 ) {
   1.100 +		if ( verbose ) {
   1.101 +			printf("16 bit value swapped incorrectly!\n");
   1.102 +		}
   1.103 +		++error;
   1.104 +	}
   1.105 +	if ( verbose ) {
   1.106 +		printf("Value 32 = 0x%X, swapped = 0x%X\n", value32, SDL_Swap32(value32));
   1.107 +	}
   1.108 +	if ( SDL_Swap32(value32) != swapped32 ) {
   1.109 +		if ( verbose ) {
   1.110 +			printf("32 bit value swapped incorrectly!\n");
   1.111 +		}
   1.112 +		++error;
   1.113 +	}
   1.114 +#ifdef SDL_HAS_64BIT_TYPE
   1.115 +	if ( verbose ) {
   1.116 +		printf("Value 64 = 0x%llX, swapped = 0x%llX\n", value64, SDL_Swap64(value64));
   1.117 +	}
   1.118 +	if ( SDL_Swap64(value64) != swapped64 ) {
   1.119 +		if ( verbose ) {
   1.120 +			printf("64 bit value swapped incorrectly!\n");
   1.121 +		}
   1.122 +		++error;
   1.123 +	}
   1.124 +#endif
   1.125 +	return( error ? 1 : 0 );
   1.126 +}
   1.127 +
   1.128 +
   1.129 +int TestCPUInfo(SDL_bool verbose)
   1.130 +{
   1.131 +	if ( verbose ) {
   1.132 +		printf("RDTSC %s\n", SDL_HasRDTSC() ? "detected" : "not detected");
   1.133 +		printf("MMX %s\n", SDL_HasMMX() ? "detected" : "not detected");
   1.134 +		printf("MMX Ext %s\n", SDL_HasMMXExt() ? "detected" : "not detected");
   1.135 +		printf("3DNow %s\n", SDL_Has3DNow() ? "detected" : "not detected");
   1.136 +		printf("3DNow Ext %s\n", SDL_Has3DNowExt() ? "detected" : "not detected");
   1.137 +		printf("SSE %s\n", SDL_HasSSE() ? "detected" : "not detected");
   1.138 +		printf("SSE2 %s\n", SDL_HasSSE2() ? "detected" : "not detected");
   1.139 +		printf("AltiVec %s\n", SDL_HasAltiVec() ? "detected" : "not detected");
   1.140 +	}
   1.141 +	return(0);
   1.142 +}
   1.143 +
   1.144 +int main(int argc, char *argv[])
   1.145 +{
   1.146 +	SDL_bool verbose = SDL_TRUE;
   1.147 +	int status = 0;
   1.148 +
   1.149 +	if ( argv[1] && (SDL_strcmp(argv[1], "-q") == 0) ) {
   1.150 +		verbose = SDL_FALSE;
   1.151 +	}
   1.152 +	if ( verbose ) {
   1.153 +		printf("This system is running %s\n",
   1.154 +#if __AIX__
   1.155 +			"AIX"
   1.156 +#elif __AMIGA__
   1.157 +			"AmigaOS"
   1.158 +#elif __BEOS__
   1.159 +			"BeOS"
   1.160 +#elif __BSDI__
   1.161 +			"BSDI"
   1.162 +#elif __DREAMCAST__
   1.163 +			"Dreamcast"
   1.164 +#elif __FREEBSD__
   1.165 +			"FreeBSD"
   1.166 +#elif __HPUX__
   1.167 +			"HP-UX"
   1.168 +#elif __IRIX__
   1.169 +			"Irix"
   1.170 +#elif __LINUX__
   1.171 +			"Linux"
   1.172 +#elif __MINT__
   1.173 +			"Atari MiNT"
   1.174 +#elif __MACOS__
   1.175 +			"MacOS Classic"
   1.176 +#elif __MACOSX__
   1.177 +			"MacOS X"
   1.178 +#elif __NETBSD__
   1.179 +			"NetBSD"
   1.180 +#elif __OPENBSD__
   1.181 +			"OpenBSD"
   1.182 +#elif __OS2__
   1.183 +			"OS/2"
   1.184 +#elif __OSF__
   1.185 +			"OSF/1"
   1.186 +#elif __QNXNTO__
   1.187 +			"QNX Neutrino"
   1.188 +#elif __RISCOS__
   1.189 +			"RISC OS"
   1.190 +#elif __SOLARIS__
   1.191 +			"Solaris"
   1.192 +#elif __WIN32__
   1.193 +#ifdef _WIN32_WCE
   1.194 +			"Windows CE"
   1.195 +#else
   1.196 +			"Windows"
   1.197 +#endif
   1.198 +#else
   1.199 +			"an unknown operating system! (see SDL_platform.h)"
   1.200 +#endif
   1.201 +		);
   1.202 +	}
   1.203 +
   1.204 +	status += TestTypes(verbose);
   1.205 +	status += TestEndian(verbose);
   1.206 +	status += TestCPUInfo(verbose);
   1.207 +	return status;
   1.208 +}