Possibility to pass class method reference
[command.git] / tests / option / handles_string_value.cpp
1 #include <cstring>
2 #include <iostream>
3
4 #include "option.h"
5
6 using namespace std;
7 using namespace command;
8
9 #define NAME "test"
10 #define VALUE "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
11
12 #define OPTION NAME "=" VALUE
13
14 typedef std::string OptionType;
15
16 OptionType test;
17
18 void _function(OptionType value) {
19     test = value;
20 }
21
22 int main() {
23     Option<OptionType> option(NAME, "Option with string value", _function);
24
25     if (option.understand(OPTION)) {
26         option.handle();
27     }
28     else {
29         cout << option.describe() << " do not understand string values\n";
30         return 1;
31     }
32
33     int cmp = strcmp(test.c_str(), VALUE);
34
35     if (cmp == 0) {
36         cout << option.describe() << " handles string values\n";
37         return 0;
38     }
39
40     cout << "Option class do not handle string values\n";
41
42     return 1;
43 }