test/testplatform.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 13 Apr 2006 13:08:26 +0000
changeset 1621 f12379c41042
parent 1615 d5298e8f22b3
child 1662 782fd950bd46
child 1895 c121d94672cb
child 3888 6d2e1961661a
permissions -rw-r--r--
Fixes bug #195:
The proper name of Apple's operating system is "Mac OS X" not "MacOS X", as can
bee seen in many places, for example http://www.apple.com/macosx/). This
contrasts the naming of the old operating system, which was called "MacOS" and
today is often refered to as "MacOS Classic".

The attached patches fixes the misuse of the name "MacOS X" in both the SDL12
and sdlweb CVS modules.
slouken@1421
     1
slouken@1421
     2
#include <stdio.h>
slouken@1421
     3
slouken@1421
     4
#include "SDL.h"
slouken@1421
     5
#include "SDL_endian.h"
slouken@1421
     6
#include "SDL_cpuinfo.h"
slouken@1421
     7
slouken@1421
     8
/*
slouken@1421
     9
 * Watcom C flags these as Warning 201: "Unreachable code" if you just
slouken@1421
    10
 *  compare them directly, so we push it through a function to keep the
slouken@1421
    11
 *  compiler quiet.  --ryan.
slouken@1421
    12
 */
slouken@1421
    13
static int badsize(size_t sizeoftype, size_t hardcodetype)
slouken@1421
    14
{
slouken@1421
    15
    return sizeoftype != hardcodetype;
slouken@1421
    16
}
slouken@1421
    17
slouken@1421
    18
int TestTypes(SDL_bool verbose)
slouken@1421
    19
{
slouken@1421
    20
	int error = 0;
slouken@1421
    21
slouken@1421
    22
	if ( badsize(sizeof(Uint8), 1) ) {
slouken@1421
    23
		if ( verbose )
slouken@1615
    24
			printf("sizeof(Uint8) != 1, instead = %ul\n",
slouken@1421
    25
								sizeof(Uint8));
slouken@1421
    26
		++error;
slouken@1421
    27
	}
slouken@1421
    28
	if ( badsize(sizeof(Uint16), 2) ) {
slouken@1421
    29
		if ( verbose )
slouken@1615
    30
			printf("sizeof(Uint16) != 2, instead = %ul\n",
slouken@1421
    31
								sizeof(Uint16));
slouken@1421
    32
		++error;
slouken@1421
    33
	}
slouken@1421
    34
	if ( badsize(sizeof(Uint32), 4) ) {
slouken@1421
    35
		if ( verbose )
slouken@1615
    36
			printf("sizeof(Uint32) != 4, instead = %ul\n",
slouken@1421
    37
								sizeof(Uint32));
slouken@1421
    38
		++error;
slouken@1421
    39
	}
slouken@1421
    40
#ifdef SDL_HAS_64BIT_TYPE
slouken@1421
    41
	if ( badsize(sizeof(Uint64), 8) ) {
slouken@1421
    42
		if ( verbose )
slouken@1615
    43
			printf("sizeof(Uint64) != 8, instead = %ul\n",
slouken@1421
    44
								sizeof(Uint64));
slouken@1421
    45
		++error;
slouken@1421
    46
	}
slouken@1421
    47
#else
slouken@1421
    48
	if ( verbose ) {
slouken@1421
    49
		printf("WARNING: No 64-bit datatype on this platform\n");
slouken@1421
    50
	}
slouken@1421
    51
#endif
slouken@1421
    52
	if ( verbose && !error )
slouken@1421
    53
		printf("All data types are the expected size.\n");
slouken@1421
    54
slouken@1421
    55
	return( error ? 1 : 0 );
slouken@1421
    56
}
slouken@1421
    57
slouken@1421
    58
int TestEndian(SDL_bool verbose)
slouken@1421
    59
{
slouken@1421
    60
	int error = 0;
slouken@1421
    61
	Uint16 value = 0x1234;
slouken@1421
    62
	int real_byteorder;
slouken@1421
    63
	Uint16 value16 = 0xCDAB;
slouken@1421
    64
	Uint16 swapped16 = 0xABCD;
slouken@1421
    65
	Uint32 value32 = 0xEFBEADDE;
slouken@1421
    66
	Uint32 swapped32 = 0xDEADBEEF;
slouken@1421
    67
#ifdef SDL_HAS_64BIT_TYPE
slouken@1421
    68
	Uint64 value64, swapped64;
slouken@1421
    69
	value64 = 0xEFBEADDE;
slouken@1421
    70
	value64 <<= 32;
slouken@1421
    71
	value64 |= 0xCDAB3412;
slouken@1421
    72
	swapped64 = 0x1234ABCD;
slouken@1421
    73
	swapped64 <<= 32;
slouken@1421
    74
	swapped64 |= 0xDEADBEEF;
slouken@1421
    75
#endif
slouken@1421
    76
slouken@1421
    77
	if ( verbose ) {
slouken@1421
    78
		printf("Detected a %s endian machine.\n",
slouken@1421
    79
			(SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big");
slouken@1421
    80
	}
slouken@1424
    81
	if ( (*((char *)&value) >> 4) == 0x1 ) {
slouken@1421
    82
		real_byteorder = SDL_BIG_ENDIAN;
slouken@1421
    83
	} else {
slouken@1421
    84
		real_byteorder = SDL_LIL_ENDIAN;
slouken@1421
    85
	}
slouken@1421
    86
	if ( real_byteorder != SDL_BYTEORDER ) {
slouken@1421
    87
		if ( verbose ) {
slouken@1421
    88
			printf("Actually a %s endian machine!\n",
slouken@1421
    89
				(real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big");
slouken@1421
    90
		}
slouken@1421
    91
		++error;
slouken@1421
    92
	}
slouken@1421
    93
	if ( verbose ) {
slouken@1421
    94
		printf("Value 16 = 0x%X, swapped = 0x%X\n", value16, SDL_Swap16(value16));
slouken@1421
    95
	}
slouken@1421
    96
	if ( SDL_Swap16(value16) != swapped16 ) {
slouken@1421
    97
		if ( verbose ) {
slouken@1421
    98
			printf("16 bit value swapped incorrectly!\n");
slouken@1421
    99
		}
slouken@1421
   100
		++error;
slouken@1421
   101
	}
slouken@1421
   102
	if ( verbose ) {
slouken@1421
   103
		printf("Value 32 = 0x%X, swapped = 0x%X\n", value32, SDL_Swap32(value32));
slouken@1421
   104
	}
slouken@1421
   105
	if ( SDL_Swap32(value32) != swapped32 ) {
slouken@1421
   106
		if ( verbose ) {
slouken@1421
   107
			printf("32 bit value swapped incorrectly!\n");
slouken@1421
   108
		}
slouken@1421
   109
		++error;
slouken@1421
   110
	}
slouken@1421
   111
#ifdef SDL_HAS_64BIT_TYPE
slouken@1421
   112
	if ( verbose ) {
slouken@1615
   113
#ifdef _MSC_VER
slouken@1615
   114
		printf("Value 64 = 0x%I64X, swapped = 0x%I64X\n", value64, SDL_Swap64(value64));
slouken@1615
   115
#else
slouken@1421
   116
		printf("Value 64 = 0x%llX, swapped = 0x%llX\n", value64, SDL_Swap64(value64));
slouken@1615
   117
#endif
slouken@1421
   118
	}
slouken@1421
   119
	if ( SDL_Swap64(value64) != swapped64 ) {
slouken@1421
   120
		if ( verbose ) {
slouken@1421
   121
			printf("64 bit value swapped incorrectly!\n");
slouken@1421
   122
		}
slouken@1421
   123
		++error;
slouken@1421
   124
	}
slouken@1421
   125
#endif
slouken@1421
   126
	return( error ? 1 : 0 );
slouken@1421
   127
}
slouken@1421
   128
slouken@1421
   129
slouken@1421
   130
int TestCPUInfo(SDL_bool verbose)
slouken@1421
   131
{
slouken@1421
   132
	if ( verbose ) {
slouken@1421
   133
		printf("RDTSC %s\n", SDL_HasRDTSC() ? "detected" : "not detected");
slouken@1421
   134
		printf("MMX %s\n", SDL_HasMMX() ? "detected" : "not detected");
slouken@1421
   135
		printf("MMX Ext %s\n", SDL_HasMMXExt() ? "detected" : "not detected");
slouken@1421
   136
		printf("3DNow %s\n", SDL_Has3DNow() ? "detected" : "not detected");
slouken@1421
   137
		printf("3DNow Ext %s\n", SDL_Has3DNowExt() ? "detected" : "not detected");
slouken@1421
   138
		printf("SSE %s\n", SDL_HasSSE() ? "detected" : "not detected");
slouken@1421
   139
		printf("SSE2 %s\n", SDL_HasSSE2() ? "detected" : "not detected");
slouken@1421
   140
		printf("AltiVec %s\n", SDL_HasAltiVec() ? "detected" : "not detected");
slouken@1421
   141
	}
slouken@1421
   142
	return(0);
slouken@1421
   143
}
slouken@1421
   144
slouken@1421
   145
int main(int argc, char *argv[])
slouken@1421
   146
{
slouken@1421
   147
	SDL_bool verbose = SDL_TRUE;
slouken@1421
   148
	int status = 0;
slouken@1421
   149
slouken@1421
   150
	if ( argv[1] && (SDL_strcmp(argv[1], "-q") == 0) ) {
slouken@1421
   151
		verbose = SDL_FALSE;
slouken@1421
   152
	}
slouken@1421
   153
	if ( verbose ) {
slouken@1421
   154
		printf("This system is running %s\n",
slouken@1421
   155
#if __AIX__
slouken@1421
   156
			"AIX"
slouken@1421
   157
#elif __AMIGA__
slouken@1421
   158
			"AmigaOS"
slouken@1421
   159
#elif __BEOS__
slouken@1421
   160
			"BeOS"
slouken@1421
   161
#elif __BSDI__
slouken@1421
   162
			"BSDI"
slouken@1421
   163
#elif __DREAMCAST__
slouken@1421
   164
			"Dreamcast"
slouken@1421
   165
#elif __FREEBSD__
slouken@1421
   166
			"FreeBSD"
slouken@1421
   167
#elif __HPUX__
slouken@1421
   168
			"HP-UX"
slouken@1421
   169
#elif __IRIX__
slouken@1421
   170
			"Irix"
slouken@1421
   171
#elif __LINUX__
slouken@1421
   172
			"Linux"
slouken@1421
   173
#elif __MINT__
slouken@1421
   174
			"Atari MiNT"
slouken@1421
   175
#elif __MACOS__
slouken@1421
   176
			"MacOS Classic"
slouken@1421
   177
#elif __MACOSX__
slouken@1621
   178
			"Mac OS X"
slouken@1421
   179
#elif __NETBSD__
slouken@1421
   180
			"NetBSD"
slouken@1421
   181
#elif __OPENBSD__
slouken@1421
   182
			"OpenBSD"
slouken@1421
   183
#elif __OS2__
slouken@1421
   184
			"OS/2"
slouken@1421
   185
#elif __OSF__
slouken@1421
   186
			"OSF/1"
slouken@1421
   187
#elif __QNXNTO__
slouken@1421
   188
			"QNX Neutrino"
slouken@1421
   189
#elif __RISCOS__
slouken@1421
   190
			"RISC OS"
slouken@1421
   191
#elif __SOLARIS__
slouken@1421
   192
			"Solaris"
slouken@1421
   193
#elif __WIN32__
slouken@1421
   194
#ifdef _WIN32_WCE
slouken@1421
   195
			"Windows CE"
slouken@1421
   196
#else
slouken@1421
   197
			"Windows"
slouken@1421
   198
#endif
slouken@1421
   199
#else
slouken@1421
   200
			"an unknown operating system! (see SDL_platform.h)"
slouken@1421
   201
#endif
slouken@1421
   202
		);
slouken@1421
   203
	}
slouken@1421
   204
slouken@1421
   205
	status += TestTypes(verbose);
slouken@1421
   206
	status += TestEndian(verbose);
slouken@1421
   207
	status += TestCPUInfo(verbose);
slouken@1421
   208
	return status;
slouken@1421
   209
}