00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <map>
00026 #include <vector>
00027 #include <memory>
00028 #include <tr1/memory>
00029 #include <iostream>
00030 #include <sstream>
00031 #include <boost/algorithm/string.hpp>
00032
00033 #include "proc/nobugcfg.hpp"
00034 #include "common/cmdline.hpp"
00035 #include "common/test/suite.hpp"
00036 #include "common/test/run.hpp"
00037 #include "common/error.hpp"
00038 #include "common/util.hpp"
00039
00040
00041
00042 namespace test
00043 {
00044 using std::map;
00045 using std::vector;
00046 using std::auto_ptr;
00047 using std::tr1::shared_ptr;
00048 using boost::algorithm::trim;
00049
00050 using util::isnil;
00051 using util::contains;
00052
00053 typedef map<string, Launcher*> TestMap;
00054 typedef shared_ptr<TestMap> PTestMap;
00055 typedef map<string,PTestMap> GroupMap;
00056
00057
00058
00068 class Registry
00069 {
00070 auto_ptr<GroupMap> groups;
00071 public:
00072 Registry() : groups(new GroupMap ) {};
00073 PTestMap& getGroup (string grpID) { return (*groups)[grpID]; };
00074 void add2group (Launcher* test, string testID, string groupID);
00075 };
00076
00077 void
00078 Registry::add2group (Launcher* test, string testID, string groupID)
00079 {
00080 REQUIRE( test );
00081 REQUIRE( !isnil(testID) );
00082 REQUIRE( !isnil(groupID) );
00083
00084 PTestMap& group = getGroup(groupID);
00085 if (!group)
00086 group.reset( new TestMap );
00087 (*group)[testID] = test;
00088 }
00089
00090 Registry testcases;
00091
00092
00093
00094
00104 void
00105 Suite::enroll (Launcher* test, string testID, string groups)
00106 {
00107 REQUIRE( test );
00108 REQUIRE( !isnil(testID) );
00109
00110 std::istringstream ss(groups);
00111 string group;
00112 while (ss >> group )
00113 testcases.add2group(test, testID, group);
00114
00115
00116 testcases.add2group(test,testID, ALLGROUP);
00117 }
00118
00120 const string Suite::ALLGROUP = "ALL";
00121
00122
00123
00129 Suite::Suite(string groupID)
00130 : groupID_(groupID)
00131 {
00132 REQUIRE( !isnil(groupID) );
00133 TRACE(test, "Test-Suite( groupID=%s )\n", groupID.c_str () );
00134
00135 if (!testcases.getGroup(groupID))
00136 throw lumiera::error::Invalid ();
00137
00138 }
00139
00140 #define VALID(test,testID) \
00141 ASSERT ((test), "NULL testcase laucher for test '%s' found in testsuite '%s'", groupID_.c_str(),testID.c_str());
00142
00143
00153 void
00154 Suite::run (Arg cmdline)
00155 {
00156 PTestMap tests = testcases.getGroup(groupID_);
00157 if (!tests)
00158 throw lumiera::error::Invalid ();
00159
00160 if (0 < cmdline.size())
00161 {
00162 string& testID (cmdline[0]);
00163 trim(testID);
00164 if ( contains (*tests, testID))
00165 {
00166
00167
00168 Launcher* test = (*tests)[testID];
00169 cmdline.erase (cmdline.begin());
00170 VALID (test,testID);
00171 (*test)()->run(cmdline);
00172 return;
00173 } }
00174
00175
00176
00177 for ( TestMap::iterator i=tests->begin(); i!=tests->end(); ++i )
00178 {
00179 std::cout << "\n ----------"<< i->first<< "----------\n";
00180 Launcher* test = (i->second);
00181 VALID (test, i->first);
00182 (*test)()->run(cmdline);
00183 }
00184 }
00185
00186
00190 void
00191 Suite::describe ()
00192 {
00193 util::Cmdline noCmdline("");
00194 PTestMap tests = testcases.getGroup(groupID_);
00195 ASSERT (tests);
00196
00197 std::cout << "TESTING \"Component Test Suite: " << groupID_ << "\" ./test-components\n\n";
00198
00199 for ( TestMap::iterator i=tests->begin(); i!=tests->end(); ++i )
00200 {
00201 string key (i->first);
00202 std::cout << "\n\n";
00203 std::cout << "TEST \""<<key<<"\" "<<key<<" <<END\n";
00204 Launcher* test = (i->second);
00205 VALID (test, i->first);
00206 try
00207 {
00208 (*test)()->run(noCmdline);
00209 }
00210 catch (...)
00211 {
00212 std::cout << "PLANNED ============= " << lumiera_error() << "\n";
00213 }
00214 std::cout << "END\n";
00215 }
00216 }
00217
00218
00219
00220 }