Go to the documentation of this file.00001
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef NumberingPolicy_cpp
00020 #define NumberingPolicy_cpp
00021
00022 #include <cppunit/ui/text/TestRunner.h>
00023 #include <cppunit/TextOutputter.h>
00024 #include <cppunit/extensions/TestFactoryRegistry.h>
00025 #include <cppunit/extensions/HelperMacros.h>
00026 #include <cppunit/TestAssert.h>
00027
00028 #include <rtm/NumberingPolicy.h>
00029
00030 namespace Tests
00031 {
00032 class NumberingPolicyTests
00033 : public CppUnit::TestFixture
00034 {
00035 CPPUNIT_TEST_SUITE(NumberingPolicyTests);
00036 CPPUNIT_TEST(test_onCreate_and_onDelete);
00037 CPPUNIT_TEST_SUITE_END();
00038
00039 private:
00040
00041 public:
00045 NumberingPolicyTests()
00046 {
00047 }
00048
00052 ~NumberingPolicyTests()
00053 {
00054 }
00055
00059 virtual void setUp()
00060 {
00061 }
00062
00066 virtual void tearDown()
00067 {
00068 }
00069
00077 void test_onCreate_and_onDelete()
00078 {
00079
00080 std::string object1 = "apple";
00081 std::string object2 = "orange";
00082 std::string object3 = "banana";
00083
00084 std::auto_ptr<NumberingPolicy> policy(new DefaultNumberingPolicy());
00085
00086
00087 CPPUNIT_ASSERT_EQUAL(std::string("0"), policy->onCreate(&object1));
00088 CPPUNIT_ASSERT_EQUAL(std::string("1"), policy->onCreate(&object2));
00089 CPPUNIT_ASSERT_EQUAL(std::string("2"), policy->onCreate(&object3));
00090
00091
00092 policy->onDelete(&object1);
00093 policy->onDelete(&object2);
00094
00095
00096
00097 CPPUNIT_ASSERT_EQUAL(std::string("0"), policy->onCreate(&object2));
00098 CPPUNIT_ASSERT_EQUAL(std::string("1"), policy->onCreate(&object1));
00099 }
00100
00101 };
00102 };
00103
00104
00105
00106
00107 CPPUNIT_TEST_SUITE_REGISTRATION(Tests::NumberingPolicyTests);
00108
00109 #ifdef LOCAL_MAIN
00110 int main(int argc, char* argv[])
00111 {
00112
00113 FORMAT format = TEXT_OUT;
00114 int target = 0;
00115 std::string xsl;
00116 std::string ns;
00117 std::string fname;
00118 std::ofstream ofs;
00119
00120 int i(1);
00121 while (i < argc)
00122 {
00123 std::string arg(argv[i]);
00124 std::string next_arg;
00125 if (i + 1 < argc) next_arg = argv[i + 1];
00126 else next_arg = "";
00127
00128 if (arg == "--text") { format = TEXT_OUT; break; }
00129 if (arg == "--xml")
00130 {
00131 if (next_arg == "")
00132 {
00133 fname = argv[0];
00134 fname += ".xml";
00135 }
00136 else
00137 {
00138 fname = next_arg;
00139 }
00140 format = XML_OUT;
00141 ofs.open(fname.c_str());
00142 }
00143 if ( arg == "--compiler" ) { format = COMPILER_OUT; break; }
00144 if ( arg == "--cerr" ) { target = 1; break; }
00145 if ( arg == "--xsl" )
00146 {
00147 if (next_arg == "") xsl = "default.xsl";
00148 else xsl = next_arg;
00149 }
00150 if ( arg == "--namespace" )
00151 {
00152 if (next_arg == "")
00153 {
00154 std::cerr << "no namespace specified" << std::endl;
00155 exit(1);
00156 }
00157 else
00158 {
00159 xsl = next_arg;
00160 }
00161 }
00162 ++i;
00163 }
00164 CppUnit::TextUi::TestRunner runner;
00165 if ( ns.empty() )
00166 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
00167 else
00168 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
00169 CppUnit::Outputter* outputter = 0;
00170 std::ostream* stream = target ? &std::cerr : &std::cout;
00171 switch ( format )
00172 {
00173 case TEXT_OUT :
00174 outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
00175 break;
00176 case XML_OUT :
00177 std::cout << "XML_OUT" << std::endl;
00178 outputter = new CppUnit::XmlOutputter(&runner.result(),
00179 ofs, "shift_jis");
00180 static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
00181 break;
00182 case COMPILER_OUT :
00183 outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
00184 break;
00185 }
00186 runner.setOutputter(outputter);
00187 runner.run();
00188 return 0;
00189 }
00190 #endif // MAIN
00191 #endif // NumberingPolicy_cpp