mavtables  0.2.1
MAVLink router and firewall.
test_config_grammar.cpp
Go to the documentation of this file.
1 // MAVLink router and firewall.
2 // Copyright (C) 2018 Michael R. Shannon <mrshannon.aerospace@gmail.com>
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 
18 #include <sstream>
19 
20 #include <catch.hpp>
21 #include <fakeit.hpp>
22 #include <pegtl.hpp>
23 
24 #include "config_grammar.hpp"
25 #include "utility.hpp"
26 
27 #include "common.hpp"
28 
29 
30 TEST_CASE("A configuration string must have at least one valid statement "
31  "or block.", "[config]")
32 {
33  tao::pegtl::string_input<> in("1337", "");
34  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
35  REQUIRE_THROWS_WITH(
36  config::parse(in),
37  ":1:0(0): expected at least one valid statement or block");
38 }
39 
40 
41 TEST_CASE("Global statements.", "[config]")
42 {
43  SECTION("Missing end of statement ';'.")
44  {
45  tao::pegtl::string_input<> in("invalid", "");
46  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
47  REQUIRE_THROWS_WITH(
48  config::parse(in),
49  ":1:7(7): expected end of statement ';' character");
50  }
51  SECTION("Invalid statement.")
52  {
53  tao::pegtl::string_input<> in("invalid;", "");
54  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
55  REQUIRE_THROWS_WITH(
56  config::parse(in), ":1:8(8): unsupported statement");
57  }
58 }
59 
60 
61 TEST_CASE("Parse global 'default_action' statement.", "[config]")
62 {
63  SECTION("Parses the 'accept' option.")
64  {
65  tao::pegtl::string_input<> in("default_action accept;", "");
66  auto root = config::parse(in);
67  REQUIRE(root != nullptr);
68  REQUIRE(
69  str(*root) ==
70  ":001: default_action\n"
71  ":001: | accept\n");
72  }
73  SECTION("Parses the 'accept' option (with comments).")
74  {
75  tao::pegtl::string_input<> in("default_action accept;# comment", "");
76  auto root = config::parse(in);
77  REQUIRE(root != nullptr);
78  REQUIRE(
79  str(*root) ==
80  ":001: default_action\n"
81  ":001: | accept\n");
82  }
83  SECTION("Parses the 'reject' option.")
84  {
85  tao::pegtl::string_input<> in("default_action reject;", "");
86  auto root = config::parse(in);
87  REQUIRE(root != nullptr);
88  REQUIRE(
89  str(*root) ==
90  ":001: default_action\n"
91  ":001: | reject\n");
92  }
93  SECTION("Parses the 'reject' option (with comments).")
94  {
95  tao::pegtl::string_input<> in("default_action reject;# comment", "");
96  auto root = config::parse(in);
97  REQUIRE(root != nullptr);
98  REQUIRE(
99  str(*root) ==
100  ":001: default_action\n"
101  ":001: | reject\n");
102  }
103  SECTION("Missing end of statement.")
104  {
105  tao::pegtl::string_input<> in("default_action accept", "");
106  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
107  REQUIRE_THROWS_WITH(
108  config::parse(in),
109  ":1:21(21): expected end of statement ';' character");
110  }
111  SECTION("Invalid default action.")
112  {
113  tao::pegtl::string_input<> in("default_action invalid;", "");
114  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
115  REQUIRE_THROWS_WITH(
116  config::parse(in), ":1:15(15): expected 'accept' or 'reject'");
117  }
118  SECTION("Missing default action value.")
119  {
120  tao::pegtl::string_input<> in("default_action;", "");
121  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
122  REQUIRE_THROWS_WITH(
123  config::parse(in), ":1:14(14): expected 'accept' or 'reject'");
124  }
125 }
126 
127 
128 TEST_CASE("UDP configuration block.", "[config]")
129 {
130  SECTION("Empty UDP blocks are allowed (single line).")
131  {
132  tao::pegtl::string_input<> in("udp {}", "");
133  auto root = config::parse(in);
134  REQUIRE(root != nullptr);
135  REQUIRE(str(*root) == ":001: udp\n");
136  }
137  SECTION("Empty UDP blocks are allowed (single line with comments).")
138  {
139  tao::pegtl::string_input<> in("udp {}# comment", "");
140  auto root = config::parse(in);
141  REQUIRE(root != nullptr);
142  REQUIRE(str(*root) == ":001: udp\n");
143  }
144  SECTION("Empty UDP blocks are allowed (1TBS style).")
145  {
146  tao::pegtl::string_input<> in("udp {\n}", "");
147  auto root = config::parse(in);
148  REQUIRE(root != nullptr);
149  REQUIRE(str(*root) == ":001: udp\n");
150  }
151  SECTION("Empty UDP blocks are allowed (1TBS style with comments).")
152  {
153  tao::pegtl::string_input<> in("udp {# comment\n}# comment", "");
154  auto root = config::parse(in);
155  REQUIRE(root != nullptr);
156  REQUIRE(str(*root) == ":001: udp\n");
157  }
158  SECTION("Empty UDP blocks are allowed (Allman style).")
159  {
160  tao::pegtl::string_input<> in("udp\n{\n}", "");
161  auto root = config::parse(in);
162  REQUIRE(root != nullptr);
163  REQUIRE(str(*root) == ":001: udp\n");
164  }
165  SECTION("Empty UDP blocks are allowed (Allman style with commentd).")
166  {
167  tao::pegtl::string_input<> in(
168  "udp# comment \n{# comment\n}# comment", "");
169  auto root = config::parse(in);
170  REQUIRE(root != nullptr);
171  REQUIRE(str(*root) == ":001: udp\n");
172  }
173  SECTION("Missing opening brace (closing brace exists).")
174  {
175  tao::pegtl::string_input<> in("udp }", "");
176  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
177  REQUIRE_THROWS_WITH(
178  config::parse(in), ":1:4(4): expected opening brace '{'");
179  }
180  SECTION("Missing opening brace (closing brace missing).")
181  {
182  tao::pegtl::string_input<> in("udp", "");
183  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
184  REQUIRE_THROWS_WITH(
185  config::parse(in), ":1:3(3): expected opening brace '{'");
186  }
187  SECTION("Missing closing brace.")
188  {
189  tao::pegtl::string_input<> in("udp {", "");
190  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
191  REQUIRE_THROWS_WITH(
192  config::parse(in), ":1:5(5): expected closing brace '}'");
193  }
194 }
195 
196 
197 TEST_CASE("UDP port setting.", "[config]")
198 {
199  SECTION("Parses port number setting.")
200  {
201  tao::pegtl::string_input<> in(
202  "udp {\n"
203  " port 14500;\n"
204  "}", "");
205  auto root = config::parse(in);
206  REQUIRE(root != nullptr);
207  REQUIRE(
208  str(*root) ==
209  ":001: udp\n"
210  ":002: | port 14500\n");
211  }
212  SECTION("Parses port number setting (with comments).")
213  {
214  tao::pegtl::string_input<> in(
215  "udp {# comment\n"
216  " port 14500;# comment\n"
217  "}# comment", "");
218  auto root = config::parse(in);
219  REQUIRE(root != nullptr);
220  REQUIRE(
221  str(*root) ==
222  ":001: udp\n"
223  ":002: | port 14500\n");
224  }
225  SECTION("Missing end of statement.")
226  {
227  tao::pegtl::string_input<> in(
228  "udp {\n"
229  " port 14500\n"
230  "}", "");
231  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
232  REQUIRE_THROWS_WITH(
233  config::parse(in),
234  ":3:0(21): expected end of statement ';' character");
235  }
236  SECTION("Invalid port number.")
237  {
238  tao::pegtl::string_input<> in(
239  "udp {\n"
240  " port a35;\n"
241  "}", "");
242  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
243  REQUIRE_THROWS_WITH(
244  config::parse(in), ":2:9(15): expected a valid port number");
245  }
246  SECTION("Missing port number.")
247  {
248  tao::pegtl::string_input<> in(
249  "udp {\n"
250  " port;\n"
251  "}", "");
252  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
253  REQUIRE_THROWS_WITH(
254  config::parse(in), ":2:8(14): expected a valid port number");
255  }
256 }
257 
258 
259 TEST_CASE("UDP IP address setting.", "[config]")
260 {
261  SECTION("Parses IP address setting.")
262  {
263  tao::pegtl::string_input<> in(
264  "udp {\n"
265  " address 127.0.0.1;\n"
266  "}", "");
267  auto root = config::parse(in);
268  REQUIRE(root != nullptr);
269  REQUIRE(
270  str(*root) ==
271  ":001: udp\n"
272  ":002: | address 127.0.0.1\n");
273  }
274  SECTION("Parses IP address setting (with comments).")
275  {
276  tao::pegtl::string_input<> in(
277  "udp {# comment\n"
278  " address 127.0.0.1;# comment\n"
279  "}# comment", "");
280  auto root = config::parse(in);
281  REQUIRE(root != nullptr);
282  REQUIRE(
283  str(*root) ==
284  ":001: udp\n"
285  ":002: | address 127.0.0.1\n");
286  }
287  SECTION("Missing end of statement.")
288  {
289  tao::pegtl::string_input<> in(
290  "udp {\n"
291  " address 127.0.0.1\n"
292  "}", "");
293  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
294  REQUIRE_THROWS_WITH(
295  config::parse(in),
296  ":3:0(28): expected end of statement ';' character");
297  }
298  SECTION("Invalid IP address [1].")
299  {
300  tao::pegtl::string_input<> in(
301  "udp {\n"
302  " address 127.0.0.1.;\n"
303  "}", "");
304  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
305  REQUIRE_THROWS_WITH(
306  config::parse(in),
307  ":2:21(27): expected end of statement ';' character");
308  }
309  SECTION("Invalid IP address [2].")
310  {
311  tao::pegtl::string_input<> in(
312  "udp {\n"
313  " address 127.0.0.;\n"
314  "}", "");
315  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
316  REQUIRE_THROWS_WITH(
317  config::parse(in), ":2:20(26): expected a valid IP address");
318  }
319  SECTION("Invalid IP address [3].")
320  {
321  tao::pegtl::string_input<> in(
322  "udp {\n"
323  " address 127.0.0;\n"
324  "}", "");
325  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
326  REQUIRE_THROWS_WITH(
327  config::parse(in), ":2:19(25): expected a valid IP address");
328  }
329  SECTION("Invalid IP address [4].")
330  {
331  tao::pegtl::string_input<> in(
332  "udp {\n"
333  " address 127.0.;\n"
334  "}", "");
335  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
336  REQUIRE_THROWS_WITH(
337  config::parse(in), ":2:18(24): expected a valid IP address");
338  }
339  SECTION("Invalid IP address [5].")
340  {
341  tao::pegtl::string_input<> in(
342  "udp {\n"
343  " address 127.0;\n"
344  "}", "");
345  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
346  REQUIRE_THROWS_WITH(
347  config::parse(in), ":2:17(23): expected a valid IP address");
348  }
349  SECTION("Invalid IP address [6].")
350  {
351  tao::pegtl::string_input<> in(
352  "udp {\n"
353  " address 127.;\n"
354  "}", "");
355  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
356  REQUIRE_THROWS_WITH(
357  config::parse(in), ":2:16(22): expected a valid IP address");
358  }
359  SECTION("Invalid IP address [7].")
360  {
361  tao::pegtl::string_input<> in(
362  "udp {\n"
363  " address 127;\n"
364  "}", "");
365  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
366  REQUIRE_THROWS_WITH(
367  config::parse(in), ":2:15(21): expected a valid IP address");
368  }
369  SECTION("Invalid IP address [8].")
370  {
371  tao::pegtl::string_input<> in(
372  "udp {\n"
373  " address 127:0:0:1;\n"
374  "}", "");
375  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
376  REQUIRE_THROWS_WITH(
377  config::parse(in), ":2:15(21): expected a valid IP address");
378  }
379  SECTION("Invalid IP address [9].")
380  {
381  tao::pegtl::string_input<> in(
382  "udp {\n"
383  " address 127.a.0.1;\n"
384  "}", "");
385  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
386  REQUIRE_THROWS_WITH(
387  config::parse(in), ":2:16(22): expected a valid IP address");
388  }
389  SECTION("Missing IP address.")
390  {
391  tao::pegtl::string_input<> in(
392  "udp {\n"
393  " address;\n"
394  "}", "");
395  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
396  REQUIRE_THROWS_WITH(
397  config::parse(in), ":2:11(17): expected a valid IP address");
398  }
399 }
400 
401 
402 TEST_CASE("UDP max_bitrate setting.", "[config]")
403 {
404  SECTION("Parses max bitrate setting.")
405  {
406  tao::pegtl::string_input<> in(
407  "udp {\n"
408  " max_bitrate 8192;\n"
409  "}", "");
410  auto root = config::parse(in);
411  REQUIRE(root != nullptr);
412  REQUIRE(
413  str(*root) ==
414  ":001: udp\n"
415  ":002: | max_bitrate 8192\n");
416  }
417  SECTION("Parses max bitrate setting (with comments).")
418  {
419  tao::pegtl::string_input<> in(
420  "udp {# comment\n"
421  " max_bitrate 8192;# comment\n"
422  "}# comment", "");
423  auto root = config::parse(in);
424  REQUIRE(root != nullptr);
425  REQUIRE(
426  str(*root) ==
427  ":001: udp\n"
428  ":002: | max_bitrate 8192\n");
429  }
430  SECTION("Missing end of statement.")
431  {
432  tao::pegtl::string_input<> in(
433  "udp {\n"
434  " max_bitrate 8192\n"
435  "}", "");
436  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
437  REQUIRE_THROWS_WITH(
438  config::parse(in),
439  ":3:0(27): expected end of statement ';' character");
440  }
441  SECTION("Invalid bitrate.")
442  {
443  tao::pegtl::string_input<> in(
444  "udp {\n"
445  " max_bitrate a512;\n"
446  "}", "");
447  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
448  REQUIRE_THROWS_WITH(
449  config::parse(in), ":2:16(22): expected a valid bitrate");
450  }
451  SECTION("Missing bitrate.")
452  {
453  tao::pegtl::string_input<> in(
454  "udp {\n"
455  " max_bitrate;\n"
456  "}", "");
457  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
458  REQUIRE_THROWS_WITH(
459  config::parse(in), ":2:15(21): expected a valid bitrate");
460  }
461 }
462 
463 
464 TEST_CASE("Serial port configuration block.", "[config]")
465 {
466  SECTION("Empty serial port blocks are allowed (single line).")
467  {
468  tao::pegtl::string_input<> in("serial {}", "");
469  auto root = config::parse(in);
470  REQUIRE(root != nullptr);
471  REQUIRE(str(*root) == ":001: serial\n");
472  }
473  SECTION("Empty serial port blocks are allowed (single line with comments).")
474  {
475  tao::pegtl::string_input<> in("serial {}# comment", "");
476  auto root = config::parse(in);
477  REQUIRE(root != nullptr);
478  REQUIRE(str(*root) == ":001: serial\n");
479  }
480  SECTION("Empty serial port blocks are allowed (1TBS style).")
481  {
482  tao::pegtl::string_input<> in("serial {\n}", "");
483  auto root = config::parse(in);
484  REQUIRE(root != nullptr);
485  REQUIRE(str(*root) == ":001: serial\n");
486  }
487  SECTION("Empty serial port blocks are allowed (1TBS style with comments).")
488  {
489  tao::pegtl::string_input<> in("serial {# comment\n}# comment", "");
490  auto root = config::parse(in);
491  REQUIRE(root != nullptr);
492  REQUIRE(str(*root) == ":001: serial\n");
493  }
494  SECTION("Empty serial port blocks are allowed (Allman style).")
495  {
496  tao::pegtl::string_input<> in("serial\n{\n}", "");
497  auto root = config::parse(in);
498  REQUIRE(root != nullptr);
499  REQUIRE(str(*root) == ":001: serial\n");
500  }
501  SECTION("Empty serial port blocks are allowed "
502  "(Allman style with comments).")
503  {
504  tao::pegtl::string_input<> in(
505  "serial# comment\n{# comment\n}# comment", "");
506  auto root = config::parse(in);
507  REQUIRE(root != nullptr);
508  REQUIRE(str(*root) == ":001: serial\n");
509  }
510  SECTION("Missing opening brace (closing brace exists).")
511  {
512  tao::pegtl::string_input<> in("serial }", "");
513  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
514  REQUIRE_THROWS_WITH(
515  config::parse(in), ":1:7(7): expected opening brace '{'");
516  }
517  SECTION("Missing opening brace (closing brace missing).")
518  {
519  tao::pegtl::string_input<> in("serial", "");
520  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
521  REQUIRE_THROWS_WITH(
522  config::parse(in), ":1:6(6): expected opening brace '{'");
523  }
524  SECTION("Missing closing brace.")
525  {
526  tao::pegtl::string_input<> in("serial {", "");
527  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
528  REQUIRE_THROWS_WITH(
529  config::parse(in), ":1:8(8): expected closing brace '}'");
530  }
531 }
532 
533 
534 TEST_CASE("Serial port device setting.", "[config]")
535 {
536  SECTION("Parses device string setting [1].")
537  {
538  tao::pegtl::string_input<> in(
539  "serial {\n"
540  " device /dev/tty_USB0;\n"
541  "}", "");
542  auto root = config::parse(in);
543  REQUIRE(root != nullptr);
544  REQUIRE(
545  str(*root) ==
546  ":001: serial\n"
547  ":002: | device /dev/tty_USB0\n");
548  }
549  SECTION("Parses device string setting (with comments) [1].")
550  {
551  tao::pegtl::string_input<> in(
552  "serial {# comment\n"
553  " device /dev/tty_USB0;# comment\n"
554  "}# comment", "");
555  auto root = config::parse(in);
556  REQUIRE(root != nullptr);
557  REQUIRE(
558  str(*root) ==
559  ":001: serial\n"
560  ":002: | device /dev/tty_USB0\n");
561  }
562  SECTION("Parses device string setting [2].")
563  {
564  tao::pegtl::string_input<> in(
565  "serial {\n"
566  " device COM1;\n"
567  "}", "");
568  auto root = config::parse(in);
569  REQUIRE(root != nullptr);
570  REQUIRE(
571  str(*root) ==
572  ":001: serial\n"
573  ":002: | device COM1\n");
574  }
575  SECTION("Parses device string setting (with comment) [2].")
576  {
577  tao::pegtl::string_input<> in(
578  "serial {# comment\n"
579  " device COM1;# comment\n"
580  "}# comment", "");
581  auto root = config::parse(in);
582  REQUIRE(root != nullptr);
583  REQUIRE(
584  str(*root) ==
585  ":001: serial\n"
586  ":002: | device COM1\n");
587  }
588  SECTION("Missing end of statement.")
589  {
590  tao::pegtl::string_input<> in(
591  "serial {\n"
592  " device ttyUSB0\n"
593  "}", "");
594  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
595  REQUIRE_THROWS_WITH(
596  config::parse(in),
597  ":3:0(28): expected end of statement ';' character");
598  }
599  SECTION("Invalid device string.")
600  {
601  tao::pegtl::string_input<> in(
602  "serial {\n"
603  " device +ab;\n"
604  "}", "");
605  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
606  REQUIRE_THROWS_WITH(
607  config::parse(in),
608  ":2:11(20): expected a valid serial port device name");
609  }
610  SECTION("Missing device string.")
611  {
612  tao::pegtl::string_input<> in(
613  "serial {\n"
614  " device;\n"
615  "}", "");
616  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
617  REQUIRE_THROWS_WITH(
618  config::parse(in),
619  ":2:10(19): expected a valid serial port device name");
620  }
621 }
622 
623 
624 TEST_CASE("Serial port baud rate setting.", "[config]")
625 {
626  SECTION("Parses baud rate setting.")
627  {
628  tao::pegtl::string_input<> in(
629  "serial {\n"
630  " baudrate 9600;\n"
631  "}", "");
632  auto root = config::parse(in);
633  REQUIRE(root != nullptr);
634  REQUIRE(
635  str(*root) ==
636  ":001: serial\n"
637  ":002: | baudrate 9600\n");
638  }
639  SECTION("Parses device string setting (with comments).")
640  {
641  tao::pegtl::string_input<> in(
642  "serial {# comment\n"
643  " baudrate 9600;# comment\n"
644  "}# comment", "");
645  auto root = config::parse(in);
646  REQUIRE(root != nullptr);
647  REQUIRE(
648  str(*root) ==
649  ":001: serial\n"
650  ":002: | baudrate 9600\n");
651  }
652  SECTION("Missing end of statement.")
653  {
654  tao::pegtl::string_input<> in(
655  "serial {\n"
656  " baudrate 9600\n"
657  "}", "");
658  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
659  REQUIRE_THROWS_WITH(
660  config::parse(in),
661  ":3:0(27): expected end of statement ';' character");
662  }
663  SECTION("Invalid baud rate.")
664  {
665  tao::pegtl::string_input<> in(
666  "serial {\n"
667  " baudrate +9600;\n"
668  "}", "");
669  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
670  REQUIRE_THROWS_WITH(
671  config::parse(in),
672  ":2:13(22): expected a valid baud rate");
673  }
674  SECTION("Missing baud rate value.")
675  {
676  tao::pegtl::string_input<> in(
677  "serial {\n"
678  " baudrate;\n"
679  "}", "");
680  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
681  REQUIRE_THROWS_WITH(
682  config::parse(in),
683  ":2:12(21): expected a valid baud rate");
684  }
685 }
686 
687 
688 TEST_CASE("Serial port flow control setting.", "[config]")
689 {
690  SECTION("Parses flow control setting (yes).")
691  {
692  tao::pegtl::string_input<> in(
693  "serial {\n"
694  " flow_control yes;\n"
695  "}", "");
696  auto root = config::parse(in);
697  REQUIRE(root != nullptr);
698  REQUIRE(
699  str(*root) ==
700  ":001: serial\n"
701  ":002: | flow_control yes\n");
702  }
703  SECTION("Parses flow control setting (yes with comments).")
704  {
705  tao::pegtl::string_input<> in(
706  "serial {# comments\n"
707  " flow_control yes;# comments\n"
708  "}# comments", "");
709  auto root = config::parse(in);
710  REQUIRE(root != nullptr);
711  REQUIRE(
712  str(*root) ==
713  ":001: serial\n"
714  ":002: | flow_control yes\n");
715  }
716  SECTION("Parses flow control setting (no).")
717  {
718  tao::pegtl::string_input<> in(
719  "serial {\n"
720  " flow_control no;\n"
721  "}", "");
722  auto root = config::parse(in);
723  REQUIRE(root != nullptr);
724  REQUIRE(
725  str(*root) ==
726  ":001: serial\n"
727  ":002: | flow_control no\n");
728  }
729  SECTION("Parses flow control setting (no with comments).")
730  {
731  tao::pegtl::string_input<> in(
732  "serial {# comments\n"
733  " flow_control no;# comments\n"
734  "}# comments", "");
735  auto root = config::parse(in);
736  REQUIRE(root != nullptr);
737  REQUIRE(
738  str(*root) ==
739  ":001: serial\n"
740  ":002: | flow_control no\n");
741  }
742  SECTION("Missing end of statement.")
743  {
744  tao::pegtl::string_input<> in(
745  "serial {\n"
746  " flow_control yes\n"
747  "}", "");
748  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
749  REQUIRE_THROWS_WITH(
750  config::parse(in),
751  ":3:0(30): expected end of statement ';' character");
752  }
753  SECTION("Invalid flow control setting.")
754  {
755  tao::pegtl::string_input<> in(
756  "serial {\n"
757  " flow_control maybe;\n"
758  "}", "");
759  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
760  REQUIRE_THROWS_WITH(
761  config::parse(in),
762  ":2:17(26): expected 'yes' or 'no'");
763  }
764  SECTION("Missing flow control setting.")
765  {
766  tao::pegtl::string_input<> in(
767  "serial {\n"
768  " flow_control;\n"
769  "}", "");
770  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
771  REQUIRE_THROWS_WITH(
772  config::parse(in),
773  ":2:16(25): expected 'yes' or 'no'");
774  }
775 }
776 
777 
778 TEST_CASE("Serial address preload.", "[config]")
779 {
780  SECTION("Parses a preload address.")
781  {
782  tao::pegtl::string_input<> in(
783  "serial {\n"
784  " preload 62.34;\n"
785  "}", "");
786  auto root = config::parse(in);
787  REQUIRE(root != nullptr);
788  REQUIRE(
789  str(*root) ==
790  ":001: serial\n"
791  ":002: | preload 62.34\n");
792  }
793  SECTION("Parses multiple preload address.")
794  {
795  tao::pegtl::string_input<> in(
796  "serial {\n"
797  " preload 1.1;\n"
798  " preload 62.34;\n"
799  "}", "");
800  auto root = config::parse(in);
801  REQUIRE(root != nullptr);
802  REQUIRE(
803  str(*root) ==
804  ":001: serial\n"
805  ":002: | preload 1.1\n"
806  ":003: | preload 62.34\n");
807  }
808  SECTION("Parses a preload address (with comments).")
809  {
810  tao::pegtl::string_input<> in(
811  "serial {# comment\n"
812  " preload 62.34;# comment\n"
813  "}# comment", "");
814  auto root = config::parse(in);
815  REQUIRE(root != nullptr);
816  REQUIRE(
817  str(*root) ==
818  ":001: serial\n"
819  ":002: | preload 62.34\n");
820  }
821  SECTION("Missing end of statement.")
822  {
823  tao::pegtl::string_input<> in(
824  "serial {\n"
825  " preload 62.34\n"
826  "}", "");
827  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
828  REQUIRE_THROWS_WITH(
829  config::parse(in),
830  ":3:0(27): expected end of statement ';' character");
831  }
832  SECTION("Invalid MAVLink address.")
833  {
834  tao::pegtl::string_input<> in(
835  "serial {\n"
836  " preload 62:34;\n"
837  "}", "");
838  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
839  REQUIRE_THROWS_WITH(
840  config::parse(in),
841  ":2:14(23): expected a valid MAVLink address");
842  }
843  SECTION("Missing MAVLink address.")
844  {
845  tao::pegtl::string_input<> in(
846  "serial {\n"
847  " preload;\n"
848  "}", "");
849  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
850  REQUIRE_THROWS_WITH(
851  config::parse(in),
852  ":2:11(20): expected a valid MAVLink address");
853  }
854 }
855 
856 
857 TEST_CASE("Chain block.", "[config]")
858 {
859  SECTION("Empty chain blocks are allowed (single line).")
860  {
861  tao::pegtl::string_input<> in("chain some_name10 {}", "");
862  auto root = config::parse(in);
863  REQUIRE(root != nullptr);
864  REQUIRE(str(*root) == ":001: chain some_name10\n");
865  }
866  SECTION("Empty chain blocks are allowed (single line with comments).")
867  {
868  tao::pegtl::string_input<> in("chain some_name10 {}# comment", "");
869  auto root = config::parse(in);
870  REQUIRE(root != nullptr);
871  REQUIRE(str(*root) == ":001: chain some_name10\n");
872  }
873  SECTION("Empty chain blocks are allowed (1TBS style).")
874  {
875  tao::pegtl::string_input<> in("chain some_name10 {\n}", "");
876  auto root = config::parse(in);
877  REQUIRE(root != nullptr);
878  REQUIRE(str(*root) == ":001: chain some_name10\n");
879  }
880  SECTION("Empty chain blocks are allowed (1TBS style with comments).")
881  {
882  tao::pegtl::string_input<> in(
883  "chain some_name10 {# comment\n}# comment", "");
884  auto root = config::parse(in);
885  REQUIRE(root != nullptr);
886  REQUIRE(str(*root) == ":001: chain some_name10\n");
887  }
888  SECTION("Empty chain blocks are allowed (Allman style).")
889  {
890  tao::pegtl::string_input<> in("chain some_name10\n{\n}", "");
891  auto root = config::parse(in);
892  REQUIRE(root != nullptr);
893  REQUIRE(str(*root) == ":001: chain some_name10\n");
894  }
895  SECTION("Empty chain blocks are allowed (Allman style with comments).")
896  {
897  tao::pegtl::string_input<> in(
898  "chain some_name10# comment\n{# comment\n}# comment", "");
899  auto root = config::parse(in);
900  REQUIRE(root != nullptr);
901  REQUIRE(str(*root) == ":001: chain some_name10\n");
902  }
903  SECTION("Chains must have a name.")
904  {
905  tao::pegtl::string_input<> in("chain {}", "");
906  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
907  REQUIRE_THROWS_WITH(
908  config::parse(in), ":1:6(6): expected a valid chain name");
909  }
910  SECTION("Chain names must be valid.")
911  {
912  tao::pegtl::string_input<> in("chain 1nv@l1d {}", "");
913  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
914  REQUIRE_THROWS_WITH(
915  config::parse(in), ":1:6(6): expected a valid chain name");
916  }
917  SECTION("Missing opening brace (closing brace exists).")
918  {
919  tao::pegtl::string_input<> in("chain some_name10 }", "");
920  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
921  REQUIRE_THROWS_WITH(
922  config::parse(in), ":1:18(18): expected opening brace '{'");
923  }
924  SECTION("Missing opening brace (closing brace missing).")
925  {
926  tao::pegtl::string_input<> in("chain some_name10", "");
927  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
928  REQUIRE_THROWS_WITH(
929  config::parse(in), ":1:17(17): expected opening brace '{'");
930  }
931  SECTION("Missing closing brace.")
932  {
933  tao::pegtl::string_input<> in("chain some_name10 {", "");
934  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
935  REQUIRE_THROWS_WITH(
936  config::parse(in), ":1:19(19): expected closing brace '}'");
937  }
938 }
939 
940 
941 TEST_CASE("Invalid rule.", "[config]")
942 {
943  SECTION("Parses 'reject' rule.")
944  {
945  tao::pegtl::string_input<> in(
946  "chain default {\n"
947  " invalid;\n"
948  "}", "");
949  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
950  REQUIRE_THROWS_WITH(
951  config::parse(in),
952  ":3:0(29): expected a valid rule");
953  }
954 }
955 
956 
957 TEST_CASE("Accept rule.", "[config]")
958 {
959  SECTION("Parses 'accept' rule.")
960  {
961  tao::pegtl::string_input<> in(
962  "chain default {\n"
963  " accept;\n"
964  "}", "");
965  auto root = config::parse(in);
966  REQUIRE(root != nullptr);
967  REQUIRE(
968  str(*root) ==
969  ":001: chain default\n"
970  ":002: | accept\n");
971  }
972  SECTION("Parses 'accept' rule (with comments).")
973  {
974  tao::pegtl::string_input<> in(
975  "chain default {# comment\n"
976  " accept;# comment\n"
977  "}# comment", "");
978  auto root = config::parse(in);
979  REQUIRE(root != nullptr);
980  REQUIRE(
981  str(*root) ==
982  ":001: chain default\n"
983  ":002: | accept\n");
984  }
985  SECTION("Missing end of statement.")
986  {
987  tao::pegtl::string_input<> in(
988  "chain default {\n"
989  " accept\n"
990  "}", "");
991  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
992  REQUIRE_THROWS_WITH(
993  config::parse(in),
994  ":2:10(26): expected end of statement ';' character");
995  }
996 }
997 
998 
999 TEST_CASE("Reject rule.", "[config]")
1000 {
1001  SECTION("Parses 'reject' rule.")
1002  {
1003  tao::pegtl::string_input<> in(
1004  "chain default {\n"
1005  " reject;\n"
1006  "}", "");
1007  auto root = config::parse(in);
1008  REQUIRE(root != nullptr);
1009  REQUIRE(
1010  str(*root) ==
1011  ":001: chain default\n"
1012  ":002: | reject\n");
1013  }
1014  SECTION("Parses 'reject' rule (with comments).")
1015  {
1016  tao::pegtl::string_input<> in(
1017  "chain default {# comment\n"
1018  " reject;# comment\n"
1019  "}# comment", "");
1020  auto root = config::parse(in);
1021  REQUIRE(root != nullptr);
1022  REQUIRE(
1023  str(*root) ==
1024  ":001: chain default\n"
1025  ":002: | reject\n");
1026  }
1027  SECTION("Missing end of statement.")
1028  {
1029  tao::pegtl::string_input<> in(
1030  "chain default {\n"
1031  " reject\n"
1032  "}", "");
1033  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
1034  REQUIRE_THROWS_WITH(
1035  config::parse(in),
1036  ":2:10(26): expected end of statement ';' character");
1037  }
1038 }
1039 
1040 
1041 TEST_CASE("Call rule.", "[config]")
1042 {
1043  SECTION("Parses 'call' rule.")
1044  {
1045  tao::pegtl::string_input<> in(
1046  "chain default {\n"
1047  " call some_name10;\n"
1048  "}", "");
1049  auto root = config::parse(in);
1050  REQUIRE(root != nullptr);
1051  REQUIRE(
1052  str(*root) ==
1053  ":001: chain default\n"
1054  ":002: | call some_name10\n");
1055  }
1056  SECTION("Parses 'call' rule (with comments).")
1057  {
1058  tao::pegtl::string_input<> in(
1059  "chain default {# comment\n"
1060  " call some_name10;# comment\n"
1061  "}# comment", "");
1062  auto root = config::parse(in);
1063  REQUIRE(root != nullptr);
1064  REQUIRE(
1065  str(*root) ==
1066  ":001: chain default\n"
1067  ":002: | call some_name10\n");
1068  }
1069  SECTION("Missing end of statement.")
1070  {
1071  tao::pegtl::string_input<> in(
1072  "chain default {\n"
1073  " call some_name10\n"
1074  "}", "");
1075  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
1076  REQUIRE_THROWS_WITH(
1077  config::parse(in),
1078  ":3:0(37): expected end of statement ';' character");
1079  }
1080  SECTION("Invalid chain name.")
1081  {
1082  tao::pegtl::string_input<> in(
1083  "chain default {\n"
1084  " call 1nv@l1d;\n"
1085  "}", "");
1086  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
1087  REQUIRE_THROWS_WITH(
1088  config::parse(in),
1089  ":2:9(25): expected a valid chain name");
1090  }
1091  SECTION("Missing chain name.")
1092  {
1093  tao::pegtl::string_input<> in(
1094  "chain default {\n"
1095  " call;\n"
1096  "}", "");
1097  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
1098  REQUIRE_THROWS_WITH(
1099  config::parse(in),
1100  ":2:8(24): expected a valid chain name");
1101  }
1102 }
1103 
1104 
1105 TEST_CASE("GoTo rule.", "[config]")
1106 {
1107  SECTION("Parses 'goto' rule.")
1108  {
1109  tao::pegtl::string_input<> in(
1110  "chain default {\n"
1111  " goto some_name10;\n"
1112  "}", "");
1113  auto root = config::parse(in);
1114  REQUIRE(root != nullptr);
1115  REQUIRE(
1116  str(*root) ==
1117  ":001: chain default\n"
1118  ":002: | goto some_name10\n");
1119  }
1120  SECTION("Parses 'goto' rule (with comments).")
1121  {
1122  tao::pegtl::string_input<> in(
1123  "chain default {# comment\n"
1124  " goto some_name10;# comment\n"
1125  "}# comment", "");
1126  auto root = config::parse(in);
1127  REQUIRE(root != nullptr);
1128  REQUIRE(
1129  str(*root) ==
1130  ":001: chain default\n"
1131  ":002: | goto some_name10\n");
1132  }
1133  SECTION("Missing end of statement.")
1134  {
1135  tao::pegtl::string_input<> in(
1136  "chain default {\n"
1137  " goto some_name10\n"
1138  "}", "");
1139  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
1140  REQUIRE_THROWS_WITH(
1141  config::parse(in),
1142  ":3:0(37): expected end of statement ';' character");
1143  }
1144  SECTION("Invalid chain name.")
1145  {
1146  tao::pegtl::string_input<> in(
1147  "chain default {\n"
1148  " goto 1nv@l1d;\n"
1149  "}", "");
1150  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
1151  REQUIRE_THROWS_WITH(
1152  config::parse(in),
1153  ":2:9(25): expected a valid chain name");
1154  }
1155  SECTION("Missing chain name.")
1156  {
1157  tao::pegtl::string_input<> in(
1158  "chain default {\n"
1159  " goto;\n"
1160  "}", "");
1161  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
1162  REQUIRE_THROWS_WITH(
1163  config::parse(in),
1164  ":2:8(24): expected a valid chain name");
1165  }
1166 }
1167 
1168 
1169 TEST_CASE("Condition.", "[config]")
1170 {
1171  SECTION("Conditions must have at least one restriction.")
1172  {
1173  tao::pegtl::string_input<> in(
1174  "chain default {\n"
1175  " accept if;\n"
1176  "}", "");
1177  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
1178  REQUIRE_THROWS_WITH(
1179  config::parse(in),
1180  ":2:13(29): condition is empty or invalid");
1181  }
1182 }
1183 
1184 
1185 TEST_CASE("Packet type condition.", "[config]")
1186 {
1187  SECTION("Parses packet type condition.")
1188  {
1189  tao::pegtl::string_input<> in(
1190  "chain default {\n"
1191  " accept if PING;\n"
1192  "}", "");
1193  auto root = config::parse(in);
1194  REQUIRE(root != nullptr);
1195  REQUIRE(
1196  str(*root) ==
1197  ":001: chain default\n"
1198  ":002: | accept\n"
1199  ":002: | | condition\n"
1200  ":002: | | | packet_type PING\n");
1201  }
1202  SECTION("Parses packet type condition (with number).")
1203  {
1204  tao::pegtl::string_input<> in(
1205  "chain default {\n"
1206  " accept if SCALED_PRESSURE3;\n"
1207  "}", "");
1208  auto root = config::parse(in);
1209  REQUIRE(root != nullptr);
1210  REQUIRE(
1211  str(*root) ==
1212  ":001: chain default\n"
1213  ":002: | accept\n"
1214  ":002: | | condition\n"
1215  ":002: | | | packet_type SCALED_PRESSURE3\n");
1216  }
1217  SECTION("Parses packet type condition (with comments).")
1218  {
1219  tao::pegtl::string_input<> in(
1220  "chain default {# comment\n"
1221  " accept if PING;# comment\n"
1222  "}# comment", "");
1223  auto root = config::parse(in);
1224  REQUIRE(root != nullptr);
1225  REQUIRE(
1226  str(*root) ==
1227  ":001: chain default\n"
1228  ":002: | accept\n"
1229  ":002: | | condition\n"
1230  ":002: | | | packet_type PING\n");
1231  }
1232  SECTION("Invalid packet type [1].")
1233  {
1234  tao::pegtl::string_input<> in(
1235  "chain default {\n"
1236  " accept if ping;\n"
1237  "}", "");
1238  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
1239  REQUIRE_THROWS_WITH(
1240  config::parse(in),
1241  ":2:14(30): condition is empty or invalid");
1242  }
1243  SECTION("Invalid packet type [2].")
1244  {
1245  tao::pegtl::string_input<> in(
1246  "chain default {\n"
1247  " accept if @;\n"
1248  "}", "");
1249  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
1250  REQUIRE_THROWS_WITH(
1251  config::parse(in),
1252  ":2:14(30): condition is empty or invalid");
1253  }
1254 }
1255 
1256 
1257 TEST_CASE("Source condition.", "[config]")
1258 {
1259  SECTION("Parses source condition [1].")
1260  {
1261  tao::pegtl::string_input<> in(
1262  "chain default {\n"
1263  " accept if from 192.0;\n"
1264  "}", "");
1265  auto root = config::parse(in);
1266  REQUIRE(root != nullptr);
1267  REQUIRE(
1268  str(*root) ==
1269  ":001: chain default\n"
1270  ":002: | accept\n"
1271  ":002: | | condition\n"
1272  ":002: | | | source 192.0\n");
1273  }
1274  SECTION("Parses source condition (with comments) [1].")
1275  {
1276  tao::pegtl::string_input<> in(
1277  "chain default {# comment\n"
1278  " accept if from 192.0;# comment\n"
1279  "}# comment", "");
1280  auto root = config::parse(in);
1281  REQUIRE(root != nullptr);
1282  REQUIRE(
1283  str(*root) ==
1284  ":001: chain default\n"
1285  ":002: | accept\n"
1286  ":002: | | condition\n"
1287  ":002: | | | source 192.0\n");
1288  }
1289  SECTION("Parses source condition [2].")
1290  {
1291  tao::pegtl::string_input<> in(
1292  "chain default {\n"
1293  " accept if from 192.0/8;\n"
1294  "}", "");
1295  auto root = config::parse(in);
1296  REQUIRE(root != nullptr);
1297  REQUIRE(
1298  str(*root) ==
1299  ":001: chain default\n"
1300  ":002: | accept\n"
1301  ":002: | | condition\n"
1302  ":002: | | | source 192.0/8\n");
1303  }
1304  SECTION("Parses source condition (with comments) [2].")
1305  {
1306  tao::pegtl::string_input<> in(
1307  "chain default {# comment\n"
1308  " accept if from 192.0/8;# comment\n"
1309  "}# comment", "");
1310  auto root = config::parse(in);
1311  REQUIRE(root != nullptr);
1312  REQUIRE(
1313  str(*root) ==
1314  ":001: chain default\n"
1315  ":002: | accept\n"
1316  ":002: | | condition\n"
1317  ":002: | | | source 192.0/8\n");
1318  }
1319  SECTION("Parses source condition [3].")
1320  {
1321  tao::pegtl::string_input<> in(
1322  "chain default {\n"
1323  " accept if from 192.0\\4;\n"
1324  "}", "");
1325  auto root = config::parse(in);
1326  REQUIRE(root != nullptr);
1327  REQUIRE(
1328  str(*root) ==
1329  ":001: chain default\n"
1330  ":002: | accept\n"
1331  ":002: | | condition\n"
1332  ":002: | | | source 192.0\\4\n");
1333  }
1334  SECTION("Parses source condition (with comments) [3].")
1335  {
1336  tao::pegtl::string_input<> in(
1337  "chain default {# comment\n"
1338  " accept if from 192.0\\4;# comment\n"
1339  "}# comment", "");
1340  auto root = config::parse(in);
1341  REQUIRE(root != nullptr);
1342  REQUIRE(
1343  str(*root) ==
1344  ":001: chain default\n"
1345  ":002: | accept\n"
1346  ":002: | | condition\n"
1347  ":002: | | | source 192.0\\4\n");
1348  }
1349  SECTION("Parses source condition [4].")
1350  {
1351  tao::pegtl::string_input<> in(
1352  "chain default {\n"
1353  " accept if from 192.0:255.255;\n"
1354  "}", "");
1355  auto root = config::parse(in);
1356  REQUIRE(root != nullptr);
1357  REQUIRE(
1358  str(*root) ==
1359  ":001: chain default\n"
1360  ":002: | accept\n"
1361  ":002: | | condition\n"
1362  ":002: | | | source 192.0:255.255\n");
1363  }
1364  SECTION("Parses source condition (with comments) [4].")
1365  {
1366  tao::pegtl::string_input<> in(
1367  "chain default {# comment\n"
1368  " accept if from 192.0:255.255;# comment\n"
1369  "}# comment", "");
1370  auto root = config::parse(in);
1371  REQUIRE(root != nullptr);
1372  REQUIRE(
1373  str(*root) ==
1374  ":001: chain default\n"
1375  ":002: | accept\n"
1376  ":002: | | condition\n"
1377  ":002: | | | source 192.0:255.255\n");
1378  }
1379  SECTION("Invalid source condition [1].")
1380  {
1381  tao::pegtl::string_input<> in(
1382  "chain default {\n"
1383  " accept if from 192;\n"
1384  "}", "");
1385  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
1386  REQUIRE_THROWS_WITH(
1387  config::parse(in),
1388  ":2:22(38): expected a valid MAVLink subnet");
1389  }
1390  SECTION("Invalid source condition [2].")
1391  {
1392  tao::pegtl::string_input<> in(
1393  "chain default {\n"
1394  " accept if from 192/8;\n"
1395  "}", "");
1396  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
1397  REQUIRE_THROWS_WITH(
1398  config::parse(in),
1399  ":2:22(38): expected a valid MAVLink subnet");
1400  }
1401  SECTION("Invalid source condition [3].")
1402  {
1403  tao::pegtl::string_input<> in(
1404  "chain default {\n"
1405  " accept if from 192\\8;\n"
1406  "}", "");
1407  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
1408  REQUIRE_THROWS_WITH(
1409  config::parse(in),
1410  ":2:22(38): expected a valid MAVLink subnet");
1411  }
1412  SECTION("Invalid source condition [4].")
1413  {
1414  tao::pegtl::string_input<> in(
1415  "chain default {\n"
1416  " accept if from 192:255.255;\n"
1417  "}", "");
1418  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
1419  REQUIRE_THROWS_WITH(
1420  config::parse(in),
1421  ":2:22(38): expected a valid MAVLink subnet");
1422  }
1423 }
1424 
1425 
1426 TEST_CASE("Destination condition.", "[config]")
1427 {
1428  SECTION("Parses destination condition [1].")
1429  {
1430  tao::pegtl::string_input<> in(
1431  "chain default {\n"
1432  " accept if to 192.0;\n"
1433  "}", "");
1434  auto root = config::parse(in);
1435  REQUIRE(root != nullptr);
1436  REQUIRE(
1437  str(*root) ==
1438  ":001: chain default\n"
1439  ":002: | accept\n"
1440  ":002: | | condition\n"
1441  ":002: | | | dest 192.0\n");
1442  }
1443  SECTION("Parses destination condition (with comments) [1].")
1444  {
1445  tao::pegtl::string_input<> in(
1446  "chain default {# comment\n"
1447  " accept if to 192.0;# comment\n"
1448  "}# comment", "");
1449  auto root = config::parse(in);
1450  REQUIRE(root != nullptr);
1451  REQUIRE(
1452  str(*root) ==
1453  ":001: chain default\n"
1454  ":002: | accept\n"
1455  ":002: | | condition\n"
1456  ":002: | | | dest 192.0\n");
1457  }
1458  SECTION("Parses destination condition [2].")
1459  {
1460  tao::pegtl::string_input<> in(
1461  "chain default {\n"
1462  " accept if to 192.0/8;\n"
1463  "}", "");
1464  auto root = config::parse(in);
1465  REQUIRE(root != nullptr);
1466  REQUIRE(
1467  str(*root) ==
1468  ":001: chain default\n"
1469  ":002: | accept\n"
1470  ":002: | | condition\n"
1471  ":002: | | | dest 192.0/8\n");
1472  }
1473  SECTION("Parses destination condition (with comments) [2].")
1474  {
1475  tao::pegtl::string_input<> in(
1476  "chain default {# comment\n"
1477  " accept if to 192.0/8;# comment\n"
1478  "}# comment", "");
1479  auto root = config::parse(in);
1480  REQUIRE(root != nullptr);
1481  REQUIRE(
1482  str(*root) ==
1483  ":001: chain default\n"
1484  ":002: | accept\n"
1485  ":002: | | condition\n"
1486  ":002: | | | dest 192.0/8\n");
1487  }
1488  SECTION("Parses destination condition [3].")
1489  {
1490  tao::pegtl::string_input<> in(
1491  "chain default {\n"
1492  " accept if to 192.0\\4;\n"
1493  "}", "");
1494  auto root = config::parse(in);
1495  REQUIRE(root != nullptr);
1496  REQUIRE(
1497  str(*root) ==
1498  ":001: chain default\n"
1499  ":002: | accept\n"
1500  ":002: | | condition\n"
1501  ":002: | | | dest 192.0\\4\n");
1502  }
1503  SECTION("Parses destination condition (with comments) [3].")
1504  {
1505  tao::pegtl::string_input<> in(
1506  "chain default {# comment\n"
1507  " accept if to 192.0\\4;# comment\n"
1508  "}# comment", "");
1509  auto root = config::parse(in);
1510  REQUIRE(root != nullptr);
1511  REQUIRE(
1512  str(*root) ==
1513  ":001: chain default\n"
1514  ":002: | accept\n"
1515  ":002: | | condition\n"
1516  ":002: | | | dest 192.0\\4\n");
1517  }
1518  SECTION("Parses destination condition [4].")
1519  {
1520  tao::pegtl::string_input<> in(
1521  "chain default {\n"
1522  " accept if to 192.0:255.255;\n"
1523  "}", "");
1524  auto root = config::parse(in);
1525  REQUIRE(root != nullptr);
1526  REQUIRE(
1527  str(*root) ==
1528  ":001: chain default\n"
1529  ":002: | accept\n"
1530  ":002: | | condition\n"
1531  ":002: | | | dest 192.0:255.255\n");
1532  }
1533  SECTION("Parses destination condition (with comments) [4].")
1534  {
1535  tao::pegtl::string_input<> in(
1536  "chain default {# comment\n"
1537  " accept if to 192.0:255.255;# comment\n"
1538  "}# comment", "");
1539  auto root = config::parse(in);
1540  REQUIRE(root != nullptr);
1541  REQUIRE(
1542  str(*root) ==
1543  ":001: chain default\n"
1544  ":002: | accept\n"
1545  ":002: | | condition\n"
1546  ":002: | | | dest 192.0:255.255\n");
1547  }
1548  SECTION("Invalid destination condition [1].")
1549  {
1550  tao::pegtl::string_input<> in(
1551  "chain default {\n"
1552  " accept if to 192;\n"
1553  "}", "");
1554  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
1555  REQUIRE_THROWS_WITH(
1556  config::parse(in),
1557  ":2:20(36): expected a valid MAVLink subnet");
1558  }
1559  SECTION("Invalid destination condition [2].")
1560  {
1561  tao::pegtl::string_input<> in(
1562  "chain default {\n"
1563  " accept if to 192/8;\n"
1564  "}", "");
1565  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
1566  REQUIRE_THROWS_WITH(
1567  config::parse(in),
1568  ":2:20(36): expected a valid MAVLink subnet");
1569  }
1570  SECTION("Invalid destination condition [3].")
1571  {
1572  tao::pegtl::string_input<> in(
1573  "chain default {\n"
1574  " accept if to 192\\8;\n"
1575  "}", "");
1576  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
1577  REQUIRE_THROWS_WITH(
1578  config::parse(in),
1579  ":2:20(36): expected a valid MAVLink subnet");
1580  }
1581  SECTION("Invalid destination condition [4].")
1582  {
1583  tao::pegtl::string_input<> in(
1584  "chain default {\n"
1585  " accept if to 192:255.255;\n"
1586  "}", "");
1587  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
1588  REQUIRE_THROWS_WITH(
1589  config::parse(in),
1590  ":2:20(36): expected a valid MAVLink subnet");
1591  }
1592 }
1593 
1594 
1595 TEST_CASE("Priority.", "[config]")
1596 {
1597  SECTION("Parses priority (no sign).")
1598  {
1599  tao::pegtl::string_input<> in(
1600  "chain default {\n"
1601  " accept with priority 99;\n"
1602  "}", "");
1603  auto root = config::parse(in);
1604  REQUIRE(root != nullptr);
1605  REQUIRE(
1606  str(*root) ==
1607  ":001: chain default\n"
1608  ":002: | accept\n"
1609  ":002: | | priority 99\n");
1610  }
1611  SECTION("Parses priority (no sign with comments).")
1612  {
1613  tao::pegtl::string_input<> in(
1614  "chain default {# comment\n"
1615  " accept with priority 99;# comment\n"
1616  "}# comment", "");
1617  auto root = config::parse(in);
1618  REQUIRE(root != nullptr);
1619  REQUIRE(
1620  str(*root) ==
1621  ":001: chain default\n"
1622  ":002: | accept\n"
1623  ":002: | | priority 99\n");
1624  }
1625  SECTION("Parses priority (positive).")
1626  {
1627  tao::pegtl::string_input<> in(
1628  "chain default {\n"
1629  " accept with priority +99;\n"
1630  "}", "");
1631  auto root = config::parse(in);
1632  REQUIRE(root != nullptr);
1633  REQUIRE(
1634  str(*root) ==
1635  ":001: chain default\n"
1636  ":002: | accept\n"
1637  ":002: | | priority +99\n");
1638  }
1639  SECTION("Parses priority (positive with comments).")
1640  {
1641  tao::pegtl::string_input<> in(
1642  "chain default {# comment\n"
1643  " accept with priority +99;# comment\n"
1644  "}# comment", "");
1645  auto root = config::parse(in);
1646  REQUIRE(root != nullptr);
1647  REQUIRE(
1648  str(*root) ==
1649  ":001: chain default\n"
1650  ":002: | accept\n"
1651  ":002: | | priority +99\n");
1652  }
1653  SECTION("Parses priority (negative).")
1654  {
1655  tao::pegtl::string_input<> in(
1656  "chain default {\n"
1657  " accept with priority -99;\n"
1658  "}", "");
1659  auto root = config::parse(in);
1660  REQUIRE(root != nullptr);
1661  REQUIRE(
1662  str(*root) ==
1663  ":001: chain default\n"
1664  ":002: | accept\n"
1665  ":002: | | priority -99\n");
1666  }
1667  SECTION("Parses priority (negative with comments).")
1668  {
1669  tao::pegtl::string_input<> in(
1670  "chain default {# comment\n"
1671  " accept with priority -99;# comment\n"
1672  "}# comment", "");
1673  auto root = config::parse(in);
1674  REQUIRE(root != nullptr);
1675  REQUIRE(
1676  str(*root) ==
1677  ":001: chain default\n"
1678  ":002: | accept\n"
1679  ":002: | | priority -99\n");
1680  }
1681  SECTION("'with priority' must be followed by a valid priority.")
1682  {
1683  tao::pegtl::string_input<> in(
1684  "chain default {\n"
1685  " accept with priority *99;\n"
1686  "}", "");
1687  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
1688  REQUIRE_THROWS_WITH(
1689  config::parse(in),
1690  ":2:25(41): expected priority level");
1691  }
1692  SECTION("'with priority' must be followed by a priority.")
1693  {
1694  tao::pegtl::string_input<> in(
1695  "chain default {\n"
1696  " accept with priority;\n"
1697  "}", "");
1698  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
1699  REQUIRE_THROWS_WITH(
1700  config::parse(in),
1701  ":2:24(40): expected priority level");
1702  }
1703  SECTION("'with' must be followed by 'priority'.")
1704  {
1705  tao::pegtl::string_input<> in(
1706  "chain default {\n"
1707  " accept with;\n"
1708  "}", "");
1709  REQUIRE_THROWS_AS(config::parse(in), tao::pegtl::parse_error);
1710  REQUIRE_THROWS_WITH(
1711  config::parse(in),
1712  ":2:15(31): 'with' keyword must be followed by the "
1713  "'priority' keyword");
1714  }
1715 }
1716 
1717 
1718 TEST_CASE("Rule combinations with 'accept'.", "[config]")
1719 {
1720  SECTION("accept")
1721  {
1722  tao::pegtl::string_input<> in(
1723  "chain default {\n"
1724  " accept;\n"
1725  "}", "");
1726  auto root = config::parse(in);
1727  REQUIRE(root != nullptr);
1728  REQUIRE(
1729  str(*root) ==
1730  ":001: chain default\n"
1731  ":002: | accept\n");
1732  }
1733  SECTION("accept if PING")
1734  {
1735  tao::pegtl::string_input<> in(
1736  "chain default {\n"
1737  " accept if PING;\n"
1738  "}", "");
1739  auto root = config::parse(in);
1740  REQUIRE(root != nullptr);
1741  REQUIRE(
1742  str(*root) ==
1743  ":001: chain default\n"
1744  ":002: | accept\n"
1745  ":002: | | condition\n"
1746  ":002: | | | packet_type PING\n");
1747  }
1748  SECTION("accept if PING from 127.1")
1749  {
1750  tao::pegtl::string_input<> in(
1751  "chain default {\n"
1752  " accept if PING from 127.1;\n"
1753  "}", "");
1754  auto root = config::parse(in);
1755  REQUIRE(root != nullptr);
1756  REQUIRE(
1757  str(*root) ==
1758  ":001: chain default\n"
1759  ":002: | accept\n"
1760  ":002: | | condition\n"
1761  ":002: | | | packet_type PING\n"
1762  ":002: | | | source 127.1\n");
1763  }
1764  SECTION("accept if PING to 192.0")
1765  {
1766  tao::pegtl::string_input<> in(
1767  "chain default {\n"
1768  " accept if PING to 192.0;\n"
1769  "}", "");
1770  auto root = config::parse(in);
1771  REQUIRE(root != nullptr);
1772  REQUIRE(
1773  str(*root) ==
1774  ":001: chain default\n"
1775  ":002: | accept\n"
1776  ":002: | | condition\n"
1777  ":002: | | | packet_type PING\n"
1778  ":002: | | | dest 192.0\n");
1779  }
1780  SECTION("accept if PING from 127.1 to 192.0")
1781  {
1782  tao::pegtl::string_input<> in(
1783  "chain default {\n"
1784  " accept if PING from 127.1 to 192.0;\n"
1785  "}", "");
1786  auto root = config::parse(in);
1787  REQUIRE(root != nullptr);
1788  REQUIRE(
1789  str(*root) ==
1790  ":001: chain default\n"
1791  ":002: | accept\n"
1792  ":002: | | condition\n"
1793  ":002: | | | packet_type PING\n"
1794  ":002: | | | source 127.1\n"
1795  ":002: | | | dest 192.0\n");
1796  }
1797  SECTION("accept if from 127.1")
1798  {
1799  tao::pegtl::string_input<> in(
1800  "chain default {\n"
1801  " accept if from 127.1;\n"
1802  "}", "");
1803  auto root = config::parse(in);
1804  REQUIRE(root != nullptr);
1805  REQUIRE(
1806  str(*root) ==
1807  ":001: chain default\n"
1808  ":002: | accept\n"
1809  ":002: | | condition\n"
1810  ":002: | | | source 127.1\n");
1811  }
1812  SECTION("accept if to 192.0")
1813  {
1814  tao::pegtl::string_input<> in(
1815  "chain default {\n"
1816  " accept if to 192.0;\n"
1817  "}", "");
1818  auto root = config::parse(in);
1819  REQUIRE(root != nullptr);
1820  REQUIRE(
1821  str(*root) ==
1822  ":001: chain default\n"
1823  ":002: | accept\n"
1824  ":002: | | condition\n"
1825  ":002: | | | dest 192.0\n");
1826  }
1827  SECTION("accept if from 127.1 to 192.0")
1828  {
1829  tao::pegtl::string_input<> in(
1830  "chain default {\n"
1831  " accept if from 127.1 to 192.0;\n"
1832  "}", "");
1833  auto root = config::parse(in);
1834  REQUIRE(root != nullptr);
1835  REQUIRE(
1836  str(*root) ==
1837  ":001: chain default\n"
1838  ":002: | accept\n"
1839  ":002: | | condition\n"
1840  ":002: | | | source 127.1\n"
1841  ":002: | | | dest 192.0\n");
1842  }
1843  SECTION("accept with priority 99")
1844  {
1845  tao::pegtl::string_input<> in(
1846  "chain default {\n"
1847  " accept with priority 99 if to 192.0;\n"
1848  "}", "");
1849  auto root = config::parse(in);
1850  REQUIRE(root != nullptr);
1851  REQUIRE(
1852  str(*root) ==
1853  ":001: chain default\n"
1854  ":002: | accept\n"
1855  ":002: | | priority 99\n"
1856  ":002: | | condition\n"
1857  ":002: | | | dest 192.0\n");
1858  }
1859  SECTION("accept with priority 99 if PING")
1860  {
1861  tao::pegtl::string_input<> in(
1862  "chain default {\n"
1863  " accept with priority 99 if PING;\n"
1864  "}", "");
1865  auto root = config::parse(in);
1866  REQUIRE(root != nullptr);
1867  REQUIRE(
1868  str(*root) ==
1869  ":001: chain default\n"
1870  ":002: | accept\n"
1871  ":002: | | priority 99\n"
1872  ":002: | | condition\n"
1873  ":002: | | | packet_type PING\n");
1874  }
1875  SECTION("accept with priority 99 if PING from 127.1")
1876  {
1877  tao::pegtl::string_input<> in(
1878  "chain default {\n"
1879  " accept with priority 99 if PING from 127.1;\n"
1880  "}", "");
1881  auto root = config::parse(in);
1882  REQUIRE(root != nullptr);
1883  REQUIRE(
1884  str(*root) ==
1885  ":001: chain default\n"
1886  ":002: | accept\n"
1887  ":002: | | priority 99\n"
1888  ":002: | | condition\n"
1889  ":002: | | | packet_type PING\n"
1890  ":002: | | | source 127.1\n");
1891  }
1892  SECTION("accept with priority 99 if PING to 192.0")
1893  {
1894  tao::pegtl::string_input<> in(
1895  "chain default {\n"
1896  " accept with priority 99 if PING to 192.0;\n"
1897  "}", "");
1898  auto root = config::parse(in);
1899  REQUIRE(root != nullptr);
1900  REQUIRE(
1901  str(*root) ==
1902  ":001: chain default\n"
1903  ":002: | accept\n"
1904  ":002: | | priority 99\n"
1905  ":002: | | condition\n"
1906  ":002: | | | packet_type PING\n"
1907  ":002: | | | dest 192.0\n");
1908  }
1909  SECTION("accept with priority 99 if PING from 127.1 to 192.0")
1910  {
1911  tao::pegtl::string_input<> in(
1912  "chain default {\n"
1913  " accept with priority 99 if PING from 127.1 to 192.0;\n"
1914  "}", "");
1915  auto root = config::parse(in);
1916  REQUIRE(root != nullptr);
1917  REQUIRE(
1918  str(*root) ==
1919  ":001: chain default\n"
1920  ":002: | accept\n"
1921  ":002: | | priority 99\n"
1922  ":002: | | condition\n"
1923  ":002: | | | packet_type PING\n"
1924  ":002: | | | source 127.1\n"
1925  ":002: | | | dest 192.0\n");
1926  }
1927  SECTION("accept with priority 99 if from 127.1")
1928  {
1929  tao::pegtl::string_input<> in(
1930  "chain default {\n"
1931  " accept with priority 99 if from 127.1;\n"
1932  "}", "");
1933  auto root = config::parse(in);
1934  REQUIRE(root != nullptr);
1935  REQUIRE(
1936  str(*root) ==
1937  ":001: chain default\n"
1938  ":002: | accept\n"
1939  ":002: | | priority 99\n"
1940  ":002: | | condition\n"
1941  ":002: | | | source 127.1\n");
1942  }
1943  SECTION("accept with priority 99 if to 192.0")
1944  {
1945  tao::pegtl::string_input<> in(
1946  "chain default {\n"
1947  " accept with priority 99 if to 192.0;\n"
1948  "}", "");
1949  auto root = config::parse(in);
1950  REQUIRE(root != nullptr);
1951  REQUIRE(
1952  str(*root) ==
1953  ":001: chain default\n"
1954  ":002: | accept\n"
1955  ":002: | | priority 99\n"
1956  ":002: | | condition\n"
1957  ":002: | | | dest 192.0\n");
1958  }
1959  SECTION("accept with priority 99 if from 127.1 to 192.0")
1960  {
1961  tao::pegtl::string_input<> in(
1962  "chain default {\n"
1963  " accept with priority 99 if from 127.1 to 192.0;\n"
1964  "}", "");
1965  auto root = config::parse(in);
1966  REQUIRE(root != nullptr);
1967  REQUIRE(
1968  str(*root) ==
1969  ":001: chain default\n"
1970  ":002: | accept\n"
1971  ":002: | | priority 99\n"
1972  ":002: | | condition\n"
1973  ":002: | | | source 127.1\n"
1974  ":002: | | | dest 192.0\n");
1975  }
1976 }
1977 
1978 
1979 TEST_CASE("Rule combinations with 'reject'.", "[config]")
1980 {
1981  SECTION("reject")
1982  {
1983  tao::pegtl::string_input<> in(
1984  "chain default {\n"
1985  " reject;\n"
1986  "}", "");
1987  auto root = config::parse(in);
1988  REQUIRE(root != nullptr);
1989  REQUIRE(
1990  str(*root) ==
1991  ":001: chain default\n"
1992  ":002: | reject\n");
1993  }
1994  SECTION("reject if PING.")
1995  {
1996  tao::pegtl::string_input<> in(
1997  "chain default {\n"
1998  " reject if PING;\n"
1999  "}", "");
2000  auto root = config::parse(in);
2001  REQUIRE(root != nullptr);
2002  REQUIRE(
2003  str(*root) ==
2004  ":001: chain default\n"
2005  ":002: | reject\n"
2006  ":002: | | condition\n"
2007  ":002: | | | packet_type PING\n");
2008  }
2009  SECTION("reject if PING from 127.1")
2010  {
2011  tao::pegtl::string_input<> in(
2012  "chain default {\n"
2013  " reject if PING from 127.1;\n"
2014  "}", "");
2015  auto root = config::parse(in);
2016  REQUIRE(root != nullptr);
2017  REQUIRE(
2018  str(*root) ==
2019  ":001: chain default\n"
2020  ":002: | reject\n"
2021  ":002: | | condition\n"
2022  ":002: | | | packet_type PING\n"
2023  ":002: | | | source 127.1\n");
2024  }
2025  SECTION("reject if PING to 192.0")
2026  {
2027  tao::pegtl::string_input<> in(
2028  "chain default {\n"
2029  " reject if PING to 192.0;\n"
2030  "}", "");
2031  auto root = config::parse(in);
2032  REQUIRE(root != nullptr);
2033  REQUIRE(
2034  str(*root) ==
2035  ":001: chain default\n"
2036  ":002: | reject\n"
2037  ":002: | | condition\n"
2038  ":002: | | | packet_type PING\n"
2039  ":002: | | | dest 192.0\n");
2040  }
2041  SECTION("reject if PING from 127.1 to 192.0")
2042  {
2043  tao::pegtl::string_input<> in(
2044  "chain default {\n"
2045  " reject if PING from 127.1 to 192.0;\n"
2046  "}", "");
2047  auto root = config::parse(in);
2048  REQUIRE(root != nullptr);
2049  REQUIRE(
2050  str(*root) ==
2051  ":001: chain default\n"
2052  ":002: | reject\n"
2053  ":002: | | condition\n"
2054  ":002: | | | packet_type PING\n"
2055  ":002: | | | source 127.1\n"
2056  ":002: | | | dest 192.0\n");
2057  }
2058  SECTION("reject if from 127.1")
2059  {
2060  tao::pegtl::string_input<> in(
2061  "chain default {\n"
2062  " reject if from 127.1;\n"
2063  "}", "");
2064  auto root = config::parse(in);
2065  REQUIRE(root != nullptr);
2066  REQUIRE(
2067  str(*root) ==
2068  ":001: chain default\n"
2069  ":002: | reject\n"
2070  ":002: | | condition\n"
2071  ":002: | | | source 127.1\n");
2072  }
2073  SECTION("reject if to 192.0")
2074  {
2075  tao::pegtl::string_input<> in(
2076  "chain default {\n"
2077  " reject if to 192.0;\n"
2078  "}", "");
2079  auto root = config::parse(in);
2080  REQUIRE(root != nullptr);
2081  REQUIRE(
2082  str(*root) ==
2083  ":001: chain default\n"
2084  ":002: | reject\n"
2085  ":002: | | condition\n"
2086  ":002: | | | dest 192.0\n");
2087  }
2088  SECTION("reject if from 127.1 to 192.0")
2089  {
2090  tao::pegtl::string_input<> in(
2091  "chain default {\n"
2092  " reject if from 127.1 to 192.0;\n"
2093  "}", "");
2094  auto root = config::parse(in);
2095  REQUIRE(root != nullptr);
2096  REQUIRE(
2097  str(*root) ==
2098  ":001: chain default\n"
2099  ":002: | reject\n"
2100  ":002: | | condition\n"
2101  ":002: | | | source 127.1\n"
2102  ":002: | | | dest 192.0\n");
2103  }
2104  SECTION("reject with priority 99")
2105  {
2106  tao::pegtl::string_input<> in(
2107  "chain default {\n"
2108  " reject with priority 99 if to 192.0;\n"
2109  "}", "");
2110  auto root = config::parse(in);
2111  REQUIRE(root != nullptr);
2112  REQUIRE(
2113  str(*root) ==
2114  ":001: chain default\n"
2115  ":002: | reject\n"
2116  ":002: | | priority 99\n"
2117  ":002: | | condition\n"
2118  ":002: | | | dest 192.0\n");
2119  }
2120  SECTION("reject with priority 99 if PING")
2121  {
2122  tao::pegtl::string_input<> in(
2123  "chain default {\n"
2124  " reject with priority 99 if PING;\n"
2125  "}", "");
2126  auto root = config::parse(in);
2127  REQUIRE(root != nullptr);
2128  REQUIRE(
2129  str(*root) ==
2130  ":001: chain default\n"
2131  ":002: | reject\n"
2132  ":002: | | priority 99\n"
2133  ":002: | | condition\n"
2134  ":002: | | | packet_type PING\n");
2135  }
2136  SECTION("reject with priority 99 if PING from 127.1")
2137  {
2138  tao::pegtl::string_input<> in(
2139  "chain default {\n"
2140  " reject with priority 99 if PING from 127.1;\n"
2141  "}", "");
2142  auto root = config::parse(in);
2143  REQUIRE(root != nullptr);
2144  REQUIRE(
2145  str(*root) ==
2146  ":001: chain default\n"
2147  ":002: | reject\n"
2148  ":002: | | priority 99\n"
2149  ":002: | | condition\n"
2150  ":002: | | | packet_type PING\n"
2151  ":002: | | | source 127.1\n");
2152  }
2153  SECTION("reject with priority 99 if PING to 192.0")
2154  {
2155  tao::pegtl::string_input<> in(
2156  "chain default {\n"
2157  " reject with priority 99 if PING to 192.0;\n"
2158  "}", "");
2159  auto root = config::parse(in);
2160  REQUIRE(root != nullptr);
2161  REQUIRE(
2162  str(*root) ==
2163  ":001: chain default\n"
2164  ":002: | reject\n"
2165  ":002: | | priority 99\n"
2166  ":002: | | condition\n"
2167  ":002: | | | packet_type PING\n"
2168  ":002: | | | dest 192.0\n");
2169  }
2170  SECTION("reject with priority 99 if PING from 127.1 to 192.0")
2171  {
2172  tao::pegtl::string_input<> in(
2173  "chain default {\n"
2174  " reject with priority 99 if PING from 127.1 to 192.0;\n"
2175  "}", "");
2176  auto root = config::parse(in);
2177  REQUIRE(root != nullptr);
2178  REQUIRE(
2179  str(*root) ==
2180  ":001: chain default\n"
2181  ":002: | reject\n"
2182  ":002: | | priority 99\n"
2183  ":002: | | condition\n"
2184  ":002: | | | packet_type PING\n"
2185  ":002: | | | source 127.1\n"
2186  ":002: | | | dest 192.0\n");
2187  }
2188  SECTION("reject with priority 99 if from 127.1")
2189  {
2190  tao::pegtl::string_input<> in(
2191  "chain default {\n"
2192  " reject with priority 99 if from 127.1;\n"
2193  "}", "");
2194  auto root = config::parse(in);
2195  REQUIRE(root != nullptr);
2196  REQUIRE(
2197  str(*root) ==
2198  ":001: chain default\n"
2199  ":002: | reject\n"
2200  ":002: | | priority 99\n"
2201  ":002: | | condition\n"
2202  ":002: | | | source 127.1\n");
2203  }
2204  SECTION("reject with priority 99 if to 192.0")
2205  {
2206  tao::pegtl::string_input<> in(
2207  "chain default {\n"
2208  " reject with priority 99 if to 192.0;\n"
2209  "}", "");
2210  auto root = config::parse(in);
2211  REQUIRE(root != nullptr);
2212  REQUIRE(
2213  str(*root) ==
2214  ":001: chain default\n"
2215  ":002: | reject\n"
2216  ":002: | | priority 99\n"
2217  ":002: | | condition\n"
2218  ":002: | | | dest 192.0\n");
2219  }
2220  SECTION("reject with priority 99 if from 127.1 to 192.0")
2221  {
2222  tao::pegtl::string_input<> in(
2223  "chain default {\n"
2224  " reject with priority 99 if from 127.1 to 192.0;\n"
2225  "}", "");
2226  auto root = config::parse(in);
2227  REQUIRE(root != nullptr);
2228  REQUIRE(
2229  str(*root) ==
2230  ":001: chain default\n"
2231  ":002: | reject\n"
2232  ":002: | | priority 99\n"
2233  ":002: | | condition\n"
2234  ":002: | | | source 127.1\n"
2235  ":002: | | | dest 192.0\n");
2236  }
2237 }
2238 
2239 
2240 TEST_CASE("Rule combinations with 'call'.", "[config]")
2241 {
2242  SECTION("call some_name10")
2243  {
2244  tao::pegtl::string_input<> in(
2245  "chain default {\n"
2246  " call some_name10;\n"
2247  "}", "");
2248  auto root = config::parse(in);
2249  REQUIRE(root != nullptr);
2250  REQUIRE(
2251  str(*root) ==
2252  ":001: chain default\n"
2253  ":002: | call some_name10\n");
2254  }
2255  SECTION("call some_name10 if PING.")
2256  {
2257  tao::pegtl::string_input<> in(
2258  "chain default {\n"
2259  " call some_name10 if PING;\n"
2260  "}", "");
2261  auto root = config::parse(in);
2262  REQUIRE(root != nullptr);
2263  REQUIRE(
2264  str(*root) ==
2265  ":001: chain default\n"
2266  ":002: | call some_name10\n"
2267  ":002: | | condition\n"
2268  ":002: | | | packet_type PING\n");
2269  }
2270  SECTION("call some_name10 if PING from 127.1")
2271  {
2272  tao::pegtl::string_input<> in(
2273  "chain default {\n"
2274  " call some_name10 if PING from 127.1;\n"
2275  "}", "");
2276  auto root = config::parse(in);
2277  REQUIRE(root != nullptr);
2278  REQUIRE(
2279  str(*root) ==
2280  ":001: chain default\n"
2281  ":002: | call some_name10\n"
2282  ":002: | | condition\n"
2283  ":002: | | | packet_type PING\n"
2284  ":002: | | | source 127.1\n");
2285  }
2286  SECTION("call some_name10 if PING to 192.0")
2287  {
2288  tao::pegtl::string_input<> in(
2289  "chain default {\n"
2290  " call some_name10 if PING to 192.0;\n"
2291  "}", "");
2292  auto root = config::parse(in);
2293  REQUIRE(root != nullptr);
2294  REQUIRE(
2295  str(*root) ==
2296  ":001: chain default\n"
2297  ":002: | call some_name10\n"
2298  ":002: | | condition\n"
2299  ":002: | | | packet_type PING\n"
2300  ":002: | | | dest 192.0\n");
2301  }
2302  SECTION("call some_name10 if PING from 127.1 to 192.0")
2303  {
2304  tao::pegtl::string_input<> in(
2305  "chain default {\n"
2306  " call some_name10 if PING from 127.1 to 192.0;\n"
2307  "}", "");
2308  auto root = config::parse(in);
2309  REQUIRE(root != nullptr);
2310  REQUIRE(
2311  str(*root) ==
2312  ":001: chain default\n"
2313  ":002: | call some_name10\n"
2314  ":002: | | condition\n"
2315  ":002: | | | packet_type PING\n"
2316  ":002: | | | source 127.1\n"
2317  ":002: | | | dest 192.0\n");
2318  }
2319  SECTION("call some_name10 if from 127.1")
2320  {
2321  tao::pegtl::string_input<> in(
2322  "chain default {\n"
2323  " call some_name10 if from 127.1;\n"
2324  "}", "");
2325  auto root = config::parse(in);
2326  REQUIRE(root != nullptr);
2327  REQUIRE(
2328  str(*root) ==
2329  ":001: chain default\n"
2330  ":002: | call some_name10\n"
2331  ":002: | | condition\n"
2332  ":002: | | | source 127.1\n");
2333  }
2334  SECTION("call some_name10 if to 192.0")
2335  {
2336  tao::pegtl::string_input<> in(
2337  "chain default {\n"
2338  " call some_name10 if to 192.0;\n"
2339  "}", "");
2340  auto root = config::parse(in);
2341  REQUIRE(root != nullptr);
2342  REQUIRE(
2343  str(*root) ==
2344  ":001: chain default\n"
2345  ":002: | call some_name10\n"
2346  ":002: | | condition\n"
2347  ":002: | | | dest 192.0\n");
2348  }
2349  SECTION("call some_name10 if from 127.1 to 192.0")
2350  {
2351  tao::pegtl::string_input<> in(
2352  "chain default {\n"
2353  " call some_name10 if from 127.1 to 192.0;\n"
2354  "}", "");
2355  auto root = config::parse(in);
2356  REQUIRE(root != nullptr);
2357  REQUIRE(
2358  str(*root) ==
2359  ":001: chain default\n"
2360  ":002: | call some_name10\n"
2361  ":002: | | condition\n"
2362  ":002: | | | source 127.1\n"
2363  ":002: | | | dest 192.0\n");
2364  }
2365  SECTION("call some_name10 with priority 99")
2366  {
2367  tao::pegtl::string_input<> in(
2368  "chain default {\n"
2369  " call some_name10 with priority 99 if to 192.0;\n"
2370  "}", "");
2371  auto root = config::parse(in);
2372  REQUIRE(root != nullptr);
2373  REQUIRE(
2374  str(*root) ==
2375  ":001: chain default\n"
2376  ":002: | call some_name10\n"
2377  ":002: | | priority 99\n"
2378  ":002: | | condition\n"
2379  ":002: | | | dest 192.0\n");
2380  }
2381  SECTION("call some_name10 with priority 99 if PING")
2382  {
2383  tao::pegtl::string_input<> in(
2384  "chain default {\n"
2385  " call some_name10 with priority 99 if PING;\n"
2386  "}", "");
2387  auto root = config::parse(in);
2388  REQUIRE(root != nullptr);
2389  REQUIRE(
2390  str(*root) ==
2391  ":001: chain default\n"
2392  ":002: | call some_name10\n"
2393  ":002: | | priority 99\n"
2394  ":002: | | condition\n"
2395  ":002: | | | packet_type PING\n");
2396  }
2397  SECTION("call some_name10 with priority 99 if PING from 127.1")
2398  {
2399  tao::pegtl::string_input<> in(
2400  "chain default {\n"
2401  " call some_name10 with priority 99 if PING from 127.1;\n"
2402  "}", "");
2403  auto root = config::parse(in);
2404  REQUIRE(root != nullptr);
2405  REQUIRE(
2406  str(*root) ==
2407  ":001: chain default\n"
2408  ":002: | call some_name10\n"
2409  ":002: | | priority 99\n"
2410  ":002: | | condition\n"
2411  ":002: | | | packet_type PING\n"
2412  ":002: | | | source 127.1\n");
2413  }
2414  SECTION("call some_name10 with priority 99 if PING to 192.0")
2415  {
2416  tao::pegtl::string_input<> in(
2417  "chain default {\n"
2418  " call some_name10 with priority 99 if PING to 192.0;\n"
2419  "}", "");
2420  auto root = config::parse(in);
2421  REQUIRE(root != nullptr);
2422  REQUIRE(
2423  str(*root) ==
2424  ":001: chain default\n"
2425  ":002: | call some_name10\n"
2426  ":002: | | priority 99\n"
2427  ":002: | | condition\n"
2428  ":002: | | | packet_type PING\n"
2429  ":002: | | | dest 192.0\n");
2430  }
2431  SECTION("call some_name10 with priority 99 if PING from 127.1 to 192.0")
2432  {
2433  tao::pegtl::string_input<> in(
2434  "chain default {\n"
2435  " call some_name10 with priority 99 "
2436  "if PING from 127.1 to 192.0;\n"
2437  "}", "");
2438  auto root = config::parse(in);
2439  REQUIRE(root != nullptr);
2440  REQUIRE(
2441  str(*root) ==
2442  ":001: chain default\n"
2443  ":002: | call some_name10\n"
2444  ":002: | | priority 99\n"
2445  ":002: | | condition\n"
2446  ":002: | | | packet_type PING\n"
2447  ":002: | | | source 127.1\n"
2448  ":002: | | | dest 192.0\n");
2449  }
2450  SECTION("call some_name10 with priority 99 if from 127.1")
2451  {
2452  tao::pegtl::string_input<> in(
2453  "chain default {\n"
2454  " call some_name10 with priority 99 if from 127.1;\n"
2455  "}", "");
2456  auto root = config::parse(in);
2457  REQUIRE(root != nullptr);
2458  REQUIRE(
2459  str(*root) ==
2460  ":001: chain default\n"
2461  ":002: | call some_name10\n"
2462  ":002: | | priority 99\n"
2463  ":002: | | condition\n"
2464  ":002: | | | source 127.1\n");
2465  }
2466  SECTION("call some_name10 with priority 99 if to 192.0")
2467  {
2468  tao::pegtl::string_input<> in(
2469  "chain default {\n"
2470  " call some_name10 with priority 99 if to 192.0;\n"
2471  "}", "");
2472  auto root = config::parse(in);
2473  REQUIRE(root != nullptr);
2474  REQUIRE(
2475  str(*root) ==
2476  ":001: chain default\n"
2477  ":002: | call some_name10\n"
2478  ":002: | | priority 99\n"
2479  ":002: | | condition\n"
2480  ":002: | | | dest 192.0\n");
2481  }
2482  SECTION("call some_name10 with priority 99 if from 127.1 to 192.0")
2483  {
2484  tao::pegtl::string_input<> in(
2485  "chain default {\n"
2486  " call some_name10 with priority 99 if from 127.1 to 192.0;\n"
2487  "}", "");
2488  auto root = config::parse(in);
2489  REQUIRE(root != nullptr);
2490  REQUIRE(
2491  str(*root) ==
2492  ":001: chain default\n"
2493  ":002: | call some_name10\n"
2494  ":002: | | priority 99\n"
2495  ":002: | | condition\n"
2496  ":002: | | | source 127.1\n"
2497  ":002: | | | dest 192.0\n");
2498  }
2499 }
2500 
2501 
2502 TEST_CASE("Rule combinations with 'goto'.", "[config]")
2503 {
2504  SECTION("goto some_name10")
2505  {
2506  tao::pegtl::string_input<> in(
2507  "chain default {\n"
2508  " goto some_name10;\n"
2509  "}", "");
2510  auto root = config::parse(in);
2511  REQUIRE(root != nullptr);
2512  REQUIRE(
2513  str(*root) ==
2514  ":001: chain default\n"
2515  ":002: | goto some_name10\n");
2516  }
2517  SECTION("goto some_name10 if PING.")
2518  {
2519  tao::pegtl::string_input<> in(
2520  "chain default {\n"
2521  " goto some_name10 if PING;\n"
2522  "}", "");
2523  auto root = config::parse(in);
2524  REQUIRE(root != nullptr);
2525  REQUIRE(
2526  str(*root) ==
2527  ":001: chain default\n"
2528  ":002: | goto some_name10\n"
2529  ":002: | | condition\n"
2530  ":002: | | | packet_type PING\n");
2531  }
2532  SECTION("goto some_name10 if PING from 127.1")
2533  {
2534  tao::pegtl::string_input<> in(
2535  "chain default {\n"
2536  " goto some_name10 if PING from 127.1;\n"
2537  "}", "");
2538  auto root = config::parse(in);
2539  REQUIRE(root != nullptr);
2540  REQUIRE(
2541  str(*root) ==
2542  ":001: chain default\n"
2543  ":002: | goto some_name10\n"
2544  ":002: | | condition\n"
2545  ":002: | | | packet_type PING\n"
2546  ":002: | | | source 127.1\n");
2547  }
2548  SECTION("goto some_name10 if PING to 192.0")
2549  {
2550  tao::pegtl::string_input<> in(
2551  "chain default {\n"
2552  " goto some_name10 if PING to 192.0;\n"
2553  "}", "");
2554  auto root = config::parse(in);
2555  REQUIRE(root != nullptr);
2556  REQUIRE(
2557  str(*root) ==
2558  ":001: chain default\n"
2559  ":002: | goto some_name10\n"
2560  ":002: | | condition\n"
2561  ":002: | | | packet_type PING\n"
2562  ":002: | | | dest 192.0\n");
2563  }
2564  SECTION("goto some_name10 if PING from 127.1 to 192.0")
2565  {
2566  tao::pegtl::string_input<> in(
2567  "chain default {\n"
2568  " goto some_name10 if PING from 127.1 to 192.0;\n"
2569  "}", "");
2570  auto root = config::parse(in);
2571  REQUIRE(root != nullptr);
2572  REQUIRE(
2573  str(*root) ==
2574  ":001: chain default\n"
2575  ":002: | goto some_name10\n"
2576  ":002: | | condition\n"
2577  ":002: | | | packet_type PING\n"
2578  ":002: | | | source 127.1\n"
2579  ":002: | | | dest 192.0\n");
2580  }
2581  SECTION("goto some_name10 if from 127.1")
2582  {
2583  tao::pegtl::string_input<> in(
2584  "chain default {\n"
2585  " goto some_name10 if from 127.1;\n"
2586  "}", "");
2587  auto root = config::parse(in);
2588  REQUIRE(root != nullptr);
2589  REQUIRE(
2590  str(*root) ==
2591  ":001: chain default\n"
2592  ":002: | goto some_name10\n"
2593  ":002: | | condition\n"
2594  ":002: | | | source 127.1\n");
2595  }
2596  SECTION("goto some_name10 if to 192.0")
2597  {
2598  tao::pegtl::string_input<> in(
2599  "chain default {\n"
2600  " goto some_name10 if to 192.0;\n"
2601  "}", "");
2602  auto root = config::parse(in);
2603  REQUIRE(root != nullptr);
2604  REQUIRE(
2605  str(*root) ==
2606  ":001: chain default\n"
2607  ":002: | goto some_name10\n"
2608  ":002: | | condition\n"
2609  ":002: | | | dest 192.0\n");
2610  }
2611  SECTION("goto some_name10 if from 127.1 to 192.0")
2612  {
2613  tao::pegtl::string_input<> in(
2614  "chain default {\n"
2615  " goto some_name10 if from 127.1 to 192.0;\n"
2616  "}", "");
2617  auto root = config::parse(in);
2618  REQUIRE(root != nullptr);
2619  REQUIRE(
2620  str(*root) ==
2621  ":001: chain default\n"
2622  ":002: | goto some_name10\n"
2623  ":002: | | condition\n"
2624  ":002: | | | source 127.1\n"
2625  ":002: | | | dest 192.0\n");
2626  }
2627  SECTION("goto some_name10 with priority 99")
2628  {
2629  tao::pegtl::string_input<> in(
2630  "chain default {\n"
2631  " goto some_name10 with priority 99 if to 192.0;\n"
2632  "}", "");
2633  auto root = config::parse(in);
2634  REQUIRE(root != nullptr);
2635  REQUIRE(
2636  str(*root) ==
2637  ":001: chain default\n"
2638  ":002: | goto some_name10\n"
2639  ":002: | | priority 99\n"
2640  ":002: | | condition\n"
2641  ":002: | | | dest 192.0\n");
2642  }
2643  SECTION("goto some_name10 with priority 99 if PING")
2644  {
2645  tao::pegtl::string_input<> in(
2646  "chain default {\n"
2647  " goto some_name10 with priority 99 if PING;\n"
2648  "}", "");
2649  auto root = config::parse(in);
2650  REQUIRE(root != nullptr);
2651  REQUIRE(
2652  str(*root) ==
2653  ":001: chain default\n"
2654  ":002: | goto some_name10\n"
2655  ":002: | | priority 99\n"
2656  ":002: | | condition\n"
2657  ":002: | | | packet_type PING\n");
2658  }
2659  SECTION("goto some_name10 with priority 99 if PING from 127.1")
2660  {
2661  tao::pegtl::string_input<> in(
2662  "chain default {\n"
2663  " goto some_name10 with priority 99 if PING from 127.1;\n"
2664  "}", "");
2665  auto root = config::parse(in);
2666  REQUIRE(root != nullptr);
2667  REQUIRE(
2668  str(*root) ==
2669  ":001: chain default\n"
2670  ":002: | goto some_name10\n"
2671  ":002: | | priority 99\n"
2672  ":002: | | condition\n"
2673  ":002: | | | packet_type PING\n"
2674  ":002: | | | source 127.1\n");
2675  }
2676  SECTION("goto some_name10 with priority 99 if PING to 192.0")
2677  {
2678  tao::pegtl::string_input<> in(
2679  "chain default {\n"
2680  " goto some_name10 with priority 99 if PING to 192.0;\n"
2681  "}", "");
2682  auto root = config::parse(in);
2683  REQUIRE(root != nullptr);
2684  REQUIRE(
2685  str(*root) ==
2686  ":001: chain default\n"
2687  ":002: | goto some_name10\n"
2688  ":002: | | priority 99\n"
2689  ":002: | | condition\n"
2690  ":002: | | | packet_type PING\n"
2691  ":002: | | | dest 192.0\n");
2692  }
2693  SECTION("goto some_name10 with priority 99 if PING from 127.1 to 192.0")
2694  {
2695  tao::pegtl::string_input<> in(
2696  "chain default {\n"
2697  " goto some_name10 with priority 99 "
2698  "if PING from 127.1 to 192.0;\n"
2699  "}", "");
2700  auto root = config::parse(in);
2701  REQUIRE(root != nullptr);
2702  REQUIRE(
2703  str(*root) ==
2704  ":001: chain default\n"
2705  ":002: | goto some_name10\n"
2706  ":002: | | priority 99\n"
2707  ":002: | | condition\n"
2708  ":002: | | | packet_type PING\n"
2709  ":002: | | | source 127.1\n"
2710  ":002: | | | dest 192.0\n");
2711  }
2712  SECTION("goto some_name10 with priority 99 if from 127.1")
2713  {
2714  tao::pegtl::string_input<> in(
2715  "chain default {\n"
2716  " goto some_name10 with priority 99 if from 127.1;\n"
2717  "}", "");
2718  auto root = config::parse(in);
2719  REQUIRE(root != nullptr);
2720  REQUIRE(
2721  str(*root) ==
2722  ":001: chain default\n"
2723  ":002: | goto some_name10\n"
2724  ":002: | | priority 99\n"
2725  ":002: | | condition\n"
2726  ":002: | | | source 127.1\n");
2727  }
2728  SECTION("goto some_name10 with priority 99 if to 192.0")
2729  {
2730  tao::pegtl::string_input<> in(
2731  "chain default {\n"
2732  " goto some_name10 with priority 99 if to 192.0;\n"
2733  "}", "");
2734  auto root = config::parse(in);
2735  REQUIRE(root != nullptr);
2736  REQUIRE(
2737  str(*root) ==
2738  ":001: chain default\n"
2739  ":002: | goto some_name10\n"
2740  ":002: | | priority 99\n"
2741  ":002: | | condition\n"
2742  ":002: | | | dest 192.0\n");
2743  }
2744  SECTION("goto some_name10 with priority 99 if from 127.1 to 192.0")
2745  {
2746  tao::pegtl::string_input<> in(
2747  "chain default {\n"
2748  " goto some_name10 with priority 99 if from 127.1 to 192.0;\n"
2749  "}", "");
2750  auto root = config::parse(in);
2751  REQUIRE(root != nullptr);
2752  REQUIRE(
2753  str(*root) ==
2754  ":001: chain default\n"
2755  ":002: | goto some_name10\n"
2756  ":002: | | priority 99\n"
2757  ":002: | | condition\n"
2758  ":002: | | | source 127.1\n"
2759  ":002: | | | dest 192.0\n");
2760  }
2761 }
2762 
2763 
2764 TEST_CASE("'print_node' method prints an abstract syntax tree.", "[config]")
2765 {
2766  SECTION("Print without line information.")
2767  {
2768  tao::pegtl::string_input<> in(
2769  "chain default {\n"
2770  " call some_name10 with priority 99 "
2771  "if PING from 127.1 to 192.0;\n"
2772  "}", "");
2773  auto root = config::parse(in);
2774  REQUIRE(root != nullptr);
2775  std::stringstream ss;
2776  config::print_node(ss, *root, false);
2777  REQUIRE(
2778  ss.str() ==
2779  "chain default\n"
2780  "| call some_name10\n"
2781  "| | priority 99\n"
2782  "| | condition\n"
2783  "| | | packet_type PING\n"
2784  "| | | source 127.1\n"
2785  "| | | dest 192.0\n");
2786  }
2787  SECTION("Print with line information.")
2788  {
2789  tao::pegtl::string_input<> in(
2790  "chain default {\n"
2791  " call some_name10 with priority 99 "
2792  "if PING from 127.1 to 192.0;\n"
2793  "}", "");
2794  auto root = config::parse(in);
2795  REQUIRE(root != nullptr);
2796  std::stringstream ss;
2797  config::print_node(ss, *root, true);
2798  REQUIRE(
2799  ss.str() ==
2800  ":001: chain default\n"
2801  ":002: | call some_name10\n"
2802  ":002: | | priority 99\n"
2803  ":002: | | condition\n"
2804  ":002: | | | packet_type PING\n"
2805  ":002: | | | source 127.1\n"
2806  ":002: | | | dest 192.0\n");
2807  }
2808 }
std::string str(const T &object)
Definition: utility.hpp:128
std::ostream & print_node(std::ostream &os, const config::parse_tree::node &node, bool print_location, const std::string &prefix)
std::unique_ptr< config::parse_tree::node > parse(Input &in)
TEST_CASE("A configuration string must have at least one valid statement " "or block.", "[config]")