From 1c27c5a4b947106c87ebda4caeb805802fd7cec8 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 23 Feb 2004 08:03:14 +0000 Subject: [PATCH] Added an endian detection and byte swapping test program --- test/Makefile.am | 3 ++- test/testendian.c | 25 +++++++++++++++++++++++++ test/testver.c | 3 --- 3 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 test/testendian.c diff --git a/test/Makefile.am b/test/Makefile.am index 6ac100e2e..01db22ade 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,7 +1,8 @@ AUTOMAKE_OPTIONS = no-dependencies noinst_PROGRAMS = \ - testver testtypes testcpuinfo testhread testlock testerror testsem testtimer \ + testver testtypes testendian testcpuinfo \ + testhread testlock testerror testsem testtimer \ loopwave testcdrom testkeys testvidinfo checkkeys testwin graywin \ testsprite testbitmap testalpha testgamma testpalette testwm \ threadwin testoverlay testoverlay2 testgl testdyngl testjoystick diff --git a/test/testendian.c b/test/testendian.c new file mode 100644 index 000000000..e8988af88 --- /dev/null +++ b/test/testendian.c @@ -0,0 +1,25 @@ + +/* Test program to check SDL's CPU endian detection and byte swapping routines */ + +#include + +#include "SDL.h" +#include "SDL_endian.h" + +int main(int argc, char *argv[]) +{ + Uint16 value16 = 0xCDAB; + Uint32 value32 = 0xEFBEADDE; +#if defined(__GNUC__) && defined(SDL_HAS_64BIT_TYPE) + Uint64 value64 = 0xEFBEADDECDAB3412LL; +#endif + + printf("This is a %s endian machine.\n", + (SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big"); + printf("Value 16 = 0x%X, swapped = 0x%X\n", value16, SDL_Swap16(value16)); + printf("Value 32 = 0x%X, swapped = 0x%X\n", value32, SDL_Swap32(value32)); +#if defined(__GNUC__) && defined(SDL_HAS_64BIT_TYPE) + printf("Value 64 = 0x%llX, swapped = 0x%llX\n", value64, SDL_Swap64(value64)); +#endif + return(0); +} diff --git a/test/testver.c b/test/testver.c index 174f14ba0..4155a0941 100644 --- a/test/testver.c +++ b/test/testver.c @@ -6,7 +6,6 @@ #include #include "SDL.h" -#include "SDL_byteorder.h" int main(int argc, char *argv[]) { @@ -32,8 +31,6 @@ int main(int argc, char *argv[]) SDL_Linked_Version()->major, SDL_Linked_Version()->minor, SDL_Linked_Version()->patch); - printf("This is a %s endian machine.\n", - (SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big"); SDL_Quit(); return(0); }