]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/test/test/writing-test-ts/assertion-construction-test.cpp
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / boost / libs / test / test / writing-test-ts / assertion-construction-test.cpp
1 // (C) Copyright Gennadiy Rozental 2011-2015.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5
6 // See http://www.boost.org/libs/test for the library home page.
7 //
8 // File : $RCSfile$
9 //
10 // Version : $Revision: 62023 $
11 //
12 // Description : unit test for new assertion construction based on input expression
13 // ***************************************************************************
14
15 // Boost.Test
16 #define BOOST_TEST_MODULE Boost.Test assertion consruction test
17 #include <boost/test/unit_test.hpp>
18 #include <boost/test/tools/assertion.hpp>
19 #include <boost/test/utils/is_forward_iterable.hpp>
20
21 #include <boost/noncopyable.hpp>
22
23 #include <map>
24 #include <set>
25
26 namespace utf = boost::unit_test;
27
28 //____________________________________________________________________________//
29
30 #define EXPR_TYPE( expr ) ( assertion::seed() ->* expr )
31
32
33 #if !defined(BOOST_TEST_FWD_ITERABLE_CXX03)
34 // some broken compilers do not implement properly decltype on expressions
35 // partial implementation of is_forward_iterable when decltype not available
36 struct not_fwd_iterable_1 {
37 typedef int const_iterator;
38 typedef int value_type;
39
40 bool size();
41 };
42
43 struct not_fwd_iterable_2 {
44 typedef int const_iterator;
45 typedef int value_type;
46
47 bool begin();
48 };
49
50 struct not_fwd_iterable_3 {
51 typedef int value_type;
52 bool begin();
53 bool size();
54 };
55
56 // this one does not have const_iterator, but should be forward iterable
57 struct fwd_iterable_4 {
58 typedef int value_type;
59 struct iterator {
60 typedef unsigned int value_type;
61 };
62 iterator begin();
63 iterator end();
64 bool size();
65 };
66
67 struct fwd_iterable_custom {
68 typedef std::vector<int>::const_iterator custom_iterator; // named "exotic" on purpose
69
70 custom_iterator begin() const { return values.begin(); }
71 custom_iterator end() const { return values.end(); }
72
73 #if !defined(BOOST_MSVC) || (BOOST_MSVC_FULL_VER > 180040629)
74 #define MY_TEST_HAS_INIT_LIST
75 fwd_iterable_custom(std::initializer_list<int> ilist) : values{ilist}
76 {}
77 #else
78 fwd_iterable_custom(int v1, int v2, int v3) {
79 values.push_back(v1);
80 values.push_back(v2);
81 values.push_back(v3);
82 }
83 #endif
84 private:
85 std::vector<int> values;
86 };
87
88 BOOST_AUTO_TEST_CASE( test_forward_iterable_concept )
89 {
90 {
91 typedef std::vector<int> type;
92 BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_size<type>::value, "has_member_size failed");
93 BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_begin<type>::value, "has_member_begin failed");
94 BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_end<type>::value, "has_member_end failed");
95 BOOST_CHECK_MESSAGE(utf::is_forward_iterable< type >::value, "is_forward_iterable failed");
96 BOOST_CHECK_MESSAGE(utf::is_container_forward_iterable< type >::value, "is_container_forward_iterable failed");
97 }
98
99 {
100 // should also work for references, but from is_forward_iterable
101 typedef std::vector<int>& type;
102 BOOST_CHECK_MESSAGE(utf::is_forward_iterable< type >::value, "is_forward_iterable failed");
103 BOOST_CHECK_MESSAGE(utf::is_container_forward_iterable< type >::value, "is_container_forward_iterable failed");
104 }
105
106
107 {
108 typedef std::list<int> type;
109 BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_size<type>::value, "has_member_size failed");
110 BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_begin<type>::value, "has_member_begin failed");
111 BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_end<type>::value, "has_member_end failed");
112 BOOST_CHECK_MESSAGE(utf::is_forward_iterable< type >::value, "is_forward_iterable failed");
113 BOOST_CHECK_MESSAGE(utf::is_container_forward_iterable< type >::value, "is_container_forward_iterable failed");
114 }
115
116 {
117 typedef std::map<int, int> type;
118 BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_size<type>::value, "has_member_size failed");
119 BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_begin<type>::value, "has_member_begin failed");
120 BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_end<type>::value, "has_member_end failed");
121 BOOST_CHECK_MESSAGE(utf::is_forward_iterable< type >::value, "is_forward_iterable failed");
122 BOOST_CHECK_MESSAGE(utf::is_container_forward_iterable< type >::value, "is_container_forward_iterable failed");
123 }
124
125 {
126 typedef std::set<int> type;
127 BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_size<type>::value, "has_member_size failed");
128 BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_begin<type>::value, "has_member_begin failed");
129 BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_end<type>::value, "has_member_end failed");
130 BOOST_CHECK_MESSAGE(utf::is_forward_iterable< type >::value, "is_forward_iterable failed");
131 BOOST_CHECK_MESSAGE(utf::is_container_forward_iterable< type >::value, "is_container_forward_iterable failed");
132 }
133
134
135 {
136 typedef float type;
137 BOOST_CHECK_MESSAGE(!utf::ut_detail::has_member_size<type>::value, "has_member_size failed");
138 BOOST_CHECK_MESSAGE(!utf::ut_detail::has_member_begin<type>::value, "has_member_begin failed");
139 BOOST_CHECK_MESSAGE(!utf::is_forward_iterable< type >::value, "is_forward_iterable failed");
140 BOOST_CHECK_MESSAGE(!utf::is_container_forward_iterable< type >::value, "is_container_forward_iterable failed");
141 }
142
143 {
144 typedef not_fwd_iterable_1 type;
145 BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_size<type>::value, "has_member_size failed");
146 BOOST_CHECK_MESSAGE(!utf::ut_detail::has_member_begin<type>::value, "has_member_begin failed");
147 BOOST_CHECK_MESSAGE(!utf::ut_detail::has_member_end<type>::value, "has_member_end failed");
148 BOOST_CHECK_MESSAGE(!utf::is_forward_iterable< type >::value, "is_forward_iterable failed");
149 BOOST_CHECK_MESSAGE(!utf::is_container_forward_iterable< type >::value, "is_container_forward_iterable failed");
150 }
151
152
153
154 {
155 typedef not_fwd_iterable_2 type;
156 BOOST_CHECK_MESSAGE(!utf::ut_detail::has_member_size<type>::value, "has_member_size failed");
157 BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_begin<type>::value, "has_member_begin failed");
158 BOOST_CHECK_MESSAGE(!utf::ut_detail::has_member_end<type>::value, "has_member_end failed");
159 BOOST_CHECK_MESSAGE(!utf::is_forward_iterable< type >::value, "is_forward_iterable failed");
160 BOOST_CHECK_MESSAGE(!utf::is_container_forward_iterable< type >::value, "is_container_forward_iterable failed");
161 }
162
163 {
164 typedef not_fwd_iterable_3 type;
165 BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_size<type>::value, "has_member_size failed");
166 BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_begin<type>::value, "has_member_begin failed");
167 BOOST_CHECK_MESSAGE(!utf::ut_detail::has_member_end<type>::value, "has_member_end failed");
168 BOOST_CHECK_MESSAGE(!utf::is_forward_iterable< type >::value, "is_forward_iterable failed");
169 BOOST_CHECK_MESSAGE(!utf::is_container_forward_iterable< type >::value, "is_container_forward_iterable failed");
170 }
171
172 {
173 typedef fwd_iterable_4 type;
174 BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_size<type>::value, "has_member_size failed");
175 BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_begin<type>::value, "has_member_begin failed");
176 BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_end<type>::value, "has_member_end failed");
177 BOOST_CHECK_MESSAGE(utf::is_forward_iterable< type >::value, "is_forward_iterable failed");
178 BOOST_CHECK_MESSAGE(!utf::is_container_forward_iterable< type >::value, "is_container_forward_iterable failed");
179 }
180
181 {
182 // for this one we should be able to get the size
183 typedef fwd_iterable_custom type;
184 BOOST_CHECK_MESSAGE(!utf::ut_detail::has_member_size<type>::value, "has_member_size failed");
185 BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_begin<type>::value, "has_member_begin failed");
186 BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_end<type>::value, "has_member_end failed");
187 BOOST_CHECK_MESSAGE(utf::is_forward_iterable< type >::value, "is_forward_iterable failed");
188 BOOST_CHECK_MESSAGE(!utf::is_container_forward_iterable< type >::value, "is_container_forward_iterable failed");
189
190 #ifdef MY_TEST_HAS_INIT_LIST
191 fwd_iterable_custom a{3,4,5};
192 #else
193 fwd_iterable_custom a(3,4,5);
194 #endif
195 BOOST_TEST( utf::bt_iterator_traits<fwd_iterable_custom>::size(a) == 3 );
196 }
197 {
198 typedef char type;
199 BOOST_CHECK_MESSAGE(!utf::ut_detail::has_member_size<type>::value, "has_member_size failed");
200 BOOST_CHECK_MESSAGE(!utf::ut_detail::has_member_begin<type>::value, "has_member_begin failed");
201 BOOST_CHECK_MESSAGE(!utf::ut_detail::has_member_end<type>::value, "has_member_end failed");
202 BOOST_CHECK_MESSAGE(!utf::is_forward_iterable< type >::value, "is_forward_iterable failed");
203 BOOST_CHECK_MESSAGE(!utf::is_container_forward_iterable< type >::value, "is_container_forward_iterable failed");
204 }
205
206 {
207 // C-tables are in the forward_iterable concept, but are not containers
208 typedef int type[10];
209 BOOST_CHECK_MESSAGE(!utf::ut_detail::has_member_size<type>::value, "has_member_size failed");
210 BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_begin<type>::value, "has_member_begin failed");
211 BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_end<type>::value, "has_member_end failed");
212 BOOST_CHECK_MESSAGE(utf::is_forward_iterable< type >::value, "is_forward_iterable failed");
213 BOOST_CHECK_MESSAGE(!utf::is_container_forward_iterable< type >::value, "is_container_forward_iterable failed");
214 }
215
216 {
217 // basic_cstring should be forward iterable and container
218 typedef boost::unit_test::basic_cstring<char> type;
219 BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_size<type>::value, "has_member_size failed");
220 BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_begin<type>::value, "has_member_begin failed");
221 BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_end<type>::value, "has_member_end failed");
222 BOOST_CHECK_MESSAGE(utf::is_forward_iterable< type >::value, "is_forward_iterable failed");
223 BOOST_CHECK_MESSAGE(utf::is_container_forward_iterable< type >::value, "is_container_forward_iterable failed");
224
225 typedef boost::unit_test::basic_cstring<const char> type2;
226 BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_size<type2>::value, "has_member_size failed");
227 BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_begin<type2>::value, "has_member_begin failed");
228 BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_end<type2>::value, "has_member_end failed");
229 BOOST_CHECK_MESSAGE(utf::is_forward_iterable< type2 >::value, "is_forward_iterable failed");
230 BOOST_CHECK_MESSAGE(utf::is_container_forward_iterable< type2 >::value, "is_container_forward_iterable failed");
231 }
232 }
233
234
235 //is_container_forward_iterable_impl
236 #endif
237
238 BOOST_AUTO_TEST_CASE( test_basic_value_expression_construction )
239 {
240 using namespace boost::test_tools;
241
242 {
243 predicate_result const& res = EXPR_TYPE( 1 ).evaluate();
244 BOOST_TEST( res );
245 BOOST_TEST( res.message().is_empty() );
246 }
247
248 {
249 predicate_result const& res = EXPR_TYPE( 0 ).evaluate();
250 BOOST_TEST( !res );
251 BOOST_TEST( res.message() == " ['0' evaluates to false]" );
252 }
253
254 {
255 predicate_result const& res = EXPR_TYPE( true ).evaluate();
256 BOOST_TEST( res );
257 BOOST_TEST( res.message().is_empty() );
258 }
259
260 {
261 predicate_result const& res = EXPR_TYPE( 1.5 ).evaluate();
262 BOOST_TEST( res );
263 }
264
265 {
266 predicate_result const& res = EXPR_TYPE( "abc" ).evaluate();
267 BOOST_TEST( res );
268 }
269
270 {
271 predicate_result const& res = EXPR_TYPE( 1>2 ).evaluate();
272 BOOST_TEST( !res );
273 BOOST_TEST( res.message() == " [1 <= 2]" );
274 }
275
276 }
277
278 //____________________________________________________________________________//
279
280 BOOST_AUTO_TEST_CASE( test_comparison_expression )
281 {
282 using namespace boost::test_tools;
283
284 {
285 predicate_result const& res = EXPR_TYPE( 1>2 ).evaluate();
286 BOOST_TEST( !res );
287 BOOST_TEST( res.message() == " [1 <= 2]" );
288 }
289
290 {
291 predicate_result const& res = EXPR_TYPE( 100 < 50 ).evaluate();
292 BOOST_TEST( !res );
293 BOOST_TEST( res.message() == " [100 >= 50]" );
294 }
295
296 {
297 predicate_result const& res = EXPR_TYPE( 5 <= 4 ).evaluate();
298 BOOST_TEST( !res );
299 BOOST_TEST( res.message() == " [5 > 4]" );
300 }
301
302 {
303 predicate_result const& res = EXPR_TYPE( 10>=20 ).evaluate();
304 BOOST_TEST( !res );
305 BOOST_TEST( res.message() == " [10 < 20]" );
306 }
307
308 {
309 int i = 10;
310 predicate_result const& res = EXPR_TYPE( i != 10 ).evaluate();
311 BOOST_TEST( !res );
312 BOOST_TEST( res.message() == " [10 == 10]" );
313 }
314
315 {
316 int i = 5;
317 predicate_result const& res = EXPR_TYPE( i == 3 ).evaluate();
318 BOOST_TEST( !res );
319 BOOST_TEST( res.message() == " [5 != 3]" );
320 }
321 }
322
323 //____________________________________________________________________________//
324
325 BOOST_AUTO_TEST_CASE( test_arithmetic_ops )
326 {
327 using namespace boost::test_tools;
328
329 {
330 int i = 3;
331 int j = 5;
332 predicate_result const& res = EXPR_TYPE( i+j !=8 ).evaluate();
333 BOOST_TEST( !res );
334 BOOST_TEST( res.message() == " [3 + 5 == 8]" );
335 }
336
337 {
338 int i = 3;
339 int j = 5;
340 predicate_result const& res = EXPR_TYPE( 2*i-j > 1 ).evaluate();
341 BOOST_TEST( !res );
342 BOOST_TEST( res.message() == " [2 * 3 - 5 <= 1]" );
343 }
344
345 {
346 int j = 5;
347 predicate_result const& res = EXPR_TYPE( 2<<j < 30 ).evaluate();
348 BOOST_TEST( !res );
349 BOOST_TEST( res.message() == " [2 << 5 >= 30]" );
350 }
351
352 {
353 int i = 2;
354 int j = 5;
355 predicate_result const& res = EXPR_TYPE( i&j ).evaluate();
356 BOOST_TEST( !res );
357 BOOST_TEST( res.message() == " [2 & 5]" );
358 }
359
360 {
361 int i = 3;
362 int j = 5;
363 predicate_result const& res = EXPR_TYPE( i^j^6 ).evaluate();
364 BOOST_TEST( !res );
365 BOOST_TEST( res.message() == " [3 ^ 5 ^ 6]" );
366 }
367
368 // do not support
369 // EXPR_TYPE( 99/2 == 48 || 101/2 > 50 );
370 // EXPR_TYPE( a ? 100 < 50 : 25*2 == 50 );
371 // EXPR_TYPE( true,false );
372 }
373
374 //____________________________________________________________________________//
375
376 struct Testee {
377 static int s_copy_counter;
378
379 Testee() : m_value( false ) {}
380 Testee( Testee const& ) : m_value(false) { s_copy_counter++; }
381 Testee( Testee&& ) : m_value(false) {}
382 Testee( Testee const&& ) : m_value(false) {}
383
384 bool foo() { return m_value; }
385 operator bool() const { return m_value; }
386
387 friend std::ostream& operator<<( std::ostream& ostr, Testee const& ) { return ostr << "Testee"; }
388
389 bool m_value;
390 };
391
392 int Testee::s_copy_counter = 0;
393
394 Testee get_obj() { return Testee(); }
395 Testee const get_const_obj() { return Testee(); }
396
397 class NC : boost::noncopyable {
398 public:
399 NC() {}
400
401 bool operator==(NC const&) const { return false; }
402 friend std::ostream& operator<<(std::ostream& ostr, NC const&)
403 {
404 return ostr << "NC";
405 }
406 };
407
408 BOOST_AUTO_TEST_CASE( test_objects )
409 {
410 using namespace boost::test_tools;
411
412 int expected_copy_count = 0;
413
414 {
415 Testee obj;
416 Testee::s_copy_counter = 0;
417
418 predicate_result const& res = EXPR_TYPE( obj ).evaluate();
419 BOOST_TEST( !res );
420 BOOST_TEST( res.message() == " ['Testee' evaluates to false]" );
421 BOOST_TEST( Testee::s_copy_counter == expected_copy_count );
422 }
423
424 {
425 Testee const obj;
426 Testee::s_copy_counter = 0;
427
428 predicate_result const& res = EXPR_TYPE( obj ).evaluate();
429 BOOST_TEST( !res );
430 BOOST_TEST( res.message() == " ['Testee' evaluates to false]" );
431 BOOST_TEST( Testee::s_copy_counter == expected_copy_count );
432 }
433
434 {
435 Testee::s_copy_counter = 0;
436
437 predicate_result const& res = EXPR_TYPE( get_obj() ).evaluate();
438 BOOST_TEST( !res );
439 BOOST_TEST( res.message() == " ['Testee' evaluates to false]" );
440 BOOST_TEST( Testee::s_copy_counter == expected_copy_count );
441 }
442
443 {
444 Testee::s_copy_counter = 0;
445
446 predicate_result const& res = EXPR_TYPE( get_const_obj() ).evaluate();
447 BOOST_TEST( !res );
448 BOOST_TEST( res.message() == " ['Testee' evaluates to false]" );
449 BOOST_TEST( Testee::s_copy_counter == expected_copy_count );
450 }
451
452 {
453 Testee::s_copy_counter = 0;
454
455 Testee t1;
456 Testee t2;
457
458 predicate_result const& res = EXPR_TYPE( t1 != t2 ).evaluate();
459 BOOST_TEST( !res );
460 BOOST_TEST( res.message() == " [Testee == Testee]" );
461 BOOST_TEST( Testee::s_copy_counter == 0 );
462 }
463
464 {
465 NC nc1;
466 NC nc2;
467
468 predicate_result const& res = EXPR_TYPE( nc1 == nc2 ).evaluate();
469 BOOST_TEST( !res );
470 BOOST_TEST( res.message() == " [NC != NC]" );
471 }
472 }
473
474 //____________________________________________________________________________//
475
476 BOOST_AUTO_TEST_CASE( test_pointers )
477 {
478 using namespace boost::test_tools;
479
480 {
481 Testee* ptr = 0;
482
483 predicate_result const& res = EXPR_TYPE( ptr ).evaluate();
484 BOOST_TEST( !res );
485 }
486
487 {
488 Testee obj1;
489 Testee obj2;
490
491 predicate_result const& res = EXPR_TYPE( &obj1 == &obj2 ).evaluate();
492 BOOST_TEST( !res );
493 }
494
495 {
496 Testee obj;
497 Testee* ptr =&obj;
498
499 predicate_result const& res = EXPR_TYPE( *ptr ).evaluate();
500 BOOST_TEST( !res );
501 BOOST_TEST( res.message() == " ['Testee' evaluates to false]" );
502 }
503
504 {
505 Testee obj;
506 Testee* ptr =&obj;
507 bool Testee::* mem_ptr =&Testee::m_value;
508
509 predicate_result const& res = EXPR_TYPE( ptr->*mem_ptr ).evaluate();
510 BOOST_TEST( !res );
511 }
512
513 // do not support
514 // Testee obj;
515 // bool Testee::* mem_ptr =&Testee::m_value;
516 // EXPR_TYPE( obj.*mem_ptr );
517 }
518
519 //____________________________________________________________________________//
520
521 BOOST_AUTO_TEST_CASE( test_mutating_ops )
522 {
523 using namespace boost::test_tools;
524
525 {
526 int j = 5;
527
528 predicate_result const& res = EXPR_TYPE( j = 0 ).evaluate();
529 BOOST_TEST( !res );
530 BOOST_TEST( res.message() == " ['0' evaluates to false]" );
531 BOOST_TEST( j == 0 );
532 }
533
534 {
535 int j = 5;
536
537 predicate_result const& res = EXPR_TYPE( j -= 5 ).evaluate();
538 BOOST_TEST( !res );
539 BOOST_TEST( res.message() == " ['0' evaluates to false]" );
540 BOOST_TEST( j == 0 );
541 }
542
543 {
544 int j = 5;
545
546 predicate_result const& res = EXPR_TYPE( j *= 0 ).evaluate();
547 BOOST_TEST( !res );
548 BOOST_TEST( res.message() == " ['0' evaluates to false]" );
549 BOOST_TEST( j == 0 );
550 }
551
552 {
553 int j = 5;
554
555 predicate_result const& res = EXPR_TYPE( j /= 10 ).evaluate();
556 BOOST_TEST( !res );
557 BOOST_TEST( res.message() == " ['0' evaluates to false]" );
558 BOOST_TEST( j == 0 );
559 }
560
561 {
562 int j = 4;
563
564 predicate_result const& res = EXPR_TYPE( j %= 2 ).evaluate();
565 BOOST_TEST( !res );
566 BOOST_TEST( res.message() == " ['0' evaluates to false]" );
567 BOOST_TEST( j == 0 );
568 }
569
570 {
571 int j = 5;
572
573 predicate_result const& res = EXPR_TYPE( j ^= j ).evaluate();
574 BOOST_TEST( !res );
575 BOOST_TEST( res.message() == " ['0' evaluates to false]" );
576 BOOST_TEST( j == 0 );
577 }
578 }
579
580 BOOST_AUTO_TEST_CASE( test_specialized_comparator_string )
581 {
582 using namespace boost::test_tools;
583
584 {
585 std::string s("abc");
586
587 predicate_result const& res = EXPR_TYPE( s == "a" ).evaluate();
588 BOOST_TEST( !res );
589 BOOST_TEST( res.message() == " [abc != a]" );
590 BOOST_TEST( s == "abc" );
591 }
592
593 {
594 predicate_result const& res = EXPR_TYPE( std::string("abc") == "a" ).evaluate();
595 BOOST_TEST( !res );
596 BOOST_TEST( res.message() == " [abc != a]" );
597 }
598
599 {
600 predicate_result const& res = EXPR_TYPE( "abc" == std::string("a") ).evaluate();
601 BOOST_TEST( !res );
602 BOOST_TEST( res.message() == " [abc != a]" );
603 }
604
605 {
606 predicate_result const& res = EXPR_TYPE( std::string("abc") == std::string("a") ).evaluate();
607 BOOST_TEST( !res );
608 BOOST_TEST( res.message() == " [abc != a]" );
609 }
610 }
611
612 BOOST_AUTO_TEST_CASE( test_comparison_with_arrays )
613 {
614 using namespace boost::test_tools;
615
616 {
617 char c_string_array[] = "abc";
618
619 predicate_result const& res = EXPR_TYPE( c_string_array == "a" ).evaluate();
620 BOOST_TEST( !res );
621 BOOST_TEST( res.message() == " [abc != a]" );
622 BOOST_TEST( c_string_array == "abc" );
623 }
624
625 {
626 char c_string_array[] = "abc";
627
628 predicate_result const& res = EXPR_TYPE( "a" == c_string_array ).evaluate();
629 BOOST_TEST( !res );
630 BOOST_TEST( res.message() == " [a != abc]" );
631 BOOST_TEST( "abc" == c_string_array );
632 }
633
634 {
635 char const c_string_array[] = "abc";
636
637 predicate_result const& res = EXPR_TYPE( c_string_array == "a" ).evaluate();
638 BOOST_TEST( !res );
639 BOOST_TEST( res.message() == " [abc != a]" );
640 BOOST_TEST( c_string_array == "abc" );
641 }
642
643 {
644 char const c_string_array[] = "abc";
645
646 predicate_result const& res = EXPR_TYPE( "a" == c_string_array ).evaluate();
647 BOOST_TEST( !res );
648 BOOST_TEST( res.message() == " [a != abc]" );
649 BOOST_TEST( "abc" == c_string_array );
650 }
651
652
653 {
654 long int c_long_array[] = {3,4,7};
655 std::vector<long int> v_long_array(c_long_array, c_long_array + sizeof(c_long_array)/sizeof(c_long_array[0]));
656 std::swap(v_long_array[1], v_long_array[2]);
657
658 predicate_result const& res = EXPR_TYPE( c_long_array == v_long_array ).evaluate();
659 BOOST_TEST( !res );
660 BOOST_TEST( res.message() == ": \n - mismatch at position 1: [4 == 7] is false\n - mismatch at position 2: [7 == 4] is false" );
661
662 std::swap(v_long_array[1], v_long_array[2]);
663 BOOST_TEST( c_long_array == v_long_array );
664 }
665
666 {
667 long int c_long_array[] = {3,4,7};
668
669 std::vector<long int> v_long_array(c_long_array, c_long_array + sizeof(c_long_array)/sizeof(c_long_array[0]));
670 std::swap(v_long_array[1], v_long_array[2]);
671
672 predicate_result const& res = EXPR_TYPE( v_long_array == c_long_array ).evaluate();
673 BOOST_TEST( !res );
674 BOOST_TEST( res.message() == ": \n - mismatch at position 1: [7 == 4] is false\n - mismatch at position 2: [4 == 7] is false" );
675 std::swap(v_long_array[1], v_long_array[2]);
676 BOOST_TEST( c_long_array == v_long_array );
677 }
678
679 {
680 long int const c_long_array[] = {3,4,7};
681 std::vector<long int> v_long_array(c_long_array, c_long_array + sizeof(c_long_array)/sizeof(c_long_array[0]));
682 std::swap(v_long_array[1], v_long_array[2]);
683
684 predicate_result const& res = EXPR_TYPE( c_long_array == v_long_array ).evaluate();
685 BOOST_TEST( !res );
686 BOOST_TEST( res.message() == ": \n - mismatch at position 1: [4 == 7] is false\n - mismatch at position 2: [7 == 4] is false" );
687
688 std::swap(v_long_array[1], v_long_array[2]);
689 BOOST_TEST( c_long_array == v_long_array );
690 }
691
692 {
693 long int const c_long_array[] = {3,4,7};
694
695 std::vector<long int> v_long_array(c_long_array, c_long_array + sizeof(c_long_array)/sizeof(c_long_array[0]));
696 std::swap(v_long_array[1], v_long_array[2]);
697
698 predicate_result const& res = EXPR_TYPE( v_long_array == c_long_array ).evaluate();
699 BOOST_TEST( !res );
700 BOOST_TEST( res.message() == ": \n - mismatch at position 1: [7 == 4] is false\n - mismatch at position 2: [4 == 7] is false" );
701 std::swap(v_long_array[1], v_long_array[2]);
702 BOOST_TEST( c_long_array == v_long_array );
703 }
704
705 }
706
707 // EOF