Merging two heads.
authorMarkus Kauppila
Sun, 17 Jul 2011 19:19:35 +0300
changeset 5765f4ed7142727a
parent 5764 5cf913feab69
parent 5763 7e74c43ecda2
child 5766 8cc2ae74cd83
Merging two heads.
     1.1 --- a/test/test-automation/testplatform/testplatform.c	Sun Jul 17 11:17:40 2011 +0300
     1.2 +++ b/test/test-automation/testplatform/testplatform.c	Sun Jul 17 19:19:35 2011 +0300
     1.3 @@ -1,5 +1,6 @@
     1.4  /**
     1.5   * Original code: automated SDL platform test written by Edgar Simo "bobbens"
     1.6 + * Extended and updated by aschiffler at ferzkopp dot net
     1.7   */
     1.8  
     1.9  #include <stdio.h>
    1.10 @@ -10,20 +11,38 @@
    1.11  
    1.12  /* Test cases */
    1.13  static const TestCaseReference test1 =
    1.14 -		(TestCaseReference){ "platform_testTypes", "description", TEST_ENABLED, 0, 0 };
    1.15 +		(TestCaseReference){ "platform_testTypes", "Tests predefined types", TEST_ENABLED, 0, 0 };
    1.16  
    1.17  static const TestCaseReference test2 =
    1.18 -		(TestCaseReference){ "platform_testEndianessAndSwap", "description", TEST_ENABLED, 0, 0 };
    1.19 +		(TestCaseReference){ "platform_testEndianessAndSwap", "Tests endianess and swap functions", TEST_ENABLED, 0, 0 };
    1.20  
    1.21  static const TestCaseReference test3 =
    1.22 -		(TestCaseReference){ "platform_testGetFunctions", "description", TEST_ENABLED, 0, 0 };
    1.23 +		(TestCaseReference){ "platform_testGetFunctions", "Tests various SDL_GetXYZ functions", TEST_ENABLED, 0, 0 };
    1.24  
    1.25  static const TestCaseReference test4 =
    1.26 -		(TestCaseReference){ "platform_testHasFunctions", "description", TEST_ENABLED, 0, 0 };
    1.27 +		(TestCaseReference){ "platform_testHasFunctions", "Tests various SDL_HasXYZ functions", TEST_ENABLED, 0, 0 };
    1.28 +
    1.29 +static const TestCaseReference test5 =
    1.30 +		(TestCaseReference){ "platform_testGetVersion", "Tests SDL_GetVersion function", TEST_ENABLED, 0, 0 };
    1.31 +
    1.32 +static const TestCaseReference test6 =
    1.33 +		(TestCaseReference){ "platform_testSDLVersion", "Tests SDL_VERSION macro", TEST_ENABLED, 0, 0 };
    1.34 +
    1.35 +static const TestCaseReference test7 =
    1.36 +		(TestCaseReference){ "platform_testDefaultInit", "Tests default SDL_Init", TEST_ENABLED, 0, 0 };
    1.37 +
    1.38 +static const TestCaseReference test8 =
    1.39 +		(TestCaseReference){ "platform_testGetSetClearError", "Tests SDL_Get/Set/ClearError", TEST_ENABLED, 0, 0 };
    1.40 +
    1.41 +static const TestCaseReference test9 =
    1.42 +		(TestCaseReference){ "platform_testSetErrorEmptyInput", "Tests SDL_SetError with empty input", TEST_ENABLED, 0, 0 };
    1.43 +
    1.44 +static const TestCaseReference test10 =
    1.45 +		(TestCaseReference){ "platform_testSetErrorInvalidInput", "Tests SDL_SetError with invalid input", TEST_ENABLED, 0, 0 };
    1.46  
    1.47  /* Test suite */
    1.48  extern const TestCaseReference *testSuite[] =  {
    1.49 -	&test1, &test2, &test3, &test4, NULL
    1.50 +	&test1, &test2, &test3, &test4, &test5, &test6, &test7, &test8, &test9, &test10, NULL
    1.51  };
    1.52  
    1.53  TestCaseReference **QueryTestSuite() {
    1.54 @@ -50,16 +69,16 @@
    1.55     int ret;
    1.56  
    1.57     ret = _compareSizeOfType( sizeof(Uint8), 1 );
    1.58 -   AssertTrue( ret == 0, "sizeof(Uint8) = %lu instead of 1", sizeof(Uint8) );
    1.59 +   AssertTrue( ret == 0, "sizeof(Uint8) = %lu, expected  1", sizeof(Uint8) );
    1.60  
    1.61     ret = _compareSizeOfType( sizeof(Uint16), 2 );
    1.62 -   AssertTrue( ret == 0, "sizeof(Uint16) = %lu instead of 2", sizeof(Uint16) );
    1.63 +   AssertTrue( ret == 0, "sizeof(Uint16) = %lu, expected 2", sizeof(Uint16) );
    1.64  
    1.65     ret = _compareSizeOfType( sizeof(Uint32), 4 );
    1.66 -   AssertTrue( ret == 0, "sizeof(Uint32) = %lu instead of 4", sizeof(Uint32) );
    1.67 +   AssertTrue( ret == 0, "sizeof(Uint32) = %lu, expected 4", sizeof(Uint32) );
    1.68  
    1.69     ret = _compareSizeOfType( sizeof(Uint64), 8 );
    1.70 -   AssertTrue( ret == 0, "sizeof(Uint64) = %lu instead of 8", sizeof(Uint64) );
    1.71 +   AssertTrue( ret == 0, "sizeof(Uint64) = %lu, expected 8", sizeof(Uint64) );
    1.72  }
    1.73  
    1.74  /**
    1.75 @@ -90,42 +109,62 @@
    1.76  
    1.77      /* Test endianness. */    
    1.78      AssertTrue( real_byteorder == SDL_BYTEORDER,
    1.79 -             "Machine detected as %s endian but appears to be %s endian.",
    1.80 +             "Machine detected as %s endian, appears to be %s endian.",
    1.81               (SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big",
    1.82               (real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big" );
    1.83  
    1.84      /* Test 16 swap. */
    1.85      AssertTrue( SDL_Swap16(value16) == swapped16,
    1.86 -             "SDL_Swap16(): 16 bit swapped incorrectly: 0x%X => 0x%X",
    1.87 +             "SDL_Swap16(): 16 bit swapped: 0x%X => 0x%X",
    1.88               value16, SDL_Swap16(value16) );
    1.89  
    1.90      /* Test 32 swap. */
    1.91      AssertTrue( SDL_Swap32(value32) == swapped32,
    1.92 -             "SDL_Swap32(): 32 bit swapped incorrectly: 0x%X => 0x%X",
    1.93 +             "SDL_Swap32(): 32 bit swapped: 0x%X => 0x%X",
    1.94               value32, SDL_Swap32(value32) );
    1.95  
    1.96      /* Test 64 swap. */
    1.97      AssertTrue( SDL_Swap64(value64) == swapped64,
    1.98  #ifdef _MSC_VER
    1.99 -             "SDL_Swap64(): 64 bit swapped incorrectly: 0x%I64X => 0x%I64X",
   1.100 +             "SDL_Swap64(): 64 bit swapped: 0x%I64X => 0x%I64X",
   1.101  #else
   1.102 -             "SDL_Swap64(): 64 bit swapped incorrectly: 0x%llX => 0x%llX",
   1.103 +             "SDL_Swap64(): 64 bit swapped: 0x%llX => 0x%llX",
   1.104  #endif
   1.105               value64, SDL_Swap64(value64) );
   1.106  }
   1.107  
   1.108  /*!
   1.109   * \brief Tests SDL_GetXYZ() functions
   1.110 + * \sa
   1.111 + * http://wiki.libsdl.org/moin.cgi/SDL_GetPlatform
   1.112   */
   1.113  int platform_testGetFunctions (void *arg)
   1.114  {
   1.115 +   char *platform;
   1.116 +   char *revision;
   1.117     int ret;
   1.118 +   int len;
   1.119   
   1.120 -   ret = SDL_GetPlatform();
   1.121 +   platform = (char *)SDL_GetPlatform();
   1.122     AssertPass("SDL_GetPlatform()");
   1.123 - 
   1.124 +   AssertTrue(platform != NULL, "SDL_GetPlatform() != NULL");
   1.125 +   if (platform != NULL) {
   1.126 +     len = strlen(platform);
   1.127 +     AssertTrue(len > 0, 
   1.128 +             "SDL_GetPlatform(): expected non-empty platform, was platform: '%s', len: %i", 
   1.129 +             platform, 
   1.130 +             len);
   1.131 +   }
   1.132 +    
   1.133     ret = SDL_GetCPUCount();
   1.134     AssertPass("SDL_GetCPUCount()");
   1.135 +
   1.136 +   revision = (char *)SDL_GetRevision();
   1.137 +   AssertPass("SDL_GetRevision()");
   1.138 +   AssertTrue(revision != NULL, "SDL_GetRevision() != NULL");
   1.139 +
   1.140 +   ret = SDL_GetRevisionNumber();
   1.141 +   AssertPass("SDL_GetRevisionNumber()");
   1.142  }
   1.143  
   1.144  /*!
   1.145 @@ -164,3 +203,163 @@
   1.146     ret = SDL_HasSSE42();
   1.147     AssertPass("SDL_HasSSE42()");
   1.148  }
   1.149 +
   1.150 +/*!
   1.151 + * \brief Tests SDL_GetVersion
   1.152 + */
   1.153 +int platform_testGetVersion(void *arg)
   1.154 +{
   1.155 +   SDL_version linked;
   1.156 +   
   1.157 +   SDL_GetVersion(&linked);
   1.158 +   AssertTrue( linked.major >= SDL_MAJOR_VERSION,
   1.159 +             "SDL_GetVersion(): returned major %i (>= %i)",
   1.160 +             linked.major,
   1.161 +             SDL_MAJOR_VERSION);   
   1.162 +   AssertTrue( linked.minor >= SDL_MINOR_VERSION,
   1.163 +             "SDL_GetVersion(): returned minor %i (>= %i)",
   1.164 +             linked.minor,
   1.165 +             SDL_MINOR_VERSION);   
   1.166 +}
   1.167 +
   1.168 +/*!
   1.169 + * \brief Tests SDL_VERSION macro
   1.170 + */
   1.171 +int platform_testSDLVersion(void *arg)
   1.172 +{
   1.173 +   SDL_version compiled;
   1.174 +   
   1.175 +   SDL_VERSION(&compiled);
   1.176 +   AssertTrue( compiled.major >= SDL_MAJOR_VERSION,
   1.177 +             "SDL_VERSION() returned major %i (>= %i)",
   1.178 +             compiled.major,
   1.179 +             SDL_MAJOR_VERSION);   
   1.180 +   AssertTrue( compiled.minor >= SDL_MINOR_VERSION,
   1.181 +             "SDL_VERSION() returned minor %i (>= %i)",
   1.182 +             compiled.minor,
   1.183 +             SDL_MINOR_VERSION);   
   1.184 +}
   1.185 +
   1.186 +/*!
   1.187 + * \brief Tests default SDL_Init
   1.188 + */
   1.189 +int platform_testDefaultInit(void *arg)
   1.190 +{
   1.191 +   int ret;
   1.192 +   int subsystem;
   1.193 +   
   1.194 +   ret = SDL_Init(0);   
   1.195 +   AssertTrue( ret == 0, 
   1.196 +             "SDL_Init(0): returned %i, expected 0, error: %s",
   1.197 +             ret,
   1.198 +             SDL_GetError());
   1.199 +             
   1.200 +   subsystem = SDL_WasInit(0);
   1.201 +   AssertTrue( subsystem == 0, 
   1.202 +             "SDL_WasInit(0): returned %i, expected 0",
   1.203 +             ret);   
   1.204 +             
   1.205 +   SDL_Quit();
   1.206 +}
   1.207 +
   1.208 +/*!
   1.209 + * \brief Tests SDL_Get/Set/ClearError
   1.210 + * \sa 
   1.211 + * http://wiki.libsdl.org/moin.cgi/SDL_GetError
   1.212 + * http://wiki.libsdl.org/moin.cgi/SDL_SetError
   1.213 + * http://wiki.libsdl.org/moin.cgi/SDL_ClearError
   1.214 + */
   1.215 +int platform_testGetSetClearError(void *arg)
   1.216 +{
   1.217 +   const char *testError = "Testing";
   1.218 +   char *lastError;
   1.219 +   int len;
   1.220 +   
   1.221 +   SDL_ClearError();
   1.222 +   AssertPass("SDL_ClearError()");
   1.223 +   
   1.224 +   lastError = (char *)SDL_GetError();   
   1.225 +   AssertPass("SDL_GetError()");
   1.226 +   AssertTrue(lastError != NULL, 
   1.227 +             "SDL_GetError() != NULL");
   1.228 +   if (lastError != NULL)
   1.229 +   {
   1.230 +     len = strlen(lastError);
   1.231 +     AssertTrue(len == 0, 
   1.232 +             "SDL_GetError(): no message expected, len: %i", len);
   1.233 +   }
   1.234 +   
   1.235 +   SDL_SetError("%s", testError);
   1.236 +   AssertPass("SDL_SetError()");
   1.237 +   lastError = (char *)SDL_GetError();   
   1.238 +   AssertTrue(lastError != NULL, 
   1.239 +             "SDL_GetError() != NULL");
   1.240 +   if (lastError != NULL)
   1.241 +   {
   1.242 +     len = strlen(lastError);
   1.243 +     AssertTrue(len == strlen(testError), 
   1.244 +             "SDL_GetError(): expected message len %i, was len: %i", 
   1.245 +             strlen(testError), 
   1.246 +             len);
   1.247 +     AssertTrue(strcmp(lastError, testError) == 0, 
   1.248 +             "SDL_GetError(): expected message %s, was message: %s", 
   1.249 +             testError, 
   1.250 +             lastError);
   1.251 +   }
   1.252 +
   1.253 +   // Clean up                
   1.254 +   SDL_ClearError();
   1.255 +}
   1.256 +
   1.257 +/*!
   1.258 + * \brief Tests SDL_SetError with empty input
   1.259 + * \sa
   1.260 + * http://wiki.libsdl.org/moin.cgi/SDL_SetError
   1.261 + */
   1.262 +int platform_testSetErrorEmptyInput(void *arg)
   1.263 +{
   1.264 +   const char *testError = "";
   1.265 +   char *lastError;
   1.266 +   int len;
   1.267 +   
   1.268 +   SDL_SetError("%s", testError);
   1.269 +   AssertPass("SDL_SetError()");
   1.270 +   lastError = (char *)SDL_GetError();   
   1.271 +   AssertTrue(lastError != NULL, 
   1.272 +             "SDL_GetError() != NULL");
   1.273 +   if (lastError != NULL)
   1.274 +   {
   1.275 +     len = strlen(lastError);
   1.276 +     AssertTrue(len == strlen(testError), 
   1.277 +             "SDL_GetError(): expected message len %i, was len: %i", 
   1.278 +             strlen(testError), 
   1.279 +             len);
   1.280 +     AssertTrue(strcmp(lastError, testError) == 0, 
   1.281 +             "SDL_GetError(): expected message '%s', was message: '%s'", 
   1.282 +             testError, 
   1.283 +             lastError);
   1.284 +   }
   1.285 +
   1.286 +   // Clean up                
   1.287 +   SDL_ClearError();
   1.288 +}
   1.289 +
   1.290 +/*!
   1.291 + * \brief Tests SDL_SetError with invalid input
   1.292 + * \sa 
   1.293 + * http://wiki.libsdl.org/moin.cgi/SDL_SetError
   1.294 + */
   1.295 +int platform_testSetErrorInvalidInput(void *arg)
   1.296 +{
   1.297 +   const char *testError = NULL;
   1.298 +   char *lastError;
   1.299 +   
   1.300 +   SDL_SetError(testError);
   1.301 +   AssertPass("SDL_SetError()");
   1.302 +   lastError = (char *)SDL_GetError();   
   1.303 +   AssertTrue(lastError == NULL, 
   1.304 +             "SDL_GetError() == NULL");
   1.305 +
   1.306 +   // Clean up                
   1.307 +   SDL_ClearError();
   1.308 +}