Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core7/test/core/class/SubclassIdentifierTest.cc @ 10400

Last change on this file since 10400 was 10400, checked in by landauf, 9 years ago

fixed tests. however there are some open issues:

  • the class-hierarchy must be built exactly 1 times in core_test. this is currently done in CommandTest.cc because that's the first test to run in core_test which actually needs the class hierarchy. the order of tests is not guaranteed though, so this should be solved more generic
  • during creation of class hierarchy, config values are used. this fails in the tests, so it had to be disabled with a static flag in Identifier. this should be solved in a cleaner way.
  • because the class hierarchy is now statically generated for all tests in core_test in CommandTest.cc, there is no way to test identifiers in an uninitialized state. because of this, three tests had to be disabled (*_NoFixture tests)

⇒ make the creation of the class hierarchy more modular and fix these issues

  • Property svn:eol-style set to native
File size: 2.1 KB
Line 
1#include <gtest/gtest.h>
2#include "core/CoreIncludes.h"
3#include "core/class/Identifiable.h"
4#include "core/class/SubclassIdentifier.h"
5#include "core/class/OrxonoxClass.h"
6
7namespace orxonox
8{
9    namespace
10    {
11        class TestClass : public OrxonoxClass
12        {
13            public:
14                TestClass(Context* context = NULL) { RegisterObject(TestClass); }
15        };
16
17        class TestSubclass : public TestClass
18        {
19            public:
20                TestSubclass(Context* context = NULL) { RegisterObject(TestSubclass); }
21        };
22
23        RegisterClass(TestClass);
24        RegisterClass(TestSubclass);
25
26        // Fixture
27        class SubclassIdentifierTest : public ::testing::Test
28        {
29            public:
30                virtual void SetUp()
31                {
32                    Context::setRootContext(new Context(NULL));
33                }
34
35                virtual void TearDown()
36                {
37                    Context::setRootContext(NULL);
38                }
39        };
40    }
41
42    TEST_F(SubclassIdentifierTest, CanCreateIdentifier)
43    {
44        TestSubclass test;
45
46        SubclassIdentifier<TestClass> subclassIdentifier;
47    }
48
49    TEST_F(SubclassIdentifierTest, DefaultsToNormalIdentifier)
50    {
51        TestSubclass test;
52
53        SubclassIdentifier<TestClass> subclassIdentifier;
54        EXPECT_EQ(Class(TestClass), subclassIdentifier.getIdentifier());
55    }
56
57    TEST_F(SubclassIdentifierTest, CanAssignIdentifierOfSubclass)
58    {
59        TestSubclass test;
60        SubclassIdentifier<TestClass> subclassIdentifier;
61        subclassIdentifier = Class(TestSubclass);
62        EXPECT_EQ(Class(TestSubclass), subclassIdentifier.getIdentifier());
63    }
64
65    TEST_F(SubclassIdentifierTest, CanCreateSubclass)
66    {
67        TestSubclass test;
68        SubclassIdentifier<TestClass> subclassIdentifier;
69        subclassIdentifier = Class(TestSubclass);
70
71        TestClass* instance = subclassIdentifier.fabricate(NULL);
72        ASSERT_TRUE(instance != NULL);
73        EXPECT_EQ(Class(TestSubclass), instance->getIdentifier());
74        delete instance;
75    }
76}
Note: See TracBrowser for help on using the repository browser.