|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r74879 - trunk/libs/test/test
From: gennadiy.rozental_at_[hidden]
Date: 2011-10-10 04:36:54
Author: rogeeff
Date: 2011-10-10 04:36:49 EDT (Mon, 10 Oct 2011)
New Revision: 74879
URL: http://svn.boost.org/trac/boost/changeset/74879
Log:
new test
Added:
trunk/libs/test/test/test_assertion_construction.cpp (contents, props changed)
Text files modified:
trunk/libs/test/test/Jamfile.v2 | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
Modified: trunk/libs/test/test/Jamfile.v2
==============================================================================
--- trunk/libs/test/test/Jamfile.v2 (original)
+++ trunk/libs/test/test/Jamfile.v2 2011-10-10 04:36:49 EDT (Mon, 10 Oct 2011)
@@ -83,6 +83,7 @@
[ test-btl-lib run : boost_check_equal_str : boost_unit_test_framework ]
[ test-btl-lib run : test_tree_management_test : boost_unit_test_framework ]
[ test-btl-lib run : run_by_name_label_test : boost_unit_test_framework/<link>static ]
+ [ test-btl-lib run : test_assertion_construction : boost_unit_test_framework/<link>static ]
;
test-suite "multithreaded_test"
Added: trunk/libs/test/test/test_assertion_construction.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/test/test/test_assertion_construction.cpp 2011-10-10 04:36:49 EDT (Mon, 10 Oct 2011)
@@ -0,0 +1,370 @@
+// (C) Copyright Gennadiy Rozental 2003-2010.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org/libs/test for the library home page.
+//
+// File : $RCSfile$
+//
+// Version : $Revision: 62023 $
+//
+// Description : unit test for new assertion construction based on input expression
+// ***************************************************************************
+
+// Boost.Test
+#define BOOST_TEST_MODULE Boost.Test assertion consruction test
+#include <boost/test/unit_test.hpp>
+#include <boost/test/tools/assertion.hpp>
+
+//____________________________________________________________________________//
+
+BOOST_AUTO_TEST_CASE( test_basic_value_expression_construction )
+{
+ using namespace boost::test_tools;
+ assertion::seed seed;
+
+ {
+ assertion::expression const& E = seed->*1;
+ predicate_result const& res = E.evaluate();
+ BOOST_CHECK( res );
+ BOOST_CHECK( res.message().is_empty() );
+ }
+
+ {
+ assertion::expression const& E = seed->*0;
+ predicate_result const& res = E.evaluate();
+ BOOST_CHECK( !res );
+ BOOST_CHECK_EQUAL( res.message(), "(bool)0 is false" );
+ }
+
+ {
+ assertion::expression const& E = seed->*true;
+ predicate_result const& res = E.evaluate();
+ BOOST_CHECK( res );
+ BOOST_CHECK( res.message().is_empty() );
+ }
+
+ {
+ assertion::expression const& E = seed->*1.5;
+ predicate_result const& res = E.evaluate();
+ BOOST_CHECK( res );
+ }
+
+ {
+ assertion::expression const& E = seed->* "abc";
+ predicate_result const& res = E.evaluate();
+ BOOST_CHECK( res );
+ }
+
+ {
+ assertion::expression const& E = seed->* 1>2;
+ predicate_result const& res = E.evaluate();
+ BOOST_CHECK( !res );
+ BOOST_CHECK_EQUAL( res.message(), "1<=2" );
+ }
+
+}
+
+//____________________________________________________________________________//
+
+BOOST_AUTO_TEST_CASE( test_comparison_expression )
+{
+ using namespace boost::test_tools;
+ assertion::seed seed;
+
+ {
+ assertion::expression const& E = seed->* 1>2;
+ predicate_result const& res = E.evaluate();
+ BOOST_CHECK( !res );
+ BOOST_CHECK_EQUAL( res.message(), "1<=2" );
+ }
+
+ {
+ assertion::expression const& E = seed->* 100 < 50;
+ predicate_result const& res = E.evaluate();
+ BOOST_CHECK( !res );
+ BOOST_CHECK_EQUAL( res.message(), "100>=50" );
+ }
+
+ {
+ assertion::expression const& E = seed->* 5<=4;
+ predicate_result const& res = E.evaluate();
+ BOOST_CHECK( !res );
+ BOOST_CHECK_EQUAL( res.message(), "5>4" );
+ }
+
+ {
+ assertion::expression const& E = seed->* 10>=20;
+ predicate_result const& res = E.evaluate();
+ BOOST_CHECK( !res );
+ BOOST_CHECK_EQUAL( res.message(), "10<20" );
+ }
+
+ {
+ int i = 10;
+ assertion::expression const& E = seed->* i != 10;
+ predicate_result const& res = E.evaluate();
+ BOOST_CHECK( !res );
+ BOOST_CHECK_EQUAL( res.message(), "10==10" );
+ }
+
+ {
+ int i = 5;
+ assertion::expression const& E = seed->* i == 3;
+ predicate_result const& res = E.evaluate();
+ BOOST_CHECK( !res );
+ BOOST_CHECK_EQUAL( res.message(), "5!=3" );
+ }
+}
+
+//____________________________________________________________________________//
+
+BOOST_AUTO_TEST_CASE( test_arithmetic_ops )
+{
+ using namespace boost::test_tools;
+ assertion::seed seed;
+
+ {
+ int i = 3;
+ int j = 5;
+ assertion::expression const& E = seed->* i+j !=8;
+ predicate_result const& res = E.evaluate();
+ BOOST_CHECK( !res );
+ BOOST_CHECK_EQUAL( res.message(), "3+5==8" );
+ }
+
+ {
+ int i = 3;
+ int j = 5;
+ assertion::expression const& E = seed->* 2*i-j > 1;
+ predicate_result const& res = E.evaluate();
+ BOOST_CHECK( !res );
+ BOOST_CHECK_EQUAL( res.message(), "2*3-5<=1" );
+ }
+
+ {
+ int j = 5;
+ assertion::expression const& E = seed->* 2<<j < 30;
+ predicate_result const& res = E.evaluate();
+ BOOST_CHECK( !res );
+ BOOST_CHECK_EQUAL( res.message(), "2<<5>=30" );
+ }
+
+ {
+ int i = 2;
+ int j = 5;
+ assertion::expression const& E = seed->* i&j;
+ predicate_result const& res = E.evaluate();
+ BOOST_CHECK( !res );
+ BOOST_CHECK_EQUAL( res.message(), "2&5" );
+ }
+
+ {
+ int i = 3;
+ int j = 5;
+ assertion::expression const& E = seed->* i^j^6;
+ predicate_result const& res = E.evaluate();
+ BOOST_CHECK( !res );
+ BOOST_CHECK_EQUAL( res.message(), "3^5^6" );
+ }
+
+ // do not support
+ // assertion::expression const& E = seed->*99/2 == 48 || 101/2 > 50;
+ // assertion::expression const& E = seed->* a ? 100 < 50 : 25*2 == 50;
+ // assertion::expression const& E = seed->* true,false;
+
+//____________________________________________________________________________//
+
+struct Testee {
+ static int s_copy_counter;
+
+ Testee() : m_value( false ) {}
+ Testee( Testee const& ) : m_value(false) { s_copy_counter++; }
+ Testee( Testee&& ) : m_value(false) {}
+
+ bool foo() { return m_value; }
+ operator bool() const { return m_value; }
+
+ friend std::ostream& operator<<( std::ostream& ostr, Testee const& ) { return ostr << "Testee"; }
+
+ bool m_value;
+};
+
+int Testee::s_copy_counter = 0;
+
+Testee get_obj() { return std::move( Testee() ); }
+
+Testee const get_const_obj() { return std::move( Testee() ); }
+
+BOOST_AUTO_TEST_CASE( test_objects )
+{
+ using namespace boost::test_tools;
+ assertion::seed seed;
+
+ {
+ Testee obj;
+ Testee::s_copy_counter = 0;
+
+ assertion::expression const& E = seed->* obj;
+ predicate_result const& res = E.evaluate();
+ BOOST_CHECK( !res );
+ BOOST_CHECK_EQUAL( res.message(), "(bool)Testee is false" );
+ BOOST_CHECK_EQUAL( Testee::s_copy_counter, 0 );
+ }
+
+ {
+ Testee const obj;
+ Testee::s_copy_counter = 0;
+
+ assertion::expression const& E = seed->* obj;
+ predicate_result const& res = E.evaluate();
+ BOOST_CHECK( !res );
+ BOOST_CHECK_EQUAL( res.message(), "(bool)Testee is false" );
+ BOOST_CHECK_EQUAL( Testee::s_copy_counter, 0 );
+ }
+
+ {
+ Testee::s_copy_counter = 0;
+
+ assertion::expression const& E = seed->* get_obj();
+ predicate_result const& res = E.evaluate();
+ BOOST_CHECK( !res );
+ BOOST_CHECK_EQUAL( res.message(), "(bool)Testee is false" );
+ BOOST_CHECK_EQUAL( Testee::s_copy_counter, 1 ); // !! ??
+ }
+
+ {
+ Testee::s_copy_counter = 0;
+
+ assertion::expression const& E = seed->* get_const_obj();
+ predicate_result const& res = E.evaluate();
+ BOOST_CHECK( !res );
+ BOOST_CHECK_EQUAL( res.message(), "(bool)Testee is false" );
+ BOOST_CHECK_EQUAL( Testee::s_copy_counter, 1 ); // !! ??
+ }
+}
+
+//____________________________________________________________________________//
+
+BOOST_AUTO_TEST_CASE( test_pointers )
+{
+ using namespace boost::test_tools;
+ assertion::seed seed;
+
+ {
+ Testee* ptr = 0;
+
+ assertion::expression const& E = seed->* ptr;
+ predicate_result const& res = E.evaluate();
+ BOOST_CHECK( !res );
+ BOOST_CHECK_EQUAL( res.message(), "(bool)00000000 is false" );
+ }
+
+ {
+ Testee obj1;
+ Testee obj2;
+
+ assertion::expression const& E = seed->* &obj1 == &obj2;
+ predicate_result const& res = E.evaluate();
+ BOOST_CHECK( !res );
+ }
+
+ {
+ Testee obj;
+ Testee* ptr =&obj;
+
+ assertion::expression const& E = seed->* *ptr;
+ predicate_result const& res = E.evaluate();
+ BOOST_CHECK( !res );
+ BOOST_CHECK_EQUAL( res.message(), "(bool)Testee is false" );
+ }
+
+ {
+ Testee obj;
+ Testee* ptr =&obj;
+ bool Testee::* mem_ptr =&Testee::m_value;
+
+ assertion::expression const& E = seed->* ptr->*mem_ptr;
+ predicate_result const& res = E.evaluate();
+ BOOST_CHECK( !res );
+ }
+
+ // do not support
+ // Testee obj;
+ // bool Testee::* mem_ptr =&Testee::m_value;
+ // assertion::expression const& E = seed->* obj.*mem_ptr;
+}
+
+//____________________________________________________________________________//
+
+BOOST_AUTO_TEST_CASE( test_mutating_ops )
+{
+ using namespace boost::test_tools;
+ assertion::seed seed;
+
+ {
+ int j = 5;
+
+ assertion::expression const& E = seed->* j = 0;
+ predicate_result const& res = E.evaluate();
+ BOOST_CHECK( !res );
+ BOOST_CHECK_EQUAL( res.message(), "(bool)0 is false" );
+ BOOST_CHECK_EQUAL( j, 0 );
+ }
+
+ {
+ int j = 5;
+
+ assertion::expression const& E = seed->* j -= 5;
+ predicate_result const& res = E.evaluate();
+ BOOST_CHECK( !res );
+ BOOST_CHECK_EQUAL( res.message(), "(bool)0 is false" );
+ BOOST_CHECK_EQUAL( j, 0 );
+ }
+
+ {
+ int j = 5;
+
+ assertion::expression const& E = seed->* j *= 0;
+ predicate_result const& res = E.evaluate();
+ BOOST_CHECK( !res );
+ BOOST_CHECK_EQUAL( res.message(), "(bool)0 is false" );
+ BOOST_CHECK_EQUAL( j, 0 );
+ }
+
+ {
+ int j = 5;
+
+ assertion::expression const& E = seed->* j /= 10;
+ predicate_result const& res = E.evaluate();
+ BOOST_CHECK( !res );
+ BOOST_CHECK_EQUAL( res.message(), "(bool)0 is false" );
+ BOOST_CHECK_EQUAL( j, 0 );
+ }
+
+ {
+ int j = 4;
+
+ assertion::expression const& E = seed->* j %= 2;
+ predicate_result const& res = E.evaluate();
+ BOOST_CHECK( !res );
+ BOOST_CHECK_EQUAL( res.message(), "(bool)0 is false" );
+ BOOST_CHECK_EQUAL( j, 0 );
+ }
+
+ {
+ int j = 5;
+
+ assertion::expression const& E = seed->* j ^= j;
+ predicate_result const& res = E.evaluate();
+ BOOST_CHECK( !res );
+ BOOST_CHECK_EQUAL( res.message(), "(bool)0 is false" );
+ BOOST_CHECK_EQUAL( j, 0 );
+ }
+}
+
+//____________________________________________________________________________//
+
+// EOF
+
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk