Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r69494 - in sandbox/enums/libs/enums/test: . enum_set/cons
From: vicente.botet_at_[hidden]
Date: 2011-03-02 18:32:52


Author: viboes
Date: 2011-03-02 18:32:46 EST (Wed, 02 Mar 2011)
New Revision: 69494
URL: http://svn.boost.org/trac/boost/changeset/69494

Log:
Enums: Added test for enum_set constructor from c-str and std::string
Added:
   sandbox/enums/libs/enums/test/enum_set/cons/char_ptr_ctor.pass.cpp (contents, props changed)
   sandbox/enums/libs/enums/test/enum_set/cons/string_ctor.pass.cpp (contents, props changed)
Text files modified:
   sandbox/enums/libs/enums/test/Jamfile.v2 | 2 ++
   sandbox/enums/libs/enums/test/enum_set/cons/ull_ctor.pass.cpp | 1 +
   2 files changed, 3 insertions(+), 0 deletions(-)

Modified: sandbox/enums/libs/enums/test/Jamfile.v2
==============================================================================
--- sandbox/enums/libs/enums/test/Jamfile.v2 (original)
+++ sandbox/enums/libs/enums/test/Jamfile.v2 2011-03-02 18:32:46 EST (Wed, 02 Mar 2011)
@@ -75,5 +75,7 @@
         #[ run enum_set/types.pass.cpp : : : : enum_set__types__pass ]
         [ run enum_set/cons/default.pass.cpp : : : : enum_set__cons_default__pass ]
         [ run enum_set/cons/ull_ctor.pass.cpp : : : : enum_set__cons_ull_ctor__pass ]
+ #[ run enum_set/cons/char_ptr_ctor.pass.cpp : : : : enum_set__char_ptr_ull_ctor__pass ]
+ #[ run enum_set/cons/string_ctor.pass.cpp : : : : enum_set__cons_string_ctor__pass ]
   ;
   
\ No newline at end of file

Added: sandbox/enums/libs/enums/test/enum_set/cons/char_ptr_ctor.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/enums/libs/enums/test/enum_set/cons/char_ptr_ctor.pass.cpp 2011-03-02 18:32:46 EST (Wed, 02 Mar 2011)
@@ -0,0 +1,73 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2011.
+// 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/enums for documentation.
+//
+// Adapted from libcxx tests
+//
+//////////////////////////////////////////////////////////////////////////////
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// template <class charT>
+// explicit bitset(const charT* str,
+// typename basic_string<charT>::size_type n = basic_string<charT>::npos,
+// charT zero = charT('0'), charT one = charT('1'));
+
+#include "./Ex.hpp"
+#include <boost/enums/enum_set.hpp>
+#include <boost/enums/size.hpp>
+#include <boost/enums/val.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+using namespace boost::enums;
+
+template <typename EC>
+void test_char_pointer_ctor()
+{
+ {
+ try
+ {
+ enum_set<EC> v("xxx1010101010xxxx");
+ BOOST_TEST(false);
+ }
+ catch (std::invalid_argument&)
+ {
+ }
+ }
+
+ {
+ const char str[] ="1010101010";
+ enum_set<EC> v(str);
+ std::size_t M = std::min<std::size_t>(meta::size<EC>::value, 10);
+ for (std::size_t i = 0; i < M; ++i)
+ BOOST_TEST(v[val<EC>(i)] == (str[M - 1 - i] == '1'));
+ for (std::size_t i = 10; i < meta::size<EC>::value; ++i)
+ BOOST_TEST(v[val<EC>(i)] == false);
+ }
+}
+
+int main()
+{
+ test_char_pointer_ctor<EC3>();
+ //~ test_char_pointer_ctor<1>();
+ //~ test_char_pointer_ctor<31>();
+ //~ test_char_pointer_ctor<32>();
+ //~ test_char_pointer_ctor<33>();
+ //~ test_char_pointer_ctor<63>();
+ //~ test_char_pointer_ctor<64>();
+ //~ test_char_pointer_ctor<65>();
+ //~ test_char_pointer_ctor<1000>();
+ return boost::report_errors();
+}

Added: sandbox/enums/libs/enums/test/enum_set/cons/string_ctor.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/enums/libs/enums/test/enum_set/cons/string_ctor.pass.cpp 2011-03-02 18:32:46 EST (Wed, 02 Mar 2011)
@@ -0,0 +1,105 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2011.
+// 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/enums for documentation.
+//
+// Adapted from libcxx tests
+//
+//////////////////////////////////////////////////////////////////////////////
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// test bitset(string, pos, n, zero, one);
+
+#include "./Ex.hpp"
+#include <boost/enums/enum_set.hpp>
+#include <boost/enums/val.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+using namespace boost::enums;
+
+
+template <typename EC>
+void test_string_ctor()
+{
+ {
+ try
+ {
+ std::string str("xxx1010101010xxxx");
+ enum_set<EC> v(str, str.size()+1, 10);
+ BOOST_TEST(false);
+ }
+ catch (std::out_of_range&)
+ {
+ }
+ }
+
+ {
+ try
+ {
+ std::string str("xxx1010101010xxxx");
+ enum_set<EC> v(str, 2, 10);
+ BOOST_TEST(false);
+ }
+ catch (std::invalid_argument&)
+ {
+ }
+ }
+
+ {
+ std::string str("xxx1010101010xxxx");
+ enum_set<EC> v(str, 3, 10);
+ std::size_t M = std::min<std::size_t>(meta::size<EC>::value, 10);
+ for (std::size_t i = 0; i < M; ++i)
+ BOOST_TEST(v[val<EC>(i)] == (str[3 + M - 1 - i] == '1'));
+ for (std::size_t i = 10; i < meta::size<EC>::value; ++i)
+ BOOST_TEST(v[val<EC>(i)] == false);
+ }
+
+ {
+ try
+ {
+ std::string str("xxxbababababaxxxx");
+ enum_set<EC> v(str, 2, 10, 'a', 'b');
+ BOOST_TEST(false);
+ }
+ catch (std::invalid_argument&)
+ {
+ }
+ }
+
+ {
+ std::string str("xxxbababababaxxxx");
+ enum_set<EC> v(str, 3, 10, 'a', 'b');
+ std::size_t M = std::min<std::size_t>(meta::size<EC>::value, 10);
+ for (std::size_t i = 0; i < M; ++i)
+ BOOST_TEST(v[val<EC>(i)] == (str[3 + M - 1 - i] == 'b'));
+ for (std::size_t i = 10; i < meta::size<EC>::value; ++i)
+ BOOST_TEST(v[val<EC>(i)] == false);
+ }
+}
+
+int main()
+{
+ test_string_ctor<EC3>();
+ //~ test_string_ctor<1>();
+ //~ test_string_ctor<31>();
+ //~ test_string_ctor<32>();
+ //~ test_string_ctor<33>();
+ //~ test_string_ctor<63>();
+ //~ test_string_ctor<64>();
+ //~ test_string_ctor<65>();
+ //~ test_string_ctor<1000>();
+ return boost::report_errors();
+}

Modified: sandbox/enums/libs/enums/test/enum_set/cons/ull_ctor.pass.cpp
==============================================================================
--- sandbox/enums/libs/enums/test/enum_set/cons/ull_ctor.pass.cpp (original)
+++ sandbox/enums/libs/enums/test/enum_set/cons/ull_ctor.pass.cpp 2011-03-02 18:32:46 EST (Wed, 02 Mar 2011)
@@ -24,6 +24,7 @@
 
 #include "./Ex.hpp"
 #include <boost/enums/enum_set.hpp>
+#include <boost/enums/val.hpp>
 #include <boost/detail/lightweight_test.hpp>
 
 using namespace boost::enums;


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