aboutsummaryrefslogtreecommitdiffstats
path: root/meowpp.test/src/dsa.cpp
blob: c38009881a121481caf80c97366acf8bf490b67f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "meowpp.h"

#include <vector>
#include <string>
#include <cstdlib>
#include <ctime>

#include "meowpp/Usage.h"

////////////////////////////
meow::Usage usg("meowpp"), usg2;
int count = 0;
////////////////////////

int main(int argc, char** argv){
  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"
                    "random generate lots of data to test");
  usg.addUsageEnd  ("zzzzzzzzzzzzzzz....");
  usg.import(usg2);
  
  std::string err;
  if(usg.setArguments(argc, argv, &err) == false){
    printf("%s\n\n%s\n", err.c_str(), usg.getUsage().c_str());
    return 1;
  }else if(usg.hasOptionSetup('h')){
    printf("%s", usg.getUsage().c_str());
    return 0;
  }else{
    usg2.update(usg);
    if(usg2.getOptionValuesCount('t') > 0){
      for(int i = 0, I = usg2.getOptionValuesCount('t'); i < I; i++){
        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{
      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());
          delete tmp;
        }
        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());
        }
        delete f;
      }
      printf("\n");
    }
  }
  return 0;
}