1 | // |
---|---|
2 | // ManifestTest.cpp |
3 | // |
4 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
5 | // and Contributors. |
6 | // |
7 | // SPDX-License-Identifier: BSL-1.0 |
8 | // |
9 | |
10 | |
11 | #include "ManifestTest.h" |
12 | #include "Poco/CppUnit/TestCaller.h" |
13 | #include "Poco/CppUnit/TestSuite.h" |
14 | #include "Poco/Manifest.h" |
15 | #include "Poco/MetaObject.h" |
16 | #include <set> |
17 | |
18 | |
19 | using Poco::Manifest; |
20 | using Poco::MetaObject; |
21 | |
22 | |
23 | class MfTestBase |
24 | { |
25 | }; |
26 | |
27 | |
28 | class MfTestObject: public MfTestBase |
29 | { |
30 | }; |
31 | |
32 | |
33 | ManifestTest::ManifestTest(const std::string& rName): CppUnit::TestCase(rName) |
34 | { |
35 | } |
36 | |
37 | |
38 | ManifestTest::~ManifestTest() |
39 | { |
40 | } |
41 | |
42 | |
43 | void ManifestTest::testManifest() |
44 | { |
45 | Manifest<MfTestBase> manifest; |
46 | assertTrue (manifest.empty()); |
47 | assertTrue (manifest.size() == 0); |
48 | assertTrue (manifest.insert(new MetaObject<MfTestObject, MfTestBase>("MfTestObject1"))); |
49 | assertTrue (!manifest.empty()); |
50 | assertTrue (manifest.size() == 1); |
51 | assertTrue (manifest.insert(new MetaObject<MfTestObject, MfTestBase>("MfTestObject2"))); |
52 | MetaObject<MfTestObject, MfTestBase>* pMeta = new MetaObject<MfTestObject, MfTestBase>("MfTestObject2"); |
53 | assertTrue (!manifest.insert(pMeta)); |
54 | delete pMeta; |
55 | assertTrue (!manifest.empty()); |
56 | assertTrue (manifest.size() == 2); |
57 | assertTrue (manifest.insert(new MetaObject<MfTestObject, MfTestBase>("MfTestObject3"))); |
58 | assertTrue (manifest.size() == 3); |
59 | |
60 | assertTrue (manifest.find("MfTestObject1") != manifest.end()); |
61 | assertTrue (manifest.find("MfTestObject2") != manifest.end()); |
62 | assertTrue (manifest.find("MfTestObject3") != manifest.end()); |
63 | assertTrue (manifest.find("MfTestObject4") == manifest.end()); |
64 | |
65 | std::set<std::string> classes; |
66 | |
67 | Manifest<MfTestBase>::Iterator it = manifest.begin(); |
68 | assertTrue (it != manifest.end()); |
69 | classes.insert(it->name()); |
70 | ++it; |
71 | assertTrue (it != manifest.end()); |
72 | classes.insert(it->name()); |
73 | ++it; |
74 | assertTrue (it != manifest.end()); |
75 | classes.insert(it->name()); |
76 | it++; |
77 | assertTrue (it == manifest.end()); |
78 | |
79 | assertTrue (classes.find("MfTestObject1") != classes.end()); |
80 | assertTrue (classes.find("MfTestObject2") != classes.end()); |
81 | assertTrue (classes.find("MfTestObject3") != classes.end()); |
82 | |
83 | manifest.clear(); |
84 | assertTrue (manifest.empty()); |
85 | assertTrue (manifest.size() == 0); |
86 | assertTrue (manifest.insert(new MetaObject<MfTestObject, MfTestBase>("MfTestObject4"))); |
87 | assertTrue (!manifest.empty()); |
88 | assertTrue (manifest.size() == 1); |
89 | it = manifest.begin(); |
90 | assertTrue (it != manifest.end()); |
91 | assertTrue (std::string(it->name()) == "MfTestObject4"); |
92 | ++it; |
93 | assertTrue (it == manifest.end()); |
94 | } |
95 | |
96 | |
97 | void ManifestTest::setUp() |
98 | { |
99 | } |
100 | |
101 | |
102 | void ManifestTest::tearDown() |
103 | { |
104 | } |
105 | |
106 | |
107 | CppUnit::Test* ManifestTest::suite() |
108 | { |
109 | CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ManifestTest"); |
110 | |
111 | CppUnit_addTest(pSuite, ManifestTest, testManifest); |
112 | |
113 | return pSuite; |
114 | } |
115 |