#include "dsa.h" #include #include #include #include #include "meowpp/Usage.h" //////////////////////////// meow::Usage usg("meowpp"), usg2; int count = 0; //////////////////////// int main(int argc, char** argv){ std::vector ids(meow::ObjSelector<0>::names()); usg2.optionAdd("t", "Select which subject to test", "", "", false); for(size_t i = 0; i < ids.size(); i++){ TestFunction* tmp = (TestFunction*)meow::ObjSelector<0>::get(ids[i]); usg2.optionValueAcceptAdd("t", ids[i], tmp->name()+", "+tmp->description()); } usg.optionAdd("h", "Display this help document"); usg.optionAdd("help", "Display this help document"); usg.usageBeginAdd(" is a little test program to check whether" "the data structures in the template is correct by" "random generate lots of data to test"); usg.usageEndAdd ("zzzzzzzzzzzzzzz...."); usg.import(usg2); std::string err; if(usg.arguments(argc, argv, &err) == false){ printf("%s\n\n%s\n", err.c_str(), usg.usage().c_str()); return 1; }else if(usg.hasOptionSetup("h") || usg.hasOptionSetup("help")) { printf("%s", usg.usage().c_str()); return 0; }else{ usg2.update(usg); if(usg2.optionValuesSize("t") > 0){ for(int i = 0, I = usg2.optionValuesSize("t"); i < I; i++){ std::string wh = usg2.optionValue("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()); } } }else{ while(true){ for(int i = 0, I = ids.size(); i < I; i++){ TestFunction* tmp = (TestFunction*)meow::ObjSelector<0>::get(ids[i]); printf(" %s) %s\n", ids[i].c_str(), tmp->name().c_str()); } printf("please select(EOF to quit): "); int id; if(!~scanf("%d", &id)){ break; } printf("\n"); 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", f->name().c_str()); return 1; }else{ printf("%s success\n", f->name().c_str()); } } printf("\n"); } } return 0; }