diff options
Diffstat (limited to '_test/meowpp.cpp')
-rw-r--r-- | _test/meowpp.cpp | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/_test/meowpp.cpp b/_test/meowpp.cpp index e45a4c1..c380098 100644 --- a/_test/meowpp.cpp +++ b/_test/meowpp.cpp @@ -1,5 +1,6 @@ #include "meowpp.h" +#include <vector> #include <string> #include <cstdlib> #include <ctime> @@ -9,11 +10,19 @@ //////////////////////////// meow::Usage usg("meowpp"), usg2; int count = 0; -TestFunctions tests; //////////////////////// int main(int argc, char** argv){ - //srand(time(NULL)); + std::vector<std::string> ids(meow::ObjSelector<0>::lst()); + usg2.addOption('t', "Select which subject to test", + "<number>", "", + false); + for(size_t i = 0; i < ids.size(); i++){ + TestFunction* tmp = (TestFunction*)meow::ObjSelector<0>::get(ids[i]); + usg2.addOptionValueAccept('t', ids[i], tmp->name() + ", " + tmp->description()); + delete tmp; + } + usg.addOption('h', "Display this help document"); usg.addUsageBegin("<name> is a little test program to check whether" "the data structures in the template is correct by" @@ -32,21 +41,22 @@ int main(int argc, char** argv){ usg2.update(usg); if(usg2.getOptionValuesCount('t') > 0){ for(int i = 0, I = usg2.getOptionValuesCount('t'); i < I; i++){ - int id = atoi(usg2.getOptionValue('t', i).c_str()); - TestFunction* f = (TestFunction*)tests.getImplement(id); + std::string wh = usg2.getOptionValue('t', i); + TestFunction* f = (TestFunction*)meow::ObjSelector<0>::get(wh); if(f->run() == false){ printf("error occure on %s\n", f->name().c_str()); return 1; }else{ printf("%s success\n", f->name().c_str()); } + delete f; } }else{ - std::vector<int> ids = tests.getIdentifys(); while(true){ for(int i = 0, I = ids.size(); i < I; i++){ - TestFunction* f = (TestFunction*)tests.getImplement(i); - printf(" %d) %s\n", ids[i], f->name().c_str()); + TestFunction* tmp = (TestFunction*)meow::ObjSelector<0>::get(ids[i]); + printf(" %s) %s\n", ids[i].c_str(), tmp->name().c_str()); + delete tmp; } printf("please select(EOF to quit): "); int id; @@ -54,21 +64,21 @@ int main(int argc, char** argv){ break; } printf("\n"); - TestFunction* f = (TestFunction*)tests.getImplement(id); + TestFunction* f = (TestFunction*)meow::ObjSelector<0>::get(meow::stringPrintf("%d", id)); if(f == NULL){ printf("Bad value!\n\n"); continue; } if(f->run() == false){ - printf("error occure on %s\n\n", f->name().c_str()); + printf("error occure on %s\n", f->name().c_str()); return 1; }else{ - printf("%s success\n\n", f->name().c_str()); + printf("%s success\n", f->name().c_str()); } + delete f; } printf("\n"); } - return 0; } return 0; } |