Index: /code/branches/core6/test/core/CMakeLists.txt
===================================================================
--- /code/branches/core6/test/core/CMakeLists.txt	(revision 9602)
+++ /code/branches/core6/test/core/CMakeLists.txt	(revision 9603)
@@ -14,4 +14,9 @@
     class/SubclassIdentifierTest.cc
     class/SuperTest.cc
+    command/CommandTest.cc
+    object/ClassFactoryTest.cc
+    object/DestroyableTest.cc
+    object/SmartPtrTest.cc
+    object/WeakPtrTest.cc
 )
 ADD_DEPENDENCIES(test core_test)
Index: /code/branches/core6/test/core/command/CommandTest.cc
===================================================================
--- /code/branches/core6/test/core/command/CommandTest.cc	(revision 9603)
+++ /code/branches/core6/test/core/command/CommandTest.cc	(revision 9603)
@@ -0,0 +1,175 @@
+#include <gtest/gtest.h>
+#include "core/command/ConsoleCommand.h"
+#include "core/command/CommandExecutor.h"
+#include "core/object/Destroyable.h"
+
+namespace orxonox
+{
+    namespace
+    {
+        int functionNr = 0;
+        int valueA = 0;
+        int valueB = 0;
+        int valueC = 0;
+
+        void testfunction1(int a);
+        void testfunction2(int a, int b);
+        void testfunction3(int a, int b);
+        void testfunction4(int a, int b, int c);
+
+        class Testclass : public Destroyable
+        {
+            public:
+                void testfunction5(int a);
+                void testfunction6(int a);
+
+                Testclass* other_;
+                int b_;
+        };
+
+        SetConsoleCommand("test", &testfunction1);
+
+        Testclass* class1 = new Testclass();
+        Testclass* class2 = new Testclass();
+
+        void testfunction1(int a)
+        {
+            functionNr = 1;
+            valueA = a;
+            valueB = 0;
+            valueC = 0;
+
+            if (a == 1)
+                ModifyConsoleCommand("test").pushFunction().defaultValue(1, 10).setFunction(&testfunction2);
+            else if (a == -1)
+                ModifyConsoleCommand("test").popFunction();
+        }
+
+        void testfunction2(int a, int b)
+        {
+            functionNr = 2;
+            valueA = a;
+            valueB = b;
+            valueC = 0;
+
+            if (a == 1)
+                ModifyConsoleCommand("test").pushFunction().defaultValue(1, 20).setFunction(&testfunction3);
+            else if (a == -1)
+                ModifyConsoleCommand("test").popFunction();
+        }
+
+        void testfunction3(int a, int b)
+        {
+            functionNr = 3;
+            valueA = a;
+            valueB = b;
+            valueC = 0;
+
+            if (a == 1)
+                ModifyConsoleCommand("test").pushFunction().defaultValue(1, 30).defaultValue(2, 40).setFunction(&testfunction4);
+            else if (a == -1)
+                ModifyConsoleCommand("test").popFunction();
+        }
+
+        void testfunction4(int a, int b, int c)
+        {
+            functionNr = 4;
+            valueA = a;
+            valueB = b;
+            valueC = c;
+
+            if (a == 1)
+                ModifyConsoleCommand("test").pushFunction().setFunction(&Testclass::testfunction5).setObject(class1);
+            else if (a == -1)
+                ModifyConsoleCommand("test").popFunction();
+        }
+
+        void Testclass::testfunction5(int a)
+        {
+            class1->b_ = 11;
+            class2->b_ = 22;
+
+            class1->other_ = class2;
+            class2->other_ = class1;
+
+            functionNr = 5;
+            valueA = a;
+            valueB = b_;
+            valueC = 0;
+
+            if (a == 2)
+                ModifyConsoleCommand("test").pushObject(this->other_);
+            else if (a == -2)
+                ModifyConsoleCommand("test").popObject();
+            else if (a == 1)
+                ModifyConsoleCommand("test").pushFunction(&Testclass::testfunction6, this);
+            else if (a == -1)
+                ModifyConsoleCommand("test").popFunction();
+        }
+
+        void Testclass::testfunction6(int a)
+        {
+            class1->b_ = 11;
+            class2->b_ = 22;
+
+            class1->other_ = class2;
+            class2->other_ = class1;
+
+            functionNr = 6;
+            valueA = a;
+            valueB = b_;
+            valueC = 0;
+
+            if (a == 2)
+                ModifyConsoleCommand("test").pushObject(this->other_);
+            else if (a == -2)
+                ModifyConsoleCommand("test").popObject();
+            else if (a == 1)
+                ModifyConsoleCommand("test").setFunction(FunctorPtr(0));
+            else if (a == -1)
+                ModifyConsoleCommand("test").popFunction();
+        }
+    }
+
+    void test(int function, int b, int c)
+    {
+        EXPECT_EQ(function, functionNr);
+        EXPECT_EQ(b, valueB);
+        EXPECT_EQ(c, valueC);
+    }
+
+    TEST(CommandTest, ModuleTest)
+    {
+        test(0, 0, 0);
+        CommandExecutor::execute("test 0", false);
+        test(1, 0, 0);
+        CommandExecutor::execute("test 1", false);
+        test(1, 0, 0);
+        CommandExecutor::execute("test 0", false);
+        test(2, 10, 0);
+        CommandExecutor::execute("test 0 123", false);
+        test(2, 123, 0);
+        CommandExecutor::execute("test 1 1234", false);
+        test(2, 1234, 0);
+        CommandExecutor::execute("test 1", false);
+        test(3, 20, 0);
+        CommandExecutor::execute("test 0", false);
+        test(4, 30, 40);
+        CommandExecutor::execute("test 1 100 200", false);
+        test(4, 100, 200);
+        CommandExecutor::execute("test 0", false);
+        test(5, 11, 0);
+        CommandExecutor::execute("test 1", false);
+        test(5, 11, 0);
+        CommandExecutor::execute("test 2", false);
+        test(6, 11, 0);
+        CommandExecutor::execute("test 0", false);
+        test(6, 22, 0);
+        CommandExecutor::execute("test -1", false);
+        test(6, 22, 0);
+        CommandExecutor::execute("test -1", false);
+        test(5, 11, 0);
+        CommandExecutor::execute("test 0", false);
+        test(4, 30, 40);
+    }
+}
Index: /code/branches/core6/test/core/object/ClassFactoryTest.cc
===================================================================
--- /code/branches/core6/test/core/object/ClassFactoryTest.cc	(revision 9603)
+++ /code/branches/core6/test/core/object/ClassFactoryTest.cc	(revision 9603)
@@ -0,0 +1,17 @@
+#include <gtest/gtest.h>
+#include "core/object/ClassFactory.h"
+#include "core/BaseObject.h"
+
+namespace orxonox
+{
+    TEST(ClassFactoryTest, CanFabricateObject)
+    {
+        Factory* factory = new ClassFactory<BaseObject>("BaseObject");
+        OrxonoxClass* object = factory->fabricate(NULL);
+        ASSERT_TRUE(object != NULL);
+        BaseObject* baseObject = dynamic_cast<BaseObject*>(object);
+        EXPECT_TRUE(baseObject != NULL);
+        delete object;
+        // don't delete factory - it remains in the identifier
+    }
+}
Index: /code/branches/core6/test/core/object/DestroyableTest.cc
===================================================================
--- /code/branches/core6/test/core/object/DestroyableTest.cc	(revision 9603)
+++ /code/branches/core6/test/core/object/DestroyableTest.cc	(revision 9603)
@@ -0,0 +1,64 @@
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+#include "core/object/Destroyable.h"
+
+namespace orxonox
+{
+    namespace
+    {
+        class DestroyableTest : public Destroyable
+        {
+            public:
+                DestroyableTest(bool& destroyed) : destroyed_(destroyed) { destroyed_ = false; }
+                virtual ~DestroyableTest() { destroyed_ = true; }
+                MOCK_METHOD0(preDestroy, void());
+
+            private:
+                bool& destroyed_;
+        };
+
+        class DestructionListenerMock : public DestructionListener
+        {
+            public:
+                MOCK_METHOD0(objectDeleted, void());
+                inline void registerAsDestructionListener(Destroyable* object)
+                    { this->DestructionListener::registerAsDestructionListener(object); }
+        };
+    }
+
+    TEST(DestroyableTest, DestroyDeletesInstance)
+    {
+        bool destroyed = false;
+        DestroyableTest* test = new DestroyableTest(destroyed);
+        EXPECT_FALSE(destroyed);
+        EXPECT_TRUE(test != NULL);
+        test->destroy();
+        EXPECT_TRUE(destroyed);
+    }
+
+    TEST(DestroyableTest, DestroyCallsPreDestroy)
+    {
+        bool bla;
+        DestroyableTest* test = new DestroyableTest(bla);
+        EXPECT_CALL(*test, preDestroy());
+        test->destroy();
+    }
+
+    TEST(DestroyableTest, DestroyCallsListener)
+    {
+        bool bla;
+        DestroyableTest* test = new DestroyableTest(bla);
+        DestructionListenerMock listener;
+        listener.registerAsDestructionListener(test);
+        EXPECT_CALL(listener, objectDeleted());
+        test->destroy();
+    }
+
+    TEST(DestroyableTest, ReferenceCounterIsZero)
+    {
+        bool bla;
+        DestroyableTest* test = new DestroyableTest(bla);
+        EXPECT_EQ(0u, test->getReferenceCount());
+        test->destroy();
+    }
+}
Index: /code/branches/core6/test/core/object/SmartPtrTest.cc
===================================================================
--- /code/branches/core6/test/core/object/SmartPtrTest.cc	(revision 9603)
+++ /code/branches/core6/test/core/object/SmartPtrTest.cc	(revision 9603)
@@ -0,0 +1,93 @@
+#include <gtest/gtest.h>
+#include "core/object/SmartPtr.h"
+
+namespace orxonox
+{
+    namespace
+    {
+        class DestroyableTest : public Destroyable
+        {
+            public:
+                DestroyableTest(bool& destroyed) : destroyed_(destroyed) { destroyed_ = false; }
+                virtual ~DestroyableTest() { destroyed_ = true; }
+
+            private:
+                bool& destroyed_;
+        };
+    }
+
+    TEST(SmartPtrTest, CanReferenceObject)
+    {
+        bool bla;
+        DestroyableTest* test = new DestroyableTest(bla);
+        SmartPtr<DestroyableTest> smartPtr = test;
+        EXPECT_EQ(test, smartPtr.get());
+        test->destroy();
+    }
+
+    TEST(SmartPtrTest, IncreasesReferenceCount)
+    {
+        bool bla;
+        DestroyableTest* test = new DestroyableTest(bla);
+        EXPECT_EQ(0u, test->getReferenceCount());
+        {
+            SmartPtr<DestroyableTest> smartPtr = test;
+            EXPECT_EQ(1u, test->getReferenceCount());
+        }
+        EXPECT_EQ(0u, test->getReferenceCount());
+        test->destroy();
+    }
+
+    TEST(SmartPtrTest, DestroyDeletesInstance)
+    {
+        bool destroyed = false;
+        DestroyableTest* test = new DestroyableTest(destroyed);
+        EXPECT_FALSE(destroyed);
+        test->destroy();
+        EXPECT_TRUE(destroyed);
+    }
+
+    TEST(SmartPtrTest, PreventsDestruction)
+    {
+        bool destroyed = false;
+        DestroyableTest* test = new DestroyableTest(destroyed);
+        EXPECT_FALSE(destroyed);
+        SmartPtr<DestroyableTest> smartPtr = test;
+        test->destroy();
+        EXPECT_FALSE(destroyed);
+    }
+
+    TEST(SmartPtrTest, DestroysIfSmartPtrRemoved)
+    {
+        bool destroyed = false;
+        DestroyableTest* test = new DestroyableTest(destroyed);
+        EXPECT_FALSE(destroyed);
+        {
+            SmartPtr<DestroyableTest> smartPtr = test;
+            test->destroy();
+            EXPECT_FALSE(destroyed);
+        }
+        EXPECT_TRUE(destroyed);
+    }
+
+    TEST(SmartPtrTest, DestroysIfAllSmartPtrsRemoved)
+    {
+        bool destroyed = false;
+        DestroyableTest* test = new DestroyableTest(destroyed);
+        EXPECT_FALSE(destroyed);
+        {
+            SmartPtr<DestroyableTest> smartPtr1 = test;
+            {
+                SmartPtr<DestroyableTest> smartPtr2 = test;
+                {
+                    SmartPtr<DestroyableTest> smartPtr3 = test;
+                    test->destroy();
+                    EXPECT_FALSE(destroyed);
+                }
+                EXPECT_FALSE(destroyed);
+            }
+            EXPECT_FALSE(destroyed);
+        }
+        EXPECT_TRUE(destroyed);
+    }
+}
Index: /code/branches/core6/test/core/object/WeakPtrTest.cc
===================================================================
--- /code/branches/core6/test/core/object/WeakPtrTest.cc	(revision 9603)
+++ /code/branches/core6/test/core/object/WeakPtrTest.cc	(revision 9603)
@@ -0,0 +1,47 @@
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+#include "core/object/WeakPtr.h"
+
+namespace orxonox
+{
+    namespace
+    {
+        class DestroyableTest : public Destroyable
+        {
+        };
+
+        class Callback
+        {
+            public:
+                virtual ~Callback() {}
+                MOCK_METHOD0(callback, void());
+        };
+    }
+
+    TEST(WeakPtrTest, CanReferenceObject)
+    {
+        DestroyableTest* test = new DestroyableTest();
+        WeakPtr<DestroyableTest> weakPtr = test;
+        EXPECT_EQ(test, weakPtr.get());
+        test->destroy();
+    }
+
+    TEST(WeakPtrTest, DestroyRemovesReference)
+    {
+        DestroyableTest* test = new DestroyableTest();
+        WeakPtr<DestroyableTest> weakPtr = test;
+        EXPECT_EQ(test, weakPtr.get());
+        test->destroy();
+        EXPECT_EQ(NULL, weakPtr.get());
+    }
+
+    TEST(WeakPtrTest, DestroyCallsCallback)
+    {
+        DestroyableTest* test = new DestroyableTest();
+        WeakPtr<DestroyableTest> weakPtr = test;
+        Callback callback;
+        weakPtr.setCallback(createFunctor(&Callback::callback, &callback));
+        EXPECT_CALL(callback, callback());
+        test->destroy();
+    }
+}
