Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
authorAndreas Schiffler <aschiffler@ferzkopp.net>
Mon, 21 Jan 2013 09:16:27 -0800
changeset 6819 afef68703f54
parent 6818 6f17d1353ffa
child 6820 0ce561f6c805
Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops)
src/audio/SDL_audiocvt.c
test/testautomation_audio.c
test/testautomation_rwops.c
--- a/src/audio/SDL_audiocvt.c	Mon Jan 21 03:33:42 2013 -0500
+++ b/src/audio/SDL_audiocvt.c	Mon Jan 21 09:16:27 2013 -0800
@@ -968,6 +968,12 @@
      * !!! FIXME: good in practice as it sounds in theory, though.
      */
 
+    /* Sanity check target pointer */
+    if (cvt == NULL) {
+        SDL_InvalidParamError("cvt");
+        return -1;
+    }
+    
     /* there are no unsigned types over 16 bits, so catch this up front. */
     if ((SDL_AUDIO_BITSIZE(src_fmt) > 16) && (!SDL_AUDIO_ISSIGNED(src_fmt))) {
         SDL_SetError("Invalid source format");
@@ -979,6 +985,10 @@
     }
 
     /* prevent possible divisions by zero, etc. */
+    if ((src_channels == 0) || (dst_channels == 0)) {
+        SDL_SetError("Source or destination channels is zero");
+        return -1;
+    }
     if ((src_rate == 0) || (dst_rate == 0)) {
         SDL_SetError("Source or destination rate is zero");
         return -1;
--- a/test/testautomation_audio.c	Mon Jan 21 03:33:42 2013 -0500
+++ b/test/testautomation_audio.c	Mon Jan 21 09:16:27 2013 -0800
@@ -4,6 +4,7 @@
  */
 
 #include <stdio.h>
+#include <string.h>
 
 #include "SDL.h"
 #include "SDL_test.h"
@@ -133,7 +134,10 @@
 
 
 /**
- * @brief Checks available audio driver names.
+ * \brief Checks available audio driver names.
+ *
+ * \sa http://wiki.libsdl.org/moin.cgi/SDL_GetNumAudioDrivers
+ * \sa http://wiki.libsdl.org/moin.cgi/SDL_GetAudioDriver
  */
 int audio_printAudioDrivers()
 {
@@ -163,7 +167,9 @@
 
 
 /**
- * @brief Checks current audio driver name with initialized audio.
+ * \brief Checks current audio driver name with initialized audio.
+ *
+ * \sa http://wiki.libsdl.org/moin.cgi/SDL_GetCurrentAudioDriver
  */
 int audio_printCurrentAudioDriver()
 {
@@ -180,6 +186,316 @@
    return TEST_COMPLETED;
 }
 
+
+/**
+ * \brief Builds various audio conversion structures
+ *
+ * \sa http://wiki.libsdl.org/moin.cgi/SDL_BuildAudioCVT
+ */
+int audio_buildAudioCVT()
+{
+  int result;
+  SDL_AudioCVT  cvt;
+  SDL_AudioSpec spec1;
+  SDL_AudioSpec spec2;
+  int i, j, k;
+  const int numFormats = 18;
+  SDL_AudioFormat formats[] = { AUDIO_S8, AUDIO_U8, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_S16SYS, AUDIO_S16, AUDIO_U16LSB, 
+                                AUDIO_U16MSB, AUDIO_U16SYS, AUDIO_U16, AUDIO_S32LSB, AUDIO_S32MSB, AUDIO_S32SYS, AUDIO_S32, 
+                                AUDIO_F32LSB, AUDIO_F32MSB, AUDIO_F32SYS, AUDIO_F32 };
+  const int numChannels = 4;
+  Uint8 channels[] = { 1, 2, 4, 6 };
+  const int numFrequencies = 4;
+  int frequencies[] = { 11025, 22050, 44100, 48000 };
+  
+  /* No conversion needed */
+  spec1.format = AUDIO_S16LSB;
+  spec1.channels = 2;
+  spec1.freq = 22050;
+  result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
+                                   spec1.format, spec1.channels, spec1.freq);
+  SDLTest_AssertPass("Call to SDL_BuildAudioCVT(spec1 ==> spec1)");
+  SDLTest_AssertCheck(result == 0, "Verify result value; expected: 0, got: %i", result);
+
+  /* Typical conversion */
+  spec1.format = AUDIO_S8;
+  spec1.channels = 1;
+  spec1.freq = 22050;
+  spec2.format = AUDIO_S16LSB;
+  spec2.channels = 2;
+  spec2.freq = 44100;  
+  result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
+                                   spec2.format, spec2.channels, spec2.freq);
+  SDLTest_AssertPass("Call to SDL_BuildAudioCVT(spec1 ==> spec2)");
+  SDLTest_AssertCheck(result == 1, "Verify result value; expected: 1, got: %i", result);
+
+  /* All source conversions with random conversion targets */
+  for (i=0; i<numFormats; i++) {
+    for (j=0; j<numChannels; j++) {
+      for (k=0; k<numFrequencies; k++) {
+        spec1.format = formats[i];
+        spec1.channels = channels[j];
+        spec1.freq = frequencies[k];
+        spec2.format = formats[SDLTest_RandomIntegerInRange(0, numFormats - 1)];
+        spec2.channels = channels[SDLTest_RandomIntegerInRange(0, numChannels - 1)];
+        spec2.freq = frequencies[SDLTest_RandomIntegerInRange(0, numFrequencies - 1)];
+        result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
+                                        spec2.format, spec2.channels, spec2.freq);
+        SDLTest_AssertPass("Call to SDL_BuildAudioCVT(format=%i,channels=%i,freq=%i ==> format=%i,channels=%i,freq=%i)", 
+            spec1.format, spec1.channels, spec1.freq, spec2.format, spec2.channels, spec2.freq);
+        SDLTest_AssertCheck(result == 0 || result == 1, "Verify result value; expected: 0 or 1, got: %i", result);
+        if (result<0) {
+          SDLTest_LogError(SDL_GetError());
+        }
+      }
+    }
+  }
+
+   return TEST_COMPLETED;
+}
+
+/**
+ * \brief Checkes calls with invalid input to SDL_BuildAudioCVT
+ *
+ * \sa http://wiki.libsdl.org/moin.cgi/SDL_BuildAudioCVT
+ */
+int audio_buildAudioCVTNegative()
+{
+  const char *expectedError = "Parameter 'cvt' is invalid";
+  const char *error;   
+  int result;
+  SDL_AudioCVT  cvt;
+  SDL_AudioSpec spec1;
+  SDL_AudioSpec spec2;
+  int i;
+  char message[256];
+
+  /* Valid format */  
+  spec1.format = AUDIO_S8;
+  spec1.channels = 1;
+  spec1.freq = 22050;
+  spec2.format = AUDIO_S16LSB;
+  spec2.channels = 2;
+  spec2.freq = 44100;  
+
+  SDL_ClearError();
+  SDLTest_AssertPass("Call to SDL_ClearError()");
+
+  /* NULL input for CVT buffer */
+  result = SDL_BuildAudioCVT((SDL_AudioCVT *)NULL, spec1.format, spec1.channels, spec1.freq,
+                                                   spec2.format, spec2.channels, spec2.freq);
+  SDLTest_AssertPass("Call to SDL_BuildAudioCVT(NULL,...)");
+  SDLTest_AssertCheck(result == -1, "Verify result value; expected: -1, got: %i", result); 
+  error = SDL_GetError();
+  SDLTest_AssertPass("Call to SDL_GetError()");
+  SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
+  if (error != NULL) {
+      SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0, 
+          "Validate error message, expected: '%s', got: '%s'", expectedError, error);
+  }
+
+  /* Invalid conversions */
+  for (i = 1; i < 64; i++) {
+    /* Valid format to start with */  
+    spec1.format = AUDIO_S8;
+    spec1.channels = 1;
+    spec1.freq = 22050;
+    spec2.format = AUDIO_S16LSB;
+    spec2.channels = 2;
+    spec2.freq = 44100;  
+
+    SDL_ClearError();
+    SDLTest_AssertPass("Call to SDL_ClearError()");
+   
+    /* Set various invalid format inputs */
+    strcpy(message, "Invalid: ");
+    if (i & 1) {
+        strcat(message, " spec1.format");
+        spec1.format = 0;
+    }
+    if (i & 2) { 
+        strcat(message, " spec1.channels");
+        spec1.channels = 0;
+    }
+    if (i & 4) { 
+        strcat(message, " spec1.freq");
+        spec1.freq = 0;
+    }
+    if (i & 8) { 
+        strcat(message, " spec2.format");
+        spec2.format = 0;
+    }
+    if (i & 16) { 
+        strcat(message, " spec2.channels");
+        spec2.channels = 0;
+    }
+    if (i & 32) { 
+        strcat(message, " spec2.freq");
+        spec2.freq = 0;
+    }
+    SDLTest_Log(message);
+    result = SDL_BuildAudioCVT(&cvt, spec1.format, spec1.channels, spec1.freq,
+                                   spec2.format, spec2.channels, spec2.freq);
+    SDLTest_AssertPass("Call to SDL_BuildAudioCVT(spec1 ==> spec2)");
+    SDLTest_AssertCheck(result == -1, "Verify result value; expected: -1, got: %i", result);
+    error = SDL_GetError();
+    SDLTest_AssertPass("Call to SDL_GetError()");
+    SDLTest_AssertCheck(error != NULL && SDL_strlen(error)>0, "Validate that error message was not NULL or empty");
+  }
+
+  SDL_ClearError();
+  SDLTest_AssertPass("Call to SDL_ClearError()");
+                                                
+  return TEST_COMPLETED;
+}
+
+/**
+ * \brief Checks current audio status.
+ *
+ * \sa http://wiki.libsdl.org/moin.cgi/SDL_GetAudioStatus
+ */
+int audio_getAudioStatus()
+{
+   SDL_AudioStatus result;
+
+   /* Check current audio status */
+   result = SDL_GetAudioStatus();
+   SDLTest_AssertPass("Call to SDL_GetAudioStatus()");
+   SDLTest_AssertCheck(result == SDL_AUDIO_STOPPED || result == SDL_AUDIO_PLAYING || result == SDL_AUDIO_PAUSED,
+        "Verify returned value; expected: STOPPED (%i) | PLAYING (%i) | PAUSED (%i), got: %i", 
+        SDL_AUDIO_STOPPED, SDL_AUDIO_PLAYING, SDL_AUDIO_PAUSED, result);
+
+   return TEST_COMPLETED;
+}
+
+
+/* Test callback function */
+void _audio_testCallback(void *userdata, Uint8 *stream, int len)
+{
+}
+
+/**
+ * \brief Opens, checks current audio status, and closes a device.
+ *
+ * \sa http://wiki.libsdl.org/moin.cgi/SDL_GetAudioStatus
+ */
+int audio_openCloseAndGetAudioStatus()
+{
+   SDL_AudioStatus result;
+   int i;
+   int count;
+   char *device;   
+   SDL_AudioDeviceID id;
+   SDL_AudioSpec desired, obtained;
+   
+   /* Get number of devices. */
+   count = SDL_GetNumAudioDevices(0);
+   SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
+   if (count>0) {
+     for (i=0; i< count; i++) {
+       /* Get device name */
+       device = (char *)SDL_GetAudioDeviceName(i, 0);
+       SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
+       SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
+       if (device == NULL) return TEST_ABORTED;
+
+       /* Set standard desired spec */
+       desired.freq=22050;
+       desired.format=AUDIO_S16SYS;
+       desired.channels=2;
+       desired.samples=4096;
+       desired.callback=_audio_testCallback;
+       desired.userdata=NULL;
+       
+       /* Open device */
+       id = SDL_OpenAudioDevice((const char *)device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
+       SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
+       SDLTest_AssertCheck(id > 1, "Validate device ID; expected: >=2, got: %i", id);
+       if (id > 1) {
+     
+         /* Check device audio status */
+         result = SDL_GetAudioDeviceStatus(id);
+         SDLTest_AssertPass("Call to SDL_GetAudioDeviceStatus()");
+         SDLTest_AssertCheck(result == SDL_AUDIO_STOPPED || result == SDL_AUDIO_PLAYING || result == SDL_AUDIO_PAUSED,
+            "Verify returned value; expected: STOPPED (%i) | PLAYING (%i) | PAUSED (%i), got: %i", 
+            SDL_AUDIO_STOPPED, SDL_AUDIO_PLAYING, SDL_AUDIO_PAUSED, result);         
+         
+         /* Close device again */
+         SDL_CloseAudioDevice(id);
+         SDLTest_AssertPass("Call to SDL_CloseAudioDevice()");
+       }
+     }
+   } else {
+     SDLTest_Log("No devices to test with");
+   }
+   
+   return TEST_COMPLETED;
+}
+
+/**
+ * \brief Locks and unlocks open audio device.
+ *
+ * \sa http://wiki.libsdl.org/moin.cgi/SDL_LockAudioDevice
+ * \sa http://wiki.libsdl.org/moin.cgi/SDL_UnlockAudioDevice
+ */
+int audio_lockUnlockOpenAudioDevice()
+{
+   int i;
+   int count;
+   char *device;   
+   SDL_AudioDeviceID id;
+   SDL_AudioSpec desired, obtained;
+   
+   /* Get number of devices. */
+   count = SDL_GetNumAudioDevices(0);
+   SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
+   if (count>0) {
+     for (i=0; i< count; i++) {
+       /* Get device name */
+       device = (char *)SDL_GetAudioDeviceName(i, 0);
+       SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
+       SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
+       if (device == NULL) return TEST_ABORTED;
+
+       /* Set standard desired spec */
+       desired.freq=22050;
+       desired.format=AUDIO_S16SYS;
+       desired.channels=2;
+       desired.samples=4096;
+       desired.callback=_audio_testCallback;
+       desired.userdata=NULL;
+       
+       /* Open device */
+       id = SDL_OpenAudioDevice((const char *)device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
+       SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
+       SDLTest_AssertCheck(id > 1, "Validate device ID; expected: >=2, got: %i", id);
+       if (id > 1) {     
+         /* Lock to protect callback */
+         SDL_LockAudioDevice(id);
+         SDLTest_AssertPass("SDL_LockAudioDevice(%i)", id);
+         
+         /* Simulate callback processing */
+         SDL_Delay(10);
+         SDLTest_Log("Simulate callback processing - delay");
+         
+         /* Unlock again*/         
+         SDL_UnlockAudioDevice(id);
+         SDLTest_AssertPass("SDL_UnlockAudioDevice(%i)", id);         
+         
+         /* Close device again */
+         SDL_CloseAudioDevice(id);
+         SDLTest_AssertPass("Call to SDL_CloseAudioDevice()");
+       }
+     }
+   } else {
+     SDLTest_Log("No devices to test with");
+   }
+   
+   return TEST_COMPLETED;
+}
+
+
+
 /* ================= Test Case References ================== */
 
 /* Audio test cases */
@@ -195,9 +511,24 @@
 static const SDLTest_TestCaseReference audioTest4 =
 		{ (SDLTest_TestCaseFp)audio_printCurrentAudioDriver, "audio_printCurrentAudioDriver", "Checks current audio driver name with initialized audio.", TEST_ENABLED };
 
+static const SDLTest_TestCaseReference audioTest5 =
+		{ (SDLTest_TestCaseFp)audio_buildAudioCVT, "audio_buildAudioCVT", "Builds various audio conversion structures.", TEST_ENABLED };
+
+static const SDLTest_TestCaseReference audioTest6 =
+		{ (SDLTest_TestCaseFp)audio_buildAudioCVTNegative, "audio_buildAudioCVTNegative", "Checks calls with invalid input to SDL_BuildAudioCVT", TEST_ENABLED };
+
+static const SDLTest_TestCaseReference audioTest7 =
+		{ (SDLTest_TestCaseFp)audio_getAudioStatus, "audio_getAudioStatus", "Checks current audio status.", TEST_ENABLED };
+
+static const SDLTest_TestCaseReference audioTest8 =
+		{ (SDLTest_TestCaseFp)audio_openCloseAndGetAudioStatus, "audio_openCloseAndGetAudioStatus", "Opens and closes audio device and get audio status.", TEST_ENABLED };
+
+static const SDLTest_TestCaseReference audioTest9 =
+		{ (SDLTest_TestCaseFp)audio_lockUnlockOpenAudioDevice, "audio_lockUnlockOpenAudioDevice", "Locks and unlocks an open audio device.", TEST_ENABLED };
+
 /* Sequence of Audio test cases */
 static const SDLTest_TestCaseReference *audioTests[] =  {
-	&audioTest1, &audioTest2, &audioTest3, &audioTest4, NULL
+	&audioTest1, &audioTest2, &audioTest3, &audioTest4, &audioTest5, &audioTest6, &audioTest7, &audioTest8, &audioTest9, NULL
 };
 
 /* Audio test suite (global) */
--- a/test/testautomation_rwops.c	Mon Jan 21 03:33:42 2013 -0500
+++ b/test/testautomation_rwops.c	Mon Jan 21 09:16:27 2013 -0800
@@ -4,7 +4,7 @@
  *
  * Original code written by Edgar Simo "bobbens"
  * Ported by Markus Kauppila (markus.kauppila@gmail.com)
- * Updated for SDL_test by aschiffler at ferzkopp dot net
+ * Updated and extended for SDL_test by aschiffler at ferzkopp dot net
  *
  * Released under Public Domain.
  */
@@ -42,7 +42,7 @@
 	/* Create a test file */
 	handle = fopen(RWopsReadTestFilename, "w");
 	SDLTest_AssertCheck(handle != NULL, "Verify creation of file '%s' returned non NULL handle", RWopsReadTestFilename);
-    if (handle == NULL) return;
+        if (handle == NULL) return;
 
 	/* Write some known test into it */
 	writtenLen = (int)fwrite(RWopsHelloWorldTestString, 1, fileLen, handle);
@@ -177,6 +177,7 @@
  * @brief Tests opening from memory.
  *
  * \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromMem
+ * http://wiki.libsdl.org/moin.cgi/SDL_RWClose
  */
 int
 rwops_testMem (void)
@@ -211,6 +212,7 @@
  *
  * \sa
  * http://wiki.libsdl.org/moin.cgi/SDL_RWFromConstMem
+ * http://wiki.libsdl.org/moin.cgi/SDL_RWClose
  */
 int 
 rwops_testConstMem (void)
@@ -241,7 +243,7 @@
  *
  * \sa
  * http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile
- * http://wiki.libsdl.org/moin.cgi/SDL_FreeRW
+ * http://wiki.libsdl.org/moin.cgi/SDL_RWClose
  */
 int
 rwops_testFileRead(void)
@@ -267,11 +269,11 @@
 }
 
 /**
- * @brief Tests writing from memory.
+ * @brief Tests writing from file.
  *
  * \sa
  * http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile
- * http://wiki.libsdl.org/moin.cgi/SDL_FreeRW
+ * http://wiki.libsdl.org/moin.cgi/SDL_RWClose
  */
 int
 rwops_testFileWrite(void)
@@ -302,7 +304,7 @@
  *
  * \sa
  * http://wiki.libsdl.org/moin.cgi/SDL_RWFromFP
- * http://wiki.libsdl.org/moin.cgi/SDL_FreeRW
+ * http://wiki.libsdl.org/moin.cgi/SDL_RWClose
  *
  */
 int
@@ -345,7 +347,7 @@
  *
  * \sa
  * http://wiki.libsdl.org/moin.cgi/SDL_RWFromFP
- * http://wiki.libsdl.org/moin.cgi/SDL_FreeRW
+ * http://wiki.libsdl.org/moin.cgi/SDL_RWClose
  *
  */
 int
@@ -385,8 +387,8 @@
 /**
  * @brief Tests alloc and free RW context.
  *
+ * \sa http://wiki.libsdl.org/moin.cgi/SDL_AllocRW
  * \sa http://wiki.libsdl.org/moin.cgi/SDL_FreeRW
- * \sa http://wiki.libsdl.org/moin.cgi/SDL_AllocRW
  */
 int
 rwops_testAllocFree (void)
@@ -404,6 +406,130 @@
    return TEST_COMPLETED;
 }
 
+/**
+ * @brief Tests writing and reading from file using endian aware functions.
+ *
+ * \sa
+ * http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile
+ * http://wiki.libsdl.org/moin.cgi/SDL_RWClose
+ * http://wiki.libsdl.org/moin.cgi/SDL_ReadBE16
+ * http://wiki.libsdl.org/moin.cgi/SDL_WriteBE16
+ */
+int
+rwops_testFileWriteReadEndian(void)
+{
+   SDL_RWops *rw;
+   int result;
+   int mode;
+   size_t objectsWritten;
+   Uint16 BE16value;
+   Uint32 BE32value;
+   Uint64 BE64value;
+   Uint16 LE16value;
+   Uint32 LE32value;
+   Uint64 LE64value;
+   Uint16 BE16test;
+   Uint32 BE32test;
+   Uint64 BE64test;
+   Uint16 LE16test;
+   Uint32 LE32test;
+   Uint64 LE64test;
+
+   for (mode = 0; mode < 3; mode++) {
+   
+     /* Create test data */
+     switch (mode) {
+       case 0:
+        SDLTest_Log("All 0 values");
+        BE16value = 0;
+        BE32value = 0;
+        BE64value = 0;
+        LE16value = 0;
+        LE32value = 0;
+        LE64value = 0;
+        break;
+       case 1:
+        SDLTest_Log("All 1 values");
+        BE16value = 1;
+        BE32value = 1;
+        BE64value = 1;
+        LE16value = 1;
+        LE32value = 1;
+        LE64value = 1;
+        break;
+       case 2:
+        SDLTest_Log("Random values");
+        BE16value = SDLTest_RandomUint16();
+        BE32value = SDLTest_RandomUint32();
+        BE64value = SDLTest_RandomUint64();
+        LE16value = SDLTest_RandomUint16();
+        LE32value = SDLTest_RandomUint32();
+        LE64value = SDLTest_RandomUint64();
+        break;
+     }
+   
+     /* Write test. */
+     rw = SDL_RWFromFile(RWopsWriteTestFilename, "w+");
+     SDLTest_AssertPass("Call to SDL_RWFromFile(..,\"w+\")");
+     SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFile in write mode does not return NULL");
+
+     // Bail out if NULL
+     if (rw == NULL) return TEST_ABORTED;
+
+     /* Write test data */
+     objectsWritten = SDL_WriteBE16(rw, BE16value);
+     SDLTest_AssertPass("Call to SDL_WriteBE16");
+     SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", objectsWritten);   
+     objectsWritten = SDL_WriteBE32(rw, BE32value);
+     SDLTest_AssertPass("Call to SDL_WriteBE32");
+     SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", objectsWritten);   
+     objectsWritten = SDL_WriteBE64(rw, BE64value);
+     SDLTest_AssertPass("Call to SDL_WriteBE64");
+     SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", objectsWritten);   
+     objectsWritten = SDL_WriteLE16(rw, LE16value);
+     SDLTest_AssertPass("Call to SDL_WriteLE16");
+     SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", objectsWritten);   
+     objectsWritten = SDL_WriteLE32(rw, LE32value);
+     SDLTest_AssertPass("Call to SDL_WriteLE32");
+     SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", objectsWritten);   
+     objectsWritten = SDL_WriteLE64(rw, LE64value);
+     SDLTest_AssertPass("Call to SDL_WriteLE64");
+     SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", objectsWritten);   
+
+     /* Test seek to start */
+     result = SDL_RWseek( rw, 0, RW_SEEK_SET );
+     SDLTest_AssertPass("Call to SDL_RWseek succeeded");
+     SDLTest_AssertCheck(result == 0, "Verify result from position 0 with SDL_RWseek, expected 0, got %i", result);
+
+     /* Read test data */
+     BE16test = SDL_ReadBE16(rw);
+     SDLTest_AssertPass("Call to SDL_ReadBE16");
+     SDLTest_AssertCheck(BE16test == BE16value, "Validate return value from SDL_ReadBE16, expected: %hu, got: %hu", BE16value, BE16test);
+     BE32test = SDL_ReadBE32(rw);
+     SDLTest_AssertPass("Call to SDL_ReadBE32");
+     SDLTest_AssertCheck(BE32test == BE32value, "Validate return value from SDL_ReadBE32, expected: %u, got: %u", BE32value, BE32test);   
+     BE64test = SDL_ReadBE64(rw);
+     SDLTest_AssertPass("Call to SDL_ReadBE64");
+     SDLTest_AssertCheck(BE64test == BE64value, "Validate return value from SDL_ReadBE64, expected: %llu, got: %llu", BE64value, BE64test);   
+     LE16test = SDL_ReadLE16(rw);
+     SDLTest_AssertPass("Call to SDL_ReadLE16");
+     SDLTest_AssertCheck(LE16test == LE16value, "Validate return value from SDL_ReadLE16, expected: %hu, got: %hu", LE16value, LE16test);
+     LE32test = SDL_ReadLE32(rw);
+     SDLTest_AssertPass("Call to SDL_ReadLE32");
+     SDLTest_AssertCheck(LE32test == LE32value, "Validate return value from SDL_ReadLE32, expected: %u, got: %u", LE32value, LE32test);   
+     LE64test = SDL_ReadLE64(rw);
+     SDLTest_AssertPass("Call to SDL_ReadLE64");
+     SDLTest_AssertCheck(LE64test == LE64value, "Validate return value from SDL_ReadLE64, expected: %llu, got: %llu", LE64value, LE64test);
+
+     /* Close handle */
+     SDL_RWclose(rw);
+     SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
+   
+   }
+
+   return TEST_COMPLETED;
+}
+
 
 /* ================= Test References ================== */
 
@@ -432,9 +558,13 @@
 static const SDLTest_TestCaseReference rwopsTest8 =
 		{ (SDLTest_TestCaseFp)rwops_testAllocFree, "rwops_testAllocFree", "Test alloc and free of RW context", TEST_ENABLED };
 
+static const SDLTest_TestCaseReference rwopsTest9 =
+		{ (SDLTest_TestCaseFp)rwops_testFileWriteReadEndian, "rwops_testFileWriteReadEndian", "Test writing and reading via the Endian aware functions", TEST_ENABLED };
+
 /* Sequence of RWops test cases */
 static const SDLTest_TestCaseReference *rwopsTests[] =  {
-	&rwopsTest1, &rwopsTest2, &rwopsTest3, &rwopsTest4, &rwopsTest5, &rwopsTest6, &rwopsTest7, &rwopsTest8, NULL
+	&rwopsTest1, &rwopsTest2, &rwopsTest3, &rwopsTest4, &rwopsTest5, &rwopsTest6, 
+	&rwopsTest7, &rwopsTest8, &rwopsTest9, NULL
 };
 
 /* RWops test suite (global) */