test/testendian.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 21 Feb 2006 09:11:53 +0000
changeset 1405 983df4f9c1c6
parent 850 c203b4a42701
permissions -rw-r--r--
Added a test case
slouken@850
     1
slouken@850
     2
/* Test program to check SDL's CPU endian detection and byte swapping routines */
slouken@850
     3
slouken@850
     4
#include <stdio.h>
slouken@850
     5
slouken@850
     6
#include "SDL.h"
slouken@850
     7
#include "SDL_endian.h"
slouken@850
     8
slouken@850
     9
int main(int argc, char *argv[])
slouken@850
    10
{
slouken@850
    11
	Uint16 value16 = 0xCDAB;
slouken@850
    12
	Uint32 value32 = 0xEFBEADDE;
slouken@850
    13
#if defined(__GNUC__) && defined(SDL_HAS_64BIT_TYPE)
slouken@850
    14
	Uint64 value64 = 0xEFBEADDECDAB3412LL;
slouken@850
    15
#endif
slouken@850
    16
slouken@1405
    17
	printf("This system is running %s\n",
slouken@1405
    18
#if __AIX__
slouken@1405
    19
			"AIX"
slouken@1405
    20
#elif __AMIGA__
slouken@1405
    21
			"AmigaOS"
slouken@1405
    22
#elif __BEOS__
slouken@1405
    23
			"BeOS"
slouken@1405
    24
#elif __BSDI__
slouken@1405
    25
			"BSDI"
slouken@1405
    26
#elif __DREAMCAST__
slouken@1405
    27
			"Dreamcast"
slouken@1405
    28
#elif __FREEBSD__
slouken@1405
    29
			"FreeBSD"
slouken@1405
    30
#elif __HPUX__
slouken@1405
    31
			"HP-UX"
slouken@1405
    32
#elif __IRIX__
slouken@1405
    33
			"Irix"
slouken@1405
    34
#elif __LINUX__
slouken@1405
    35
			"Linux"
slouken@1405
    36
#elif __MACOS__
slouken@1405
    37
			"MacOS Classic"
slouken@1405
    38
#elif __MACOSX__
slouken@1405
    39
			"MacOS X"
slouken@1405
    40
#elif __NETBSD__
slouken@1405
    41
			"NetBSD"
slouken@1405
    42
#elif __OPENBSD__
slouken@1405
    43
			"OpenBSD"
slouken@1405
    44
#elif __OS2__
slouken@1405
    45
			"OS/2"
slouken@1405
    46
#elif __OSF__
slouken@1405
    47
			"OSF/1"
slouken@1405
    48
#elif __QNXNTO__
slouken@1405
    49
			"QNX Neutrino"
slouken@1405
    50
#elif __RISCOS__
slouken@1405
    51
			"RISC OS"
slouken@1405
    52
#elif __SOLARIS__
slouken@1405
    53
			"Solaris"
slouken@1405
    54
#elif __WIN32__
slouken@1405
    55
#ifdef _WIN32_WCE
slouken@1405
    56
			"Windows CE"
slouken@1405
    57
#else
slouken@1405
    58
			"Windows"
slouken@1405
    59
#endif
slouken@1405
    60
#else
slouken@1405
    61
			"an unknown operating system!"
slouken@1405
    62
#endif
slouken@1405
    63
			);
slouken@1405
    64
slouken@850
    65
	printf("This is a %s endian machine.\n",
slouken@850
    66
		(SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big");
slouken@850
    67
	printf("Value 16 = 0x%X, swapped = 0x%X\n", value16, SDL_Swap16(value16));
slouken@850
    68
	printf("Value 32 = 0x%X, swapped = 0x%X\n", value32, SDL_Swap32(value32));
slouken@850
    69
#if defined(__GNUC__) && defined(SDL_HAS_64BIT_TYPE)
slouken@850
    70
	printf("Value 64 = 0x%llX, swapped = 0x%llX\n", value64, SDL_Swap64(value64));
slouken@850
    71
#endif
slouken@850
    72
	return(0);
slouken@850
    73
}