test/testautomation_pixels.c
changeset 7142 f4a670e51cde
parent 7134 09ee216e6a25
child 7151 99a4964db4c3
     1.1 --- a/test/testautomation_pixels.c	Sat May 04 04:46:00 2013 -0700
     1.2 +++ b/test/testautomation_pixels.c	Sat May 04 09:11:18 2013 -0700
     1.3 @@ -101,6 +101,9 @@
     1.4  
     1.5  /**
     1.6   * @brief Call to SDL_AllocFormat and SDL_FreeFormat
     1.7 + *
     1.8 + * @sa http://wiki.libsdl.org/moin.fcg/SDL_AllocFormat
     1.9 + * @sa http://wiki.libsdl.org/moin.fcg/SDL_FreeFormat 
    1.10   */
    1.11  int
    1.12  pixels_allocFreeFormat(void *arg)
    1.13 @@ -145,18 +148,100 @@
    1.14      SDLTest_AssertCheck(result == NULL, "Verify result is NULL");  
    1.15    }
    1.16    
    1.17 +  /* Negative cases */
    1.18 +  format = 0xffffffff;
    1.19 +  result = SDL_AllocFormat(format);
    1.20 +  SDLTest_AssertPass("Call to SDL_AllocFormat(0xffffffff)");
    1.21 +  SDLTest_AssertCheck(result == NULL, "Verify result is NULL");  
    1.22 +  /* TODO: check error code */
    1.23 +
    1.24 +  SDL_FreeFormat(NULL);
    1.25 +  SDLTest_AssertPass("Call to SDL_FreeFormat(NULL)");
    1.26 +  /* TODO: check error code */
    1.27 +  
    1.28 +  return TEST_COMPLETED;
    1.29 +}
    1.30 +
    1.31 +/**
    1.32 + * @brief Call to SDL_AllocPalette and SDL_FreePalette
    1.33 + *
    1.34 + * @sa http://wiki.libsdl.org/moin.fcg/SDL_AllocPalette
    1.35 + * @sa http://wiki.libsdl.org/moin.fcg/SDL_FreePalette
    1.36 + */
    1.37 +int
    1.38 +pixels_allocFreePalette(void *arg)
    1.39 +{
    1.40 +  int variation;
    1.41 +  int i;
    1.42 +  int ncolors;
    1.43 +  SDL_Palette* result;
    1.44 +
    1.45 +  /* Allocate palette */
    1.46 +  for (variation = 1; variation <= 3; variation++) {  
    1.47 +    switch (variation) {
    1.48 +      /* Just one color */
    1.49 +      case 1:
    1.50 +        ncolors = 1;
    1.51 +        break;
    1.52 +      /* Two colors */
    1.53 +      case 2:
    1.54 +        ncolors = 2;
    1.55 +        break;
    1.56 +      /* More than two colors */
    1.57 +      case 3:
    1.58 +        ncolors = SDLTest_RandomIntegerInRange(8, 16);
    1.59 +        break;
    1.60 +    }
    1.61 +
    1.62 +    result = SDL_AllocPalette(ncolors);
    1.63 +    SDLTest_AssertPass("Call to SDL_AllocPalette(%d)", ncolors);
    1.64 +    SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");  
    1.65 +    if (result != NULL) {
    1.66 +      SDLTest_AssertCheck(result->ncolors == ncolors, "Verify value of result.ncolors; expected: %u, got %u", ncolors, result->ncolors);  
    1.67 +      if (result->ncolors > 0) {
    1.68 +        SDLTest_AssertCheck(result->colors != NULL, "Verify value of result.colors is not NULL");
    1.69 +        if (result->colors != NULL) {
    1.70 +          for(i = 0; i < result->ncolors; i++) {
    1.71 +            SDLTest_AssertCheck(result->colors[i].r == 255, "Verify value of result.colors[%d].r; expected: 255, got %u", i, result->colors[i].r);  
    1.72 +            SDLTest_AssertCheck(result->colors[i].g == 255, "Verify value of result.colors[%d].g; expected: 255, got %u", i, result->colors[i].g);  
    1.73 +            SDLTest_AssertCheck(result->colors[i].b == 255, "Verify value of result.colors[%d].b; expected: 255, got %u", i, result->colors[i].b);  
    1.74 +           }
    1.75 +         } 
    1.76 +      }
    1.77 +      
    1.78 +      /* Deallocate again */
    1.79 +      SDL_FreePalette(result);
    1.80 +      SDLTest_AssertPass("Call to SDL_FreePalette()");          
    1.81 +    }
    1.82 +  }
    1.83 +
    1.84 +  /* Negative cases */
    1.85 +  for (ncolors = 0; ncolors > -3; ncolors--) {
    1.86 +    result = SDL_AllocPalette(ncolors);
    1.87 +    SDLTest_AssertPass("Call to SDL_AllocPalette(%d)", ncolors);
    1.88 +    SDLTest_AssertCheck(result == NULL, "Verify result is NULL");
    1.89 +    /* TODO: check error code */
    1.90 +  }
    1.91 +
    1.92 +  SDL_FreePalette(NULL);
    1.93 +  SDLTest_AssertPass("Call to SDL_FreePalette(NULL)");
    1.94 +  /* TODO: check error code */
    1.95 +    
    1.96    return TEST_COMPLETED;
    1.97  }
    1.98  
    1.99  /* ================= Test References ================== */
   1.100  
   1.101 -/* SysWM test cases */
   1.102 +/* Pixels test cases */
   1.103  static const SDLTest_TestCaseReference pixelsTest1 =
   1.104  		{ (SDLTest_TestCaseFp)pixels_allocFreeFormat, "pixels_allocFreeFormat", "Call to SDL_AllocFormat and SDL_FreeFormat", TEST_ENABLED };
   1.105  
   1.106 +static const SDLTest_TestCaseReference pixelsTest2 =
   1.107 +		{ (SDLTest_TestCaseFp)pixels_allocFreePalette, "pixels_allocFreePalette", "Call to SDL_AllocPalette and SDL_FreePalette", TEST_ENABLED };
   1.108 +
   1.109  /* Sequence of Pixels test cases */
   1.110  static const SDLTest_TestCaseReference *pixelsTests[] =  {
   1.111 -	&pixelsTest1, NULL
   1.112 +	&pixelsTest1, &pixelsTest2, NULL
   1.113  };
   1.114  
   1.115  /* Pixels test suite (global) */