Index: code/trunk/test/core_plugin/PluginTest.cc
===================================================================
--- code/trunk/test/core_plugin/PluginTest.cc	(revision 11012)
+++ code/trunk/test/core_plugin/PluginTest.cc	(revision 11013)
@@ -21,4 +21,9 @@
         {
             public:
+                PluginTest()
+                {
+                    this->plugin_ = NULL;
+                }
+
                 static void SetUpTestCase()
                 {
@@ -30,16 +35,32 @@
                     delete &Core::getInstance();
                 }
+
+                void loadPlugin()
+                {
+                    this->plugin_ = new PluginReference("testplugin");
+                }
+
+                void unloadPlugin()
+                {
+                    delete this->plugin_;
+                    this->plugin_ = NULL;
+                }
+
+                virtual void TearDown()
+                {
+                    // make sure the plugin is unloaded
+                    this->unloadPlugin();
+                }
+
+            private:
+                PluginReference* plugin_;
         };
     }
 
-    PluginReference* loadPlugin()
-    {
-        return new PluginReference("testplugin");
-    }
 
     TEST_F(PluginTest, CanLoadPlugin)
     {
-        PluginReference* plugin = loadPlugin();
-        delete plugin;
+        this->loadPlugin();
+        this->unloadPlugin();
     }
 
@@ -57,14 +78,14 @@
     {
         EXPECT_TRUE(getIdentifier() == NULL);
-        PluginReference* plugin = loadPlugin();
-        EXPECT_TRUE(getIdentifier() != NULL);
-        delete plugin;
+        this->loadPlugin();
+        EXPECT_TRUE(getIdentifier() != NULL);
+        this->unloadPlugin();
     }
 
     TEST_F(PluginTest, UnloadsIdentifier)
     {
-        PluginReference* plugin = loadPlugin();
-        EXPECT_TRUE(getIdentifier() != NULL);
-        delete plugin;
+        this->loadPlugin();
+        EXPECT_TRUE(getIdentifier() != NULL);
+        this->unloadPlugin();
         EXPECT_TRUE(getIdentifier() == NULL);
     }
@@ -72,16 +93,16 @@
     TEST_F(PluginTest, ReloadsIdentifier)
     {
-        PluginReference* plugin = loadPlugin();
-        EXPECT_TRUE(getIdentifier() != NULL);
-        delete plugin;
+        this->loadPlugin();
+        EXPECT_TRUE(getIdentifier() != NULL);
+        this->unloadPlugin();
         EXPECT_TRUE(getIdentifier() == NULL);
-        plugin = loadPlugin();
-        EXPECT_TRUE(getIdentifier() != NULL);
-        delete plugin;
+        this->loadPlugin();
+        EXPECT_TRUE(getIdentifier() != NULL);
+        this->unloadPlugin();
     }
 
     TEST_F(PluginTest, CanCreateObjectFromIdentifier)
     {
-        PluginReference* plugin = loadPlugin();
+        this->loadPlugin();
 
         Identifier* identifier = getIdentifier();
@@ -96,5 +117,5 @@
         EXPECT_EQ(666, testclass->getValue());
 
-        delete plugin;
+        this->unloadPlugin();
     }
 
@@ -131,14 +152,14 @@
     {
         EXPECT_TRUE(getSingleton() == NULL);
-        PluginReference* plugin = loadPlugin();
-        EXPECT_TRUE(getSingleton() != NULL);
-        delete plugin;
+        this->loadPlugin();
+        EXPECT_TRUE(getSingleton() != NULL);
+        this->unloadPlugin();
     }
 
     TEST_F(PluginTest, UnloadsSingleton)
     {
-        PluginReference* plugin = loadPlugin();
-        EXPECT_TRUE(getSingleton() != NULL);
-        delete plugin;
+        this->loadPlugin();
+        EXPECT_TRUE(getSingleton() != NULL);
+        this->unloadPlugin();
         EXPECT_TRUE(getSingleton() == NULL);
     }
@@ -146,16 +167,16 @@
     TEST_F(PluginTest, ReloadsSingleton)
     {
-        PluginReference* plugin = loadPlugin();
-        EXPECT_TRUE(getSingleton() != NULL);
-        delete plugin;
+        this->loadPlugin();
+        EXPECT_TRUE(getSingleton() != NULL);
+        this->unloadPlugin();
         EXPECT_TRUE(getSingleton() == NULL);
-        plugin = loadPlugin();
-        EXPECT_TRUE(getSingleton() != NULL);
-        delete plugin;
+        this->loadPlugin();
+        EXPECT_TRUE(getSingleton() != NULL);
+        this->unloadPlugin();
     }
 
     TEST_F(PluginTest, CanCallFunctionOnSingleton)
     {
-        PluginReference* plugin = loadPlugin();
+        this->loadPlugin();
 
         Testsingleton* singleton = getSingleton();
@@ -164,5 +185,5 @@
         EXPECT_EQ(999, singleton->getValue());
 
-        delete plugin;
+        this->unloadPlugin();
     }
 
@@ -188,14 +209,14 @@
     {
         EXPECT_FALSE(hasCommandLineArgument());
-        PluginReference* plugin = loadPlugin();
-        EXPECT_TRUE(hasCommandLineArgument());
-        delete plugin;
+        this->loadPlugin();
+        EXPECT_TRUE(hasCommandLineArgument());
+        this->unloadPlugin();
     }
 
     TEST_F(PluginTest, UnloadsCommandLineArgument)
     {
-        PluginReference* plugin = loadPlugin();
-        EXPECT_TRUE(hasCommandLineArgument());
-        delete plugin;
+        this->loadPlugin();
+        EXPECT_TRUE(hasCommandLineArgument());
+        this->unloadPlugin();
         EXPECT_FALSE(hasCommandLineArgument());
     }
@@ -203,21 +224,21 @@
     TEST_F(PluginTest, ReloadsCommandLineArgument)
     {
-        PluginReference* plugin = loadPlugin();
-        EXPECT_TRUE(hasCommandLineArgument());
-        delete plugin;
+        this->loadPlugin();
+        EXPECT_TRUE(hasCommandLineArgument());
+        this->unloadPlugin();
         EXPECT_FALSE(hasCommandLineArgument());
-        plugin = loadPlugin();
-        EXPECT_TRUE(hasCommandLineArgument());
-        delete plugin;
+        this->loadPlugin();
+        EXPECT_TRUE(hasCommandLineArgument());
+        this->unloadPlugin();
     }
 
     TEST_F(PluginTest, CommandLineArgumentHasCorrectValue)
     {
-        PluginReference* plugin = loadPlugin();
+        this->loadPlugin();
 
         ASSERT_TRUE(hasCommandLineArgument());
         EXPECT_EQ(333, CommandLineParser::getValue("testvalue").get<int>());
 
-        delete plugin;
+        this->unloadPlugin();
     }
 
@@ -235,14 +256,14 @@
     {
         EXPECT_TRUE(getConsoleCommand() == NULL);
-        PluginReference* plugin = loadPlugin();
-        EXPECT_TRUE(getConsoleCommand() != NULL);
-        delete plugin;
+        this->loadPlugin();
+        EXPECT_TRUE(getConsoleCommand() != NULL);
+        this->unloadPlugin();
     }
 
     TEST_F(PluginTest, UnloadsConsoleCommand)
     {
-        PluginReference* plugin = loadPlugin();
-        EXPECT_TRUE(getConsoleCommand() != NULL);
-        delete plugin;
+        this->loadPlugin();
+        EXPECT_TRUE(getConsoleCommand() != NULL);
+        this->unloadPlugin();
         EXPECT_TRUE(getConsoleCommand() == NULL);
     }
@@ -250,16 +271,16 @@
     TEST_F(PluginTest, ReloadsConsoleCommand)
     {
-        PluginReference* plugin = loadPlugin();
-        EXPECT_TRUE(getConsoleCommand() != NULL);
-        delete plugin;
+        this->loadPlugin();
+        EXPECT_TRUE(getConsoleCommand() != NULL);
+        this->unloadPlugin();
         EXPECT_TRUE(getConsoleCommand() == NULL);
-        plugin = loadPlugin();
-        EXPECT_TRUE(getConsoleCommand() != NULL);
-        delete plugin;
+        this->loadPlugin();
+        EXPECT_TRUE(getConsoleCommand() != NULL);
+        this->unloadPlugin();
     }
 
     TEST_F(PluginTest, CanCallConsoleCommand)
     {
-        PluginReference* plugin = loadPlugin();
+        this->loadPlugin();
 
         ConsoleCommand* command = getConsoleCommand();
@@ -268,5 +289,5 @@
         EXPECT_EQ(999, (*command->getExecutor())(333, 666).get<int>());
 
-        delete plugin;
+        this->unloadPlugin();
     }
 }
