diff --git a/VisualC/tests/testautomation/testautomation.vcxproj b/VisualC/tests/testautomation/testautomation.vcxproj
index d58dc0b32..ff09adef5 100644
--- a/VisualC/tests/testautomation/testautomation.vcxproj
+++ b/VisualC/tests/testautomation/testautomation.vcxproj
@@ -224,6 +224,7 @@
+
@@ -231,4 +232,4 @@
-
+
\ No newline at end of file
diff --git a/test/Makefile.in b/test/Makefile.in
index 93df6360e..e6a6dcfc7 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -151,6 +151,7 @@ testautomation$(EXE): $(srcdir)/testautomation.c \
$(srcdir)/testautomation_rwops.c \
$(srcdir)/testautomation_sdltest.c \
$(srcdir)/testautomation_stdlib.c \
+ $(srcdir)/testautomation_subsystems.c \
$(srcdir)/testautomation_surface.c \
$(srcdir)/testautomation_syswm.c \
$(srcdir)/testautomation_timer.c \
diff --git a/test/testautomation_subsystems.c b/test/testautomation_subsystems.c
new file mode 100644
index 000000000..d25edeeb7
--- /dev/null
+++ b/test/testautomation_subsystems.c
@@ -0,0 +1,239 @@
+/**
+ * Subsystem test suite
+ */
+
+#include "SDL.h"
+#include "SDL_test.h"
+
+/* ================= Test Case Implementation ================== */
+
+/* Fixture */
+
+static void subsystemsSetUp(void *arg)
+{
+ /* Reset each one of the SDL subsystems */
+ /* CHECKME: can we use SDL_Quit here, or this will break the flow of tests? */
+ SDL_Quit();
+ /* Alternate variant without SDL_Quit:
+ while (SDL_WasInit(SDL_INIT_EVERYTHING) != 0) {
+ SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
+ }
+ */
+ SDLTest_AssertPass("Reset all subsystems before subsystems test");
+ SDLTest_AssertCheck(SDL_WasInit(SDL_INIT_EVERYTHING) == 0, "Check result from SDL_WasInit(SDL_INIT_EVERYTHING)");
+}
+
+static void subsystemsTearDown(void *arg)
+{
+ /* Reset each one of the SDL subsystems */
+ SDL_Quit();
+
+ SDLTest_AssertPass("Cleanup of subsystems test completed");
+}
+
+/* Test case functions */
+
+/**
+ * \brief Inits and Quits particular subsystem, checking its Init status.
+ *
+ * \sa SDL_InitSubSystem
+ * \sa SDL_QuitSubSystem
+ *
+ */
+static int subsystems_referenceCount()
+{
+ const int system = SDL_INIT_VIDEO;
+ int result;
+ /* Ensure that we start with a non-initialized subsystem. */
+ SDLTest_AssertCheck(SDL_WasInit(system) == 0, "Check result from SDL_WasInit(0x%x)", system);
+
+ /* Init subsystem once, and quit once */
+ SDL_InitSubSystem(system);
+ SDLTest_AssertPass("Call to SDL_InitSubSystem(0x%x)", system);
+ result = SDL_WasInit(system);
+ SDLTest_AssertCheck(result == system, "Check result from SDL_WasInit(0x%x), expected: 0x%x, got: 0x%x", system, system, result);
+
+ SDL_QuitSubSystem(system);
+ SDLTest_AssertPass("Call to SDL_QuitSubSystem(0x%x)", system);
+ result = SDL_WasInit(system);
+ SDLTest_AssertCheck(result == 0, "Check result from SDL_WasInit(0x%x), expected: 0, got: 0x%x", system, result);
+
+ /* Init subsystem number of times, then decrement reference count until it's disposed of. */
+ SDL_InitSubSystem(system);
+ SDL_InitSubSystem(system);
+ SDL_InitSubSystem(system);
+ SDLTest_AssertPass("Call to SDL_InitSubSystem(0x%x) x3 times", system);
+ result = SDL_WasInit(system);
+ SDLTest_AssertCheck(result == system, "Check result from SDL_WasInit(0x%x), expected: 0x%x, got: 0x%x", system, system, result);
+
+ SDL_QuitSubSystem(system);
+ SDLTest_AssertPass("Call to SDL_QuitSubSystem(0x%x) x1", system);
+ result = SDL_WasInit(system);
+ SDLTest_AssertCheck(result == system, "Check result from SDL_WasInit(0x%x), expected: 0x%x, got: 0x%x", system, system, result);
+ SDL_QuitSubSystem(system);
+ SDLTest_AssertPass("Call to SDL_QuitSubSystem(0x%x) x2", system);
+ result = SDL_WasInit(system);
+ SDLTest_AssertCheck(result == system, "Check result from SDL_WasInit(0x%x), expected: 0x%x, got: 0x%x", system, system, result);
+ SDL_QuitSubSystem(system);
+ SDLTest_AssertPass("Call to SDL_QuitSubSystem(0x%x) x3", system);
+ result = SDL_WasInit(system);
+ SDLTest_AssertCheck(result == 0, "Check result from SDL_WasInit(0x%x), expected: 0, got: 0x%x", system, result);
+
+ return TEST_COMPLETED;
+}
+
+/**
+ * \brief Inits and Quits subsystems that have another as dependency;
+ * check that the dependency is not removed before the last of its dependents.
+ *
+ * \sa SDL_InitSubSystem
+ * \sa SDL_QuitSubSystem
+ *
+ */
+static int subsystems_dependRefCountInitAllQuitByOne()
+{
+ int result;
+ /* Ensure that we start with reset subsystems. */
+ SDLTest_AssertCheck(SDL_WasInit(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_EVENTS) == 0,
+ "Check result from SDL_WasInit(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_EVENTS)");
+
+ /* Following should init SDL_INIT_EVENTS and give it +3 ref counts. */
+ SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK);
+ SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK)");
+ result = SDL_WasInit(SDL_INIT_EVENTS);
+ SDLTest_AssertCheck(result == SDL_INIT_EVENTS, "Check result from SDL_WasInit(SDL_INIT_EVENTS), expected: 0x4000, got: 0x%x", result);
+
+ /* Quit systems one by one. */
+ SDL_QuitSubSystem(SDL_INIT_VIDEO);
+ SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_VIDEO)");
+ result = SDL_WasInit(SDL_INIT_EVENTS);
+ SDLTest_AssertCheck(result == SDL_INIT_EVENTS, "Check result from SDL_WasInit(SDL_INIT_EVENTS), expected: 0x4000, got: 0x%x", result);
+ SDL_QuitSubSystem(SDL_INIT_AUDIO);
+ SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
+ result = SDL_WasInit(SDL_INIT_EVENTS);
+ SDLTest_AssertCheck(result == SDL_INIT_EVENTS, "Check result from SDL_WasInit(SDL_INIT_EVENTS), expected: 0x4000, got: 0x%x", result);
+ SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
+ SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_JOYSTICK)");
+ result = SDL_WasInit(SDL_INIT_EVENTS);
+ SDLTest_AssertCheck(result == 0, "Check result from SDL_WasInit(SDL_INIT_EVENTS), expected: 0, got: 0x%x", result);
+
+ return TEST_COMPLETED;
+}
+
+/**
+ * \brief Inits and Quits subsystems that have another as dependency;
+ * check that the dependency is not removed before the last of its dependents.
+ *
+ * \sa SDL_InitSubSystem
+ * \sa SDL_QuitSubSystem
+ *
+ */
+static int subsystems_dependRefCountInitByOneQuitAll()
+{
+ int result;
+ /* Ensure that we start with reset subsystems. */
+ SDLTest_AssertCheck(SDL_WasInit(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_EVENTS) == 0,
+ "Check result from SDL_WasInit(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_EVENTS)");
+
+ /* Following should init SDL_INIT_EVENTS and give it +3 ref counts. */
+ SDL_InitSubSystem(SDL_INIT_VIDEO);
+ SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_VIDEO)");
+ result = SDL_WasInit(SDL_INIT_EVENTS);
+ SDLTest_AssertCheck(result == SDL_INIT_EVENTS, "Check result from SDL_WasInit(SDL_INIT_EVENTS), expected: 0x4000, got: 0x%x", result);
+ SDL_InitSubSystem(SDL_INIT_AUDIO);
+ SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_AUDIO)");
+ SDL_InitSubSystem(SDL_INIT_JOYSTICK);
+ SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_JOYSTICK)");
+
+ /* Quit systems all at once. */
+ SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK);
+ SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK)");
+ result = SDL_WasInit(SDL_INIT_EVENTS);
+ SDLTest_AssertCheck(result == 0, "Check result from SDL_WasInit(SDL_INIT_EVENTS), expected: 0, got: 0x%x", result);
+
+ return TEST_COMPLETED;
+}
+
+/**
+ * \brief Inits and Quits subsystems that have another as dependency,
+ * but also inits that dependency explicitly, giving it extra ref count.
+ * Check that the dependency is not removed before the last reference is gone.
+ *
+ * \sa SDL_InitSubSystem
+ * \sa SDL_QuitSubSystem
+ *
+ */
+static int subsystems_dependRefCountWithExtraInit()
+{
+ int result;
+ /* Ensure that we start with reset subsystems. */
+ SDLTest_AssertCheck(SDL_WasInit(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_EVENTS) == 0,
+ "Check result from SDL_WasInit(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_EVENTS)");
+
+ /* Init EVENTS explicitly, +1 ref count. */
+ SDL_InitSubSystem(SDL_INIT_EVENTS);
+ SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_EVENTS)");
+ result = SDL_WasInit(SDL_INIT_EVENTS);
+ SDLTest_AssertCheck(result == SDL_INIT_EVENTS, "Check result from SDL_WasInit(SDL_INIT_EVENTS), expected: 0x4000, got: 0x%x", result);
+ /* Following should init SDL_INIT_EVENTS and give it +3 ref counts. */
+ SDL_InitSubSystem(SDL_INIT_VIDEO);
+ SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_VIDEO)");
+ SDL_InitSubSystem(SDL_INIT_AUDIO);
+ SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_AUDIO)");
+ SDL_InitSubSystem(SDL_INIT_JOYSTICK);
+ SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_JOYSTICK)");
+
+ /* Quit EVENTS explicitly, -1 ref count. */
+ SDL_QuitSubSystem(SDL_INIT_EVENTS);
+ SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_EVENTS)");
+ result = SDL_WasInit(SDL_INIT_EVENTS);
+ SDLTest_AssertCheck(result == SDL_INIT_EVENTS, "Check result from SDL_WasInit(SDL_INIT_EVENTS), expected: 0x4000, got: 0x%x", result);
+
+ /* Quit systems one by one. */
+ SDL_QuitSubSystem(SDL_INIT_VIDEO);
+ SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_VIDEO)");
+ result = SDL_WasInit(SDL_INIT_EVENTS);
+ SDLTest_AssertCheck(result == SDL_INIT_EVENTS, "Check result from SDL_WasInit(SDL_INIT_EVENTS), expected: 0x4000, got: 0x%x", result);
+ SDL_QuitSubSystem(SDL_INIT_AUDIO);
+ SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
+ result = SDL_WasInit(SDL_INIT_EVENTS);
+ SDLTest_AssertCheck(result == SDL_INIT_EVENTS, "Check result from SDL_WasInit(SDL_INIT_EVENTS), expected: 0x4000, got: 0x%x", result);
+ SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
+ SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_JOYSTICK)");
+ result = SDL_WasInit(SDL_INIT_EVENTS);
+ SDLTest_AssertCheck(result == 0, "Check result from SDL_WasInit(SDL_INIT_EVENTS), expected: 0, got: 0x%x", result);
+
+ return TEST_COMPLETED;
+}
+
+/* ================= Test References ================== */
+
+/* Subsystems test cases */
+static const SDLTest_TestCaseReference subsystemsTest1 = {
+ (SDLTest_TestCaseFp)subsystems_referenceCount, "subsystems_referenceCount", "Makes sure that subsystem stays until number of quits matches inits.", TEST_ENABLED
+};
+
+static const SDLTest_TestCaseReference subsystemsTest2 = {
+ (SDLTest_TestCaseFp)subsystems_dependRefCountInitAllQuitByOne, "subsystems_dependRefCountInitAllQuitByOne", "Check reference count of subsystem dependencies.", TEST_ENABLED
+};
+
+static const SDLTest_TestCaseReference subsystemsTest3 = {
+ (SDLTest_TestCaseFp)subsystems_dependRefCountInitByOneQuitAll, "subsystems_dependRefCountInitByOneQuitAll", "Check reference count of subsystem dependencies.", TEST_ENABLED
+};
+
+static const SDLTest_TestCaseReference subsystemsTest4 = {
+ (SDLTest_TestCaseFp)subsystems_dependRefCountWithExtraInit, "subsystems_dependRefCountWithExtraInit", "Check reference count of subsystem dependencies.", TEST_ENABLED
+};
+
+/* Sequence of Events test cases */
+static const SDLTest_TestCaseReference *subsystemsTests[] = {
+ &subsystemsTest1, &subsystemsTest2, &subsystemsTest3, &subsystemsTest4, NULL
+};
+
+/* Events test suite (global) */
+SDLTest_TestSuiteReference subsystemsTestSuite = {
+ "Subsystems",
+ subsystemsSetUp,
+ subsystemsTests,
+ subsystemsTearDown
+};
diff --git a/test/testautomation_suites.h b/test/testautomation_suites.h
index 6fdcd8388..24909db70 100644
--- a/test/testautomation_suites.h
+++ b/test/testautomation_suites.h
@@ -26,6 +26,7 @@ extern SDLTest_TestSuiteReference renderTestSuite;
extern SDLTest_TestSuiteReference rwopsTestSuite;
extern SDLTest_TestSuiteReference sdltestTestSuite;
extern SDLTest_TestSuiteReference stdlibTestSuite;
+extern SDLTest_TestSuiteReference subsystemsTestSuite;
extern SDLTest_TestSuiteReference surfaceTestSuite;
extern SDLTest_TestSuiteReference syswmTestSuite;
extern SDLTest_TestSuiteReference timerTestSuite;
@@ -54,6 +55,7 @@ SDLTest_TestSuiteReference *testSuites[] = {
&syswmTestSuite,
&timerTestSuite,
&videoTestSuite,
+ &subsystemsTestSuite, /* run last, not interfere with other test enviroment */
NULL
};
diff --git a/test/watcom.mif b/test/watcom.mif
index 2189fd49c..46b8659a8 100644
--- a/test/watcom.mif
+++ b/test/watcom.mif
@@ -58,9 +58,9 @@ TASRCS = testautomation.c &
testautomation_pixels.c testautomation_platform.c &
testautomation_rect.c testautomation_render.c &
testautomation_rwops.c testautomation_sdltest.c &
- testautomation_stdlib.c testautomation_surface.c &
- testautomation_syswm.c testautomation_timer.c &
- testautomation_video.c
+ testautomation_stdlib.c testautomation_subsystems.c &
+ testautomation_surface.c testautomation_syswm.c &
+ testautomation_timer.c testautomation_video.c
OBJS = $(TARGETS:.exe=.obj)
COBJS = $(CSRCS:.c=.obj)