Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r71079 - in trunk/libs/filesystem/v3: src test
From: bdawes_at_[hidden]
Date: 2011-04-07 10:34:36


Author: bemandawes
Date: 2011-04-07 10:34:33 EDT (Thu, 07 Apr 2011)
New Revision: 71079
URL: http://svn.boost.org/trac/boost/changeset/71079

Log:
Fix #5404 and #5434. Add make_preferred_tests. Add comment cautioning for Windows class path relational operators when difference between slash and backslash is significant.
Text files modified:
   trunk/libs/filesystem/v3/src/path.cpp | 6 +++---
   trunk/libs/filesystem/v3/test/path_test.cpp | 40 +++++++++++++++++++++++++++++++++++-----
   2 files changed, 38 insertions(+), 8 deletions(-)

Modified: trunk/libs/filesystem/v3/src/path.cpp
==============================================================================
--- trunk/libs/filesystem/v3/src/path.cpp (original)
+++ trunk/libs/filesystem/v3/src/path.cpp 2011-04-07 10:34:33 EDT (Thu, 07 Apr 2011)
@@ -159,14 +159,14 @@
   const std::string path::generic_string(const codecvt_type& cvt) const
   {
     path tmp(*this);
- tmp.make_preferred();
+ std::replace(tmp.m_pathname.begin(), tmp.m_pathname.end(), L'\\', L'/');
     return tmp.string(cvt);
   }
 
   const std::wstring path::generic_wstring() const
   {
     path tmp(*this);
- tmp.make_preferred();
+ std::replace(tmp.m_pathname.begin(), tmp.m_pathname.end(), L'\\', L'/');
     return tmp.wstring();
   }
 
@@ -207,7 +207,7 @@
 # ifdef BOOST_WINDOWS_API
   path & path::make_preferred()
   {
- std::replace(m_pathname.begin(), m_pathname.end(), L'\\', L'/');
+ std::replace(m_pathname.begin(), m_pathname.end(), L'/', L'\\');
     return *this;
   }
 # endif

Modified: trunk/libs/filesystem/v3/test/path_test.cpp
==============================================================================
--- trunk/libs/filesystem/v3/test/path_test.cpp (original)
+++ trunk/libs/filesystem/v3/test/path_test.cpp 2011-04-07 10:34:33 EDT (Thu, 07 Apr 2011)
@@ -13,6 +13,17 @@
 // on basename(), extension(), and change_extension() tests from the original
 // convenience_test.cpp by Vladimir Prus.
 
+//--------------------------------------------------------------------------------------//
+// //
+// Caution //
+// //
+// The class path relational operators (==, !=, <, etc.) on Windows treat slash and //
+// backslash as equal. Thus any tests on Windows where the difference between slash //
+// and backslash is significant should compare based on native observers rather than //
+// directly on path objects. //
+// //
+//--------------------------------------------------------------------------------------//
+
 #define BOOST_FILESYSTEM_VERSION 3
 
 #include <boost/config.hpp>
@@ -415,11 +426,11 @@
     if (platform == "Windows")
     {
       BOOST_TEST(path("foo\\bar") == "foo/bar");
- BOOST_TEST((b / a).string() == "b\\a");
- BOOST_TEST((bs / a).string() == "b\\a");
- BOOST_TEST((bcs / a).string() == "b\\a");
- BOOST_TEST((b / as).string() == "b\\a");
- BOOST_TEST((b / acs).string() == "b\\a");
+ BOOST_TEST((b / a).native() == path("b\\a").native());
+ BOOST_TEST((bs / a).native() == path("b\\a").native());
+ BOOST_TEST((bcs / a).native() == path("b\\a").native());
+ BOOST_TEST((b / as).native() == path("b\\a").native());
+ BOOST_TEST((b / acs).native() == path("b\\a").native());
       PATH_CHECK(path("a") / "b", "a\\b");
       PATH_CHECK(path("..") / "", "..");
       PATH_CHECK(path("foo") / path("bar"), "foo\\bar"); // path arg
@@ -1567,6 +1578,24 @@
     BOOST_TEST(path("a/b").replace_extension(".c") == "a/b.c");
     BOOST_TEST_EQ(path("a.txt/b").replace_extension(".c"), "a.txt/b.c"); // ticket 4702
   }
+
+ // make_preferred_tests ------------------------------------------------------------//
+
+ void make_preferred_tests()
+ {
+ std::cout << "make_preferred_tests..." << std::endl;
+
+ if (platform == "Windows")
+ {
+ BOOST_TEST(path("//abc\\def/ghi").make_preferred().native()
+ == path("\\\\abc\\def\\ghi").native());
+ }
+ else
+ {
+ BOOST_TEST(path("//abc\\def/ghi").make_preferred().native()
+ == path("//abc\\def/ghi").native());
+ }
+ }
 
 } // unnamed namespace
 
@@ -1605,6 +1634,7 @@
   exception_tests();
   name_function_tests();
   replace_extension_tests();
+ make_preferred_tests();
 
   // verify deprecated names still available
 


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