Fix incorrect use of SDL_FreeRW in rwops suite; add testcase for SDL_AllocRW/SDL_FreeRW to rwops test suite
authorAndreas Schiffler <aschiffler@ferzkopp.net>
Sun, 30 Dec 2012 19:05:50 -0800
changeset 678117a9b53a5ac3
parent 6780 111b37940b35
child 6782 582d35419e8a
Fix incorrect use of SDL_FreeRW in rwops suite; add testcase for SDL_AllocRW/SDL_FreeRW to rwops test suite
test/testautomation_rwops.c
     1.1 --- a/test/testautomation_rwops.c	Sun Dec 30 11:12:31 2012 -0800
     1.2 +++ b/test/testautomation_rwops.c	Sun Dec 30 19:05:50 2012 -0800
     1.3 @@ -1,3 +1,4 @@
     1.4 +
     1.5  /**
     1.6   * Automated SDL_RWops test.
     1.7   *
     1.8 @@ -200,8 +201,6 @@
     1.9     /* Close */
    1.10     SDL_RWclose(rw);
    1.11     SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
    1.12 -   SDL_FreeRW(rw);
    1.13 -   SDLTest_AssertPass("Call to SDL_FreeRW() succeeded");
    1.14  
    1.15     return TEST_COMPLETED;
    1.16  }
    1.17 @@ -232,8 +231,6 @@
    1.18     /* Close handle */
    1.19     SDL_RWclose(rw);
    1.20     SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
    1.21 -   SDL_FreeRW( rw );
    1.22 -   SDLTest_AssertPass("Call to SDL_FreeRW() succeeded");
    1.23  
    1.24    return TEST_COMPLETED;
    1.25  }
    1.26 @@ -265,8 +262,6 @@
    1.27     /* Close handle */
    1.28     SDL_RWclose(rw);
    1.29     SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
    1.30 -   SDL_FreeRW( rw );
    1.31 -   SDLTest_AssertPass("Call to SDL_FreeRW() succeeded");
    1.32  
    1.33     return TEST_COMPLETED;
    1.34  }
    1.35 @@ -297,8 +292,6 @@
    1.36     /* Close handle */
    1.37     SDL_RWclose(rw);
    1.38     SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
    1.39 -   SDL_FreeRW( rw );
    1.40 -   SDLTest_AssertPass("Call to SDL_FreeRW() succeeded");
    1.41  
    1.42     return TEST_COMPLETED;
    1.43  }
    1.44 @@ -331,7 +324,10 @@
    1.45     SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFP in read mode does not return NULL");
    1.46  
    1.47     /* Bail out if NULL */
    1.48 -   if (rw == NULL) return TEST_ABORTED;
    1.49 +   if (rw == NULL) {
    1.50 +     fclose(fp);
    1.51 +     return TEST_ABORTED;
    1.52 +   }
    1.53  
    1.54     /* Run generic tests */
    1.55     _testGenericRWopsValidations( rw, 0 );
    1.56 @@ -339,8 +335,6 @@
    1.57     /* Close handle */
    1.58     SDL_RWclose(rw);
    1.59     SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
    1.60 -   SDL_FreeRW( rw );
    1.61 -   SDLTest_AssertPass("Call to SDL_FreeRW() succeeded");
    1.62     fclose(fp);
    1.63  
    1.64     return TEST_COMPLETED;
    1.65 @@ -374,7 +368,10 @@
    1.66     SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFP in write mode does not return NULL");
    1.67  
    1.68     /* Bail out if NULL */
    1.69 -   if (rw == NULL) return TEST_ABORTED;
    1.70 +   if (rw == NULL) {
    1.71 +     fclose(fp);
    1.72 +     return TEST_ABORTED;
    1.73 +   }
    1.74  
    1.75     /* Run generic tests */
    1.76     _testGenericRWopsValidations( rw, 1 );
    1.77 @@ -382,13 +379,34 @@
    1.78     /* Close handle */
    1.79     SDL_RWclose(rw);
    1.80     SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
    1.81 -   SDL_FreeRW( rw );
    1.82 -   SDLTest_AssertPass("Call to SDL_FreeRW() succeeded");
    1.83     fclose(fp);
    1.84  
    1.85     return TEST_COMPLETED;
    1.86  }
    1.87  
    1.88 +/**
    1.89 + * @brief Tests alloc and free RW context.
    1.90 + *
    1.91 + * \sa http://wiki.libsdl.org/moin.cgi/SDL_FreeRW
    1.92 + * \sa http://wiki.libsdl.org/moin.cgi/SDL_AllocRW
    1.93 + */
    1.94 +int
    1.95 +rwops_testAllocFree (void)
    1.96 +{
    1.97 +   /* Allocate context */
    1.98 +   SDL_RWops *rw = SDL_AllocRW();
    1.99 +   SDLTest_AssertPass("Call to SDL_AllocRW() succeeded");
   1.100 +   SDLTest_AssertCheck(rw != NULL, "Validate result from SDL_AllocRW() is not NULL");
   1.101 +   if (rw==NULL) return TEST_ABORTED;
   1.102 +          
   1.103 +   /* Free context again */
   1.104 +   SDL_FreeRW(rw);
   1.105 +   SDLTest_AssertPass("Call to SDL_FreeRW() succeeded");
   1.106 +
   1.107 +   return TEST_COMPLETED;
   1.108 +}
   1.109 +
   1.110 +
   1.111  /* ================= Test References ================== */
   1.112  
   1.113  /* RWops test cases */
   1.114 @@ -413,9 +431,12 @@
   1.115  static const SDLTest_TestCaseReference rwopsTest7 =
   1.116  		{ (SDLTest_TestCaseFp)rwops_testFPWrite, "rwops_testFPWrite", "Test writing to file pointer", TEST_ENABLED };
   1.117  
   1.118 +static const SDLTest_TestCaseReference rwopsTest8 =
   1.119 +		{ (SDLTest_TestCaseFp)rwops_testAllocFree, "rwops_testAllocFree", "Test alloc and free of RW context", TEST_ENABLED };
   1.120 +
   1.121  /* Sequence of RWops test cases */
   1.122  static const SDLTest_TestCaseReference *rwopsTests[] =  {
   1.123 -	&rwopsTest1, &rwopsTest2, &rwopsTest3, &rwopsTest4, &rwopsTest5, &rwopsTest6, &rwopsTest7, NULL
   1.124 +	&rwopsTest1, &rwopsTest2, &rwopsTest3, &rwopsTest4, &rwopsTest5, &rwopsTest6, &rwopsTest7, &rwopsTest8, NULL
   1.125  };
   1.126  
   1.127  /* RWops test suite (global) */