1 |
#ifndef TEST_PROPERTYMAPTESTCASE_HPP |
2 |
#define TEST_PROPERTYMAPTESTCASE_HPP |
3 |
|
4 |
#include <string> |
5 |
#include <cppunit/extensions/HelperMacros.h> |
6 |
#include "utils/GenericFactory.hpp" |
7 |
|
8 |
using namespace OpenMD; |
9 |
|
10 |
|
11 |
class Shape { |
12 |
public: |
13 |
std::string getType() {return type_;} |
14 |
void setType(const std::string& type) { type_ = type;} |
15 |
protected: |
16 |
Shape(){}; |
17 |
private: |
18 |
std::string type_; |
19 |
|
20 |
}; |
21 |
|
22 |
typedef GenericFactory<Shape> ShapeFactory; |
23 |
|
24 |
class Line : public Shape { |
25 |
public: |
26 |
Line() { |
27 |
setType("Line"); |
28 |
} |
29 |
}; |
30 |
|
31 |
Shape* createLine(){ |
32 |
return new Line(); |
33 |
} |
34 |
|
35 |
//register createLine |
36 |
const bool registeredCreateLine = ShapeFactory::getInstance()->registerCreator("MyLine", createLine); |
37 |
|
38 |
|
39 |
class Circle : public Shape { |
40 |
public: |
41 |
Circle() { |
42 |
setType("Circle"); |
43 |
} |
44 |
|
45 |
}; |
46 |
|
47 |
Shape* createCircle() { |
48 |
return new Circle(); |
49 |
} |
50 |
|
51 |
//register createLine |
52 |
const bool registeredCreateCircle = ShapeFactory::getInstance()->registerCreator("MyCircle", createCircle); |
53 |
|
54 |
|
55 |
class AnotherCircle : public Shape { |
56 |
public: |
57 |
AnotherCircle() { |
58 |
setType("AnotherCircle"); |
59 |
} |
60 |
|
61 |
}; |
62 |
|
63 |
Shape* createAnotherCircle() { |
64 |
return new AnotherCircle(); |
65 |
} |
66 |
|
67 |
class Cubic : public Shape { |
68 |
public: |
69 |
Cubic() { |
70 |
setType("Cubic"); |
71 |
} |
72 |
}; |
73 |
|
74 |
DECLARE_CREATOR(Shape, Cubic) |
75 |
|
76 |
class GenericFactoryTestCase : public CPPUNIT_NS::TestFixture { |
77 |
CPPUNIT_TEST_SUITE( GenericFactoryTestCase ); |
78 |
CPPUNIT_TEST(testGenericFactory); |
79 |
CPPUNIT_TEST_SUITE_END(); |
80 |
|
81 |
public: |
82 |
|
83 |
void testGenericFactory(); |
84 |
}; |
85 |
|
86 |
|
87 |
#endif //TEST_PROPERTYMAPTESTCASE_HPP |
88 |
|