2 * Copyright Andrey Semashev 2007 - 2015.
3 * Distributed under the Boost Software License, Version 1.0.
4 * (See accompanying file LICENSE_1_0.txt or copy at
5 * http://www.boost.org/LICENSE_1_0.txt)
8 * \file setup_filter_parser.cpp
9 * \author Andrey Semashev
12 * \brief This header contains tests for the filter parser.
15 #define BOOST_TEST_MODULE setup_filter_parser
18 #include <boost/test/unit_test.hpp>
19 #include <boost/log/utility/setup/filter_parser.hpp>
21 #if !defined(BOOST_LOG_WITHOUT_SETTINGS_PARSERS) && !defined(BOOST_LOG_WITHOUT_DEFAULT_FACTORIES)
23 #include <boost/smart_ptr/shared_ptr.hpp>
24 #include <boost/log/exceptions.hpp>
25 #include <boost/log/attributes/constant.hpp>
26 #include <boost/log/attributes/attribute_set.hpp>
27 #include <boost/log/attributes/attribute_value_set.hpp>
28 #include <boost/log/expressions/filter.hpp>
30 namespace logging
= boost::log
;
31 namespace attrs
= logging::attributes
;
33 typedef logging::attribute_set attr_set
;
34 typedef logging::attribute_value_set attr_values
;
36 // Tests for attribute presence check
37 BOOST_AUTO_TEST_CASE(attr_presence
)
39 attrs::constant
< int > attr1(10);
40 attr_set set1
, set2
, set3
;
42 attr_values
values1(set1
, set2
, set3
);
45 set1
["MyAttr"] = attr1
;
46 attr_values
values2(set1
, set2
, set3
);
50 logging::filter f
= logging::parse_filter("%MyAttr%");
51 BOOST_CHECK(!f(values1
));
52 BOOST_CHECK(f(values2
));
55 logging::filter f
= logging::parse_filter(" % MyAttr % ");
56 BOOST_CHECK(!f(values1
));
57 BOOST_CHECK(f(values2
));
61 // Tests for integer relation filter
62 BOOST_AUTO_TEST_CASE(int_relation
)
64 attrs::constant
< int > attr1(10);
65 attrs::constant
< long > attr2(20);
66 attrs::constant
< int > attr3(-2);
67 attr_set set1
, set2
, set3
;
69 attr_values
values1(set1
, set2
, set3
);
72 set1
["MyAttr"] = attr1
;
73 attr_values
values2(set1
, set2
, set3
);
76 set1
["MyAttr"] = attr2
;
77 attr_values
values3(set1
, set2
, set3
);
80 set1
["MyAttr"] = attr3
;
81 attr_values
values4(set1
, set2
, set3
);
85 logging::filter f
= logging::parse_filter("%MyAttr% = 10");
86 BOOST_CHECK(!f(values1
));
87 BOOST_CHECK(f(values2
));
88 BOOST_CHECK(!f(values3
));
89 BOOST_CHECK(!f(values4
));
92 logging::filter f
= logging::parse_filter("%MyAttr% != 10");
93 BOOST_CHECK(!f(values1
));
94 BOOST_CHECK(!f(values2
));
95 BOOST_CHECK(f(values3
));
96 BOOST_CHECK(f(values4
));
99 logging::filter f
= logging::parse_filter("%MyAttr% < 20");
100 BOOST_CHECK(!f(values1
));
101 BOOST_CHECK(f(values2
));
102 BOOST_CHECK(!f(values3
));
103 BOOST_CHECK(f(values4
));
106 logging::filter f
= logging::parse_filter("%MyAttr% < -7");
107 BOOST_CHECK(!f(values1
));
108 BOOST_CHECK(!f(values2
));
109 BOOST_CHECK(!f(values3
));
110 BOOST_CHECK(!f(values4
));
113 logging::filter f
= logging::parse_filter("%MyAttr% > 10");
114 BOOST_CHECK(!f(values1
));
115 BOOST_CHECK(!f(values2
));
116 BOOST_CHECK(f(values3
));
117 BOOST_CHECK(!f(values4
));
120 logging::filter f
= logging::parse_filter("%MyAttr% > -5");
121 BOOST_CHECK(!f(values1
));
122 BOOST_CHECK(f(values2
));
123 BOOST_CHECK(f(values3
));
124 BOOST_CHECK(f(values4
));
127 logging::filter f
= logging::parse_filter("%MyAttr% <= 20");
128 BOOST_CHECK(!f(values1
));
129 BOOST_CHECK(f(values2
));
130 BOOST_CHECK(f(values3
));
131 BOOST_CHECK(f(values4
));
134 logging::filter f
= logging::parse_filter("%MyAttr% >= 20");
135 BOOST_CHECK(!f(values1
));
136 BOOST_CHECK(!f(values2
));
137 BOOST_CHECK(f(values3
));
138 BOOST_CHECK(!f(values4
));
142 // Tests for floating point relation filter
143 BOOST_AUTO_TEST_CASE(fp_relation
)
145 attrs::constant
< float > attr1(2.5f
);
146 attrs::constant
< float > attr2(8.8f
);
147 attrs::constant
< double > attr3(-9.1);
148 attrs::constant
< float > attr4(0.0f
);
149 attr_set set1
, set2
, set3
;
151 attr_values
values1(set1
, set2
, set3
);
154 set1
["MyAttr"] = attr1
;
155 attr_values
values2(set1
, set2
, set3
);
158 set1
["MyAttr"] = attr2
;
159 attr_values
values3(set1
, set2
, set3
);
162 set1
["MyAttr"] = attr3
;
163 attr_values
values4(set1
, set2
, set3
);
166 set1
["MyAttr"] = attr4
;
167 attr_values
values5(set1
, set2
, set3
);
171 logging::filter f
= logging::parse_filter("%MyAttr% = 10.3");
172 BOOST_CHECK(!f(values1
));
173 BOOST_CHECK(!f(values2
));
174 BOOST_CHECK(!f(values3
));
175 BOOST_CHECK(!f(values4
));
176 BOOST_CHECK(!f(values5
));
179 logging::filter f
= logging::parse_filter("%MyAttr% != 10");
180 BOOST_CHECK(!f(values1
));
181 BOOST_CHECK(f(values2
));
182 BOOST_CHECK(f(values3
));
183 BOOST_CHECK(f(values4
));
184 BOOST_CHECK(f(values5
));
187 logging::filter f
= logging::parse_filter("%MyAttr% < 5.5");
188 BOOST_CHECK(!f(values1
));
189 BOOST_CHECK(f(values2
));
190 BOOST_CHECK(!f(values3
));
191 BOOST_CHECK(f(values4
));
192 BOOST_CHECK(f(values5
));
195 logging::filter f
= logging::parse_filter("%MyAttr% < -7");
196 BOOST_CHECK(!f(values1
));
197 BOOST_CHECK(!f(values2
));
198 BOOST_CHECK(!f(values3
));
199 BOOST_CHECK(f(values4
));
200 BOOST_CHECK(!f(values5
));
203 logging::filter f
= logging::parse_filter("%MyAttr% > 5.6");
204 BOOST_CHECK(!f(values1
));
205 BOOST_CHECK(!f(values2
));
206 BOOST_CHECK(f(values3
));
207 BOOST_CHECK(!f(values4
));
208 BOOST_CHECK(!f(values5
));
211 logging::filter f
= logging::parse_filter("%MyAttr% > -5");
212 BOOST_CHECK(!f(values1
));
213 BOOST_CHECK(f(values2
));
214 BOOST_CHECK(f(values3
));
215 BOOST_CHECK(!f(values4
));
216 BOOST_CHECK(f(values5
));
219 logging::filter f
= logging::parse_filter("%MyAttr% <= 20");
220 BOOST_CHECK(!f(values1
));
221 BOOST_CHECK(f(values2
));
222 BOOST_CHECK(f(values3
));
223 BOOST_CHECK(f(values4
));
224 BOOST_CHECK(f(values5
));
227 logging::filter f
= logging::parse_filter("%MyAttr% >= 20");
228 BOOST_CHECK(!f(values1
));
229 BOOST_CHECK(!f(values2
));
230 BOOST_CHECK(!f(values3
));
231 BOOST_CHECK(!f(values4
));
232 BOOST_CHECK(!f(values5
));
236 // Tests for string relation filter
237 BOOST_AUTO_TEST_CASE(string_relation
)
239 attrs::constant
< std::string
> attr1("hello");
240 attr_set set1
, set2
, set3
;
242 attr_values
values1(set1
, set2
, set3
);
245 set1
["MyStr"] = attr1
;
246 attr_values
values2(set1
, set2
, set3
);
250 logging::filter f
= logging::parse_filter("%MyStr% = hello");
251 BOOST_CHECK(!f(values1
));
252 BOOST_CHECK(f(values2
));
255 logging::filter f
= logging::parse_filter("%MyStr% = \"hello\"");
256 BOOST_CHECK(!f(values1
));
257 BOOST_CHECK(f(values2
));
260 logging::filter f
= logging::parse_filter(" % MyStr % = \"hello\" ");
261 BOOST_CHECK(!f(values1
));
262 BOOST_CHECK(f(values2
));
265 logging::filter f
= logging::parse_filter("%MyStr% = \" hello\"");
266 BOOST_CHECK(!f(values1
));
267 BOOST_CHECK(!f(values2
));
270 logging::filter f
= logging::parse_filter("%MyStr% = \"hello \"");
271 BOOST_CHECK(!f(values1
));
272 BOOST_CHECK(!f(values2
));
275 logging::filter f
= logging::parse_filter("%MyStr% = \"world\"");
276 BOOST_CHECK(!f(values1
));
277 BOOST_CHECK(!f(values2
));
280 logging::filter f
= logging::parse_filter("%MyStr% = \"Hello\"");
281 BOOST_CHECK(!f(values1
));
282 BOOST_CHECK(!f(values2
));
285 logging::filter f
= logging::parse_filter("%MyStr% != hello");
286 BOOST_CHECK(!f(values1
));
287 BOOST_CHECK(!f(values2
));
290 logging::filter f
= logging::parse_filter("%MyStr% != world");
291 BOOST_CHECK(!f(values1
));
292 BOOST_CHECK(f(values2
));
295 logging::filter f
= logging::parse_filter("%MyStr% < world");
296 BOOST_CHECK(!f(values1
));
297 BOOST_CHECK(f(values2
));
300 logging::filter f
= logging::parse_filter("%MyStr% > world");
301 BOOST_CHECK(!f(values1
));
302 BOOST_CHECK(!f(values2
));
305 // Check that strings that look like numbers can still be used in filters
306 attrs::constant
< std::string
> attr2("55");
307 set1
["MyStr"] = attr2
;
308 attr_values
values3(set1
, set2
, set3
);
312 logging::filter f
= logging::parse_filter("%MyStr% = \"55\"");
313 BOOST_CHECK(f(values3
));
316 logging::filter f
= logging::parse_filter("%MyStr% < \"555\"");
317 BOOST_CHECK(f(values3
));
320 logging::filter f
= logging::parse_filter("%MyStr% > \"44\"");
321 BOOST_CHECK(f(values3
));
325 // Tests for multiple expression filter
326 BOOST_AUTO_TEST_CASE(multi_expression
)
328 attrs::constant
< int > attr1(10);
329 attrs::constant
< int > attr2(20);
330 attrs::constant
< std::string
> attr3("hello");
331 attrs::constant
< std::string
> attr4("world");
332 attr_set set1
, set2
, set3
;
334 attr_values
values1(set1
, set2
, set3
);
337 set1
["MyAttr"] = attr1
;
338 attr_values
values2(set1
, set2
, set3
);
341 set1
["MyAttr"] = attr2
;
342 attr_values
values3(set1
, set2
, set3
);
345 set1
["MyStr"] = attr3
;
346 attr_values
values4(set1
, set2
, set3
);
349 set1
["MyStr"] = attr4
;
350 attr_values
values5(set1
, set2
, set3
);
354 logging::filter f
= logging::parse_filter("%MyAttr% = 10 & %MyStr% = \"hello\"");
355 BOOST_CHECK(!f(values1
));
356 BOOST_CHECK(!f(values2
));
357 BOOST_CHECK(!f(values3
));
358 BOOST_CHECK(!f(values4
));
359 BOOST_CHECK(!f(values5
));
362 logging::filter f
= logging::parse_filter("%MyAttr% > 10 & %MyStr% = \"hello\"");
363 BOOST_CHECK(!f(values1
));
364 BOOST_CHECK(!f(values2
));
365 BOOST_CHECK(!f(values3
));
366 BOOST_CHECK(f(values4
));
367 BOOST_CHECK(!f(values5
));
370 logging::filter f
= logging::parse_filter("%MyAttr% > 10 and %MyStr% = \"hello\"");
371 BOOST_CHECK(!f(values1
));
372 BOOST_CHECK(!f(values2
));
373 BOOST_CHECK(!f(values3
));
374 BOOST_CHECK(f(values4
));
375 BOOST_CHECK(!f(values5
));
378 logging::filter f
= logging::parse_filter("%MyAttr% = 10 | %MyStr% = \"world\"");
379 BOOST_CHECK(!f(values1
));
380 BOOST_CHECK(f(values2
));
381 BOOST_CHECK(!f(values3
));
382 BOOST_CHECK(!f(values4
));
383 BOOST_CHECK(f(values5
));
386 logging::filter f
= logging::parse_filter("%MyAttr% > 10 | %MyStr% = \"world\"");
387 BOOST_CHECK(!f(values1
));
388 BOOST_CHECK(!f(values2
));
389 BOOST_CHECK(f(values3
));
390 BOOST_CHECK(f(values4
));
391 BOOST_CHECK(f(values5
));
394 logging::filter f
= logging::parse_filter("%MyAttr% = 10 or %MyStr% = \"world\"");
395 BOOST_CHECK(!f(values1
));
396 BOOST_CHECK(f(values2
));
397 BOOST_CHECK(!f(values3
));
398 BOOST_CHECK(!f(values4
));
399 BOOST_CHECK(f(values5
));
402 logging::filter f
= logging::parse_filter("%MyAttr% > 0 & %MyAttr% < 20 | %MyStr% = \"hello\"");
403 BOOST_CHECK(!f(values1
));
404 BOOST_CHECK(f(values2
));
405 BOOST_CHECK(!f(values3
));
406 BOOST_CHECK(f(values4
));
407 BOOST_CHECK(!f(values5
));
411 // Tests for negation
412 BOOST_AUTO_TEST_CASE(negation
)
414 attrs::constant
< int > attr1(10);
415 attrs::constant
< int > attr2(20);
416 attrs::constant
< std::string
> attr3("hello");
417 attr_set set1
, set2
, set3
;
419 attr_values
values1(set1
, set2
, set3
);
422 set1
["MyAttr"] = attr1
;
423 attr_values
values2(set1
, set2
, set3
);
426 set1
["MyAttr"] = attr2
;
427 attr_values
values3(set1
, set2
, set3
);
430 set1
["MyStr"] = attr3
;
431 attr_values
values4(set1
, set2
, set3
);
434 // Test with presence filter
436 logging::filter f
= logging::parse_filter("!%MyAttr%");
437 BOOST_CHECK(f(values1
));
438 BOOST_CHECK(!f(values2
));
441 logging::filter f
= logging::parse_filter(" ! % MyAttr % ");
442 BOOST_CHECK(f(values1
));
443 BOOST_CHECK(!f(values2
));
446 logging::filter f
= logging::parse_filter("not %MyAttr%");
447 BOOST_CHECK(f(values1
));
448 BOOST_CHECK(!f(values2
));
451 logging::filter f
= logging::parse_filter("!!%MyAttr%");
452 BOOST_CHECK(!f(values1
));
453 BOOST_CHECK(f(values2
));
456 // Test with relations
458 logging::filter f
= logging::parse_filter("!(%MyAttr% = 10)");
459 BOOST_CHECK(f(values1
));
460 BOOST_CHECK(!f(values2
));
461 BOOST_CHECK(f(values3
));
464 logging::filter f
= logging::parse_filter("not ( %MyAttr% = 10 ) ");
465 BOOST_CHECK(f(values1
));
466 BOOST_CHECK(!f(values2
));
467 BOOST_CHECK(f(values3
));
470 logging::filter f
= logging::parse_filter("!(%MyAttr% < 20)");
471 BOOST_CHECK(f(values1
));
472 BOOST_CHECK(!f(values2
));
473 BOOST_CHECK(f(values3
));
476 // Test with multiple subexpressions
478 logging::filter f
= logging::parse_filter("!(%MyAttr% = 20 & %MyStr% = hello)");
479 BOOST_CHECK(f(values1
));
480 BOOST_CHECK(f(values2
));
481 BOOST_CHECK(f(values3
));
482 BOOST_CHECK(!f(values4
));
485 logging::filter f
= logging::parse_filter("!(%MyAttr% = 10 | %MyStr% = hello)");
486 BOOST_CHECK(f(values1
));
487 BOOST_CHECK(!f(values2
));
488 BOOST_CHECK(f(values3
));
489 BOOST_CHECK(!f(values4
));
493 // Tests for begins_with relation filter
494 BOOST_AUTO_TEST_CASE(begins_with_relation
)
496 attrs::constant
< std::string
> attr1("abcdABCD");
497 attr_set set1
, set2
, set3
;
499 set1
["MyStr"] = attr1
;
500 attr_values
values1(set1
, set2
, set3
);
504 logging::filter f
= logging::parse_filter("%MyStr% begins_with \"abcd\"");
505 BOOST_CHECK(f(values1
));
508 logging::filter f
= logging::parse_filter("%MyStr% begins_with \"ABCD\"");
509 BOOST_CHECK(!f(values1
));
512 logging::filter f
= logging::parse_filter("%MyStr% begins_with \"efgh\"");
513 BOOST_CHECK(!f(values1
));
517 // Tests for ends_with relation filter
518 BOOST_AUTO_TEST_CASE(ends_with_relation
)
520 attrs::constant
< std::string
> attr1("abcdABCD");
521 attr_set set1
, set2
, set3
;
523 set1
["MyStr"] = attr1
;
524 attr_values
values1(set1
, set2
, set3
);
528 logging::filter f
= logging::parse_filter("%MyStr% ends_with \"abcd\"");
529 BOOST_CHECK(!f(values1
));
532 logging::filter f
= logging::parse_filter("%MyStr% ends_with \"ABCD\"");
533 BOOST_CHECK(f(values1
));
536 logging::filter f
= logging::parse_filter("%MyStr% ends_with \"efgh\"");
537 BOOST_CHECK(!f(values1
));
541 // Tests for contains relation filter
542 BOOST_AUTO_TEST_CASE(contains_relation
)
544 attrs::constant
< std::string
> attr1("abcdABCD");
545 attr_set set1
, set2
, set3
;
547 set1
["MyStr"] = attr1
;
548 attr_values
values1(set1
, set2
, set3
);
552 logging::filter f
= logging::parse_filter("%MyStr% contains \"abcd\"");
553 BOOST_CHECK(f(values1
));
556 logging::filter f
= logging::parse_filter("%MyStr% contains \"ABCD\"");
557 BOOST_CHECK(f(values1
));
560 logging::filter f
= logging::parse_filter("%MyStr% contains \"cdAB\"");
561 BOOST_CHECK(f(values1
));
564 logging::filter f
= logging::parse_filter("%MyStr% contains \"efgh\"");
565 BOOST_CHECK(!f(values1
));
569 // Tests for regex matching relation filter
570 BOOST_AUTO_TEST_CASE(matches_relation
)
572 attrs::constant
< std::string
> attr1("hello");
573 attrs::constant
< std::string
> attr2("127.0.0.1");
574 attr_set set1
, set2
, set3
;
576 set1
["MyStr"] = attr1
;
577 set1
["MyIP"] = attr2
;
578 attr_values
values1(set1
, set2
, set3
);
582 logging::filter f
= logging::parse_filter("%MyStr% matches \"h.*\"");
583 BOOST_CHECK(f(values1
));
586 logging::filter f
= logging::parse_filter("%MyStr% matches \"w.*\"");
587 BOOST_CHECK(!f(values1
));
590 logging::filter f
= logging::parse_filter("%MyStr% matches \"\\\\d*\"");
591 BOOST_CHECK(!f(values1
));
594 logging::filter f
= logging::parse_filter("%MyStr% matches \"[a-z]*\"");
595 BOOST_CHECK(f(values1
));
598 logging::filter f
= logging::parse_filter("%MyIP% matches \"\\\\d*\\\\.\\\\d*\\\\.\\\\d*\\\\.\\\\d*\"");
599 BOOST_CHECK(f(values1
));
605 class test_filter_factory
:
606 public logging::filter_factory
< char >
609 typedef logging::filter_factory
< char > base_type
;
624 typedef base_type::string_type string_type
;
627 explicit test_filter_factory(logging::attribute_name
const& name
) : m_name(name
), m_rel(custom
), m_called(false)
631 void expect_relation(relation_type rel
, string_type
const& arg
)
635 m_custom_rel
.clear();
638 void expect_relation(string_type
const& rel
, string_type
const& arg
)
647 BOOST_CHECK(m_called
);
651 logging::filter
on_exists_test(logging::attribute_name
const& name
)
653 BOOST_CHECK_EQUAL(m_name
, name
);
654 BOOST_CHECK_EQUAL(m_rel
, exists
);
656 return logging::filter();
658 logging::filter
on_equality_relation(logging::attribute_name
const& name
, string_type
const& arg
)
660 BOOST_CHECK_EQUAL(m_name
, name
);
661 BOOST_CHECK_EQUAL(m_rel
, equality
);
662 BOOST_CHECK_EQUAL(m_arg
, arg
);
664 return logging::filter();
666 logging::filter
on_inequality_relation(logging::attribute_name
const& name
, string_type
const& arg
)
668 BOOST_CHECK_EQUAL(m_name
, name
);
669 BOOST_CHECK_EQUAL(m_rel
, inequality
);
670 BOOST_CHECK_EQUAL(m_arg
, arg
);
672 return logging::filter();
674 logging::filter
on_less_relation(logging::attribute_name
const& name
, string_type
const& arg
)
676 BOOST_CHECK_EQUAL(m_name
, name
);
677 BOOST_CHECK_EQUAL(m_rel
, less
);
678 BOOST_CHECK_EQUAL(m_arg
, arg
);
680 return logging::filter();
682 logging::filter
on_greater_relation(logging::attribute_name
const& name
, string_type
const& arg
)
684 BOOST_CHECK_EQUAL(m_name
, name
);
685 BOOST_CHECK_EQUAL(m_rel
, greater
);
686 BOOST_CHECK_EQUAL(m_arg
, arg
);
688 return logging::filter();
690 logging::filter
on_less_or_equal_relation(logging::attribute_name
const& name
, string_type
const& arg
)
692 BOOST_CHECK_EQUAL(m_name
, name
);
693 BOOST_CHECK_EQUAL(m_rel
, less_or_equal
);
694 BOOST_CHECK_EQUAL(m_arg
, arg
);
696 return logging::filter();
698 logging::filter
on_greater_or_equal_relation(logging::attribute_name
const& name
, string_type
const& arg
)
700 BOOST_CHECK_EQUAL(m_name
, name
);
701 BOOST_CHECK_EQUAL(m_rel
, greater_or_equal
);
702 BOOST_CHECK_EQUAL(m_arg
, arg
);
704 return logging::filter();
706 logging::filter
on_custom_relation(logging::attribute_name
const& name
, string_type
const& rel
, string_type
const& arg
)
708 BOOST_CHECK_EQUAL(m_name
, name
);
709 BOOST_CHECK_EQUAL(m_rel
, custom
);
710 BOOST_CHECK_EQUAL(m_custom_rel
, rel
);
711 BOOST_CHECK_EQUAL(m_arg
, arg
);
713 return logging::filter();
717 logging::attribute_name m_name
;
720 string_type m_custom_rel
;
726 // Tests for filter factory
727 BOOST_AUTO_TEST_CASE(filter_factory
)
729 logging::attribute_name
attr_name("MyCustomAttr");
730 boost::shared_ptr
< test_filter_factory
> factory(new test_filter_factory(attr_name
));
731 logging::register_filter_factory(attr_name
, factory
);
733 BOOST_TEST_CHECKPOINT("filter_factory::exists");
734 factory
->expect_relation(test_filter_factory::exists
, "");
735 logging::parse_filter("%MyCustomAttr%");
736 factory
->check_called();
738 BOOST_TEST_CHECKPOINT("filter_factory::equality");
739 factory
->expect_relation(test_filter_factory::equality
, "15");
740 logging::parse_filter("%MyCustomAttr% = 15");
741 factory
->check_called();
743 BOOST_TEST_CHECKPOINT("filter_factory::equality");
744 factory
->expect_relation(test_filter_factory::equality
, "hello");
745 logging::parse_filter("%MyCustomAttr% = hello");
746 factory
->check_called();
748 BOOST_TEST_CHECKPOINT("filter_factory::equality");
749 factory
->expect_relation(test_filter_factory::equality
, "hello");
750 logging::parse_filter("%MyCustomAttr% = \"hello\"");
751 factory
->check_called();
753 BOOST_TEST_CHECKPOINT("filter_factory::equality");
754 factory
->expect_relation(test_filter_factory::equality
, "hello\nworld");
755 logging::parse_filter("%MyCustomAttr% = \"hello\\nworld\"");
756 factory
->check_called();
758 BOOST_TEST_CHECKPOINT("filter_factory::inequality");
759 factory
->expect_relation(test_filter_factory::inequality
, "hello");
760 logging::parse_filter("%MyCustomAttr% != \"hello\"");
761 factory
->check_called();
763 BOOST_TEST_CHECKPOINT("filter_factory::less");
764 factory
->expect_relation(test_filter_factory::less
, "hello");
765 logging::parse_filter("%MyCustomAttr% < \"hello\"");
766 factory
->check_called();
768 BOOST_TEST_CHECKPOINT("filter_factory::greater");
769 factory
->expect_relation(test_filter_factory::greater
, "hello");
770 logging::parse_filter("%MyCustomAttr% > \"hello\"");
771 factory
->check_called();
773 BOOST_TEST_CHECKPOINT("filter_factory::less_or_equal");
774 factory
->expect_relation(test_filter_factory::less_or_equal
, "hello");
775 logging::parse_filter("%MyCustomAttr% <= \"hello\"");
776 factory
->check_called();
778 BOOST_TEST_CHECKPOINT("filter_factory::greater_or_equal");
779 factory
->expect_relation(test_filter_factory::greater_or_equal
, "hello");
780 logging::parse_filter("%MyCustomAttr% >= \"hello\"");
781 factory
->check_called();
783 BOOST_TEST_CHECKPOINT("filter_factory::custom");
784 factory
->expect_relation("my_relation", "hello");
785 logging::parse_filter("%MyCustomAttr% my_relation \"hello\"");
786 factory
->check_called();
789 // Tests for invalid filters
790 BOOST_AUTO_TEST_CASE(invalid
)
792 BOOST_CHECK_THROW(logging::parse_filter("%MyStr"), logging::parse_error
);
793 BOOST_CHECK_THROW(logging::parse_filter("MyStr%"), logging::parse_error
);
794 BOOST_CHECK_THROW(logging::parse_filter("%MyStr% abcd"), logging::parse_error
);
795 BOOST_CHECK_THROW(logging::parse_filter("(%MyStr%"), logging::parse_error
);
796 BOOST_CHECK_THROW(logging::parse_filter("%MyStr%)"), logging::parse_error
);
797 BOOST_CHECK_THROW(logging::parse_filter("%%"), logging::parse_error
);
798 BOOST_CHECK_THROW(logging::parse_filter("%"), logging::parse_error
);
799 BOOST_CHECK_THROW(logging::parse_filter("!"), logging::parse_error
);
800 BOOST_CHECK_THROW(logging::parse_filter("!()"), logging::parse_error
);
801 BOOST_CHECK_THROW(logging::parse_filter("\"xxx\" == %MyStr%"), logging::parse_error
);
802 BOOST_CHECK_THROW(logging::parse_filter("%MyStr% == \"xxx"), logging::parse_error
);
803 BOOST_CHECK_THROW(logging::parse_filter("%MyStr% === \"xxx\""), logging::parse_error
);
804 BOOST_CHECK_THROW(logging::parse_filter("%MyStr% ! \"xxx\""), logging::parse_error
);
805 BOOST_CHECK_THROW(logging::parse_filter("%MyStr% %MyStr2%"), logging::parse_error
);
808 #endif // !defined(BOOST_LOG_WITHOUT_SETTINGS_PARSERS) && !defined(BOOST_LOG_WITHOUT_DEFAULT_FACTORIES)