Possibility to pass class method reference
[command.git] / tests / option / handles_boolean_value.cpp
1 #include <iostream>
2
3 #include "option.h"
4
5 using namespace std;
6 using namespace command;
7
8 #define NAME "test"
9 #define FALSE "0"
10 #define TRUE "1"
11
12 #define OPTION1 NAME "=" FALSE
13 #define OPTION2 NAME "=" TRUE
14
15 typedef bool OptionType;
16
17 OptionType test;
18
19 void _function(OptionType value) {
20     test = value;
21 }
22
23 int main() {
24     Option<OptionType> option(NAME, "Option with boolean value", _function);
25
26     if (option.understand(OPTION1)) {
27         option.handle();
28     }
29     else {
30         cout << option.describe() << " do not understand " << FALSE << " values\n";
31         return 1;
32     }
33
34     if (test == (bool)std::stoi(FALSE)) {
35         cout << option.describe() << " handles " << FALSE << " values\n";
36     }
37
38     Option<OptionType> option2(NAME, "Option with boolean value", _function);
39
40     if (option2.understand(OPTION2)) {
41         option2.handle();
42     }
43     else {
44         cout << option.describe() << " do not understand " << TRUE << " values\n";
45         return 1;
46     }
47
48     if (test == (bool)std::stoi(TRUE)) {
49         cout << option.describe() << " handles " << TRUE << " values\n";
50         return 0;
51     }
52
53     cout << "Option class do not handle boolean values\n" << test;
54
55     return 1;
56 }