test/testautomation_rwops.c
changeset 6781 17a9b53a5ac3
parent 6779 c3b579c78059
child 6814 fccdef204fcf
equal deleted inserted replaced
6780:111b37940b35 6781:17a9b53a5ac3
       
     1 
     1 /**
     2 /**
     2  * Automated SDL_RWops test.
     3  * Automated SDL_RWops test.
     3  *
     4  *
     4  * Original code written by Edgar Simo "bobbens"
     5  * Original code written by Edgar Simo "bobbens"
     5  * Ported by Markus Kauppila (markus.kauppila@gmail.com)
     6  * Ported by Markus Kauppila (markus.kauppila@gmail.com)
   198    _testGenericRWopsValidations(rw, 1);
   199    _testGenericRWopsValidations(rw, 1);
   199 
   200 
   200    /* Close */
   201    /* Close */
   201    SDL_RWclose(rw);
   202    SDL_RWclose(rw);
   202    SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
   203    SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
   203    SDL_FreeRW(rw);
       
   204    SDLTest_AssertPass("Call to SDL_FreeRW() succeeded");
       
   205 
   204 
   206    return TEST_COMPLETED;
   205    return TEST_COMPLETED;
   207 }
   206 }
   208 
   207 
   209 
   208 
   230    _testGenericRWopsValidations( rw, 0 );
   229    _testGenericRWopsValidations( rw, 0 );
   231 
   230 
   232    /* Close handle */
   231    /* Close handle */
   233    SDL_RWclose(rw);
   232    SDL_RWclose(rw);
   234    SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
   233    SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
   235    SDL_FreeRW( rw );
       
   236    SDLTest_AssertPass("Call to SDL_FreeRW() succeeded");
       
   237 
   234 
   238   return TEST_COMPLETED;
   235   return TEST_COMPLETED;
   239 }
   236 }
   240 
   237 
   241 
   238 
   263    _testGenericRWopsValidations( rw, 0 );
   260    _testGenericRWopsValidations( rw, 0 );
   264 
   261 
   265    /* Close handle */
   262    /* Close handle */
   266    SDL_RWclose(rw);
   263    SDL_RWclose(rw);
   267    SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
   264    SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
   268    SDL_FreeRW( rw );
       
   269    SDLTest_AssertPass("Call to SDL_FreeRW() succeeded");
       
   270 
   265 
   271    return TEST_COMPLETED;
   266    return TEST_COMPLETED;
   272 }
   267 }
   273 
   268 
   274 /**
   269 /**
   295    _testGenericRWopsValidations( rw, 1 );
   290    _testGenericRWopsValidations( rw, 1 );
   296 
   291 
   297    /* Close handle */
   292    /* Close handle */
   298    SDL_RWclose(rw);
   293    SDL_RWclose(rw);
   299    SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
   294    SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
   300    SDL_FreeRW( rw );
       
   301    SDLTest_AssertPass("Call to SDL_FreeRW() succeeded");
       
   302 
   295 
   303    return TEST_COMPLETED;
   296    return TEST_COMPLETED;
   304 }
   297 }
   305 
   298 
   306 
   299 
   329    rw = SDL_RWFromFP( fp, SDL_TRUE );
   322    rw = SDL_RWFromFP( fp, SDL_TRUE );
   330    SDLTest_AssertPass("Call to SDL_RWFromFP() succeeded");
   323    SDLTest_AssertPass("Call to SDL_RWFromFP() succeeded");
   331    SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFP in read mode does not return NULL");
   324    SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFP in read mode does not return NULL");
   332 
   325 
   333    /* Bail out if NULL */
   326    /* Bail out if NULL */
   334    if (rw == NULL) return TEST_ABORTED;
   327    if (rw == NULL) {
       
   328      fclose(fp);
       
   329      return TEST_ABORTED;
       
   330    }
   335 
   331 
   336    /* Run generic tests */
   332    /* Run generic tests */
   337    _testGenericRWopsValidations( rw, 0 );
   333    _testGenericRWopsValidations( rw, 0 );
   338 
   334 
   339    /* Close handle */
   335    /* Close handle */
   340    SDL_RWclose(rw);
   336    SDL_RWclose(rw);
   341    SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
   337    SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
   342    SDL_FreeRW( rw );
       
   343    SDLTest_AssertPass("Call to SDL_FreeRW() succeeded");
       
   344    fclose(fp);
   338    fclose(fp);
   345 
   339 
   346    return TEST_COMPLETED;
   340    return TEST_COMPLETED;
   347 }
   341 }
   348 
   342 
   372    rw = SDL_RWFromFP( fp, SDL_TRUE );
   366    rw = SDL_RWFromFP( fp, SDL_TRUE );
   373    SDLTest_AssertPass("Call to SDL_RWFromFP() succeeded");
   367    SDLTest_AssertPass("Call to SDL_RWFromFP() succeeded");
   374    SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFP in write mode does not return NULL");
   368    SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFP in write mode does not return NULL");
   375 
   369 
   376    /* Bail out if NULL */
   370    /* Bail out if NULL */
   377    if (rw == NULL) return TEST_ABORTED;
   371    if (rw == NULL) {
       
   372      fclose(fp);
       
   373      return TEST_ABORTED;
       
   374    }
   378 
   375 
   379    /* Run generic tests */
   376    /* Run generic tests */
   380    _testGenericRWopsValidations( rw, 1 );
   377    _testGenericRWopsValidations( rw, 1 );
   381 
   378 
   382    /* Close handle */
   379    /* Close handle */
   383    SDL_RWclose(rw);
   380    SDL_RWclose(rw);
   384    SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
   381    SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
   385    SDL_FreeRW( rw );
   382    fclose(fp);
       
   383 
       
   384    return TEST_COMPLETED;
       
   385 }
       
   386 
       
   387 /**
       
   388  * @brief Tests alloc and free RW context.
       
   389  *
       
   390  * \sa http://wiki.libsdl.org/moin.cgi/SDL_FreeRW
       
   391  * \sa http://wiki.libsdl.org/moin.cgi/SDL_AllocRW
       
   392  */
       
   393 int
       
   394 rwops_testAllocFree (void)
       
   395 {
       
   396    /* Allocate context */
       
   397    SDL_RWops *rw = SDL_AllocRW();
       
   398    SDLTest_AssertPass("Call to SDL_AllocRW() succeeded");
       
   399    SDLTest_AssertCheck(rw != NULL, "Validate result from SDL_AllocRW() is not NULL");
       
   400    if (rw==NULL) return TEST_ABORTED;
       
   401           
       
   402    /* Free context again */
       
   403    SDL_FreeRW(rw);
   386    SDLTest_AssertPass("Call to SDL_FreeRW() succeeded");
   404    SDLTest_AssertPass("Call to SDL_FreeRW() succeeded");
   387    fclose(fp);
   405 
   388 
   406    return TEST_COMPLETED;
   389    return TEST_COMPLETED;
   407 }
   390 }
   408 
   391 
   409 
   392 /* ================= Test References ================== */
   410 /* ================= Test References ================== */
   393 
   411 
   394 /* RWops test cases */
   412 /* RWops test cases */
   395 static const SDLTest_TestCaseReference rwopsTest1 =
   413 static const SDLTest_TestCaseReference rwopsTest1 =
   411 		{ (SDLTest_TestCaseFp)rwops_testFPRead, "rwops_testFPRead", "Test reading from file pointer", TEST_ENABLED };
   429 		{ (SDLTest_TestCaseFp)rwops_testFPRead, "rwops_testFPRead", "Test reading from file pointer", TEST_ENABLED };
   412 
   430 
   413 static const SDLTest_TestCaseReference rwopsTest7 =
   431 static const SDLTest_TestCaseReference rwopsTest7 =
   414 		{ (SDLTest_TestCaseFp)rwops_testFPWrite, "rwops_testFPWrite", "Test writing to file pointer", TEST_ENABLED };
   432 		{ (SDLTest_TestCaseFp)rwops_testFPWrite, "rwops_testFPWrite", "Test writing to file pointer", TEST_ENABLED };
   415 
   433 
       
   434 static const SDLTest_TestCaseReference rwopsTest8 =
       
   435 		{ (SDLTest_TestCaseFp)rwops_testAllocFree, "rwops_testAllocFree", "Test alloc and free of RW context", TEST_ENABLED };
       
   436 
   416 /* Sequence of RWops test cases */
   437 /* Sequence of RWops test cases */
   417 static const SDLTest_TestCaseReference *rwopsTests[] =  {
   438 static const SDLTest_TestCaseReference *rwopsTests[] =  {
   418 	&rwopsTest1, &rwopsTest2, &rwopsTest3, &rwopsTest4, &rwopsTest5, &rwopsTest6, &rwopsTest7, NULL
   439 	&rwopsTest1, &rwopsTest2, &rwopsTest3, &rwopsTest4, &rwopsTest5, &rwopsTest6, &rwopsTest7, &rwopsTest8, NULL
   419 };
   440 };
   420 
   441 
   421 /* RWops test suite (global) */
   442 /* RWops test suite (global) */
   422 SDLTest_TestSuiteReference rwopsTestSuite = {
   443 SDLTest_TestSuiteReference rwopsTestSuite = {
   423 	"RWops",
   444 	"RWops",