38 #ifndef ObjectManager_cpp 39 #define ObjectManager_cpp 41 #include <cppunit/ui/text/TestRunner.h> 42 #include <cppunit/TextOutputter.h> 43 #include <cppunit/extensions/TestFactoryRegistry.h> 44 #include <cppunit/extensions/HelperMacros.h> 45 #include <cppunit/TestAssert.h> 62 std::string
getId()
const {
return std::string(
m_id); }
80 :
public CppUnit::TestFixture
83 CPPUNIT_TEST(test_registerObject);
84 CPPUNIT_TEST(test_registerObject_with_overlapped_identifier);
85 CPPUNIT_TEST(test_find);
86 CPPUNIT_TEST(test_unregisterObject_and_find);
87 CPPUNIT_TEST(test_getObjects);
88 CPPUNIT_TEST_SUITE_END();
181 CPPUNIT_ASSERT(pObjRet1 != NULL);
182 CPPUNIT_ASSERT_EQUAL(std::string(
"ID 1"), pObjRet1->getId());
185 CPPUNIT_ASSERT(pObjRet2 != NULL);
186 CPPUNIT_ASSERT_EQUAL(std::string(
"ID 2"), pObjRet2->getId());
189 CPPUNIT_ASSERT_EQUAL((
ObjectMock*) NULL, objMgr.
find(
"INEXIST ID"));
213 CPPUNIT_ASSERT(pObjRet1 != NULL);
214 CPPUNIT_ASSERT_EQUAL(std::string(
"ID 1"), pObjRet1->getId());
221 CPPUNIT_ASSERT(pObjRet2 != NULL);
222 CPPUNIT_ASSERT_EQUAL(std::string(
"ID 2"), pObjRet2->getId());
243 std::vector<ObjectMock*> objs = objMgr.
getObjects();
244 CPPUNIT_ASSERT_EQUAL(2, (
int) objs.size());
245 CPPUNIT_ASSERT_EQUAL(std::string(
"ID 1"),
246 (*std::find_if(objs.begin(), objs.end(),
PredicateMock(
"ID 1")))->getId());
247 CPPUNIT_ASSERT_EQUAL(std::string(
"ID 2"),
248 (*std::find_if(objs.begin(), objs.end(),
PredicateMock(
"ID 2")))->getId());
260 int main(
int argc,
char* argv[])
273 std::string arg(argv[i]);
274 std::string next_arg;
275 if (i + 1 < argc) next_arg = argv[i + 1];
278 if (arg ==
"--text") { format =
TEXT_OUT;
break; }
291 ofs.open(fname.c_str());
293 if ( arg ==
"--compiler" ) { format =
COMPILER_OUT;
break; }
294 if ( arg ==
"--cerr" ) { target = 1;
break; }
295 if ( arg ==
"--xsl" )
297 if (next_arg ==
"") xsl =
"default.xsl";
300 if ( arg ==
"--namespace" )
304 std::cerr <<
"no namespace specified" << std::endl;
314 CppUnit::TextUi::TestRunner runner;
316 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
318 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
319 CppUnit::Outputter* outputter = 0;
320 std::ostream* stream = target ? &std::cerr : &std::cout;
324 outputter =
new CppUnit::TextOutputter(&runner.result(),*stream);
327 std::cout <<
"XML_OUT" << std::endl;
328 outputter =
new CppUnit::XmlOutputter(&runner.result(),
330 static_cast<CppUnit::XmlOutputter*
>(outputter)->setStyleSheet(xsl);
333 outputter =
new CppUnit::CompilerOutputter(&runner.result(),*stream);
336 runner.setOutputter(outputter);
341 #endif // ObjectManager_cpp
PredicateMock(const ObjectMock *obj)
int main(int argc, char **argv)
CPPUNIT_TEST_SUITE_REGISTRATION(ObjectManagerTests::ObjectManagerTests)
Object * find(const Identifier &id) const
Find the object.
ObjectManagerTests()
Constructor.
ObjectMock(const std::string &id)
virtual void tearDown()
Test finalization.
std::string getId() const
virtual void setUp()
Test initialization.
Class for managing objects.
bool registerObject(Object *obj)
Register the specified object.
Object * unregisterObject(const Identifier &id)
Unregister the specified object.
void test_find()
find()メソッドのテスト
void test_registerObject()
registerObject()メソッドのテスト
PredicateMock(const std::string &id)
void test_unregisterObject_and_find()
unregisterObject()メソッドとfind()メソッドのテスト
void test_registerObject_with_overlapped_identifier()
registerObject()メソッドのテスト
std::vector< Object * > getObjects() const
Get a list of obejects that are registerd.
bool operator()(const ObjectMock *obj)
void test_getObjects()
getObjects()メソッドのテスト
~ObjectManagerTests()
Destructor.