/** * Original code: automated SDL platform test written by Edgar Simo "bobbens" * Extended and extensively updated by aschiffler at ferzkopp dot net */ #include #include /* ================= Test Case Implementation ================== */ #define TESTRENDER_SCREEN_W 80 #define TESTRENDER_SCREEN_H 60 #define RENDER_COMPARE_FORMAT SDL_PIXELFORMAT_ARGB8888 #define RENDER_COMPARE_AMASK 0xff000000 /**< Alpha bit mask. */ #define RENDER_COMPARE_RMASK 0x00ff0000 /**< Red bit mask. */ #define RENDER_COMPARE_GMASK 0x0000ff00 /**< Green bit mask. */ #define RENDER_COMPARE_BMASK 0x000000ff /**< Blue bit mask. */ #define ALLOWABLE_ERROR_OPAQUE 0 #define ALLOWABLE_ERROR_BLENDED 64 /* Test window and renderer */ SDL_Window *window = NULL; SDL_Renderer *renderer = NULL; /* Prototypes for helper functions */ static int _clearScreen (void); static void _compare(SDL_Surface *reference, int allowable_error); static int _hasTexAlpha(void); static int _hasTexColor(void); static SDL_Texture *_loadTestFace(void); static int _hasBlendModes(void); static int _hasDrawColor(void); static int _isSupported(int code); /** * Create software renderer for tests */ void InitCreateRenderer(void *arg) { int posX = 100, posY = 100, width = 320, height = 240; renderer = NULL; window = SDL_CreateWindow("render_testCreateRenderer", posX, posY, width, height, 0); SDLTest_AssertPass("SDL_CreateWindow()"); SDLTest_AssertCheck(window != NULL, "Check SDL_CreateWindow result"); if (window == NULL) { return; } renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); SDLTest_AssertPass("SDL_CreateRenderer()"); SDLTest_AssertCheck(renderer != NULL, "Check SDL_CreateRenderer result"); if (renderer == NULL) { SDL_DestroyWindow(window); return; } } /* * Destroy renderer for tests */ void CleanupDestroyRenderer(void *arg) { if (renderer != NULL) { SDL_DestroyRenderer(renderer); renderer = NULL; SDLTest_AssertPass("SDL_DestroyRenderer()"); } if (window != NULL) { SDL_DestroyWindow(window); window = NULL; SDLTest_AssertPass("SDL_DestroyWindow"); } } /** * @brief Tests call to SDL_GetNumRenderDrivers * * \sa * http://wiki.libsdl.org/SDL_GetNumRenderDrivers */ int render_testGetNumRenderDrivers(void *arg) { int n; n = SDL_GetNumRenderDrivers(); SDLTest_AssertCheck(n >= 1, "Number of renderers >= 1, reported as %i", n); return TEST_COMPLETED; } /** * @brief Tests the SDL primitives for rendering. * * \sa * http://wiki.libsdl.org/SDL_SetRenderDrawColor * http://wiki.libsdl.org/SDL_RenderFillRect * http://wiki.libsdl.org/SDL_RenderDrawLine * */ int render_testPrimitives (void *arg) { int ret; int x, y; SDL_Rect rect; SDL_Surface *referenceSurface = NULL; int checkFailCount1; int checkFailCount2; /* Clear surface. */ _clearScreen(); /* Need drawcolor or just skip test. */ SDLTest_AssertCheck(_hasDrawColor(), "_hasDrawColor"); /* Draw a rectangle. */ rect.x = 40; rect.y = 0; rect.w = 40; rect.h = 80; ret = SDL_SetRenderDrawColor(renderer, 13, 73, 200, SDL_ALPHA_OPAQUE ); SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawColor, expected: 0, got: %i", ret); ret = SDL_RenderFillRect(renderer, &rect ); SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderFillRect, expected: 0, got: %i", ret); /* Draw a rectangle. */ rect.x = 10; rect.y = 10; rect.w = 60; rect.h = 40; ret = SDL_SetRenderDrawColor(renderer, 200, 0, 100, SDL_ALPHA_OPAQUE ); SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawColor, expected: 0, got: %i", ret); ret = SDL_RenderFillRect(renderer, &rect ); SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderFillRect, expected: 0, got: %i", ret); /* Draw some points like so: * X.X.X.X.. * .X.X.X.X. * X.X.X.X.. */ checkFailCount1 = 0; checkFailCount2 = 0; for (y=0; y<3; y++) { for (x = y % 2; x