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