Add surface test suite; minor improvements to render suite; refactor image saving into test lib compare function; fix for Haiku build
2 Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
16 #include "SDL_endian.h"
17 #include "SDL_cpuinfo.h"
18 #include "SDL_assert.h"
21 * Watcom C flags these as Warning 201: "Unreachable code" if you just
22 * compare them directly, so we push it through a function to keep the
23 * compiler quiet. --ryan.
26 badsize(size_t sizeoftype, size_t hardcodetype)
28 return sizeoftype != hardcodetype;
32 TestTypes(SDL_bool verbose)
36 if (badsize(sizeof(Uint8), 1)) {
38 printf("sizeof(Uint8) != 1, instead = %u\n",
39 (unsigned int)sizeof(Uint8));
42 if (badsize(sizeof(Uint16), 2)) {
44 printf("sizeof(Uint16) != 2, instead = %u\n",
45 (unsigned int)sizeof(Uint16));
48 if (badsize(sizeof(Uint32), 4)) {
50 printf("sizeof(Uint32) != 4, instead = %u\n",
51 (unsigned int)sizeof(Uint32));
54 if (badsize(sizeof(Uint64), 8)) {
56 printf("sizeof(Uint64) != 8, instead = %u\n",
57 (unsigned int)sizeof(Uint64));
60 if (verbose && !error)
61 printf("All data types are the expected size.\n");
63 return (error ? 1 : 0);
67 TestEndian(SDL_bool verbose)
70 Uint16 value = 0x1234;
72 Uint16 value16 = 0xCDAB;
73 Uint16 swapped16 = 0xABCD;
74 Uint32 value32 = 0xEFBEADDE;
75 Uint32 swapped32 = 0xDEADBEEF;
76 Uint64 value64, swapped64;
80 value64 |= 0xCDAB3412;
81 swapped64 = 0x1234ABCD;
83 swapped64 |= 0xDEADBEEF;
86 printf("Detected a %s endian machine.\n",
87 (SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big");
89 if ((*((char *) &value) >> 4) == 0x1) {
90 real_byteorder = SDL_BIG_ENDIAN;
92 real_byteorder = SDL_LIL_ENDIAN;
94 if (real_byteorder != SDL_BYTEORDER) {
96 printf("Actually a %s endian machine!\n",
97 (real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big");
102 printf("Value 16 = 0x%X, swapped = 0x%X\n", value16,
103 SDL_Swap16(value16));
105 if (SDL_Swap16(value16) != swapped16) {
107 printf("16 bit value swapped incorrectly!\n");
112 printf("Value 32 = 0x%X, swapped = 0x%X\n", value32,
113 SDL_Swap32(value32));
115 if (SDL_Swap32(value32) != swapped32) {
117 printf("32 bit value swapped incorrectly!\n");
123 printf("Value 64 = 0x%I64X, swapped = 0x%I64X\n", value64,
124 SDL_Swap64(value64));
126 printf("Value 64 = 0x%llX, swapped = 0x%llX\n",
127 (unsigned long long) value64,
128 (unsigned long long) SDL_Swap64(value64));
131 if (SDL_Swap64(value64) != swapped64) {
133 printf("64 bit value swapped incorrectly!\n");
137 return (error ? 1 : 0);
142 TestCPUInfo(SDL_bool verbose)
145 printf("CPU count: %d\n", SDL_GetCPUCount());
146 printf("CPU cache line size: %d\n", SDL_GetCPUCacheLineSize());
147 printf("RDTSC %s\n", SDL_HasRDTSC()? "detected" : "not detected");
148 printf("AltiVec %s\n", SDL_HasAltiVec()? "detected" : "not detected");
149 printf("MMX %s\n", SDL_HasMMX()? "detected" : "not detected");
150 printf("3DNow! %s\n", SDL_Has3DNow()? "detected" : "not detected");
151 printf("SSE %s\n", SDL_HasSSE()? "detected" : "not detected");
152 printf("SSE2 %s\n", SDL_HasSSE2()? "detected" : "not detected");
153 printf("SSE3 %s\n", SDL_HasSSE3()? "detected" : "not detected");
154 printf("SSE4.1 %s\n", SDL_HasSSE41()? "detected" : "not detected");
155 printf("SSE4.2 %s\n", SDL_HasSSE42()? "detected" : "not detected");
161 TestAssertions(SDL_bool verbose)
164 SDL_assert_release(1);
165 SDL_assert_paranoid(1);
167 SDL_assert_release(0 || 1);
168 SDL_assert_paranoid(0 || 1);
170 #if 0 /* enable this to test assertion failures. */
171 SDL_assert_release(1 == 2);
172 SDL_assert_release(5 < 4);
173 SDL_assert_release(0 && "This is a test");
177 const SDL_assert_data *item = SDL_GetAssertionReport();
179 printf("'%s', %s (%s:%d), triggered %u times, always ignore: %s.\n",
180 item->condition, item->function, item->filename,
181 item->linenum, item->trigger_count,
182 item->always_ignore ? "yes" : "no");
190 main(int argc, char *argv[])
192 SDL_bool verbose = SDL_TRUE;
195 if (argv[1] && (SDL_strcmp(argv[1], "-q") == 0)) {
199 printf("This system is running %s\n", SDL_GetPlatform());
202 status += TestTypes(verbose);
203 status += TestEndian(verbose);
204 status += TestCPUInfo(verbose);
205 status += TestAssertions(verbose);