Possibility to pass class method reference
[command.git] / tests / multiValue / should_extract_arguments_by_separator.cpp
1 #include <iostream>
2 #include <vector>
3
4 #include "argument.h"
5 #include "multiValue.h"
6
7 using namespace std;
8 using namespace command;
9
10 #define VALUE "0,1,2,3,4,5,6,7,8,9"
11
12 typedef int ArgumentType;
13
14 std::vector<ArgumentType> input;
15
16 void _function(ArgumentType value) {
17     input.push_back(value);
18     cout << "Catched value: " << value << "\n";
19 }
20
21 int main() {
22     Parameter * argument = new MultiValue(",", new Argument<ArgumentType>("Argument as multiValue int", _function));
23
24     try {
25         if (argument->understand(VALUE)) {
26             argument->handle();
27         }
28         else {
29             cout << argument->describe() << " should understand multiple int values\n";
30             return 1;
31         }
32     }
33     catch (...) {
34         delete argument;
35         cout << argument->describe() << " thrown unknown exception\n";
36         return 1;
37     }
38
39     bool test = true;
40     for (int i = 0; i < 10; i++) {
41         test &= (input[i] == i);
42         cout << i << ") input: " << input[i] << "\n";
43     }
44
45     if (test) {
46         cout << argument->describe() << " handles boolean (TRUE) values\n";
47         delete argument;
48         return 0;
49     }
50
51     cout << argument->describe() << " do not handle multiple int values\n";
52     delete argument;
53     return 1;
54 }