Add new test suites (events, keyboard, syswm, video) with a few new tests each
authorAndreas Schiffler <aschiffler@ferzkopp.net>
Sun, 06 Jan 2013 15:17:59 -0800
changeset 6800 26c6795ec1a4
parent 6799 ddf4df4dfdd6
child 6801 f92e3d5f71a2
Add new test suites (events, keyboard, syswm, video) with a few new tests each
VisualC/tests/testautomation/testautomation_vs2010.vcxproj
VisualC/tests/testautomation/testautomation_vs2012.vcxproj
test/Makefile.in
test/testautomation_events.c
test/testautomation_keyboard.c
test/testautomation_suites.h
test/testautomation_syswm.c
test/testautomation_video.c
--- a/VisualC/tests/testautomation/testautomation_vs2010.vcxproj	Mon Dec 31 19:22:05 2012 -0800
+++ b/VisualC/tests/testautomation/testautomation_vs2010.vcxproj	Sun Jan 06 15:17:59 2013 -0800
@@ -184,6 +184,10 @@
     <ClCompile Include="..\..\..\test\testautomation_render.c" />
     <ClCompile Include="..\..\..\test\testautomation_rwops.c" />
     <ClCompile Include="..\..\..\test\testautomation_surface.c" />
+    <ClCompile Include="..\..\..\test\testautomation_events.c" />
+    <ClCompile Include="..\..\..\test\testautomation_keyboard.c" />
+    <ClCompile Include="..\..\..\test\testautomation_video.c" />
+    <ClCompile Include="..\..\..\test\testautomation_syswm.c" />
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\..\test\testautomation_suites.h" />
--- a/VisualC/tests/testautomation/testautomation_vs2012.vcxproj	Mon Dec 31 19:22:05 2012 -0800
+++ b/VisualC/tests/testautomation/testautomation_vs2012.vcxproj	Sun Jan 06 15:17:59 2013 -0800
@@ -188,6 +188,10 @@
     <ClCompile Include="..\..\..\test\testautomation_render.c" />
     <ClCompile Include="..\..\..\test\testautomation_rwops.c" />
     <ClCompile Include="..\..\..\test\testautomation_surface.c" />
+    <ClCompile Include="..\..\..\test\testautomation_events.c" />
+    <ClCompile Include="..\..\..\test\testautomation_keyboard.c" />
+    <ClCompile Include="..\..\..\test\testautomation_video.c" />
+    <ClCompile Include="..\..\..\test\testautomation_syswm.c" />
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\..\test\testautomation_suites.h" />
--- a/test/Makefile.in	Mon Dec 31 19:22:05 2012 -0800
+++ b/test/Makefile.in	Sun Jan 06 15:17:59 2013 -0800
@@ -75,7 +75,11 @@
 		      $(srcdir)/testautomation_render.c \
 		      $(srcdir)/testautomation_rwops.c \
 		      $(srcdir)/testautomation_audio.c \
-		      $(srcdir)/testautomation_surface.c
+		      $(srcdir)/testautomation_surface.c \
+		      $(srcdir)/testautomation_events.c \
+		      $(srcdir)/testautomation_keyboard.c \
+		      $(srcdir)/testautomation_video.c \
+		      $(srcdir)/testautomation_syswm.c
 	$(CC) -o $@ $^ $(CFLAGS) -lSDL2_test $(LIBS) 
 
 testmultiaudio$(EXE): $(srcdir)/testmultiaudio.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/testautomation_events.c	Sun Jan 06 15:17:59 2013 -0800
@@ -0,0 +1,201 @@
+/**
+ * Events test suite
+ */
+
+#include <stdio.h>
+
+#include "SDL.h"
+#include "SDL_test.h"
+
+/* ================= Test Case Implementation ================== */
+
+/* Test case functions */
+
+/* Flag indicating if the userdata should be checked */
+int _userdataCheck = 0;
+
+/* Userdata value to check */
+int _userdataValue = 0;
+
+/* Flag indicating that the filter was called */
+int _eventFilterCalled = 0;
+
+/* Userdata values for event */
+int _userdataValue1 = 1;
+int _userdataValue2 = 2;
+
+/* Event filter that sets some flags and optionally checks userdata */
+int _events_sampleNullEventFilter(void *userdata, SDL_Event *event)
+{
+   _eventFilterCalled = 1;
+   
+   if (_userdataCheck != 0) {
+       SDLTest_AssertCheck(userdata != NULL, "Check userdata pointer, expected: non-NULL, got: %s", (userdata != NULL) ? "non-NULL" : "NULL");
+       if (userdata != NULL) {
+          SDLTest_AssertCheck(*(int *)userdata == _userdataValue, "Check userdata value, expected: %i, got: %i", _userdataValue, *(int *)userdata);
+       }
+   }
+   
+   return 0;
+}
+
+/**
+ * @brief Test pumping and peeking events.
+ *
+ * @sa http://wiki.libsdl.org/moin.cgi/SDL_PumpEvents
+ * @sa http://wiki.libsdl.org/moin.cgi/SDL_PollEvent
+ */
+int
+events_pushPumpAndPollUserevent(void *arg)
+{
+   SDL_Event event1;
+   SDL_Event event2;
+   int result;
+   
+   /* Create user event */
+   event1.type = SDL_USEREVENT;
+   event1.user.code = SDLTest_RandomSint32();
+   event1.user.data1 = (void *)&_userdataValue1;
+   event1.user.data2 = (void *)&_userdataValue2;
+   
+   /* Push a user event onto the queue and force queue update*/
+   SDL_PushEvent(&event1);
+   SDLTest_AssertPass("Call to SDL_PushEvent()");
+   SDL_PumpEvents();
+   SDLTest_AssertPass("Call to SDL_PumpEvents()");
+   
+   /* Poll for user event */
+   result = SDL_PollEvent(&event2);
+   SDLTest_AssertPass("Call to SDL_PollEvent()");
+   SDLTest_AssertCheck(result == 1, "Check result from SDL_PollEvent, expected: 1, got: %d", result);
+   
+   return TEST_COMPLETED;
+}
+
+
+/**
+ * @brief Adds and deletes an event watch function with NULL userdata
+ *
+ * @sa http://wiki.libsdl.org/moin.cgi/SDL_AddEventWatch
+ * @sa http://wiki.libsdl.org/moin.cgi/SDL_DelEventWatch
+ *
+ */
+int
+events_addDelEventWatch(void *arg)
+{
+   SDL_Event event;
+   
+   /* Create user event */
+   event.type = SDL_USEREVENT;
+   event.user.code = SDLTest_RandomSint32();;
+   event.user.data1 = (void *)&_userdataValue1;
+   event.user.data2 = (void *)&_userdataValue2;
+
+   /* Disable userdata check */
+   _userdataCheck = 0;
+
+   /* Reset event filter call tracker */
+   _eventFilterCalled = 0;
+
+   /* Add watch */      
+   SDL_AddEventWatch(_events_sampleNullEventFilter, NULL);
+   SDLTest_AssertPass("Call to SDL_AddEventWatch()");
+   
+   /* Push a user event onto the queue and force queue update*/
+   SDL_PushEvent(&event);
+   SDLTest_AssertPass("Call to SDL_PushEvent()");
+   SDL_PumpEvents();
+   SDLTest_AssertPass("Call to SDL_PumpEvents()");
+   SDLTest_AssertCheck(_eventFilterCalled == 1, "Check that event filter was called");
+
+   /* Delete watch */
+   SDL_DelEventWatch(_events_sampleNullEventFilter, NULL);
+   SDLTest_AssertPass("Call to SDL_DelEventWatch()");
+
+   /* Push a user event onto the queue and force queue update*/
+   _eventFilterCalled = 0;
+   SDL_PushEvent(&event);
+   SDLTest_AssertPass("Call to SDL_PushEvent()");
+   SDL_PumpEvents();
+   SDLTest_AssertPass("Call to SDL_PumpEvents()");
+   SDLTest_AssertCheck(_eventFilterCalled == 0, "Check that event filter was NOT called");
+
+   return TEST_COMPLETED;
+}
+
+/**
+ * @brief Adds and deletes an event watch function with userdata
+ *
+ * @sa http://wiki.libsdl.org/moin.cgi/SDL_AddEventWatch
+ * @sa http://wiki.libsdl.org/moin.cgi/SDL_DelEventWatch
+ *
+ */
+int
+events_addDelEventWatchWithUserdata(void *arg)
+{
+   SDL_Event event;
+   
+   /* Create user event */
+   event.type = SDL_USEREVENT;
+   event.user.code = SDLTest_RandomSint32();;
+   event.user.data1 = (void *)&_userdataValue1;
+   event.user.data2 = (void *)&_userdataValue2;
+   
+   /* Enable userdata check and set a value to check */
+   _userdataCheck = 1;
+   _userdataValue = SDLTest_RandomIntegerInRange(-1024, 1024);
+
+   /* Reset event filter call tracker */
+   _eventFilterCalled = 0;
+
+   /* Add watch */    
+   SDL_AddEventWatch(_events_sampleNullEventFilter, (void *)&_userdataValue);
+   SDLTest_AssertPass("Call to SDL_AddEventWatch()");
+
+   /* Push a user event onto the queue and force queue update*/
+   SDL_PushEvent(&event);
+   SDLTest_AssertPass("Call to SDL_PushEvent()");
+   SDL_PumpEvents();
+   SDLTest_AssertPass("Call to SDL_PumpEvents()");
+   SDLTest_AssertCheck(_eventFilterCalled == 1, "Check that event filter was called");
+
+   /* Delete watch */
+   SDL_DelEventWatch(_events_sampleNullEventFilter, (void *)&_userdataValue);
+   SDLTest_AssertPass("Call to SDL_DelEventWatch()");
+     
+   /* Push a user event onto the queue and force queue update*/
+   _eventFilterCalled = 0;
+   SDL_PushEvent(&event);
+   SDLTest_AssertPass("Call to SDL_PushEvent()");
+   SDL_PumpEvents();
+   SDLTest_AssertPass("Call to SDL_PumpEvents()");
+   SDLTest_AssertCheck(_eventFilterCalled == 0, "Check that event filter was NOT called");
+   
+   return TEST_COMPLETED;
+}
+
+
+/* ================= Test References ================== */
+
+/* Events test cases */
+static const SDLTest_TestCaseReference eventsTest1 =
+		{ (SDLTest_TestCaseFp)events_pushPumpAndPollUserevent, "events_pushPumpAndPollUserevent", "Pushes, pumps and polls a user event", TEST_ENABLED };
+
+static const SDLTest_TestCaseReference eventsTest2 =
+		{ (SDLTest_TestCaseFp)events_addDelEventWatch, "events_addDelEventWatch", "Adds and deletes an event watch function with NULL userdata", TEST_ENABLED };
+
+static const SDLTest_TestCaseReference eventsTest3 =
+		{ (SDLTest_TestCaseFp)events_addDelEventWatchWithUserdata, "events_addDelEventWatchWithUserdata", "Adds and deletes an event watch function with userdata", TEST_ENABLED };
+
+/* Sequence of Events test cases */
+static const SDLTest_TestCaseReference *eventsTests[] =  {
+	&eventsTest1, &eventsTest2, &eventsTest3, NULL
+};
+
+/* Events test suite (global) */
+SDLTest_TestSuiteReference eventsTestSuite = {
+	"Events",
+	NULL,
+	eventsTests,
+	NULL
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/testautomation_keyboard.c	Sun Jan 06 15:17:59 2013 -0800
@@ -0,0 +1,61 @@
+/**
+ * Keyboard test suite
+ */
+
+#include <stdio.h>
+
+#include "SDL.h"
+#include "SDL_test.h"
+
+/* ================= Test Case Implementation ================== */
+
+/*!
+ * TODO: Add tests for keyboard here
+ *
+ */
+
+/* Test case functions */
+
+/**
+ * @brief Check call to SDL_GetKeyboardState
+ * 
+ */
+int
+keyboard_getKeyboardState(void *arg)
+{
+   int numkeys;
+   Uint8 *state;
+
+   /* Case where numkeys pointer is NULL */    
+   state = SDL_GetKeyboardState(NULL);
+   SDLTest_AssertPass("Call to SDL_GetKeyboardState(NULL)");
+   SDLTest_AssertCheck(state != NULL, "Validate that return value from SDL_GetKeyboardState is not NULL");
+
+   /* Case where numkeys pointer is not NULL */
+   numkeys = -1;
+   state = SDL_GetKeyboardState(&numkeys);
+   SDLTest_AssertPass("Call to SDL_GetKeyboardState(&numkeys)");
+   SDLTest_AssertCheck(state != NULL, "Validate that return value from SDL_GetKeyboardState is not NULL");
+   SDLTest_AssertCheck(numkeys >= 0, "Validate that value of numkeys is >= 0, got: %i", numkeys);
+   
+   return TEST_COMPLETED;
+}
+
+/* ================= Test References ================== */
+
+/* Keyboard test cases */
+static const SDLTest_TestCaseReference keyboardTest1 =
+		{ (SDLTest_TestCaseFp)keyboard_getKeyboardState, "keyboard_getKeyboardState", "Check call to SDL_GetKeyboardState", TEST_ENABLED };
+
+/* Sequence of Keyboard test cases */
+static const SDLTest_TestCaseReference *keyboardTests[] =  {
+	&keyboardTest1, NULL
+};
+
+/* Keyboard test suite (global) */
+SDLTest_TestSuiteReference keyboardTestSuite = {
+	"Keyboard",
+	NULL,
+	keyboardTests,
+	NULL
+};
--- a/test/testautomation_suites.h	Mon Dec 31 19:22:05 2012 -0800
+++ b/test/testautomation_suites.h	Sun Jan 06 15:17:59 2013 -0800
@@ -11,29 +11,29 @@
 // Test collections
 extern SDLTest_TestSuiteReference audioTestSuite;
 extern SDLTest_TestSuiteReference clipboardTestSuite;
-//extern SDLTest_TestSuiteReference eventsTestSuite;
-//extern SDLTest_TestSuiteReference keyboardTestSuite;
+extern SDLTest_TestSuiteReference eventsTestSuite;
+extern SDLTest_TestSuiteReference keyboardTestSuite;
 extern SDLTest_TestSuiteReference platformTestSuite;
 extern SDLTest_TestSuiteReference rectTestSuite;
 extern SDLTest_TestSuiteReference renderTestSuite;
 extern SDLTest_TestSuiteReference rwopsTestSuite;
 extern SDLTest_TestSuiteReference surfaceTestSuite;
-//extern SDLTest_TestSuiteReference syswmTestSuite;
-//extern SDLTest_TestSuiteReference videoTestSuite;
+extern SDLTest_TestSuiteReference syswmTestSuite;
+extern SDLTest_TestSuiteReference videoTestSuite;
 
 // All test suites
 SDLTest_TestSuiteReference *testSuites[] =  {
 	&audioTestSuite,
 	&clipboardTestSuite,
-//	&eventsTestSuite,
-//	&keyboardTestSuite,
+	&eventsTestSuite,
+	&keyboardTestSuite,
 	&platformTestSuite,
 	&rectTestSuite,
 	&renderTestSuite,
 	&rwopsTestSuite,
 	&surfaceTestSuite,
-//	&syswmTestSuite,
-//	&videoTestSuite,
+	&syswmTestSuite,
+	&videoTestSuite,
 	NULL
 };
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/testautomation_syswm.c	Sun Jan 06 15:17:59 2013 -0800
@@ -0,0 +1,61 @@
+/**
+ * SysWM test suite
+ */
+
+#include <stdio.h>
+
+#include "SDL.h"
+#include "SDL_syswm.h"
+#include "SDL_test.h"
+
+/* Test case functions */
+
+/**
+ * @brief Call to SDL_GetWindowWMInfo
+ */
+int
+syswm_getWindowWMInfo(void *arg)
+{
+  SDL_bool result;
+  SDL_Window *window; 
+  SDL_SysWMinfo info;
+  
+  window = SDL_CreateWindow("", 0, 0, 0, 0, SDL_WINDOW_HIDDEN);
+  SDLTest_AssertPass("Call to SDL_CreateWindow()");
+  SDLTest_AssertCheck(window != NULL, "Check that value returned from SDL_CreateWindow is not NULL");
+  if (window == NULL) {
+     return TEST_ABORTED;
+  }
+  
+  /* Initialize info structure with SDL version info */
+  SDL_VERSION(&info.version); 
+  
+  /* Make call */
+  result = SDL_GetWindowWMInfo(window, &info);
+  SDLTest_AssertPass("Call to SDL_GetWindowWMInfo");
+  SDLTest_Log((result == SDL_TRUE) ? "Got window information" : "Couldn't get window information");
+                                                                                                      		
+  SDL_DestroyWindow(window);
+  SDLTest_AssertPass("Call to SDL_DestroyWindow()");
+  
+  return TEST_COMPLETED;
+}
+
+/* ================= Test References ================== */
+
+/* SysWM test cases */
+static const SDLTest_TestCaseReference syswmTest1 =
+		{ (SDLTest_TestCaseFp)syswm_getWindowWMInfo, "syswm_getWindowWMInfo", "Call to SDL_GetWindowWMInfo", TEST_ENABLED };
+
+/* Sequence of SysWM test cases */
+static const SDLTest_TestCaseReference *syswmTests[] =  {
+	&syswmTest1, NULL
+};
+
+/* SysWM test suite (global) */
+SDLTest_TestSuiteReference syswmTestSuite = {
+	"SysWM",
+	NULL,
+	syswmTests,
+	NULL
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/testautomation_video.c	Sun Jan 06 15:17:59 2013 -0800
@@ -0,0 +1,81 @@
+/**
+ * Video test suite
+ */
+
+#include <stdio.h>
+
+#include "SDL.h"
+#include "SDL_test.h"
+
+/* Test case functions */
+
+/**
+ * @brief Enable and disable screensaver while checking state
+ */
+int
+video_enableDisableScreensaver(void *arg)
+{
+	SDL_bool initialResult;
+	SDL_bool result;
+
+	/* Get current state and proceed according to current state */
+	initialResult = SDL_IsScreenSaverEnabled();
+	SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()");	
+	if (initialResult == SDL_TRUE) {
+	
+	  /* Currently enabled: disable first, then enable again */
+	  
+	  /* Disable screensaver and check */	
+	  SDL_DisableScreenSaver();
+	  SDLTest_AssertPass("Call to SDL_DisableScreenSaver()");	
+	  result = SDL_IsScreenSaverEnabled();
+	  SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()");
+	  SDLTest_AssertCheck(result == SDL_FALSE, "Verify result from SDL_IsScreenSaverEnabled, expected: %i, got: %i", SDL_FALSE, result);
+	
+	  /* Enable screensaver and check */	
+	  SDL_EnableScreenSaver();
+	  SDLTest_AssertPass("Call to SDL_EnableScreenSaver()");
+	  result = SDL_IsScreenSaverEnabled();
+	  SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()");
+	  SDLTest_AssertCheck(result == SDL_TRUE, "Verify result from SDL_IsScreenSaverEnabled, expected: %i, got: %i", SDL_TRUE, result);
+
+	} else {
+
+	  /* Currently disabled: enable first, then disable again */
+	  
+	  /* Enable screensaver and check */	
+	  SDL_EnableScreenSaver();
+	  SDLTest_AssertPass("Call to SDL_EnableScreenSaver()");
+	  result = SDL_IsScreenSaverEnabled();
+	  SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()");
+	  SDLTest_AssertCheck(result == SDL_TRUE, "Verify result from SDL_IsScreenSaverEnabled, expected: %i, got: %i", SDL_TRUE, result);
+
+	  /* Disable screensaver and check */	
+	  SDL_DisableScreenSaver();
+	  SDLTest_AssertPass("Call to SDL_DisableScreenSaver()");	
+	  result = SDL_IsScreenSaverEnabled();
+	  SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()");
+	  SDLTest_AssertCheck(result == SDL_FALSE, "Verify result from SDL_IsScreenSaverEnabled, expected: %i, got: %i", SDL_FALSE, result);	
+	}	
+	
+	return TEST_COMPLETED;
+}
+
+/* ================= Test References ================== */
+
+/* Video test cases */
+static const SDLTest_TestCaseReference videoTest1 =
+		{ (SDLTest_TestCaseFp)video_enableDisableScreensaver, "video_enableDisableScreensaver",  "Enable and disable screenaver while checking state", TEST_ENABLED };
+
+/* Sequence of Video test cases */
+static const SDLTest_TestCaseReference *videoTests[] =  {
+	&videoTest1, NULL
+};
+
+/* Video test suite (global) */
+SDLTest_TestSuiteReference videoTestSuite = {
+	"Video",
+	NULL,
+	videoTests,
+	NULL
+};