|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r65577 - sandbox/opaque/libs/opaque/test
From: vicente.botet_at_[hidden]
Date: 2010-09-24 13:27:02
Author: viboes
Date: 2010-09-24 13:27:01 EDT (Fri, 24 Sep 2010)
New Revision: 65577
URL: http://svn.boost.org/trac/boost/changeset/65577
Log:
Opaque: Start with new_type tests
Added:
sandbox/opaque/libs/opaque/test/new_type_test.cpp (contents, props changed)
Text files modified:
sandbox/opaque/libs/opaque/test/Jamfile.v2 | 13 +++++++++++++
1 files changed, 13 insertions(+), 0 deletions(-)
Modified: sandbox/opaque/libs/opaque/test/Jamfile.v2
==============================================================================
--- sandbox/opaque/libs/opaque/test/Jamfile.v2 (original)
+++ sandbox/opaque/libs/opaque/test/Jamfile.v2 2010-09-24 13:27:01 EDT (Fri, 24 Sep 2010)
@@ -25,8 +25,21 @@
# uncomment the line above if you build outside the Boost release
#<include>../../..
# <toolset>msvc:<asynch-exceptions>on
+ <define>BOOST_ENABLE_WARNINGS
+ <define>BOOST_RATIO_USES_MPL_ASSERT
+ <warnings>all
+ <toolset>gcc:<cxxflags>-Wextra
+ <toolset>gcc:<cxxflags>-Wno-long-long
+ <toolset>gcc-mingw-4.5.0:<cxxflags>-Wno-missing-field-initializers
+ <toolset>gcc-mingw-4.5.0:<cxxflags>-fdiagnostics-show-option
+ <toolset>msvc:<cxxflags>/wd4127
;
+ test-suite "new_type"
+ :
+ [ run new_type_test.cpp ]
+ ;
+
test-suite "opaque"
:
[ run test.cpp ]
Added: sandbox/opaque/libs/opaque/test/new_type_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/opaque/libs/opaque/test/new_type_test.cpp 2010-09-24 13:27:01 EDT (Fri, 24 Sep 2010)
@@ -0,0 +1,172 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 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/opaque for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/opaque/opaque.hpp>
+
+#include <boost/test/unit_test.hpp>
+
+using namespace boost;
+using namespace boost::unit_test;
+
+
+struct private_unsigned : boost::new_type<private_unsigned, unsigned
+ , opaque::equality_comparable1<private_unsigned
+ >
+ >
+{
+ typedef boost::new_type<private_unsigned, unsigned
+ , opaque::equality_comparable1<private_unsigned
+ >
+ > base_type;
+
+ private_unsigned(){}
+ explicit private_unsigned(unsigned v) : base_type(v) {}
+ template <typename W>
+ explicit private_unsigned(W w)
+ : base_type(w)
+ {}
+ private_unsigned(private_unsigned const& r)
+ : base_type(r.val_)
+ {}
+};
+
+struct private_unsigned2: boost::new_type<private_unsigned2, unsigned>
+{
+ typedef boost::new_type<private_unsigned2, unsigned> base_type;
+
+ private_unsigned2(){}
+ explicit private_unsigned2(unsigned v) : base_type(v) {}
+ template <typename W>
+ explicit private_unsigned2(W w)
+ : base_type(w)
+ {}
+ private_unsigned2(private_unsigned2 const& r)
+ : base_type(r.val_)
+ {}
+};
+
+void private_assign_test() {
+ private_unsigned a, a2;
+ private_unsigned2 b;
+
+ //~ a=b; // error
+ a=a2; // OK
+
+ unsigned short i;
+
+ i=new_type_static_cast<unsigned short>(a);
+ //~ i=a; // error
+
+ //~ a=i; // error
+}
+
+void private_eq_test() {
+ private_unsigned a(1), b(2), c(2);
+ BOOST_CHECK(b==c);
+ BOOST_CHECK((a==b)==false);
+}
+void private_neq_test() {
+ private_unsigned a(1), b(2), c(2);
+ BOOST_CHECK(a!=b);
+ BOOST_CHECK((b!=c)==false);
+}
+//~ void private_lt_test() {
+ //~ private_unsigned a(1), b(2), c(2);
+ //~ BOOST_CHECK(a<b);
+ //~ BOOST_CHECK((b<a)==false);
+ //~ BOOST_CHECK((b<c)==false);
+//~ }
+#if 0
+
+void private_gt_test() {
+ private_unsigned a(1), b(2), c(2);
+ BOOST_CHECK(b>a);
+ BOOST_CHECK((a>b)==false);
+ BOOST_CHECK((b>c)==false);
+}
+
+void private_le_test() {
+ private_unsigned a(1), b(2), c(2);
+ BOOST_CHECK(a<=b);
+ BOOST_CHECK((b<=a)==false);
+ BOOST_CHECK(b<=c);
+}
+void private_ge_test() {
+ private_unsigned a(1), b(2), c(2);
+ BOOST_CHECK(b>=a);
+ BOOST_CHECK((a>=b)==false);
+ BOOST_CHECK(b>=c);
+}
+
+void private_add_test() {
+ private_unsigned a(1), b(2), c(3),d(4);
+ BOOST_CHECK(a+b==c);
+ BOOST_CHECK(c==a+b);
+ BOOST_CHECK((a+b==d)==false);
+ BOOST_CHECK((d==a+b)==false);
+
+ private_unsigned2 x;
+ //~ a=a+x; // error
+
+ //~ unsigned u=3,v=0;
+ //~ BOOST_CHECK(a+b==3u);
+ //~ BOOST_CHECK(u==a+b);
+ //~ BOOST_CHECK(a+b==u);
+ //~ BOOST_CHECK((a+b==v)==false);
+ //~ BOOST_CHECK((v==a+b)==false);
+
+}
+
+void private_substract_test() {
+ private_unsigned a(1), b(2), c(3),d(4);
+ BOOST_CHECK(c-b==a);
+ BOOST_CHECK(a==c-b);
+ BOOST_CHECK((c-b==d)==false);
+ BOOST_CHECK((d==c-b)==false);
+
+ //~ unsigned u=1,v=0;
+ //~ BOOST_CHECK(c-b==1u);
+ //~ BOOST_CHECK(u==c-b);
+ //~ BOOST_CHECK(c-b==u);
+ //~ BOOST_CHECK((c-b==v)==false);
+ //~ BOOST_CHECK((v==c-b)==false);
+
+}
+
+test_suite* init_unit_test_suite(int, char*[])
+{
+ test_suite* test = BOOST_TEST_SUITE("private");
+
+
+ test->add(BOOST_TEST_CASE(&private_assign_test));
+ test->add(BOOST_TEST_CASE(&private_eq_test));
+ test->add(BOOST_TEST_CASE(&private_lt_test));
+ test->add(BOOST_TEST_CASE(&private_gt_test));
+ test->add(BOOST_TEST_CASE(&private_le_test));
+ test->add(BOOST_TEST_CASE(&private_ge_test));
+ test->add(BOOST_TEST_CASE(&private_add_test));
+ test->add(BOOST_TEST_CASE(&private_substract_test));
+
+ return test;
+}
+
+#endif
+
+test_suite* init_unit_test_suite(int, char*[])
+{
+ test_suite* test = BOOST_TEST_SUITE("new");
+
+
+ test->add(BOOST_TEST_CASE(&private_assign_test));
+ test->add(BOOST_TEST_CASE(&private_eq_test));
+ test->add(BOOST_TEST_CASE(&private_neq_test));
+
+ return test;
+}
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