|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r50652 - in sandbox/filesystem-v3: boost/filesystem libs/filesystem/src libs/filesystem/test
From: bdawes_at_[hidden]
Date: 2009-01-17 09:36:47
Author: bemandawes
Date: 2009-01-17 09:36:46 EST (Sat, 17 Jan 2009)
New Revision: 50652
URL: http://svn.boost.org/trac/boost/changeset/50652
Log:
Filesystem.v3: path_unit_test working on Linux/GCC
Text files modified:
sandbox/filesystem-v3/boost/filesystem/path.hpp | 3 -
sandbox/filesystem-v3/libs/filesystem/src/path.cpp | 27 ++++++++++++---
sandbox/filesystem-v3/libs/filesystem/test/path_unit_test.cpp | 70 +++++++++++++++++++++++++--------------
3 files changed, 66 insertions(+), 34 deletions(-)
Modified: sandbox/filesystem-v3/boost/filesystem/path.hpp
==============================================================================
--- sandbox/filesystem-v3/boost/filesystem/path.hpp (original)
+++ sandbox/filesystem-v3/boost/filesystem/path.hpp 2009-01-17 09:36:46 EST (Sat, 17 Jan 2009)
@@ -17,7 +17,6 @@
TO DO
* Windows, POSIX, conversions for char16_t, char32_t for supporting compilers.
- * Windows, POSIX, conversions for user-defined types.
* Fix inserter/extractor problems; see comments in commented out code below.
* Need an error category for codecvt errors. Seed path.cpp detail::append, etc.
* Add Alternate Data Stream test cases. See http://en.wikipedia.org/wiki/NTFS Features.
@@ -34,7 +33,7 @@
* path.cpp: locale and detail append/convert need error handling.
* path_unit_test needs to probe error handling, verify exceptions are thrown when
requested.
- * Provide the name check functions for more character types. Templatize?
+ * Provide the name check functions for more character types? Templatize?
Design Questions
Modified: sandbox/filesystem-v3/libs/filesystem/src/path.cpp
==============================================================================
--- sandbox/filesystem-v3/libs/filesystem/src/path.cpp (original)
+++ sandbox/filesystem-v3/libs/filesystem/src/path.cpp 2009-01-17 09:36:46 EST (Sat, 17 Jan 2009)
@@ -18,6 +18,11 @@
#include <cstring>
#include <cassert>
+#ifdef BOOST_FILESYSTEM_DEBUG
+# include <iostream>
+# include <iomanip>
+#endif
+
#ifdef BOOST_WINDOWS_PATH
# include <windows.h>
#endif
@@ -764,13 +769,23 @@
value_type * to, value_type * to_end,
string_type & target, error_code & ec )
{
+ //std::cout << std::hex
+ // << " from=" << std::size_t(from)
+ // << " from_end=" << std::size_t(from_end)
+ // << " to=" << std::size_t(to)
+ // << " to_end=" << std::size_t(to_end)
+ // << std::endl;
+
std::mbstate_t state = std::mbstate_t(); // perhaps unneeded, but cuts bug reports
const interface_value_type * from_next;
value_type * to_next;
- if ( wchar_t_codecvt_facet()->APPEND_DIRECTION( state, from, from_end, from_next,
- to, to_end, to_next ) != std::codecvt_base::ok )
+ std::codecvt_base::result res;
+
+ if ( (res=wchar_t_codecvt_facet()->APPEND_DIRECTION( state, from, from_end, from_next,
+ to, to_end, to_next )) != std::codecvt_base::ok )
{
+ //std::cout << " result is " << static_cast<int>(res) << std::endl;
assert( 0 && "append error handling not implemented yet" );
throw "append error handling not implemented yet";
}
@@ -795,7 +810,7 @@
return;
}
- std::size_t buf_size = end - begin; // perhaps too large, but that's OK
+ std::size_t buf_size = (end - begin) * 3; // perhaps too large, but that's OK
// dynamically allocate a buffer only if source is unusually large
if ( buf_size > default_codecvt_buf_size )
@@ -806,7 +821,7 @@
else
{
value_type buf[default_codecvt_buf_size];
- do_append( begin, end, buf, buf+buf_size, target, ec );
+ do_append( begin, end, buf, buf+default_codecvt_buf_size, target, ec );
}
}
@@ -844,8 +859,8 @@
return interface_string_type();
}
- // The codecvt length functions may not be implemented, and I don't reall
- // understand them either. Thus this code is really just a guess; it it turns
+ // The codecvt length functions may not be implemented, and I don't really
+ // understand them either. Thus this code is just a guess; if it turns
// out the buffer is too small then an error will be reported and the code
// will have to be fixed.
std::size_t buf_size = src.size() * 4;
Modified: sandbox/filesystem-v3/libs/filesystem/test/path_unit_test.cpp
==============================================================================
--- sandbox/filesystem-v3/libs/filesystem/test/path_unit_test.cpp (original)
+++ sandbox/filesystem-v3/libs/filesystem/test/path_unit_test.cpp 2009-01-17 09:36:46 EST (Sat, 17 Jan 2009)
@@ -49,14 +49,6 @@
#define PATH_IS( a, b ) check_path( a, b, __FILE__, __LINE__ )
#define IS( a,b ) check_equal( a, b, __FILE__, __LINE__ )
-// It is convenient for editing to have these ready to copy and paste
-# ifdef BOOST_WINDOWS_PATH
-# else // BOOST_POSIX_PATH
-# endif
-
-# ifndef BOOST_FILESYSTEM_NARROW_ONLY
-# endif // narrow only
-
namespace
{
int errors;
@@ -138,28 +130,30 @@
path x2(x1); // #2
PATH_IS(x2, BOO_LIT("path x1"));
- path x4(string("std::string::iterator").begin()); // #3
- PATH_IS(x4, BOO_LIT("std::string::iterator"));
-
- path x7(s.begin(), s.end()); // #4
- PATH_IS(x7, BOO_LIT("string iterators"));
-
- path x10(string("std::string")); // #5
- PATH_IS(x10, BOO_LIT("std::string"));
-
-# ifndef BOOST_FILESYSTEM_NARROW_ONLY
path x3(L"const wchar_t *"); // #3
PATH_IS(x3, L"const wchar_t *");
+ string s3a( "s3a.c_str()" );
+ path x3a( s3a.c_str() ); // #3
+ PATH_IS(x3a, BOO_LIT("s3a.c_str()"));
+
+ path x4(string("std::string::iterator").begin()); // #3
+ PATH_IS(x4, BOO_LIT("std::string::iterator"));
+
path x5(wstring(L"std::wstring::iterator").begin()); // #3
PATH_IS(x5, L"std::wstring::iterator");
+ path x7(s.begin(), s.end()); // #4
+ PATH_IS(x7, BOO_LIT("string iterators"));
+
path x8(ws.begin(), ws.end()); // #4
PATH_IS(x8, L"wstring iterators");
+ path x10(string("std::string")); // #5
+ PATH_IS(x10, BOO_LIT("std::string"));
+
path x11(wstring(L"std::wstring")); // #5
PATH_IS(x11, L"std::wstring");
-# endif
}
// test_use_cases ------------------------------------------------------------------//
@@ -201,7 +195,6 @@
s2 = p;
CHECK( s2 == "foo" );
-# ifndef BOOST_FILESYSTEM_NARROW_ONLY
wstring ws1( p );
CHECK( ws1 == L"foo" );
@@ -211,7 +204,6 @@
ws2.clear();
ws2 = p;
CHECK( ws2 == L"foo" );
-# endif
}
@@ -520,30 +512,44 @@
// \u2722 and \xE2\x9C\xA2 are UTF-16 and UTF-8 FOUR TEARDROP-SPOKED ASTERISK
+ std::cout << " testing p0 ..." << std::endl;
path p0( L"\u2722" ); // for tests that depend on detail::convert_to_string
+# ifdef BOOST_WINDOWS_PATH
CHECK( p0.string() != "\xE2\x9C\xA2" );
+# endif
string p0_string( p0.string() );
+ std::cout << " testing p1 ..." << std::endl;
path p1( "\xE2\x9C\xA2" );
+# ifdef BOOST_WINDOWS_PATH
CHECK( p1 != L"\u2722" );
+# endif
wstring p1_wstring( p1.wstring() );
// So that tests are run with known encoding, use Boost UTF-8 codecvt
std::locale global_loc = std::locale();
std::locale loc( global_loc, new fs::detail::utf8_codecvt_facet );
+ std::cout << " imbuing locale ..." << std::endl;
std::locale old_loc = path::imbue( loc );
+ std::cout << " testing with the imbued locale ..." << std::endl;
CHECK( p0.string() == "\xE2\x9C\xA2" );
path p2( "\xE2\x9C\xA2" );
CHECK( p2 == L"\u2722" );
CHECK( p2.wstring() == L"\u2722" );
+ std::cout << " imbuing the original locale ..." << std::endl;
path::imbue( old_loc );
+ std::cout << " testing with the original locale ..." << std::endl;
CHECK( p0.string() == p0_string );
path p3( "\xE2\x9C\xA2" );
+# ifdef BOOST_WINDOWS_PATH
CHECK( p3 != L"\u2722" );
+# endif
CHECK( p3.wstring() == p1_wstring );
+
+ std::cout << " locale testing complete" << std::endl;
}
// // test_locales --------------------------------------------------------------------//
@@ -580,6 +586,18 @@
target += *begin + 1; // change so that results distinguishable from char cvts
}
+# ifdef __GNUC__
+ // This specialization shouldn't be needed, and VC++, Intel, and others work
+ // fine without it. But gcc 4.3.2, and presumably other versions, need it.
+ template<>
+ void append<user_string::value_type>( const user_string::value_type * begin,
+ string_type & target, system::error_code & ec )
+ {
+ path_traits::append<user_string::value_type>( begin,
+ static_cast<const user_string::value_type *>(0), target, ec );
+ }
+# endif
+
template<>
user_string convert<user_string>( const string_type & source,
system::error_code & ec )
@@ -604,11 +622,11 @@
user_string::value_type usr_c_str[] = { 'a', 'b', 'c', 0 };
user_string usr( usr_c_str );
- //path p1( usr_c_str );
- //CHECK( p1 == path("bcd") );
- //CHECK( p1 == "bcd" );
- //user_string s1( p1.string<user_string>() );
- //CHECK( s1 == usr );
+ path p1( usr.c_str() );
+ CHECK( p1 == path("bcd") );
+ CHECK( p1 == "bcd" );
+ user_string s1( p1.string<user_string>() );
+ CHECK( s1 == usr );
}
} // unnamed namespace
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