Update of /cvsroot/boost/boost/libs/system/test
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv27554

Modified Files:
      Tag: c++0x
        error_code_test.cpp error_code_user_test.cpp 
        system_error_test.cpp 
Log Message:
Bring into sync with C++0x working paper + likely N2296 changes

Index: error_code_test.cpp
===================================================================
RCS file: /cvsroot/boost/boost/libs/system/test/error_code_test.cpp,v
retrieving revision 1.1
retrieving revision 1.1.2.1
diff -u -d -r1.1 -r1.1.2.1
--- error_code_test.cpp 3 Nov 2006 16:57:30 -0000       1.1
+++ error_code_test.cpp 17 Jun 2007 15:55:56 -0000      1.1.2.1
@@ -20,6 +20,9 @@
 
 #include <boost/test/minimal.hpp>
 #include <boost/system/error_code.hpp>
+#include <iostream>
+#include <sstream>
+#include <cerrno>
 
 //  Although using directives are not the best programming practice, testing
 //  with a boost::system using directive increases use scenario coverage.
@@ -30,80 +33,109 @@
 #   include <boost/cerrno.hpp>
 # endif
 
+namespace
+{
+  void check_ostream( error_code ec, const char * expected )
+  {
+    std::stringstream ss;
+    std::string s;
+
+    ss << ec;
+    ss >> s;
+    BOOST_CHECK( s == expected );
+  }
+}
+
 //  test_main  
---------------------------------------------------------------//
 
-// TODO: supply a build jam file
-// TODO: supply a test jam file
-// TODO: same for bjam v2
 // TODO: add message decoder tests
+// TODO: add hash_value tests
 
 int test_main( int, char ** )
 {
   error_code ec;
-  error_code ec_0_native( 0, native_ecat );
-  error_code ec_0_errno( 0, errno_ecat );
-  error_code ec_1_native( 1, native_ecat );
-  error_code ec_1_errno( 1, errno_ecat );
+  error_code ec_0_native( 0, native_category );
+  error_code ec_0_posix( 0, posix_category );
+  error_code ec_1_native( 1, native_category );
+  error_code ec_1_posix( 1, posix_category );
 
   BOOST_CHECK( !ec );
   BOOST_CHECK( ec.value() == 0 );
-  BOOST_CHECK( ec.to_errno() == 0 );
+  BOOST_CHECK( ec.posix() == 0 );
 
   BOOST_CHECK( !ec_0_native );
   BOOST_CHECK( ec_0_native.value() == 0 );
-  BOOST_CHECK( ec_0_native.to_errno() == 0 );
+  BOOST_CHECK( ec_0_native.posix() == 0 );
 
-  BOOST_CHECK( !ec_0_errno );
-  BOOST_CHECK( ec_0_errno.value() == 0 );
-  BOOST_CHECK( ec_0_errno.to_errno() == 0 );
-  BOOST_CHECK( ec == ec_0_errno );
-  BOOST_CHECK( native_ecat != errno_ecat || ec_0_native == ec_0_errno );
-  BOOST_CHECK( native_ecat == errno_ecat || ec_0_native != ec_0_errno );
+  BOOST_CHECK( !ec_0_posix );
+  BOOST_CHECK( ec_0_posix.value() == 0 );
+  BOOST_CHECK( ec_0_posix.posix() == 0 );
+  BOOST_CHECK( ec == ec_0_posix );
+  BOOST_CHECK( ec_0_native != ec_0_posix );
 
   BOOST_CHECK( ec_1_native );
   BOOST_CHECK( ec_1_native.value() == 1 );
   BOOST_CHECK( ec_1_native.value() != 0 );
-  BOOST_CHECK( ec_1_native.to_errno() != 0 );
+  BOOST_CHECK( ec_1_native.posix() != 0 );
   BOOST_CHECK( ec != ec_1_native );
   BOOST_CHECK( ec_0_native != ec_1_native );
-  BOOST_CHECK( ec_0_errno != ec_1_native );
+  BOOST_CHECK( ec_0_posix != ec_1_native );
 
-  BOOST_CHECK( ec_1_errno );
-  BOOST_CHECK( ec_1_errno.value() == 1 );
-  BOOST_CHECK( ec_1_errno.to_errno() == 1 );
-  BOOST_CHECK( ec_1_errno.to_errno() != 0 );
-  BOOST_CHECK( ec != ec_1_errno );
-  BOOST_CHECK( ec_0_native != ec_1_errno );
-  BOOST_CHECK( ec_0_errno != ec_1_errno );
+  BOOST_CHECK( ec_1_posix );
+  BOOST_CHECK( ec_1_posix.value() == 1 );
+  BOOST_CHECK( ec_1_posix.posix() == 1 );
+  BOOST_CHECK( ec_1_posix.posix() != 0 );
+  BOOST_CHECK( ec != ec_1_posix );
+  BOOST_CHECK( ec_0_native != ec_1_posix );
+  BOOST_CHECK( ec_0_posix != ec_1_posix );
 
-#ifdef BOOST_WINDOWS_API
-  BOOST_CHECK( ec != ec_0_native );
+  BOOST_CHECK( ec_0_posix.category() == posix_category );
+  BOOST_CHECK( ec_0_posix.category() == ec_1_posix.category() );
+  BOOST_CHECK( ec_0_posix.category() != native_category );
+  BOOST_CHECK( ec_0_posix.category() != ec_0_native.category() );
 
-  // these tests probe the Windows to_errno decoder
+  BOOST_CHECK( ec_0_posix.category().name() == "POSIX" );
+  BOOST_CHECK( ec_0_native.category().name() == "native" );
+
+  check_ostream( ec_0_posix, "POSIX:0" );
+  check_ostream( ec_1_posix, "POSIX:1" );
+  check_ostream( ec_0_native, "native:0" );
+  check_ostream( ec_1_native, "native:1" );
+
+  error_code ec_2_posix( no_such_file_or_directory );
+  error_code ec_3_posix( no_such_file_or_directory, posix_category );
+
+  BOOST_CHECK( ec_2_posix == ec_3_posix );
+  BOOST_CHECK( ec_2_posix == no_such_file_or_directory );
+  BOOST_CHECK( no_such_file_or_directory == ec_2_posix );
+
+
+#ifdef BOOST_WINDOWS_API
+  // these tests probe the Windows posix decoder
   //   test the first entry in the decoder table:
-  ec = error_code( ERROR_FILE_NOT_FOUND, native_ecat );
+  ec = error_code( ERROR_FILE_NOT_FOUND, native_category );
   BOOST_CHECK( ec.value() == ERROR_FILE_NOT_FOUND );
-  BOOST_CHECK( ec.to_errno() == ENOENT );
+  BOOST_CHECK( ec.posix() == ENOENT );
 
   //   test the second entry in the decoder table:
-  ec = error_code( ERROR_PATH_NOT_FOUND, native_ecat );
+  ec = error_code( ERROR_PATH_NOT_FOUND, native_category );
   BOOST_CHECK( ec.value() == ERROR_PATH_NOT_FOUND );
-  BOOST_CHECK( ec.to_errno() == ENOENT );
+  BOOST_CHECK( ec.posix() == ENOENT );
 
   //   test the third entry in the decoder table:
-  ec = error_code( ERROR_ACCESS_DENIED, native_ecat );
+  ec = error_code( ERROR_ACCESS_DENIED, native_category );
   BOOST_CHECK( ec.value() == ERROR_ACCESS_DENIED );
-  BOOST_CHECK( ec.to_errno() == EACCES );
+  BOOST_CHECK( ec.posix() == EACCES );
 
   //   test the last regular entry in the decoder table:
-  ec = error_code( ERROR_WRITE_PROTECT, native_ecat );
+  ec = error_code( ERROR_WRITE_PROTECT, native_category );
   BOOST_CHECK( ec.value() == ERROR_WRITE_PROTECT );
-  BOOST_CHECK( ec.to_errno() == EROFS );
+  BOOST_CHECK( ec.posix() == EROFS );
 
   //   test not-in-table condition:
-  ec = error_code( 1234567890, native_ecat );
+  ec = error_code( 1234567890, native_category );
   BOOST_CHECK( ec.value() == 1234567890 );
-  BOOST_CHECK( ec.to_errno() == EOTHER );
+  BOOST_CHECK( ec.posix() == EOTHER );
 
 #else
   BOOST_CHECK( ec == ec_0_native );

Index: error_code_user_test.cpp
===================================================================
RCS file: /cvsroot/boost/boost/libs/system/test/error_code_user_test.cpp,v
retrieving revision 1.1
retrieving revision 1.1.2.1
diff -u -d -r1.1 -r1.1.2.1
--- error_code_user_test.cpp    3 Nov 2006 16:57:30 -0000       1.1
+++ error_code_user_test.cpp    17 Jun 2007 15:55:56 -0000      1.1.2.1
@@ -15,6 +15,13 @@
 #include <boost/system/error_code.hpp>
 #include <boost/cerrno.hpp>
 
+
+# ifndef BOOST_NO_STD_WSTRING  // workaround Cygwin's lack of wstring_t
+    typedef std::wstring wstring_t;
+# else
+    typedef std::basic_string<wchar_t> wstring_t;
+# endif
+
 //  ------------------------------------------------------------------------  
//
 
 //  header asio.hpp
@@ -27,7 +34,15 @@
   namespace asio
   {
     // asio declares have its own error_category:
-    extern system::error_category asio_error;
+    class asio_error_category : public boost::system::error_category
+    {
+    public:
+      const std::string &         name() const;
+      boost::system::posix_errno  posix( int ev ) const;
+      std::string                 message( int ev ) const;
+      wstring_t                   wmessage( int ev ) const;
+    };
+    extern asio_error_category asio_error;
     
     namespace error
     {
@@ -46,8 +61,30 @@
 {
   namespace asio
   {
+    asio_error_category asio_error;
 
-    system::error_category asio_error = system::error_code::new_category();
+    const std::string & asio_error_category::name() const
+    {
+      static std::string s( "asio" );
+      return s;
+    }
+    boost::system::posix_errno
+      asio_error_category::posix( int ev ) const
+    {
+      return ev == BOO_BOO
+        ? boost::system::io_error
+        : boost::system::other;
+    }
+
+    std::string asio_error_category::message( int ev ) const
+    {
+      return std::string( "Barf" );
+    }
+
+    wstring_t asio_error_category::wmessage( int ev ) const
+    {
+      return wstring_t( L"Barf" );
+    }
 
     namespace error
     {
@@ -80,13 +117,8 @@
   BOOST_CHECK( ec.value() == BOO_BOO );
   BOOST_CHECK( ec.category() == boost::asio::asio_error );
 
-  // a real user can't rely on the value of an error_category object's value,
-  // but in this test program that value is known, so test for it.
-  BOOST_CHECK( ec.category().value() == boost::system::native_ecat.value()+1 );
-
-  // asio did not supply decoders, so test the defaults
-  BOOST_CHECK( ec.to_errno() == EOTHER );
-  BOOST_CHECK( ec.message() == "API error" );
-  BOOST_CHECK( ec.wmessage() == L"API error" );
+  BOOST_CHECK( ec.posix() == boost::system::io_error );
+  BOOST_CHECK( ec.message() == "Barf" );
+  BOOST_CHECK( ec.wmessage() == L"Barf" );
   return 0;
 }

Index: system_error_test.cpp
===================================================================
RCS file: /cvsroot/boost/boost/libs/system/test/system_error_test.cpp,v
retrieving revision 1.2
retrieving revision 1.2.2.1
diff -u -d -r1.2 -r1.2.2.1
--- system_error_test.cpp       15 Dec 2006 22:26:16 -0000      1.2
+++ system_error_test.cpp       17 Jun 2007 15:55:56 -0000      1.2.2.1
@@ -23,24 +23,23 @@
 #include <iostream>
 
 #ifdef BOOST_WINDOWS_API
-# include <winerror.h>
+#include <winerror.h>
 #endif
 
 using boost::system::system_error;
 using boost::system::error_code;
-using boost::system::errno_ecat;
-using boost::system::no_message;
+using boost::system::posix_category;
 
 #define TEST(x,v,w) test(#x,x,v,w)
 
 namespace
 {
   void test( const char * desc, const system_error & ex,
-    error_code::value_type v, const char * str )
+    int v, const char * str )
   {
     std::cout << "test " << desc << "\n what() returns \"" << ex.what() << 
"\"\n";
     BOOST_CHECK( ex.code().value() == v );
-    BOOST_CHECK( ex.code().category() == errno_ecat );
+    BOOST_CHECK( ex.code().category() == posix_category );
 # ifdef BOOST_WINDOWS_API
     BOOST_CHECK( std::string( ex.what() ) == str );
     if ( std::string( ex.what() ) != str )
@@ -56,28 +55,16 @@
 {
   // all combinations of constructors:
 
-  system_error se_0( error_code(0, errno_ecat) ); 
-  system_error se_1( 1, errno_ecat ); 
-  system_error se_0_m( error_code(0, errno_ecat), "se_0_m" ); 
-  system_error se_1_m( 1, errno_ecat, "se_1_m" ); 
-  system_error se_0_nm( error_code(0, errno_ecat), "" ); 
-  system_error se_1_nm( 1, errno_ecat, "" ); 
-  system_error se_0_m_im( error_code(0, errno_ecat), "se_0_m_im", no_message 
); 
-  system_error se_1_m_im( 1, errno_ecat, "se_1_m_im", no_message ); 
-  system_error se_0_nm_im( error_code(0, errno_ecat), "", no_message ); 
-  system_error se_1_nm_im( 1, errno_ecat, "", no_message );
-  system_error se_1u_m( uvalue, errno_ecat, "se_1u_m" ); 
+  system_error se_0_m( error_code(0, posix_category), "se_0_m" ); 
+  system_error se_1_m( 1, posix_category, "se_1_m" ); 
+  system_error se_0_nm( error_code(0, posix_category), "" ); 
+  system_error se_1_nm( 1, posix_category, "" ); 
+  system_error se_1u_m( uvalue, posix_category, "se_1u_m" ); 
 
-  TEST( se_0, 0, "" );
-  TEST( se_1, 1, "Operation not permitted" );
   TEST( se_0_m, 0, "se_0_m" );
   TEST( se_1_m, 1, "se_1_m: Operation not permitted" );
   TEST( se_0_nm, 0, "" );
   TEST( se_1_nm, 1, "Operation not permitted" );
-  TEST( se_0_m_im, 0, "se_0_m_im" );
-  TEST( se_1_m_im, 1, "se_1_m_im" );
-  TEST( se_0_nm_im, 0, "" );
-  TEST( se_1_nm_im, 1, "" );
   TEST( se_1u_m, 1, "se_1u_m: Operation not permitted" );
 
   return 0;


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Boost-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/boost-cvs

Reply via email to