Boost logo

Boost-Commit :

From: gennadiy.rozental_at_[hidden]
Date: 2008-07-06 23:46:11


Author: rogeeff
Date: 2008-07-06 23:46:10 EDT (Sun, 06 Jul 2008)
New Revision: 47162
URL: http://svn.boost.org/trac/boost/changeset/47162

Log:
copyright update
Added:
   trunk/libs/test/example/.cvsignore (contents, props changed)
   trunk/libs/test/example/const_string.hpp (contents, props changed)
   trunk/libs/test/example/const_string_test.cpp (contents, props changed)
   trunk/libs/test/example/unit_test_example_011.cpp (contents, props changed)
   trunk/libs/test/example/unit_test_example_012.cpp (contents, props changed)
Text files modified:
   trunk/libs/test/example/Jamfile.v2 | 4 ++++
   trunk/libs/test/example/unit_test_example_03.cpp | 2 +-
   2 files changed, 5 insertions(+), 1 deletions(-)

Added: trunk/libs/test/example/.cvsignore
==============================================================================
--- (empty file)
+++ trunk/libs/test/example/.cvsignore 2008-07-06 23:46:10 EDT (Sun, 06 Jul 2008)
@@ -0,0 +1,3 @@
+bin
+bjam.out
+

Modified: trunk/libs/test/example/Jamfile.v2
==============================================================================
--- trunk/libs/test/example/Jamfile.v2 (original)
+++ trunk/libs/test/example/Jamfile.v2 2008-07-06 23:46:10 EDT (Sun, 06 Jul 2008)
@@ -11,6 +11,8 @@
 
 # Project
 project libs/test/example
+ :
+ : requirements <toolset>msvc-6.5:<link>static
     ;
 
 # Define aliases for the needed libs to get shorter names
@@ -55,4 +57,6 @@
     [ run-fail logged_exp_example.cpp unit_test_framework ]
 
     [ run named_param_example.cpp ]
+
+ [ run const_string_test.cpp ]
 ;

Added: trunk/libs/test/example/const_string.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/test/example/const_string.hpp 2008-07-06 23:46:10 EDT (Sun, 06 Jul 2008)
@@ -0,0 +1,179 @@
+// (C) Copyright Gennadiy Rozental 2001-2008.
+// 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$
+//
+// Description : simple string class definition
+// ***************************************************************************
+
+#ifndef CONST_STRING_HPP
+#define CONST_STRING_HPP
+
+// STL
+#include <iterator>
+#include <string>
+#include <cstring>
+using std::string;
+
+namespace common_layer {
+
+// ************************************************************************** //
+// ************** const_string ************** //
+// ************************************************************************** //
+
+class const_string {
+public:
+ // Subtypes
+ typedef char const* iterator;
+ typedef char const* const_iterator;
+ typedef std::reverse_iterator<iterator> reverse_iterator;
+ typedef reverse_iterator const_reverse_iterator;
+
+ // Constructor
+ const_string()
+ : m_begin( "" ), m_end( m_begin ) {}
+
+ // Copy constructor is generated by compiler
+
+ const_string( const std::string& s )
+ : m_begin( s.c_str() ),
+ m_end( m_begin + s.length() ) {}
+
+ const_string( char const* s )
+ : m_begin( s ? s : "" )
+ , m_end( s ? m_begin + std::strlen( s ) : m_begin )
+ {}
+
+ const_string( char const* s, size_t length )
+ : m_begin( s ), m_end( m_begin + length ) { if( length == 0 ) erase(); }
+
+ const_string( char const* first, char const* last )
+ : m_begin( first ), m_end( last ) {}
+
+ // data access methods
+ char operator[]( size_t index ) const { return m_begin[index]; }
+ char at( size_t index ) const { return m_begin[index]; }
+
+ char const* data() const { return m_begin; }
+
+ // length operators
+ size_t length() const { return m_end - m_begin; }
+ bool is_empty() const { return m_end == m_begin; }
+
+ void erase() { m_begin = m_end = ""; }
+ void resize( size_t new_len ) { if( m_begin + new_len < m_end ) m_end = m_begin + new_len; }
+ void rshorten( size_t shift = 1 ) { m_end -= shift; if( m_end <= m_begin ) erase(); }
+ void lshorten( size_t shift = 1 ) { m_begin += shift; if( m_end <= m_begin ) erase(); }
+
+ // Assignment operators
+ const_string& operator=( const_string const& s );
+ const_string& operator=( string const& s ) { return *this = const_string( s ); }
+ const_string& operator=( char const* s ) { return *this = const_string( s ); }
+
+ const_string& assign( const_string const& s ) { return *this = s; }
+ const_string& assign( string const& s, size_t len ) { return *this = const_string( s.data(), len ); }
+ const_string& assign( string const& s ) { return *this = const_string( s ); }
+ const_string& assign( char const* s ) { return *this = const_string( s ); }
+ const_string& assign( char const* s, size_t len ) { return *this = const_string( s, len ); }
+ const_string& assign( char const* f, char const* l ) { return *this = const_string( f, l ); }
+
+ void swap( const_string& s ) {
+ // do not want to include alogrithm
+ char const* tmp1 = m_begin;
+ char const* tmp2 = m_end;
+
+ m_begin = s.m_begin;
+ m_end = s.m_end;
+
+ s.m_begin = tmp1;
+ s.m_end = tmp2;
+ }
+
+ // Comparison operators
+ friend bool operator==( const_string const& s1, const_string const& s2 )
+ {
+ return s1.length() == s2.length() && std::strncmp( s1.data(), s2.data(), s1.length() ) == 0;
+ }
+ friend bool operator==( const_string const& s1, char const* s2 ) { return s1 == const_string( s2 ); }
+ friend bool operator==( const_string const& s1, const string& s2 ) { return s1 == const_string( s2 ); }
+
+ friend bool operator!=( const_string const& s1, const_string const& s2 ) { return !(s1 == s2); }
+ friend bool operator!=( const_string const& s1, char const* s2 ) { return !(s1 == s2); }
+ friend bool operator!=( const_string const& s1, const string& s2 ) { return !(s1 == s2); }
+
+ friend bool operator==( char const* s2, const_string const& s1 ) { return s1 == s2; }
+ friend bool operator==( const string& s2, const_string const& s1 ) { return s1 == s2; }
+
+ friend bool operator!=( char const* s2, const_string const& s1 ) { return !(s1 == s2); }
+ friend bool operator!=( const string& s2, const_string const& s1 ) { return !(s1 == s2); }
+
+ // Iterators
+ iterator begin() const { return m_begin; }
+ iterator end() const { return m_end; }
+ reverse_iterator rbegin() const { return reverse_iterator( m_end ); }
+ reverse_iterator rend() const { return reverse_iterator( m_begin ); }
+
+private:
+
+ // Data members
+ char const* m_begin;
+ char const* m_end;
+};
+
+//____________________________________________________________________________//
+
+// first character
+class first_char {
+public:
+ char operator()( const_string source, char default_char = '\0' ) const {
+ return source.is_empty() ? default_char : *source.data();
+ }
+};
+
+//____________________________________________________________________________//
+
+// last character
+class last_char {
+public:
+ char operator()( const_string source, char default_char = '\0' ) const {
+ return source.is_empty() ? default_char : *source.rbegin();
+ }
+};
+
+//____________________________________________________________________________//
+
+inline const_string&
+const_string::operator=( const_string const& s ) {
+ if( &s != this ) {
+ m_begin = s.m_begin;
+ m_end = s.m_end;
+ }
+
+ return *this;
+}
+
+//____________________________________________________________________________//
+
+typedef const_string const literal;
+
+//____________________________________________________________________________//
+
+inline std::ostream&
+operator<<( std::ostream& os, const_string const& str )
+{
+ os << std::string( str.begin(), str.length() );
+
+ return os;
+}
+
+//____________________________________________________________________________//
+
+}; // namespace common_layer
+
+#endif // CONST_STRING_HPP

Added: trunk/libs/test/example/const_string_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/test/example/const_string_test.cpp 2008-07-06 23:46:10 EDT (Sun, 06 Jul 2008)
@@ -0,0 +1,181 @@
+// (C) Copyright Gennadiy Rozental 2001-2005.
+// 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: const_string_test.cpp,v $
+//
+// Version : $Revision$
+//
+// Description : simple string class test
+// ***************************************************************************
+
+#define BOOST_TEST_MODULE const_string test
+#include <boost/test/included/unit_test.hpp>
+
+#include "const_string.hpp"
+using common_layer::const_string;
+
+BOOST_AUTO_TEST_CASE( constructors_test )
+{
+ const_string cs0( "" );
+ BOOST_CHECK_EQUAL( cs0.length(), (size_t)0 );
+ BOOST_CHECK_EQUAL( cs0.begin(), "" );
+ BOOST_CHECK_EQUAL( cs0.end(), "" );
+ BOOST_CHECK( cs0.is_empty() );
+
+ const_string cs01( NULL );
+ BOOST_CHECK_EQUAL( cs01.length(), (size_t)0 );
+ BOOST_CHECK_EQUAL( cs01.begin(), "" );
+ BOOST_CHECK_EQUAL( cs01.end(), "" );
+ BOOST_CHECK( cs01.is_empty() );
+
+ const_string cs1( "test_string" );
+ BOOST_CHECK_EQUAL( std::strcmp( cs1.data(), "test_string" ), 0 );
+ BOOST_CHECK_EQUAL( cs1.length(), std::strlen("test_string") );
+
+ std::string s( "test_string" );
+ const_string cs2( s );
+ BOOST_CHECK_EQUAL( std::strcmp( cs2.data(), "test_string" ), 0 );
+
+ const_string cs3( cs1 );
+ BOOST_CHECK_EQUAL( std::strcmp( cs1.data(), "test_string" ), 0 );
+
+ const_string cs4( "test_string", 4 );
+ BOOST_CHECK_EQUAL( std::strncmp( cs4.data(), "test", cs4.length() ), 0 );
+
+ const_string cs5( s.data(), s.data() + s.length() );
+ BOOST_CHECK_EQUAL( std::strncmp( cs5.data(), "test_string", cs5.length() ), 0 );
+
+ const_string cs_array[] = { "str1", "str2" };
+
+ BOOST_CHECK_EQUAL( cs_array[0], "str1" );
+ BOOST_CHECK_EQUAL( cs_array[1], "str2" );
+}
+
+BOOST_AUTO_TEST_CASE( data_access_test )
+{
+ const_string cs1( "test_string" );
+ BOOST_CHECK_EQUAL( std::strcmp( cs1.data(), "test_string" ), 0 );
+
+ BOOST_CHECK_EQUAL( cs1[(size_t)0], 't' );
+ BOOST_CHECK_EQUAL( cs1[(size_t)4], '_' );
+ BOOST_CHECK_EQUAL( cs1[cs1.length()-1], 'g' );
+
+ BOOST_CHECK_EQUAL( cs1[(size_t)0], cs1.at( 0 ) );
+ BOOST_CHECK_EQUAL( cs1[(size_t)2], cs1.at( 5 ) );
+ BOOST_CHECK_EQUAL( cs1.at( cs1.length() - 1 ), 'g' );
+
+ BOOST_CHECK_THROW( cs1.at( cs1.length() ), std::out_of_range );
+
+ BOOST_CHECK_EQUAL( common_layer::first_char()( cs1 ), 't' );
+ BOOST_CHECK_EQUAL( common_layer::last_char()( cs1 ) , 'g' );
+}
+
+
+BOOST_AUTO_TEST_CASE( length_test )
+{
+ const_string cs1;
+
+ BOOST_CHECK_EQUAL( cs1.length(), (size_t)0 );
+ BOOST_CHECK( cs1.is_empty() );
+
+ cs1 = "";
+ BOOST_CHECK_EQUAL( cs1.length(), (size_t)0 );
+ BOOST_CHECK( cs1.is_empty() );
+
+ cs1 = "test_string";
+ BOOST_CHECK_EQUAL( cs1.length(), (size_t)11 );
+
+ cs1.erase();
+ BOOST_CHECK_EQUAL( cs1.length(), (size_t)0 );
+ BOOST_CHECK_EQUAL( cs1.data(), "" );
+
+ cs1 = const_string( "test_string", 4 );
+ BOOST_CHECK_EQUAL( cs1.length(), (size_t)4 );
+
+ cs1.resize( 5 );
+ BOOST_CHECK_EQUAL( cs1.length(), (size_t)4 );
+
+ cs1.resize( 3 );
+ BOOST_CHECK_EQUAL( cs1.length(), (size_t)3 );
+
+ cs1.rshorten();
+ BOOST_CHECK_EQUAL( cs1.length(), (size_t)2 );
+ BOOST_CHECK_EQUAL( cs1[(size_t)0], 't' );
+
+ cs1.lshorten();
+ BOOST_CHECK_EQUAL( cs1.length(), (size_t)1 );
+ BOOST_CHECK_EQUAL( cs1[(size_t)0], 'e' );
+
+ cs1.lshorten();
+ BOOST_CHECK( cs1.is_empty() );
+ BOOST_CHECK_EQUAL( cs1.data(), "" );
+
+ cs1 = "test_string";
+ cs1.lshorten( 11 );
+ BOOST_CHECK( cs1.is_empty() );
+ BOOST_CHECK_EQUAL( cs1.data(), "" );
+}
+
+BOOST_AUTO_TEST_CASE( asignment_test )
+{
+ const_string cs1;
+ std::string s( "test_string" );
+
+ cs1 = "test";
+ BOOST_CHECK_EQUAL( std::strcmp( cs1.data(), "test" ), 0 );
+
+ cs1 = s;
+ BOOST_CHECK_EQUAL( std::strcmp( cs1.data(), "test_string" ), 0 );
+
+ cs1.assign( "test" );
+ BOOST_CHECK_EQUAL( std::strcmp( cs1.data(), "test" ), 0 );
+
+ const_string cs2( "test_string" );
+
+ cs1.swap( cs2 );
+ BOOST_CHECK_EQUAL( std::strcmp( cs1.data(), "test_string" ), 0 );
+ BOOST_CHECK_EQUAL( std::strcmp( cs2.data(), "test" ), 0 );
+}
+
+BOOST_AUTO_TEST_CASE( comparison_test )
+{
+ const_string cs1( "test_string" );
+ const_string cs2( "test_string" );
+ std::string s( "test_string" );
+
+ BOOST_CHECK_EQUAL( cs1, "test_string" );
+ BOOST_CHECK_EQUAL( "test_string", cs1 );
+ BOOST_CHECK_EQUAL( cs1, cs2 );
+ BOOST_CHECK_EQUAL( cs1, s );
+ BOOST_CHECK_EQUAL( s , cs1 );
+
+ cs1.resize( 4 );
+
+ BOOST_CHECK( cs1 != "test_string" );
+ BOOST_CHECK( "test_string" != cs1 );
+ BOOST_CHECK( cs1 != cs2 );
+ BOOST_CHECK( cs1 != s );
+ BOOST_CHECK( s != cs1 );
+
+ BOOST_CHECK_EQUAL( cs1, "test" );
+}
+
+BOOST_AUTO_TEST_CASE( iterators_test )
+{
+ const_string cs1( "test_string" );
+ std::string s;
+
+ std::copy( cs1.begin(), cs1.end(), std::back_inserter( s ) );
+ BOOST_CHECK_EQUAL( cs1, s );
+
+ s.erase();
+
+ std::copy( cs1.rbegin(), cs1.rend(), std::back_inserter( s ) );
+ BOOST_CHECK_EQUAL( const_string( s ), "gnirts_tset" );
+}
+
+// EOF

Added: trunk/libs/test/example/unit_test_example_011.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/test/example/unit_test_example_011.cpp 2008-07-06 23:46:10 EDT (Sun, 06 Jul 2008)
@@ -0,0 +1,9 @@
+#define BOOST_TEST_MODULE broken
+#include <boost/test/included/unit_test.hpp>
+
+
+BOOST_AUTO_TEST_CASE( broken_test )
+{
+ ::system("ls");
+}
+

Added: trunk/libs/test/example/unit_test_example_012.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/test/example/unit_test_example_012.cpp 2008-07-06 23:46:10 EDT (Sun, 06 Jul 2008)
@@ -0,0 +1,24 @@
+#include <boost/test/unit_test.hpp>
+#include <cstdlib>
+
+using boost::unit_test::test_suite;
+
+void Vektor3Test1() { }
+
+test_suite* Vektor3_test_suite()
+{
+ test_suite *test = BOOST_TEST_SUITE("Vektor3 test suite");
+ test->add(BOOST_TEST_CASE(&Vektor3Test1));
+
+ return test;
+}
+
+test_suite* init_unit_test_suite(int, char *[])
+{
+ std::system("true");
+ // leads to "Test setup error: child has exited; pid: 1001; uid: 30540; exit value: 0"
+
+ test_suite *test = BOOST_TEST_SUITE("Master test suite");
+ test->add(Vektor3_test_suite());
+ return test;
+}
\ No newline at end of file

Modified: trunk/libs/test/example/unit_test_example_03.cpp
==============================================================================
--- trunk/libs/test/example/unit_test_example_03.cpp (original)
+++ trunk/libs/test/example/unit_test_example_03.cpp 2008-07-06 23:46:10 EDT (Sun, 06 Jul 2008)
@@ -1,4 +1,4 @@
-// (C) Copyright Gennadiy Rozental 2002-2006.
+// (C) Copyright Gennadiy Rozental 2002-2008.
 // (C) Copyright Gennadiy Rozental & Ullrich Koethe 2001.
 // Distributed under the Boost Software License, Version 1.0.
 // (See accompanying file LICENSE_1_0.txt or copy at


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