-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathOptionsTest.cpp
420 lines (328 loc) · 12.1 KB
/
OptionsTest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
#include "catch.hpp"
#include "Options.h"
#include <vector>
#include <string>
#include <boost/tokenizer.hpp>
#include <algorithm>
namespace {
Options opt(const std::string& str) {
std::vector<std::string> tokens;
boost::tokenizer<boost::char_separator<char>> tokenizer{str, boost::char_separator<char>{" "}};
tokens.insert(tokens.end(), tokenizer.begin(), tokenizer.end());
std::vector<const char*> cmdline{"abrade"};
transform(tokens.begin(), tokens.end(), back_inserter(cmdline),
[](const auto& str) { return str.c_str(); });
return Options{static_cast<int>(cmdline.size()), cmdline.data()};
}
}
TEST_CASE("Options") {
SECTION("throws when given") {
SECTION("empty arguments") { REQUIRE_THROWS(opt("")); }
SECTION("three positionals") { REQUIRE_THROWS(opt("lospi.net /?asdf[1-100] WHATAMIDOING")); }
}
SECTION("When given help") {
auto options = opt("--help");
SECTION("is_help is true") { REQUIRE(options.is_help()); }
SECTION("pattern is root") { REQUIRE(options.get_pattern() == "/"); }
SECTION("host is blank") { REQUIRE(options.get_host() == ""); }
SECTION("ssl is false") { REQUIRE(options.is_tls() == false); }
SECTION("verify is false") { REQUIRE(options.is_verify() == false); }
SECTION("contents is false") { REQUIRE(options.is_contents() == false); }
}
SECTION("Help string isn't blank") {
auto options = opt("--help");
REQUIRE(options.get_help().size() > 0);
}
SECTION("Parses stdin correctly with") {
auto cmdline = std::string{ "myhost.com --stdin" };
SECTION("no options") {
auto options = opt(cmdline);
REQUIRE(options.is_stdin());
REQUIRE(options.get_host() == "myhost.com");
}
}
SECTION("Parses host and pattern correctly with") {
auto host_name = "lospi.net";
auto pattern = "?asdf[1-10]";
auto cmdline = std::string{ host_name };
cmdline.append(" ");
cmdline.append(pattern);
SECTION("no options") {
auto options = opt(cmdline);
REQUIRE(options.get_host() == host_name);
REQUIRE(options.get_pattern() == pattern);
}
SECTION("with ssl") {
auto options = opt(cmdline + " --tls");
REQUIRE(options.get_host() == host_name);
REQUIRE(options.get_pattern() == pattern);
}
SECTION("with ssl and verify") {
auto options = opt(cmdline + " --tls --verify");
REQUIRE(options.get_host() == host_name);
REQUIRE(options.get_pattern() == pattern);
}
SECTION("with ssl and verify and contents") {
auto options = opt(cmdline + " --tls --verify --contents");
REQUIRE(options.get_host() == host_name);
REQUIRE(options.get_pattern() == pattern);
}
}
SECTION("Parses ssl correctly") {
auto cmdline = std::string{ "lospi.net ?asdf[1-10]" };
SECTION("with no options") {
auto options = opt(cmdline);
REQUIRE(options.is_tls() == false);
}
SECTION("with ssl") {
auto options = opt(cmdline + " --tls");
REQUIRE(options.is_tls() == true);
}
SECTION("with verify") {
auto options = opt(cmdline + " --verify");
REQUIRE(options.is_tls() == true);
}
SECTION("with ssl and verify") {
auto options = opt(cmdline + " --tls --verify");
REQUIRE(options.is_tls() == true);
}
SECTION("with contents") {
auto options = opt(cmdline + " --contents");
REQUIRE(options.is_tls() == false);
}
SECTION("with contents and ssl") {
auto options = opt(cmdline + " --contents --tls");
REQUIRE(options.is_tls() == true);
}
SECTION("with contents and verify") {
auto options = opt(cmdline + " --contents --verify");
REQUIRE(options.is_tls() == true);
}
}
SECTION("Parses contents correctly") {
auto cmdline = std::string{ "lospi.net ?asdf[1-10]" };
SECTION("with contents") {
cmdline += " --contents";
SECTION("and with ssl") {
auto options = opt(cmdline + " --tls");
REQUIRE(options.is_contents() == true);
}
SECTION("and with verify") {
auto options = opt(cmdline + " --verify");
REQUIRE(options.is_contents() == true);
}
SECTION("and with ssl and verify") {
auto options = opt(cmdline + " --tls --verify");
REQUIRE(options.is_contents() == true);
}
}
SECTION("without contents and") {
SECTION("with ssl") {
auto options = opt(cmdline + " --tls");
REQUIRE(options.is_contents() == false);
}
SECTION("with verify") {
auto options = opt(cmdline + " --verify");
REQUIRE(options.is_contents() == false);
}
SECTION("with ssl and verify") {
auto options = opt(cmdline + " --tls --verify");
REQUIRE(options.is_contents() == false);
}
}
}
SECTION("Parses output correctly with") {
auto cmdline = std::string{ "lospi.net ?asdf[1-10]" };
SECTION("default") {
auto options = opt(cmdline);
REQUIRE(options.get_output_path() == "lospi.net");
}
SECTION("default and --contents") {
auto options = opt(cmdline + " --contents");
REQUIRE(options.get_output_path() == "lospi.net-contents");
}
SECTION("custom value") {
auto options = opt(cmdline + " --out=my-custom-path");
REQUIRE(options.get_output_path() == "my-custom-path");
}
}
SECTION("Parses proxy correctly with") {
auto cmdline = std::string{ "lospi.net ?asdf[1-10]" };
SECTION("default") {
auto options = opt(cmdline);
REQUIRE(options.get_proxy() == "");
REQUIRE(options.is_proxy() == false);
}
SECTION("custom value") {
auto options = opt(cmdline + " --proxy=127.0.0.1:9050");
REQUIRE(options.get_proxy() == "127.0.0.1:9050");
REQUIRE(options.is_proxy() == true);
}
SECTION("tor") {
auto options = opt(cmdline + " --tor");
REQUIRE(options.get_proxy() == "127.0.0.1:9050");
REQUIRE(options.is_proxy() == true);
}
SECTION("tor and proxy") {
auto options = opt(cmdline + " --tor --proxy=8.8.8.8:9050");
REQUIRE(options.get_proxy() == "8.8.8.8:9050");
REQUIRE(options.is_proxy() == true);
}
}
SECTION("Parses verbose correctly") {
auto cmdline = std::string{ "lospi.net ?asdf[1-10]" };
SECTION("with no options") {
auto options = opt(cmdline);
REQUIRE(options.is_verbose() == false);
}
SECTION("with verbose option") {
auto options = opt(cmdline + " --verbose");
REQUIRE(options.is_verbose() == true);
}
}
SECTION("Parses print found correctly") {
auto cmdline = std::string{ "lospi.net ?asdf[1-10]" };
SECTION("with no options") {
auto options = opt(cmdline);
REQUIRE(options.is_print_found() == false);
}
SECTION("with found option") {
auto options = opt(cmdline + " --found");
REQUIRE(options.is_print_found() == true);
}
SECTION("with verbose option") {
auto options = opt(cmdline + " --verbose");
REQUIRE(options.is_print_found() == true);
}
SECTION("with verbose and found options") {
auto options = opt(cmdline + " --verbose --found");
REQUIRE(options.is_print_found() == true);
}
}
SECTION("Parses sensitive TCP teardown correctly") {
auto cmdline = std::string{ "lospi.net ?asdf[1-10]" };
SECTION("with no options") {
auto options = opt(cmdline);
REQUIRE(options.is_sensitive_teardown() == false);
}
SECTION("with found option") {
auto options = opt(cmdline + " --sensitive");
REQUIRE(options.is_sensitive_teardown() == true);
}
}
SECTION("Parses optimizer correctly") {
auto cmdline = std::string{ "lospi.net ?asdf[1-10]" };
SECTION("with no options") {
auto options = opt(cmdline);
REQUIRE(options.is_optimizer() == false);
}
SECTION("with fixed options") {
auto options = opt(cmdline + " --optimize");
REQUIRE(options.is_optimizer() == true);
}
}
SECTION("Parses test correctly") {
auto cmdline = std::string{ "lospi.net ?asdf[1-10]" };
SECTION("with no options") {
auto options = opt(cmdline);
REQUIRE(options.is_test() == false);
}
SECTION("with test") {
auto options = opt(cmdline + " --test");
REQUIRE(options.is_test() == true);
}
}
SECTION("Parses leading zeroes correctly") {
auto cmdline = std::string{ "lospi.net ?asdf[1-10]" };
SECTION("with no options") {
auto options = opt(cmdline);
REQUIRE(options.is_leading_zeros() == false);
}
SECTION("with leadzero") {
auto options = opt(cmdline + " --leadzero");
REQUIRE(options.is_leading_zeros() == true);
}
}
SECTION("Parses telescoping correctly") {
auto cmdline = std::string{ "lospi.net ?asdf[1-10]" };
SECTION("with no options") {
auto options = opt(cmdline);
REQUIRE(options.is_telescoping() == false);
}
SECTION("with telescoping") {
auto options = opt(cmdline + " --telescoping");
REQUIRE(options.is_telescoping() == true);
}
}
SECTION("Parses user agent correctly with") {
auto cmdline = std::string{ "lospi.net ?asdf[1-10]" };
SECTION("default") {
auto options = opt(cmdline);
REQUIRE(options.get_user_agent() == "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0");
}
SECTION("custom value") {
auto options = opt(cmdline + " --agent=my-user-agent-string");
REQUIRE(options.get_user_agent() == "my-user-agent-string");
}
}
SECTION("Parses initial coroutines correctly") {
auto cmdline = std::string{ "lospi.net ?asdf[1-10]" };
SECTION("with no options") {
auto options = opt(cmdline);
REQUIRE(options.get_initial_coroutines() == 1000);
}
SECTION("with a non-default value") {
auto options = opt(cmdline + " --init=25");
REQUIRE(options.get_initial_coroutines() == 25);
}
SECTION("with an illegal value") { REQUIRE_THROWS(opt(cmdline + " --init=0")); }
}
SECTION("Parses minimum coroutines correctly") {
auto cmdline = std::string{ "lospi.net ?asdf[1-10]" };
SECTION("with no options") {
auto options = opt(cmdline);
REQUIRE(options.get_minimum_coroutines() == 1);
}
SECTION("with a non-default value") {
auto options = opt(cmdline + " --min=25");
REQUIRE(options.get_minimum_coroutines() == 25);
}
SECTION("with an illegal value") { REQUIRE_THROWS(opt(cmdline + " --min=0")); }
}
SECTION("Parses maximum coroutines correctly") {
auto cmdline = std::string{ "lospi.net ?asdf[1-10]" };
SECTION("with no options") {
auto options = opt(cmdline);
REQUIRE(options.get_maximum_coroutines() == 25000);
}
SECTION("with a non-default value") {
auto options = opt(cmdline + " --max=25");
REQUIRE(options.get_maximum_coroutines() == 25);
}
SECTION("with an illegal value") { REQUIRE_THROWS(opt(cmdline + " --max=0")); }
}
SECTION("Parses sample size correctly") {
auto cmdline = std::string{ "lospi.net ?asdf[1-10]" };
SECTION("with no options") {
auto options = opt(cmdline);
REQUIRE(options.get_sample_size() == 50);
}
SECTION("with a non-default value") {
auto options = opt(cmdline + " --ssize=25");
REQUIRE(options.get_sample_size() == 25);
}
SECTION("with an illegal value") { REQUIRE_THROWS(opt(cmdline + " --ssize=0")); }
}
SECTION("Parses sample interval correctly") {
auto cmdline = std::string{ "lospi.net ?asdf[1-10]" };
SECTION("with no options") {
auto options = opt(cmdline);
REQUIRE(options.get_sample_interval() == 1000);
}
SECTION("with a non-default value") {
auto options = opt(cmdline + " --sint=25");
REQUIRE(options.get_sample_interval() == 25);
}
SECTION("with an illegal value") { REQUIRE_THROWS(opt(cmdline + " --sint=0")); }
}
}