Add test coverage for SDL_SetWindowData and SDL_GetWindowData to Video suite
authorAndreas Schiffler <aschiffler@ferzkopp.net>
Sat, 13 Apr 2013 09:45:39 -0700
changeset 7062c0a739679bbd
parent 7061 45df4552bdfe
child 7063 bea100d73d13
Add test coverage for SDL_SetWindowData and SDL_GetWindowData to Video suite
test/testautomation_video.c
     1.1 --- a/test/testautomation_video.c	Wed Apr 10 22:18:10 2013 -0400
     1.2 +++ b/test/testautomation_video.c	Sat Apr 13 09:45:39 2013 -0700
     1.3 @@ -601,7 +601,7 @@
     1.4    const char *invalidWindowError = "Invalid window";
     1.5    char *lastError;
     1.6  
     1.7 - lastError = (char *)SDL_GetError();
     1.8 +  lastError = (char *)SDL_GetError();
     1.9    SDLTest_AssertPass("SDL_GetError()");
    1.10    SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL");
    1.11    if (lastError != NULL) {
    1.12 @@ -1486,6 +1486,223 @@
    1.13    return TEST_COMPLETED;
    1.14  }
    1.15  
    1.16 +
    1.17 +/**
    1.18 + * @brief Tests call to SDL_SetWindowData and SDL_GetWindowData
    1.19 + *
    1.20 + * @sa http://wiki.libsdl.org/moin.fcg/SDL_SetWindowData
    1.21 + * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowData
    1.22 + */
    1.23 +int
    1.24 +video_getSetWindowData(void *arg)
    1.25 +{
    1.26 +  int returnValue = TEST_COMPLETED;
    1.27 +  const char* title = "video_setGetWindowData Test Window";
    1.28 +  SDL_Window* window;
    1.29 +  const char *referenceName = "TestName";
    1.30 +  const char *name = "TestName";
    1.31 +  const char *referenceName2 = "TestName2";
    1.32 +  const char *name2 = "TestName2";
    1.33 +  int datasize;
    1.34 +  char *referenceUserdata;
    1.35 +  char *userdata;
    1.36 +  char *referenceUserdata2;
    1.37 +  char *userdata2;
    1.38 +  char *result;
    1.39 +  int iteration;
    1.40 +
    1.41 +  /* Call against new test window */ 
    1.42 +  window = _createVideoSuiteTestWindow(title);
    1.43 +  if (window == NULL) return TEST_ABORTED;
    1.44 +
    1.45 +  /* Create testdata */
    1.46 +  datasize = SDLTest_RandomIntegerInRange(1, 32); 
    1.47 +  referenceUserdata =  SDLTest_RandomAsciiStringOfSize(datasize);
    1.48 +  if (referenceUserdata == NULL) { 
    1.49 +  	returnValue = TEST_ABORTED; 
    1.50 +  	goto cleanup; 
    1.51 +  }
    1.52 +  userdata = (char *)strdup(referenceUserdata);
    1.53 +  if (userdata == NULL) {
    1.54 +  	returnValue = TEST_ABORTED; 
    1.55 +  	goto cleanup; 
    1.56 +  }
    1.57 +  datasize = SDLTest_RandomIntegerInRange(1, 32); 
    1.58 +  referenceUserdata2 =  SDLTest_RandomAsciiStringOfSize(datasize);
    1.59 +  if (referenceUserdata2 == NULL) { 
    1.60 +  	returnValue = TEST_ABORTED; 
    1.61 +  	goto cleanup; 
    1.62 +  }
    1.63 +  userdata2 = (char *)strdup(referenceUserdata2);
    1.64 +  if (userdata2 == NULL) {
    1.65 +  	returnValue = TEST_ABORTED;
    1.66 +  	goto cleanup;
    1.67 +  }
    1.68 + 
    1.69 +  /* Get non-existent data */
    1.70 +  result = (char *)SDL_GetWindowData(window, name);
    1.71 +  SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name);
    1.72 +  SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
    1.73 +  SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
    1.74 +  
    1.75 +  /* Set data */
    1.76 +  result = SDL_SetWindowData(window, name, userdata);
    1.77 +  SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s)", name, userdata);
    1.78 +  SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
    1.79 +  SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
    1.80 +  SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
    1.81 +  
    1.82 +  /* Get data (twice) */
    1.83 +  for (iteration = 1; iteration <= 2; iteration++) {
    1.84 +    result = (char *)SDL_GetWindowData(window, name);
    1.85 +    SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [iteration %d]", name, iteration);
    1.86 +    SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
    1.87 +    SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
    1.88 +  }
    1.89 +  
    1.90 +  /* Set data again twice */
    1.91 +  for (iteration = 1; iteration <= 2; iteration++) {
    1.92 +    result = SDL_SetWindowData(window, name, userdata);
    1.93 +    SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [iteration %d]", name, userdata, iteration);
    1.94 +    SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
    1.95 +    SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
    1.96 +    SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
    1.97 +  }
    1.98 +  
    1.99 +  /* Get data again */
   1.100 +  result = (char *)SDL_GetWindowData(window, name);
   1.101 +  SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [again]", name);
   1.102 +  SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
   1.103 +  SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
   1.104 +
   1.105 +  /* Set data with new data */
   1.106 +  result = SDL_SetWindowData(window, name, userdata2);
   1.107 +  SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [new userdata]", name, userdata2);
   1.108 +  SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
   1.109 +  SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
   1.110 +  SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
   1.111 +  SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
   1.112 +
   1.113 +  /* Set data with new data again */
   1.114 +  result = SDL_SetWindowData(window, name, userdata2);
   1.115 +  SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [new userdata again]", name, userdata2);
   1.116 +  SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result);
   1.117 +  SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
   1.118 +  SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
   1.119 +  SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
   1.120 +  
   1.121 +  /* Get new data */
   1.122 +  result = (char *)SDL_GetWindowData(window, name);
   1.123 +  SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name);
   1.124 +  SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result);
   1.125 +  SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
   1.126 +
   1.127 +  /* Set data with NULL to clear */
   1.128 +  result = SDL_SetWindowData(window, name, NULL);
   1.129 +  SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,NULL)", name, userdata);
   1.130 +  SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result);
   1.131 +  SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
   1.132 +  SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
   1.133 +  SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
   1.134 +
   1.135 +  /* Set data with NULL to clear again */
   1.136 +  result = SDL_SetWindowData(window, name, NULL);
   1.137 +  SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,NULL) [again]", name, userdata);
   1.138 +  SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
   1.139 +  SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
   1.140 +  SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
   1.141 +  SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
   1.142 +  
   1.143 +  /* Get non-existent data */
   1.144 +  result = (char *)SDL_GetWindowData(window, name);
   1.145 +  SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name);
   1.146 +  SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
   1.147 +  SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
   1.148 +
   1.149 +  /* Get non-existent data new name */
   1.150 +  result = (char *)SDL_GetWindowData(window, name2);
   1.151 +  SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name2);
   1.152 +  SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
   1.153 +  SDLTest_AssertCheck(SDL_strcmp(referenceName2, name2) == 0, "Validate that name2 was not changed, expected: %s, got: %s", referenceName2, name2);
   1.154 +
   1.155 +  /* Set data (again) */
   1.156 +  result = SDL_SetWindowData(window, name, userdata);
   1.157 +  SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [again, after clear]", name, userdata);
   1.158 +  SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
   1.159 +  SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
   1.160 +  SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
   1.161 +  
   1.162 +  /* Get data (again) */
   1.163 +  result = (char *)SDL_GetWindowData(window, name);
   1.164 +  SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [again, after clear]", name);
   1.165 +  SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
   1.166 +  SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
   1.167 +
   1.168 +  /* Negative test */
   1.169 +  SDL_ClearError();
   1.170 +  SDLTest_AssertPass("Call to SDL_ClearError()");
   1.171 +
   1.172 +  /* Set with invalid window */ 
   1.173 +  result = SDL_SetWindowData(NULL, name, userdata);
   1.174 +  SDLTest_AssertPass("Call to SDL_SetWindowData(window=NULL)");
   1.175 +  SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
   1.176 +  _checkInvalidWindowError();
   1.177 +  
   1.178 +  /* Set data with NULL name, valid userdata */
   1.179 +  result = SDL_SetWindowData(window, NULL, userdata);
   1.180 +  SDLTest_AssertPass("Call to SDL_SetWindowData(name=NULL)");
   1.181 +  SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
   1.182 +  _checkInvalidParameterError();
   1.183 +
   1.184 +  /* Set data with empty name, valid userdata */
   1.185 +  result = SDL_SetWindowData(window, "", userdata);
   1.186 +  SDLTest_AssertPass("Call to SDL_SetWindowData(name='')");
   1.187 +  SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
   1.188 +  _checkInvalidParameterError();
   1.189 +
   1.190 +  /* Set data with NULL name, NULL userdata */
   1.191 +  result = SDL_SetWindowData(window, NULL, NULL);
   1.192 +  SDLTest_AssertPass("Call to SDL_SetWindowData(name=NULL,userdata=NULL)");
   1.193 +  SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
   1.194 +  _checkInvalidParameterError();
   1.195 +
   1.196 +  /* Set data with empty name, NULL userdata */
   1.197 +  result = SDL_SetWindowData(window, "", NULL);
   1.198 +  SDLTest_AssertPass("Call to SDL_SetWindowData(name='',userdata=NULL)");
   1.199 +  SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
   1.200 +  _checkInvalidParameterError();
   1.201 +
   1.202 +  /* Get with invalid window */
   1.203 +  result = SDL_GetWindowData(NULL, name);
   1.204 +  SDLTest_AssertPass("Call to SDL_GetWindowData(window=NULL)");
   1.205 +  SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
   1.206 +  _checkInvalidWindowError();
   1.207 +  
   1.208 +  /* Get data with NULL name */
   1.209 +  result = SDL_GetWindowData(window, NULL);
   1.210 +  SDLTest_AssertPass("Call to SDL_GetWindowData(name=NULL)");
   1.211 +  SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
   1.212 +  _checkInvalidParameterError();
   1.213 +
   1.214 +  /* Get data with empty name */
   1.215 +  result = SDL_GetWindowData(window, "");
   1.216 +  SDLTest_AssertPass("Call to SDL_GetWindowData(name='')");
   1.217 +  SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
   1.218 +  _checkInvalidParameterError();
   1.219 +
   1.220 +  /* Clean up */
   1.221 +  _destroyVideoSuiteTestWindow(window);
   1.222 +         
   1.223 +  cleanup:
   1.224 +  if (referenceUserdata != NULL) SDL_free(referenceUserdata);
   1.225 +  if (referenceUserdata2 != NULL) SDL_free(referenceUserdata2);
   1.226 +  if (userdata != NULL) SDL_free(userdata);
   1.227 +  if (userdata != NULL) SDL_free(userdata);
   1.228 +  
   1.229 +  return returnValue;
   1.230 +}
   1.231 +
   1.232 +
   1.233  /* ================= Test References ================== */
   1.234  
   1.235  /* Video test cases */
   1.236 @@ -1555,13 +1772,16 @@
   1.237  static const SDLTest_TestCaseReference videoTest22 =
   1.238  		{ (SDLTest_TestCaseFp)video_getSetWindowMaximumSize, "video_getSetWindowMaximumSize",  "Checks SDL_GetWindowMaximumSize and SDL_SetWindowMaximumSize positive and negative cases", TEST_ENABLED };
   1.239  
   1.240 +static const SDLTest_TestCaseReference videoTest23 =
   1.241 +		{ (SDLTest_TestCaseFp)video_getSetWindowData, "video_getSetWindowData",  "Checks SDL_SetWindowData and SDL_GetWindowData positive and negative cases", TEST_ENABLED };
   1.242 +
   1.243  /* Sequence of Video test cases */
   1.244  static const SDLTest_TestCaseReference *videoTests[] =  {
   1.245  	&videoTest1, &videoTest2, &videoTest3, &videoTest4, &videoTest5, &videoTest6, 
   1.246  	&videoTest7, &videoTest8, &videoTest9, &videoTest10, &videoTest11, &videoTest12, 
   1.247  	&videoTest13, &videoTest14, &videoTest15, &videoTest16, &videoTest17, 
   1.248  	&videoTest18, &videoTest19, &videoTest20, &videoTest21, &videoTest22, 
   1.249 -	NULL
   1.250 +	&videoTest23, NULL
   1.251  };
   1.252  
   1.253  /* Video test suite (global) */