test/testautomation_rwops.c
changeset 6819 afef68703f54
parent 6814 fccdef204fcf
child 6821 f36771112651
     1.1 --- a/test/testautomation_rwops.c	Mon Jan 21 03:33:42 2013 -0500
     1.2 +++ b/test/testautomation_rwops.c	Mon Jan 21 09:16:27 2013 -0800
     1.3 @@ -4,7 +4,7 @@
     1.4   *
     1.5   * Original code written by Edgar Simo "bobbens"
     1.6   * Ported by Markus Kauppila (markus.kauppila@gmail.com)
     1.7 - * Updated for SDL_test by aschiffler at ferzkopp dot net
     1.8 + * Updated and extended for SDL_test by aschiffler at ferzkopp dot net
     1.9   *
    1.10   * Released under Public Domain.
    1.11   */
    1.12 @@ -42,7 +42,7 @@
    1.13  	/* Create a test file */
    1.14  	handle = fopen(RWopsReadTestFilename, "w");
    1.15  	SDLTest_AssertCheck(handle != NULL, "Verify creation of file '%s' returned non NULL handle", RWopsReadTestFilename);
    1.16 -    if (handle == NULL) return;
    1.17 +        if (handle == NULL) return;
    1.18  
    1.19  	/* Write some known test into it */
    1.20  	writtenLen = (int)fwrite(RWopsHelloWorldTestString, 1, fileLen, handle);
    1.21 @@ -177,6 +177,7 @@
    1.22   * @brief Tests opening from memory.
    1.23   *
    1.24   * \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromMem
    1.25 + * http://wiki.libsdl.org/moin.cgi/SDL_RWClose
    1.26   */
    1.27  int
    1.28  rwops_testMem (void)
    1.29 @@ -211,6 +212,7 @@
    1.30   *
    1.31   * \sa
    1.32   * http://wiki.libsdl.org/moin.cgi/SDL_RWFromConstMem
    1.33 + * http://wiki.libsdl.org/moin.cgi/SDL_RWClose
    1.34   */
    1.35  int 
    1.36  rwops_testConstMem (void)
    1.37 @@ -241,7 +243,7 @@
    1.38   *
    1.39   * \sa
    1.40   * http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile
    1.41 - * http://wiki.libsdl.org/moin.cgi/SDL_FreeRW
    1.42 + * http://wiki.libsdl.org/moin.cgi/SDL_RWClose
    1.43   */
    1.44  int
    1.45  rwops_testFileRead(void)
    1.46 @@ -267,11 +269,11 @@
    1.47  }
    1.48  
    1.49  /**
    1.50 - * @brief Tests writing from memory.
    1.51 + * @brief Tests writing from file.
    1.52   *
    1.53   * \sa
    1.54   * http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile
    1.55 - * http://wiki.libsdl.org/moin.cgi/SDL_FreeRW
    1.56 + * http://wiki.libsdl.org/moin.cgi/SDL_RWClose
    1.57   */
    1.58  int
    1.59  rwops_testFileWrite(void)
    1.60 @@ -302,7 +304,7 @@
    1.61   *
    1.62   * \sa
    1.63   * http://wiki.libsdl.org/moin.cgi/SDL_RWFromFP
    1.64 - * http://wiki.libsdl.org/moin.cgi/SDL_FreeRW
    1.65 + * http://wiki.libsdl.org/moin.cgi/SDL_RWClose
    1.66   *
    1.67   */
    1.68  int
    1.69 @@ -345,7 +347,7 @@
    1.70   *
    1.71   * \sa
    1.72   * http://wiki.libsdl.org/moin.cgi/SDL_RWFromFP
    1.73 - * http://wiki.libsdl.org/moin.cgi/SDL_FreeRW
    1.74 + * http://wiki.libsdl.org/moin.cgi/SDL_RWClose
    1.75   *
    1.76   */
    1.77  int
    1.78 @@ -385,8 +387,8 @@
    1.79  /**
    1.80   * @brief Tests alloc and free RW context.
    1.81   *
    1.82 + * \sa http://wiki.libsdl.org/moin.cgi/SDL_AllocRW
    1.83   * \sa http://wiki.libsdl.org/moin.cgi/SDL_FreeRW
    1.84 - * \sa http://wiki.libsdl.org/moin.cgi/SDL_AllocRW
    1.85   */
    1.86  int
    1.87  rwops_testAllocFree (void)
    1.88 @@ -404,6 +406,130 @@
    1.89     return TEST_COMPLETED;
    1.90  }
    1.91  
    1.92 +/**
    1.93 + * @brief Tests writing and reading from file using endian aware functions.
    1.94 + *
    1.95 + * \sa
    1.96 + * http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile
    1.97 + * http://wiki.libsdl.org/moin.cgi/SDL_RWClose
    1.98 + * http://wiki.libsdl.org/moin.cgi/SDL_ReadBE16
    1.99 + * http://wiki.libsdl.org/moin.cgi/SDL_WriteBE16
   1.100 + */
   1.101 +int
   1.102 +rwops_testFileWriteReadEndian(void)
   1.103 +{
   1.104 +   SDL_RWops *rw;
   1.105 +   int result;
   1.106 +   int mode;
   1.107 +   size_t objectsWritten;
   1.108 +   Uint16 BE16value;
   1.109 +   Uint32 BE32value;
   1.110 +   Uint64 BE64value;
   1.111 +   Uint16 LE16value;
   1.112 +   Uint32 LE32value;
   1.113 +   Uint64 LE64value;
   1.114 +   Uint16 BE16test;
   1.115 +   Uint32 BE32test;
   1.116 +   Uint64 BE64test;
   1.117 +   Uint16 LE16test;
   1.118 +   Uint32 LE32test;
   1.119 +   Uint64 LE64test;
   1.120 +
   1.121 +   for (mode = 0; mode < 3; mode++) {
   1.122 +   
   1.123 +     /* Create test data */
   1.124 +     switch (mode) {
   1.125 +       case 0:
   1.126 +        SDLTest_Log("All 0 values");
   1.127 +        BE16value = 0;
   1.128 +        BE32value = 0;
   1.129 +        BE64value = 0;
   1.130 +        LE16value = 0;
   1.131 +        LE32value = 0;
   1.132 +        LE64value = 0;
   1.133 +        break;
   1.134 +       case 1:
   1.135 +        SDLTest_Log("All 1 values");
   1.136 +        BE16value = 1;
   1.137 +        BE32value = 1;
   1.138 +        BE64value = 1;
   1.139 +        LE16value = 1;
   1.140 +        LE32value = 1;
   1.141 +        LE64value = 1;
   1.142 +        break;
   1.143 +       case 2:
   1.144 +        SDLTest_Log("Random values");
   1.145 +        BE16value = SDLTest_RandomUint16();
   1.146 +        BE32value = SDLTest_RandomUint32();
   1.147 +        BE64value = SDLTest_RandomUint64();
   1.148 +        LE16value = SDLTest_RandomUint16();
   1.149 +        LE32value = SDLTest_RandomUint32();
   1.150 +        LE64value = SDLTest_RandomUint64();
   1.151 +        break;
   1.152 +     }
   1.153 +   
   1.154 +     /* Write test. */
   1.155 +     rw = SDL_RWFromFile(RWopsWriteTestFilename, "w+");
   1.156 +     SDLTest_AssertPass("Call to SDL_RWFromFile(..,\"w+\")");
   1.157 +     SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFile in write mode does not return NULL");
   1.158 +
   1.159 +     // Bail out if NULL
   1.160 +     if (rw == NULL) return TEST_ABORTED;
   1.161 +
   1.162 +     /* Write test data */
   1.163 +     objectsWritten = SDL_WriteBE16(rw, BE16value);
   1.164 +     SDLTest_AssertPass("Call to SDL_WriteBE16");
   1.165 +     SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", objectsWritten);   
   1.166 +     objectsWritten = SDL_WriteBE32(rw, BE32value);
   1.167 +     SDLTest_AssertPass("Call to SDL_WriteBE32");
   1.168 +     SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", objectsWritten);   
   1.169 +     objectsWritten = SDL_WriteBE64(rw, BE64value);
   1.170 +     SDLTest_AssertPass("Call to SDL_WriteBE64");
   1.171 +     SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", objectsWritten);   
   1.172 +     objectsWritten = SDL_WriteLE16(rw, LE16value);
   1.173 +     SDLTest_AssertPass("Call to SDL_WriteLE16");
   1.174 +     SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", objectsWritten);   
   1.175 +     objectsWritten = SDL_WriteLE32(rw, LE32value);
   1.176 +     SDLTest_AssertPass("Call to SDL_WriteLE32");
   1.177 +     SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", objectsWritten);   
   1.178 +     objectsWritten = SDL_WriteLE64(rw, LE64value);
   1.179 +     SDLTest_AssertPass("Call to SDL_WriteLE64");
   1.180 +     SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", objectsWritten);   
   1.181 +
   1.182 +     /* Test seek to start */
   1.183 +     result = SDL_RWseek( rw, 0, RW_SEEK_SET );
   1.184 +     SDLTest_AssertPass("Call to SDL_RWseek succeeded");
   1.185 +     SDLTest_AssertCheck(result == 0, "Verify result from position 0 with SDL_RWseek, expected 0, got %i", result);
   1.186 +
   1.187 +     /* Read test data */
   1.188 +     BE16test = SDL_ReadBE16(rw);
   1.189 +     SDLTest_AssertPass("Call to SDL_ReadBE16");
   1.190 +     SDLTest_AssertCheck(BE16test == BE16value, "Validate return value from SDL_ReadBE16, expected: %hu, got: %hu", BE16value, BE16test);
   1.191 +     BE32test = SDL_ReadBE32(rw);
   1.192 +     SDLTest_AssertPass("Call to SDL_ReadBE32");
   1.193 +     SDLTest_AssertCheck(BE32test == BE32value, "Validate return value from SDL_ReadBE32, expected: %u, got: %u", BE32value, BE32test);   
   1.194 +     BE64test = SDL_ReadBE64(rw);
   1.195 +     SDLTest_AssertPass("Call to SDL_ReadBE64");
   1.196 +     SDLTest_AssertCheck(BE64test == BE64value, "Validate return value from SDL_ReadBE64, expected: %llu, got: %llu", BE64value, BE64test);   
   1.197 +     LE16test = SDL_ReadLE16(rw);
   1.198 +     SDLTest_AssertPass("Call to SDL_ReadLE16");
   1.199 +     SDLTest_AssertCheck(LE16test == LE16value, "Validate return value from SDL_ReadLE16, expected: %hu, got: %hu", LE16value, LE16test);
   1.200 +     LE32test = SDL_ReadLE32(rw);
   1.201 +     SDLTest_AssertPass("Call to SDL_ReadLE32");
   1.202 +     SDLTest_AssertCheck(LE32test == LE32value, "Validate return value from SDL_ReadLE32, expected: %u, got: %u", LE32value, LE32test);   
   1.203 +     LE64test = SDL_ReadLE64(rw);
   1.204 +     SDLTest_AssertPass("Call to SDL_ReadLE64");
   1.205 +     SDLTest_AssertCheck(LE64test == LE64value, "Validate return value from SDL_ReadLE64, expected: %llu, got: %llu", LE64value, LE64test);
   1.206 +
   1.207 +     /* Close handle */
   1.208 +     SDL_RWclose(rw);
   1.209 +     SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
   1.210 +   
   1.211 +   }
   1.212 +
   1.213 +   return TEST_COMPLETED;
   1.214 +}
   1.215 +
   1.216  
   1.217  /* ================= Test References ================== */
   1.218  
   1.219 @@ -432,9 +558,13 @@
   1.220  static const SDLTest_TestCaseReference rwopsTest8 =
   1.221  		{ (SDLTest_TestCaseFp)rwops_testAllocFree, "rwops_testAllocFree", "Test alloc and free of RW context", TEST_ENABLED };
   1.222  
   1.223 +static const SDLTest_TestCaseReference rwopsTest9 =
   1.224 +		{ (SDLTest_TestCaseFp)rwops_testFileWriteReadEndian, "rwops_testFileWriteReadEndian", "Test writing and reading via the Endian aware functions", TEST_ENABLED };
   1.225 +
   1.226  /* Sequence of RWops test cases */
   1.227  static const SDLTest_TestCaseReference *rwopsTests[] =  {
   1.228 -	&rwopsTest1, &rwopsTest2, &rwopsTest3, &rwopsTest4, &rwopsTest5, &rwopsTest6, &rwopsTest7, &rwopsTest8, NULL
   1.229 +	&rwopsTest1, &rwopsTest2, &rwopsTest3, &rwopsTest4, &rwopsTest5, &rwopsTest6, 
   1.230 +	&rwopsTest7, &rwopsTest8, &rwopsTest9, NULL
   1.231  };
   1.232  
   1.233  /* RWops test suite (global) */