13
13
#include < boost/algorithm/string.hpp>
14
14
#include < boost/test/unit_test.hpp>
15
15
16
- BOOST_FIXTURE_TEST_SUITE (getarg_tests, BasicTestingSetup)
16
+ namespace getarg_tests {
17
+ class LocalTestingSetup : BasicTestingSetup {
18
+ protected:
19
+ void SetupArgs (const std::vector<std::pair<std::string, unsigned int >>& args);
20
+ void ResetArgs (const std::string& strArg);
21
+ ArgsManager m_args;
22
+ };
23
+ }
24
+
25
+ BOOST_FIXTURE_TEST_SUITE (getarg_tests, LocalTestingSetup)
17
26
18
- static void ResetArgs(const std::string& strArg)
27
+ void LocalTestingSetup :: ResetArgs(const std::string& strArg)
19
28
{
20
29
std::vector<std::string> vecArg;
21
30
if (strArg.size ())
@@ -30,14 +39,14 @@ static void ResetArgs(const std::string& strArg)
30
39
vecChar.push_back (s.c_str ());
31
40
32
41
std::string error;
33
- BOOST_CHECK (gArgs .ParseParameters (vecChar.size (), vecChar.data (), error));
42
+ BOOST_CHECK (m_args .ParseParameters (vecChar.size (), vecChar.data (), error));
34
43
}
35
44
36
- static void SetupArgs (const std::vector<std::pair<std::string, unsigned int >>& args)
45
+ void LocalTestingSetup :: SetupArgs(const std::vector<std::pair<std::string, unsigned int >>& args)
37
46
{
38
- gArgs .ClearArgs ();
47
+ m_args .ClearArgs ();
39
48
for (const auto & arg : args) {
40
- gArgs .AddArg (arg.first , " " , arg.second , OptionsCategory::OPTIONS);
49
+ m_args .AddArg (arg.first , " " , arg.second , OptionsCategory::OPTIONS);
41
50
}
42
51
}
43
52
@@ -46,52 +55,52 @@ BOOST_AUTO_TEST_CASE(boolarg)
46
55
const auto foo = std::make_pair (" -foo" , ArgsManager::ALLOW_ANY);
47
56
SetupArgs ({foo});
48
57
ResetArgs (" -foo" );
49
- BOOST_CHECK (gArgs .GetBoolArg (" -foo" , false ));
50
- BOOST_CHECK (gArgs .GetBoolArg (" -foo" , true ));
58
+ BOOST_CHECK (m_args .GetBoolArg (" -foo" , false ));
59
+ BOOST_CHECK (m_args .GetBoolArg (" -foo" , true ));
51
60
52
- BOOST_CHECK (!gArgs .GetBoolArg (" -fo" , false ));
53
- BOOST_CHECK (gArgs .GetBoolArg (" -fo" , true ));
61
+ BOOST_CHECK (!m_args .GetBoolArg (" -fo" , false ));
62
+ BOOST_CHECK (m_args .GetBoolArg (" -fo" , true ));
54
63
55
- BOOST_CHECK (!gArgs .GetBoolArg (" -fooo" , false ));
56
- BOOST_CHECK (gArgs .GetBoolArg (" -fooo" , true ));
64
+ BOOST_CHECK (!m_args .GetBoolArg (" -fooo" , false ));
65
+ BOOST_CHECK (m_args .GetBoolArg (" -fooo" , true ));
57
66
58
67
ResetArgs (" -foo=0" );
59
- BOOST_CHECK (!gArgs .GetBoolArg (" -foo" , false ));
60
- BOOST_CHECK (!gArgs .GetBoolArg (" -foo" , true ));
68
+ BOOST_CHECK (!m_args .GetBoolArg (" -foo" , false ));
69
+ BOOST_CHECK (!m_args .GetBoolArg (" -foo" , true ));
61
70
62
71
ResetArgs (" -foo=1" );
63
- BOOST_CHECK (gArgs .GetBoolArg (" -foo" , false ));
64
- BOOST_CHECK (gArgs .GetBoolArg (" -foo" , true ));
72
+ BOOST_CHECK (m_args .GetBoolArg (" -foo" , false ));
73
+ BOOST_CHECK (m_args .GetBoolArg (" -foo" , true ));
65
74
66
75
// New 0.6 feature: auto-map -nosomething to !-something:
67
76
ResetArgs (" -nofoo" );
68
- BOOST_CHECK (!gArgs .GetBoolArg (" -foo" , false ));
69
- BOOST_CHECK (!gArgs .GetBoolArg (" -foo" , true ));
77
+ BOOST_CHECK (!m_args .GetBoolArg (" -foo" , false ));
78
+ BOOST_CHECK (!m_args .GetBoolArg (" -foo" , true ));
70
79
71
80
ResetArgs (" -nofoo=1" );
72
- BOOST_CHECK (!gArgs .GetBoolArg (" -foo" , false ));
73
- BOOST_CHECK (!gArgs .GetBoolArg (" -foo" , true ));
81
+ BOOST_CHECK (!m_args .GetBoolArg (" -foo" , false ));
82
+ BOOST_CHECK (!m_args .GetBoolArg (" -foo" , true ));
74
83
75
84
ResetArgs (" -foo -nofoo" ); // -nofoo should win
76
- BOOST_CHECK (!gArgs .GetBoolArg (" -foo" , false ));
77
- BOOST_CHECK (!gArgs .GetBoolArg (" -foo" , true ));
85
+ BOOST_CHECK (!m_args .GetBoolArg (" -foo" , false ));
86
+ BOOST_CHECK (!m_args .GetBoolArg (" -foo" , true ));
78
87
79
88
ResetArgs (" -foo=1 -nofoo=1" ); // -nofoo should win
80
- BOOST_CHECK (!gArgs .GetBoolArg (" -foo" , false ));
81
- BOOST_CHECK (!gArgs .GetBoolArg (" -foo" , true ));
89
+ BOOST_CHECK (!m_args .GetBoolArg (" -foo" , false ));
90
+ BOOST_CHECK (!m_args .GetBoolArg (" -foo" , true ));
82
91
83
92
ResetArgs (" -foo=0 -nofoo=0" ); // -nofoo=0 should win
84
- BOOST_CHECK (gArgs .GetBoolArg (" -foo" , false ));
85
- BOOST_CHECK (gArgs .GetBoolArg (" -foo" , true ));
93
+ BOOST_CHECK (m_args .GetBoolArg (" -foo" , false ));
94
+ BOOST_CHECK (m_args .GetBoolArg (" -foo" , true ));
86
95
87
96
// New 0.6 feature: treat -- same as -:
88
97
ResetArgs (" --foo=1" );
89
- BOOST_CHECK (gArgs .GetBoolArg (" -foo" , false ));
90
- BOOST_CHECK (gArgs .GetBoolArg (" -foo" , true ));
98
+ BOOST_CHECK (m_args .GetBoolArg (" -foo" , false ));
99
+ BOOST_CHECK (m_args .GetBoolArg (" -foo" , true ));
91
100
92
101
ResetArgs (" --nofoo=1" );
93
- BOOST_CHECK (!gArgs .GetBoolArg (" -foo" , false ));
94
- BOOST_CHECK (!gArgs .GetBoolArg (" -foo" , true ));
102
+ BOOST_CHECK (!m_args .GetBoolArg (" -foo" , false ));
103
+ BOOST_CHECK (!m_args .GetBoolArg (" -foo" , true ));
95
104
96
105
}
97
106
@@ -101,24 +110,24 @@ BOOST_AUTO_TEST_CASE(stringarg)
101
110
const auto bar = std::make_pair (" -bar" , ArgsManager::ALLOW_ANY);
102
111
SetupArgs ({foo, bar});
103
112
ResetArgs (" " );
104
- BOOST_CHECK_EQUAL (gArgs .GetArg (" -foo" , " " ), " " );
105
- BOOST_CHECK_EQUAL (gArgs .GetArg (" -foo" , " eleven" ), " eleven" );
113
+ BOOST_CHECK_EQUAL (m_args .GetArg (" -foo" , " " ), " " );
114
+ BOOST_CHECK_EQUAL (m_args .GetArg (" -foo" , " eleven" ), " eleven" );
106
115
107
116
ResetArgs (" -foo -bar" );
108
- BOOST_CHECK_EQUAL (gArgs .GetArg (" -foo" , " " ), " " );
109
- BOOST_CHECK_EQUAL (gArgs .GetArg (" -foo" , " eleven" ), " " );
117
+ BOOST_CHECK_EQUAL (m_args .GetArg (" -foo" , " " ), " " );
118
+ BOOST_CHECK_EQUAL (m_args .GetArg (" -foo" , " eleven" ), " " );
110
119
111
120
ResetArgs (" -foo=" );
112
- BOOST_CHECK_EQUAL (gArgs .GetArg (" -foo" , " " ), " " );
113
- BOOST_CHECK_EQUAL (gArgs .GetArg (" -foo" , " eleven" ), " " );
121
+ BOOST_CHECK_EQUAL (m_args .GetArg (" -foo" , " " ), " " );
122
+ BOOST_CHECK_EQUAL (m_args .GetArg (" -foo" , " eleven" ), " " );
114
123
115
124
ResetArgs (" -foo=11" );
116
- BOOST_CHECK_EQUAL (gArgs .GetArg (" -foo" , " " ), " 11" );
117
- BOOST_CHECK_EQUAL (gArgs .GetArg (" -foo" , " eleven" ), " 11" );
125
+ BOOST_CHECK_EQUAL (m_args .GetArg (" -foo" , " " ), " 11" );
126
+ BOOST_CHECK_EQUAL (m_args .GetArg (" -foo" , " eleven" ), " 11" );
118
127
119
128
ResetArgs (" -foo=eleven" );
120
- BOOST_CHECK_EQUAL (gArgs .GetArg (" -foo" , " " ), " eleven" );
121
- BOOST_CHECK_EQUAL (gArgs .GetArg (" -foo" , " eleven" ), " eleven" );
129
+ BOOST_CHECK_EQUAL (m_args .GetArg (" -foo" , " " ), " eleven" );
130
+ BOOST_CHECK_EQUAL (m_args .GetArg (" -foo" , " eleven" ), " eleven" );
122
131
123
132
}
124
133
@@ -128,20 +137,20 @@ BOOST_AUTO_TEST_CASE(intarg)
128
137
const auto bar = std::make_pair (" -bar" , ArgsManager::ALLOW_ANY);
129
138
SetupArgs ({foo, bar});
130
139
ResetArgs (" " );
131
- BOOST_CHECK_EQUAL (gArgs .GetArg (" -foo" , 11 ), 11 );
132
- BOOST_CHECK_EQUAL (gArgs .GetArg (" -foo" , 0 ), 0 );
140
+ BOOST_CHECK_EQUAL (m_args .GetArg (" -foo" , 11 ), 11 );
141
+ BOOST_CHECK_EQUAL (m_args .GetArg (" -foo" , 0 ), 0 );
133
142
134
143
ResetArgs (" -foo -bar" );
135
- BOOST_CHECK_EQUAL (gArgs .GetArg (" -foo" , 11 ), 0 );
136
- BOOST_CHECK_EQUAL (gArgs .GetArg (" -bar" , 11 ), 0 );
144
+ BOOST_CHECK_EQUAL (m_args .GetArg (" -foo" , 11 ), 0 );
145
+ BOOST_CHECK_EQUAL (m_args .GetArg (" -bar" , 11 ), 0 );
137
146
138
147
ResetArgs (" -foo=11 -bar=12" );
139
- BOOST_CHECK_EQUAL (gArgs .GetArg (" -foo" , 0 ), 11 );
140
- BOOST_CHECK_EQUAL (gArgs .GetArg (" -bar" , 11 ), 12 );
148
+ BOOST_CHECK_EQUAL (m_args .GetArg (" -foo" , 0 ), 11 );
149
+ BOOST_CHECK_EQUAL (m_args .GetArg (" -bar" , 11 ), 12 );
141
150
142
151
ResetArgs (" -foo=NaN -bar=NotANumber" );
143
- BOOST_CHECK_EQUAL (gArgs .GetArg (" -foo" , 1 ), 0 );
144
- BOOST_CHECK_EQUAL (gArgs .GetArg (" -bar" , 11 ), 0 );
152
+ BOOST_CHECK_EQUAL (m_args .GetArg (" -foo" , 1 ), 0 );
153
+ BOOST_CHECK_EQUAL (m_args .GetArg (" -bar" , 11 ), 0 );
145
154
}
146
155
147
156
BOOST_AUTO_TEST_CASE (doubledash)
@@ -150,11 +159,11 @@ BOOST_AUTO_TEST_CASE(doubledash)
150
159
const auto bar = std::make_pair (" -bar" , ArgsManager::ALLOW_ANY);
151
160
SetupArgs ({foo, bar});
152
161
ResetArgs (" --foo" );
153
- BOOST_CHECK_EQUAL (gArgs .GetBoolArg (" -foo" , false ), true );
162
+ BOOST_CHECK_EQUAL (m_args .GetBoolArg (" -foo" , false ), true );
154
163
155
164
ResetArgs (" --foo=verbose --bar=1" );
156
- BOOST_CHECK_EQUAL (gArgs .GetArg (" -foo" , " " ), " verbose" );
157
- BOOST_CHECK_EQUAL (gArgs .GetArg (" -bar" , 0 ), 1 );
165
+ BOOST_CHECK_EQUAL (m_args .GetArg (" -foo" , " " ), " verbose" );
166
+ BOOST_CHECK_EQUAL (m_args .GetArg (" -bar" , 0 ), 1 );
158
167
}
159
168
160
169
BOOST_AUTO_TEST_CASE (boolargno)
@@ -163,24 +172,24 @@ BOOST_AUTO_TEST_CASE(boolargno)
163
172
const auto bar = std::make_pair (" -bar" , ArgsManager::ALLOW_ANY);
164
173
SetupArgs ({foo, bar});
165
174
ResetArgs (" -nofoo" );
166
- BOOST_CHECK (!gArgs .GetBoolArg (" -foo" , true ));
167
- BOOST_CHECK (!gArgs .GetBoolArg (" -foo" , false ));
175
+ BOOST_CHECK (!m_args .GetBoolArg (" -foo" , true ));
176
+ BOOST_CHECK (!m_args .GetBoolArg (" -foo" , false ));
168
177
169
178
ResetArgs (" -nofoo=1" );
170
- BOOST_CHECK (!gArgs .GetBoolArg (" -foo" , true ));
171
- BOOST_CHECK (!gArgs .GetBoolArg (" -foo" , false ));
179
+ BOOST_CHECK (!m_args .GetBoolArg (" -foo" , true ));
180
+ BOOST_CHECK (!m_args .GetBoolArg (" -foo" , false ));
172
181
173
182
ResetArgs (" -nofoo=0" );
174
- BOOST_CHECK (gArgs .GetBoolArg (" -foo" , true ));
175
- BOOST_CHECK (gArgs .GetBoolArg (" -foo" , false ));
183
+ BOOST_CHECK (m_args .GetBoolArg (" -foo" , true ));
184
+ BOOST_CHECK (m_args .GetBoolArg (" -foo" , false ));
176
185
177
186
ResetArgs (" -foo --nofoo" ); // --nofoo should win
178
- BOOST_CHECK (!gArgs .GetBoolArg (" -foo" , true ));
179
- BOOST_CHECK (!gArgs .GetBoolArg (" -foo" , false ));
187
+ BOOST_CHECK (!m_args .GetBoolArg (" -foo" , true ));
188
+ BOOST_CHECK (!m_args .GetBoolArg (" -foo" , false ));
180
189
181
190
ResetArgs (" -nofoo -foo" ); // foo always wins:
182
- BOOST_CHECK (gArgs .GetBoolArg (" -foo" , true ));
183
- BOOST_CHECK (gArgs .GetBoolArg (" -foo" , false ));
191
+ BOOST_CHECK (m_args .GetBoolArg (" -foo" , true ));
192
+ BOOST_CHECK (m_args .GetBoolArg (" -foo" , false ));
184
193
}
185
194
186
195
BOOST_AUTO_TEST_CASE (logargs)
@@ -200,7 +209,7 @@ BOOST_AUTO_TEST_CASE(logargs)
200
209
});
201
210
202
211
// Log the arguments
203
- gArgs .LogArgs ();
212
+ m_args .LogArgs ();
204
213
205
214
LogInstance ().DeleteCallback (print_connection);
206
215
// Check that what should appear does, and what shouldn't doesn't.
0 commit comments