test/testautomation_rwops.c
changeset 6999 681820ca0e78
parent 6996 bc0fd5bced25
child 7191 75360622e65f
equal deleted inserted replaced
6998:f7faeaa02efb 6999:681820ca0e78
    19 
    19 
    20 /* ================= Test Case Implementation ================== */
    20 /* ================= Test Case Implementation ================== */
    21 
    21 
    22 const char* RWopsReadTestFilename = "rwops_read";
    22 const char* RWopsReadTestFilename = "rwops_read";
    23 const char* RWopsWriteTestFilename = "rwops_write";
    23 const char* RWopsWriteTestFilename = "rwops_write";
       
    24 const char* RWopsAlphabetFilename = "rwops_alphabet";
    24 
    25 
    25 static const char RWopsHelloWorldTestString[] = "Hello World!";
    26 static const char RWopsHelloWorldTestString[] = "Hello World!";
    26 static const char RWopsHelloWorldCompString[] = "Hello World!";
    27 static const char RWopsHelloWorldCompString[] = "Hello World!";
       
    28 static const char RWopsAlphabetString[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    27 
    29 
    28 /* Fixture */
    30 /* Fixture */
    29 
    31 
    30 void
    32 void
    31 RWopsSetUp(void *arg)
    33 RWopsSetUp(void *arg)
    32 {
    34 {
    33 	int fileLen = SDL_strlen(RWopsHelloWorldTestString);
    35 	int fileLen;
    34 	FILE *handle;
    36 	FILE *handle;
    35 	int writtenLen;
    37 	int writtenLen;
    36 	int result;
    38 	int result;
    37 
    39 
    38 	/* Clean up from previous runs (if any); ignore errors */
    40 	/* Clean up from previous runs (if any); ignore errors */
    39 	remove(RWopsReadTestFilename);
    41 	remove(RWopsReadTestFilename);
    40 	remove(RWopsWriteTestFilename);
    42 	remove(RWopsWriteTestFilename);
       
    43 	remove(RWopsAlphabetFilename);
    41 
    44 
    42 	/* Create a test file */
    45 	/* Create a test file */
    43 	handle = fopen(RWopsReadTestFilename, "w");
    46 	handle = fopen(RWopsReadTestFilename, "w");
    44 	SDLTest_AssertCheck(handle != NULL, "Verify creation of file '%s' returned non NULL handle", RWopsReadTestFilename);
    47 	SDLTest_AssertCheck(handle != NULL, "Verify creation of file '%s' returned non NULL handle", RWopsReadTestFilename);
    45         if (handle == NULL) return;
    48         if (handle == NULL) return;
    46 
    49 
    47 	/* Write some known test into it */
    50 	/* Write some known text into it */
       
    51 	fileLen = SDL_strlen(RWopsHelloWorldTestString);
    48 	writtenLen = (int)fwrite(RWopsHelloWorldTestString, 1, fileLen, handle);
    52 	writtenLen = (int)fwrite(RWopsHelloWorldTestString, 1, fileLen, handle);
       
    53 	SDLTest_AssertCheck(fileLen == writtenLen, "Verify number of written bytes, expected %i, got %i", fileLen, writtenLen);
       
    54 	result = fclose(handle);
       
    55 	SDLTest_AssertCheck(result == 0, "Verify result from fclose, expected 0, got %i", result);
       
    56 
       
    57 	/* Create a second test file */
       
    58 	handle = fopen(RWopsAlphabetFilename, "w");
       
    59 	SDLTest_AssertCheck(handle != NULL, "Verify creation of file '%s' returned non NULL handle", RWopsAlphabetFilename);
       
    60         if (handle == NULL) return;
       
    61 
       
    62 	/* Write alphabet text into it */
       
    63 	fileLen = SDL_strlen(RWopsAlphabetString);
       
    64 	writtenLen = (int)fwrite(RWopsAlphabetString, 1, fileLen, handle);
    49 	SDLTest_AssertCheck(fileLen == writtenLen, "Verify number of written bytes, expected %i, got %i", fileLen, writtenLen);
    65 	SDLTest_AssertCheck(fileLen == writtenLen, "Verify number of written bytes, expected %i, got %i", fileLen, writtenLen);
    50 	result = fclose(handle);
    66 	result = fclose(handle);
    51 	SDLTest_AssertCheck(result == 0, "Verify result from fclose, expected 0, got %i", result);
    67 	SDLTest_AssertCheck(result == 0, "Verify result from fclose, expected 0, got %i", result);
    52 
    68 
    53 	SDLTest_AssertPass("Creation of test file completed");
    69 	SDLTest_AssertPass("Creation of test file completed");
    60 	
    76 	
    61 	/* Remove the created files to clean up; ignore errors for write filename */
    77 	/* Remove the created files to clean up; ignore errors for write filename */
    62 	result = remove(RWopsReadTestFilename);
    78 	result = remove(RWopsReadTestFilename);
    63 	SDLTest_AssertCheck(result == 0, "Verify result from remove(%s), expected 0, got %i", RWopsReadTestFilename, result);
    79 	SDLTest_AssertCheck(result == 0, "Verify result from remove(%s), expected 0, got %i", RWopsReadTestFilename, result);
    64 	remove(RWopsWriteTestFilename);
    80 	remove(RWopsWriteTestFilename);
       
    81 	result = remove(RWopsAlphabetFilename);
       
    82 	SDLTest_AssertCheck(result == 0, "Verify result from remove(%s), expected 0, got %i", RWopsAlphabetFilename, result);
    65 
    83 
    66 	SDLTest_AssertPass("Cleanup of test files completed");
    84 	SDLTest_AssertPass("Cleanup of test files completed");
    67 }
    85 }
    68 
    86 
    69 /**
    87 /**
   135    SDLTest_AssertCheck(
   153    SDLTest_AssertCheck(
   136 	   i == (Sint64)(sizeof(RWopsHelloWorldTestString)-2), 
   154 	   i == (Sint64)(sizeof(RWopsHelloWorldTestString)-2), 
   137 	   "Verify seek to -1 with SDL_RWseek (RW_SEEK_END), expected %i, got %i",
   155 	   "Verify seek to -1 with SDL_RWseek (RW_SEEK_END), expected %i, got %i",
   138 	   sizeof(RWopsHelloWorldTestString)-2,
   156 	   sizeof(RWopsHelloWorldTestString)-2,
   139 	   i);
   157 	   i);
       
   158 	   
       
   159    /* Invalid whence seek */
       
   160    i = SDL_RWseek( rw, 0, 999 );
       
   161    SDLTest_AssertPass("Call to SDL_RWseek(...,0,invalid_whence) succeeded");
       
   162    SDLTest_AssertCheck(
       
   163 	   i == (Sint64)(-1), 
       
   164 	   "Verify seek with SDL_RWseek (invalid_whence); expected: -1, got %i",
       
   165 	   i);
   140 }
   166 }
   141 
   167 
   142 /*!
   168 /*!
   143  * Negative test for SDL_RWFromFile parameters
   169  * Negative test for SDL_RWFromFile parameters
   144  *
   170  *
   169 
   195 
   170    rwops = SDL_RWFromFile("something", NULL);
   196    rwops = SDL_RWFromFile("something", NULL);
   171    SDLTest_AssertPass("Call to SDL_RWFromFile(\"something\", NULL) succeeded");
   197    SDLTest_AssertPass("Call to SDL_RWFromFile(\"something\", NULL) succeeded");
   172    SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(\"something\", NULL) returns NULL");
   198    SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(\"something\", NULL) returns NULL");
   173 
   199 
       
   200    rwops = SDL_RWFromMem((void *)NULL, 10);
       
   201    SDLTest_AssertPass("Call to SDL_RWFromMem(NULL, 10) succeeded");
       
   202    SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromMem(NULL, 10) returns NULL");
       
   203 
       
   204    rwops = SDL_RWFromMem((void *)RWopsAlphabetString, 0);
       
   205    SDLTest_AssertPass("Call to SDL_RWFromMem(data, 0) succeeded");
       
   206    SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromMem(data, 0) returns NULL");
       
   207 
       
   208    rwops = SDL_RWFromConstMem((const void *)RWopsAlphabetString, 0);
       
   209    SDLTest_AssertPass("Call to SDL_RWFromConstMem(data, 0) succeeded");
       
   210    SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromConstMem(data, 0) returns NULL");
       
   211 
   174    return TEST_COMPLETED;
   212    return TEST_COMPLETED;
   175 }
   213 }
   176 
   214 
   177 /**
   215 /**
   178  * @brief Tests opening from memory.
   216  * @brief Tests opening from memory.
   179  *
   217  *
   180  * \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromMem
   218  * \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromMem
   181  * http://wiki.libsdl.org/moin.cgi/SDL_RWClose
   219  * \sa http://wiki.libsdl.org/moin.cgi/SDL_RWClose
   182  */
   220  */
   183 int
   221 int
   184 rwops_testMem (void)
   222 rwops_testMem (void)
   185 {
   223 {
   186    char mem[sizeof(RWopsHelloWorldTestString)];
   224    char mem[sizeof(RWopsHelloWorldTestString)];
   187    SDL_RWops *rw;
   225    SDL_RWops *rw;
       
   226    int result;
   188 
   227 
   189    /* Clear buffer */
   228    /* Clear buffer */
   190    SDL_zero(mem);
   229    SDL_zero(mem);
   191 
   230 
   192    /* Open */
   231    /* Open */
   195    SDLTest_AssertCheck(rw != NULL, "Verify opening memory with SDL_RWFromMem does not return NULL");
   234    SDLTest_AssertCheck(rw != NULL, "Verify opening memory with SDL_RWFromMem does not return NULL");
   196 
   235 
   197    /* Bail out if NULL */
   236    /* Bail out if NULL */
   198    if (rw == NULL) return TEST_ABORTED;
   237    if (rw == NULL) return TEST_ABORTED;
   199 
   238 
       
   239    /* Check type */
       
   240    SDLTest_AssertCheck(rw->type == SDL_RWOPS_MEMORY, "Verify RWops type is SDL_RWOPS_MEMORY; expected: %d, got: %d", SDL_RWOPS_MEMORY, rw->type);
       
   241 
   200    /* Run generic tests */
   242    /* Run generic tests */
   201    _testGenericRWopsValidations(rw, 1);
   243    _testGenericRWopsValidations(rw, 1);
   202 
   244 
   203    /* Close */
   245    /* Close */
   204    SDL_RWclose(rw);
   246    result = SDL_RWclose(rw);
   205    SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
   247    SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
       
   248    SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
   206 
   249 
   207    return TEST_COMPLETED;
   250    return TEST_COMPLETED;
   208 }
   251 }
   209 
   252 
   210 
   253 
   217  */
   260  */
   218 int 
   261 int 
   219 rwops_testConstMem (void)
   262 rwops_testConstMem (void)
   220 {
   263 {
   221    SDL_RWops *rw;
   264    SDL_RWops *rw;
       
   265    int result;
   222 
   266 
   223    /* Open handle */
   267    /* Open handle */
   224    rw = SDL_RWFromConstMem( RWopsHelloWorldCompString, sizeof(RWopsHelloWorldCompString)-1 );
   268    rw = SDL_RWFromConstMem( RWopsHelloWorldCompString, sizeof(RWopsHelloWorldCompString)-1 );
   225    SDLTest_AssertPass("Call to SDL_RWFromConstMem() succeeded");
   269    SDLTest_AssertPass("Call to SDL_RWFromConstMem() succeeded");
   226    SDLTest_AssertCheck(rw != NULL, "Verify opening memory with SDL_RWFromConstMem does not return NULL");
   270    SDLTest_AssertCheck(rw != NULL, "Verify opening memory with SDL_RWFromConstMem does not return NULL");
   227 
   271 
   228    /* Bail out if NULL */
   272    /* Bail out if NULL */
   229    if (rw == NULL) return TEST_ABORTED;
   273    if (rw == NULL) return TEST_ABORTED;
   230 
   274 
       
   275    /* Check type */
       
   276    SDLTest_AssertCheck(rw->type == SDL_RWOPS_MEMORY_RO, "Verify RWops type is SDL_RWOPS_MEMORY_RO; expected: %d, got: %d", SDL_RWOPS_MEMORY_RO, rw->type);
       
   277 
   231    /* Run generic tests */
   278    /* Run generic tests */
   232    _testGenericRWopsValidations( rw, 0 );
   279    _testGenericRWopsValidations( rw, 0 );
   233 
   280 
   234    /* Close handle */
   281    /* Close handle */
   235    SDL_RWclose(rw);
   282    result = SDL_RWclose(rw);
   236    SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
   283    SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
       
   284    SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
   237 
   285 
   238   return TEST_COMPLETED;
   286   return TEST_COMPLETED;
   239 }
   287 }
   240 
   288 
   241 
   289 
   248  */
   296  */
   249 int
   297 int
   250 rwops_testFileRead(void)
   298 rwops_testFileRead(void)
   251 {
   299 {
   252    SDL_RWops *rw;
   300    SDL_RWops *rw;
       
   301    int result;
   253 
   302 
   254    /* Read test. */
   303    /* Read test. */
   255    rw = SDL_RWFromFile(RWopsReadTestFilename, "r");
   304    rw = SDL_RWFromFile(RWopsReadTestFilename, "r");
   256    SDLTest_AssertPass("Call to SDL_RWFromFile(..,\"r\") succeeded");
   305    SDLTest_AssertPass("Call to SDL_RWFromFile(..,\"r\") succeeded");
   257    SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFile in read mode does not return NULL");
   306    SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFile in read mode does not return NULL");
   258 
   307 
   259    // Bail out if NULL
   308    // Bail out if NULL
   260    if (rw == NULL) return TEST_ABORTED;
   309    if (rw == NULL) return TEST_ABORTED;
   261 
   310 
       
   311    /* Check type */
       
   312 #if defined(ANDROID)
       
   313    SDLTest_AssertCheck(
       
   314       rw->type == SDL_RWOPS_STDFILE || rw->type == SDL_RWOPS_JNIFILE, 
       
   315       "Verify RWops type is SDL_RWOPS_STDFILE or SDL_RWOPS_JNIFILE; expected: %d|%d, got: %d", SDL_RWOPS_STDFILE, SDL_RWOPS_JNIFILE, rw->type);
       
   316 #elif defined(__WIN32__)
       
   317    SDLTest_AssertCheck(
       
   318       rw->type == SDL_RWOPS_WINFILE, 
       
   319       "Verify RWops type is SDL_RWOPS_WINFILE; expected: %d, got: %d", SDL_RWOPS_WINFILE, rw->type);
       
   320 #else
       
   321    SDLTest_AssertCheck(
       
   322       rw->type == SDL_RWOPS_STDFILE, 
       
   323       "Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %d", SDL_RWOPS_STDFILE, rw->type);
       
   324 #endif
       
   325 
   262    /* Run generic tests */
   326    /* Run generic tests */
   263    _testGenericRWopsValidations( rw, 0 );
   327    _testGenericRWopsValidations( rw, 0 );
   264 
   328 
   265    /* Close handle */
   329    /* Close handle */
   266    SDL_RWclose(rw);
   330    result = SDL_RWclose(rw);
   267    SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
   331    SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
       
   332    SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
   268 
   333 
   269    return TEST_COMPLETED;
   334    return TEST_COMPLETED;
   270 }
   335 }
   271 
   336 
   272 /**
   337 /**
   278  */
   343  */
   279 int
   344 int
   280 rwops_testFileWrite(void)
   345 rwops_testFileWrite(void)
   281 {
   346 {
   282    SDL_RWops *rw;
   347    SDL_RWops *rw;
       
   348    int result;
   283 
   349 
   284    /* Write test. */
   350    /* Write test. */
   285    rw = SDL_RWFromFile(RWopsWriteTestFilename, "w+");
   351    rw = SDL_RWFromFile(RWopsWriteTestFilename, "w+");
   286    SDLTest_AssertPass("Call to SDL_RWFromFile(..,\"w+\") succeeded");
   352    SDLTest_AssertPass("Call to SDL_RWFromFile(..,\"w+\") succeeded");
   287    SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFile in write mode does not return NULL");
   353    SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFile in write mode does not return NULL");
   288 
   354 
   289    // Bail out if NULL
   355    // Bail out if NULL
   290    if (rw == NULL) return TEST_ABORTED;
   356    if (rw == NULL) return TEST_ABORTED;
   291 
   357 
       
   358    /* Check type */
       
   359 #if defined(ANDROID)
       
   360    SDLTest_AssertCheck(
       
   361       rw->type == SDL_RWOPS_STDFILE || rw->type == SDL_RWOPS_JNIFILE, 
       
   362       "Verify RWops type is SDL_RWOPS_STDFILE or SDL_RWOPS_JNIFILE; expected: %d|%d, got: %d", SDL_RWOPS_STDFILE, SDL_RWOPS_JNIFILE, rw->type);
       
   363 #elif defined(__WIN32__)
       
   364    SDLTest_AssertCheck(
       
   365       rw->type == SDL_RWOPS_WINFILE, 
       
   366       "Verify RWops type is SDL_RWOPS_WINFILE; expected: %d, got: %d", SDL_RWOPS_WINFILE, rw->type);
       
   367 #else
       
   368    SDLTest_AssertCheck(
       
   369       rw->type == SDL_RWOPS_STDFILE, 
       
   370       "Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %d", SDL_RWOPS_STDFILE, rw->type);
       
   371 #endif
       
   372 
   292    /* Run generic tests */
   373    /* Run generic tests */
   293    _testGenericRWopsValidations( rw, 1 );
   374    _testGenericRWopsValidations( rw, 1 );
   294 
   375 
   295    /* Close handle */
   376    /* Close handle */
   296    SDL_RWclose(rw);
   377    result = SDL_RWclose(rw);
   297    SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
   378    SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
       
   379    SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
   298 
   380 
   299    return TEST_COMPLETED;
   381    return TEST_COMPLETED;
   300 }
   382 }
   301 
   383 
   302 
   384 
   311 int
   393 int
   312 rwops_testFPRead(void)
   394 rwops_testFPRead(void)
   313 {
   395 {
   314    FILE *fp;
   396    FILE *fp;
   315    SDL_RWops *rw;
   397    SDL_RWops *rw;
       
   398    int result;
   316 
   399 
   317    /* Run read tests. */
   400    /* Run read tests. */
   318    fp = fopen(RWopsReadTestFilename, "r");
   401    fp = fopen(RWopsReadTestFilename, "r");
   319    SDLTest_AssertCheck(fp != NULL, "Verify handle from opening file '%s' in read mode is not NULL", RWopsReadTestFilename);
   402    SDLTest_AssertCheck(fp != NULL, "Verify handle from opening file '%s' in read mode is not NULL", RWopsReadTestFilename);
   320 
   403 
   330    if (rw == NULL) {
   413    if (rw == NULL) {
   331      fclose(fp);
   414      fclose(fp);
   332      return TEST_ABORTED;
   415      return TEST_ABORTED;
   333    }
   416    }
   334 
   417 
       
   418    /* Check type */
       
   419    SDLTest_AssertCheck(
       
   420       rw->type == SDL_RWOPS_STDFILE, 
       
   421       "Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %d", SDL_RWOPS_STDFILE, rw->type);
       
   422 
   335    /* Run generic tests */
   423    /* Run generic tests */
   336    _testGenericRWopsValidations( rw, 0 );
   424    _testGenericRWopsValidations( rw, 0 );
   337 
   425 
   338    /* Close handle - does fclose() */
   426    /* Close handle - does fclose() */
   339    SDL_RWclose(rw);
   427    result = SDL_RWclose(rw);
   340    SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
   428    SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
       
   429    SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
   341 
   430 
   342    return TEST_COMPLETED;
   431    return TEST_COMPLETED;
   343 }
   432 }
   344 
   433 
   345 
   434 
   354 int
   443 int
   355 rwops_testFPWrite(void)
   444 rwops_testFPWrite(void)
   356 {
   445 {
   357    FILE *fp;
   446    FILE *fp;
   358    SDL_RWops *rw;
   447    SDL_RWops *rw;
       
   448    int result;
   359 
   449 
   360    /* Run write tests. */
   450    /* Run write tests. */
   361    fp = fopen(RWopsWriteTestFilename, "w+");
   451    fp = fopen(RWopsWriteTestFilename, "w+");
   362    SDLTest_AssertCheck(fp != NULL, "Verify handle from opening file '%s' in write mode is not NULL", RWopsWriteTestFilename);
   452    SDLTest_AssertCheck(fp != NULL, "Verify handle from opening file '%s' in write mode is not NULL", RWopsWriteTestFilename);
   363 
   453 
   373    if (rw == NULL) {
   463    if (rw == NULL) {
   374      fclose(fp);
   464      fclose(fp);
   375      return TEST_ABORTED;
   465      return TEST_ABORTED;
   376    }
   466    }
   377 
   467 
       
   468    /* Check type */
       
   469    SDLTest_AssertCheck(
       
   470       rw->type == SDL_RWOPS_STDFILE, 
       
   471       "Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %d", SDL_RWOPS_STDFILE, rw->type);
       
   472 
   378    /* Run generic tests */
   473    /* Run generic tests */
   379    _testGenericRWopsValidations( rw, 1 );
   474    _testGenericRWopsValidations( rw, 1 );
   380 
   475 
   381    /* Close handle - does fclose() */
   476    /* Close handle - does fclose() */
   382    SDL_RWclose(rw);
   477    result = SDL_RWclose(rw);
   383    SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
   478    SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
       
   479    SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
   384 
   480 
   385    return TEST_COMPLETED;
   481    return TEST_COMPLETED;
   386 }
   482 }
   387 
   483 
   388 /**
   484 /**
   397    /* Allocate context */
   493    /* Allocate context */
   398    SDL_RWops *rw = SDL_AllocRW();
   494    SDL_RWops *rw = SDL_AllocRW();
   399    SDLTest_AssertPass("Call to SDL_AllocRW() succeeded");
   495    SDLTest_AssertPass("Call to SDL_AllocRW() succeeded");
   400    SDLTest_AssertCheck(rw != NULL, "Validate result from SDL_AllocRW() is not NULL");
   496    SDLTest_AssertCheck(rw != NULL, "Validate result from SDL_AllocRW() is not NULL");
   401    if (rw==NULL) return TEST_ABORTED;
   497    if (rw==NULL) return TEST_ABORTED;
       
   498 
       
   499    /* Check type */
       
   500    SDLTest_AssertCheck(
       
   501       rw->type == SDL_RWOPS_UNKNOWN, 
       
   502       "Verify RWops type is SDL_RWOPS_UNKNOWN; expected: %d, got: %d", SDL_RWOPS_UNKNOWN, rw->type);
   402           
   503           
   403    /* Free context again */
   504    /* Free context again */
   404    SDL_FreeRW(rw);
   505    SDL_FreeRW(rw);
   405    SDLTest_AssertPass("Call to SDL_FreeRW() succeeded");
   506    SDLTest_AssertPass("Call to SDL_FreeRW() succeeded");
   406 
   507 
       
   508    return TEST_COMPLETED;
       
   509 }
       
   510 
       
   511 /**
       
   512  * @brief Compare memory and file reads
       
   513  *
       
   514  * \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromMem
       
   515  * \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile
       
   516  */
       
   517 int
       
   518 rwops_testCompareRWFromMemWithRWFromFile(void)
       
   519 {
       
   520    int slen = 26;
       
   521    char buffer_file[27];
       
   522    char buffer_mem[27];
       
   523    size_t rv_file;
       
   524    size_t rv_mem;
       
   525    Uint64 sv_file;
       
   526    Uint64 sv_mem;
       
   527    SDL_RWops* rwops_file;
       
   528    SDL_RWops* rwops_mem;
       
   529    int size;
       
   530    int result;
       
   531 
       
   532    
       
   533    for (size=5; size<10; size++)
       
   534    {
       
   535      /* Terminate buffer */
       
   536      buffer_file[slen] = 0;
       
   537      buffer_mem[slen] = 0;
       
   538      
       
   539      /* Read/seek from memory */
       
   540      rwops_mem = SDL_RWFromMem((void *)RWopsAlphabetString, slen);
       
   541      SDLTest_AssertPass("Call to SDL_RWFromMem()");
       
   542      rv_mem = SDL_RWread(rwops_mem, buffer_mem, size, 6);
       
   543      SDLTest_AssertPass("Call to SDL_RWread(mem, size=%d)", size);
       
   544      sv_mem = SDL_RWseek(rwops_mem, 0, SEEK_END);
       
   545      SDLTest_AssertPass("Call to SDL_RWseek(mem,SEEK_END)");
       
   546      result = SDL_RWclose(rwops_mem);
       
   547      SDLTest_AssertPass("Call to SDL_RWclose(mem)");
       
   548      SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
       
   549 
       
   550      /* Read/see from file */
       
   551      rwops_file = SDL_RWFromFile(RWopsAlphabetFilename, "r");
       
   552      SDLTest_AssertPass("Call to SDL_RWFromFile()");
       
   553      rv_file = SDL_RWread(rwops_file, buffer_file, size, 6);
       
   554      SDLTest_AssertPass("Call to SDL_RWread(file, size=%d)", size);
       
   555      sv_file = SDL_RWseek(rwops_file, 0, SEEK_END);
       
   556      SDLTest_AssertPass("Call to SDL_RWseek(file,SEEK_END)");
       
   557      result = SDL_RWclose(rwops_file);
       
   558      SDLTest_AssertPass("Call to SDL_RWclose(file)");
       
   559      SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
       
   560    
       
   561      /* Compare */
       
   562      SDLTest_AssertCheck(rv_mem == rv_file, "Verify returned read blocks matches for mem and file reads; got: rv_mem=%d rv_file=%d", rv_mem, rv_file);
       
   563      SDLTest_AssertCheck(sv_mem == sv_file, "Verify SEEK_END position matches for mem and file seeks; got: sv_mem=%llu sv_file=%llu", sv_mem, sv_file);
       
   564      SDLTest_AssertCheck(buffer_mem[slen] == 0, "Verify mem buffer termination; expected: 0, got: %d", buffer_mem[slen]);
       
   565      SDLTest_AssertCheck(buffer_file[slen] == 0, "Verify file buffer termination; expected: 0, got: %d", buffer_file[slen]);
       
   566      SDLTest_AssertCheck(
       
   567        SDL_strncmp(buffer_mem, RWopsAlphabetString, slen) == 0,
       
   568        "Verify mem buffer contain alphabet string; expected: %s, got: %s", RWopsAlphabetString, buffer_mem);
       
   569      SDLTest_AssertCheck(
       
   570        SDL_strncmp(buffer_file, RWopsAlphabetString, slen) == 0,
       
   571        "Verify file buffer contain alphabet string; expected: %s, got: %s", RWopsAlphabetString, buffer_file);
       
   572    }
       
   573       
   407    return TEST_COMPLETED;
   574    return TEST_COMPLETED;
   408 }
   575 }
   409 
   576 
   410 /**
   577 /**
   411  * @brief Tests writing and reading from file using endian aware functions.
   578  * @brief Tests writing and reading from file using endian aware functions.
   433    Uint32 BE32test;
   600    Uint32 BE32test;
   434    Uint64 BE64test;
   601    Uint64 BE64test;
   435    Uint16 LE16test;
   602    Uint16 LE16test;
   436    Uint32 LE32test;
   603    Uint32 LE32test;
   437    Uint64 LE64test;
   604    Uint64 LE64test;
       
   605    int cresult;
   438 
   606 
   439    for (mode = 0; mode < 3; mode++) {
   607    for (mode = 0; mode < 3; mode++) {
   440    
   608    
   441      /* Create test data */
   609      /* Create test data */
   442      switch (mode) {
   610      switch (mode) {
   521      LE64test = SDL_ReadLE64(rw);
   689      LE64test = SDL_ReadLE64(rw);
   522      SDLTest_AssertPass("Call to SDL_ReadLE64");
   690      SDLTest_AssertPass("Call to SDL_ReadLE64");
   523      SDLTest_AssertCheck(LE64test == LE64value, "Validate return value from SDL_ReadLE64, expected: %llu, got: %llu", LE64value, LE64test);
   691      SDLTest_AssertCheck(LE64test == LE64value, "Validate return value from SDL_ReadLE64, expected: %llu, got: %llu", LE64value, LE64test);
   524 
   692 
   525      /* Close handle */
   693      /* Close handle */
   526      SDL_RWclose(rw);
   694      cresult = SDL_RWclose(rw);
   527      SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
   695      SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
   528    
   696      SDLTest_AssertCheck(cresult == 0, "Verify result value is 0; got: %d", cresult);   
   529    }
   697    }
   530 
   698 
   531    return TEST_COMPLETED;
   699    return TEST_COMPLETED;
   532 }
   700 }
   533 
   701 
   560 		{ (SDLTest_TestCaseFp)rwops_testAllocFree, "rwops_testAllocFree", "Test alloc and free of RW context", TEST_ENABLED };
   728 		{ (SDLTest_TestCaseFp)rwops_testAllocFree, "rwops_testAllocFree", "Test alloc and free of RW context", TEST_ENABLED };
   561 
   729 
   562 static const SDLTest_TestCaseReference rwopsTest9 =
   730 static const SDLTest_TestCaseReference rwopsTest9 =
   563 		{ (SDLTest_TestCaseFp)rwops_testFileWriteReadEndian, "rwops_testFileWriteReadEndian", "Test writing and reading via the Endian aware functions", TEST_ENABLED };
   731 		{ (SDLTest_TestCaseFp)rwops_testFileWriteReadEndian, "rwops_testFileWriteReadEndian", "Test writing and reading via the Endian aware functions", TEST_ENABLED };
   564 
   732 
       
   733 static const SDLTest_TestCaseReference rwopsTest10 =
       
   734 		{ (SDLTest_TestCaseFp)rwops_testCompareRWFromMemWithRWFromFile, "rwops_testCompareRWFromMemWithRWFromFile", "Compare RWFromMem and RWFromFile RWops for read and seek", TEST_ENABLED };
       
   735 
   565 /* Sequence of RWops test cases */
   736 /* Sequence of RWops test cases */
   566 static const SDLTest_TestCaseReference *rwopsTests[] =  {
   737 static const SDLTest_TestCaseReference *rwopsTests[] =  {
   567 	&rwopsTest1, &rwopsTest2, &rwopsTest3, &rwopsTest4, &rwopsTest5, &rwopsTest6, 
   738 	&rwopsTest1, &rwopsTest2, &rwopsTest3, &rwopsTest4, &rwopsTest5, &rwopsTest6, 
   568 	&rwopsTest7, &rwopsTest8, &rwopsTest9, NULL
   739 	&rwopsTest7, &rwopsTest8, &rwopsTest9, &rwopsTest10, NULL
   569 };
   740 };
   570 
   741 
   571 /* RWops test suite (global) */
   742 /* RWops test suite (global) */
   572 SDLTest_TestSuiteReference rwopsTestSuite = {
   743 SDLTest_TestSuiteReference rwopsTestSuite = {
   573 	"RWops",
   744 	"RWops",