$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
From: technews_at_[hidden]
Date: 2007-12-23 21:20:17
Author: turkanis
Date: 2007-12-23 21:20:17 EST (Sun, 23 Dec 2007)
New Revision: 42268
URL: http://svn.boost.org/trac/boost/changeset/42268
Log:
fixed #823 and added a test case
Text files modified: 
   branches/iostreams_dev/boost/iostreams/device/file_descriptor.hpp   |    14 +++++                                   
   branches/iostreams_dev/libs/iostreams/test/detail/verification.hpp  |    91 ++++++++++++++++++++++++++++++++++++++- 
   branches/iostreams_dev/libs/iostreams/test/file_descriptor_test.cpp |    24 ++++++++++                              
   3 files changed, 123 insertions(+), 6 deletions(-)
Modified: branches/iostreams_dev/boost/iostreams/device/file_descriptor.hpp
==============================================================================
--- branches/iostreams_dev/boost/iostreams/device/file_descriptor.hpp	(original)
+++ branches/iostreams_dev/boost/iostreams/device/file_descriptor.hpp	2007-12-23 21:20:17 EST (Sun, 23 Dec 2007)
@@ -102,8 +102,13 @@
     typedef void*  handle_type;
 #endif
     typedef char   char_type;
-    struct category : public source_tag, closable_tag { };
+    struct category
+      : input_seekable,
+        device_tag,
+        closable_tag
+      { };
     using file_descriptor::read;
+    using file_descriptor::seek;
     using file_descriptor::open;
     using file_descriptor::is_open;
     using file_descriptor::close;
@@ -128,8 +133,13 @@
     typedef void*  handle_type;
 #endif
     typedef char   char_type;
-    struct category : public sink_tag, closable_tag { };
+    struct category
+      : output_seekable,
+        device_tag,
+        closable_tag
+      { };
     using file_descriptor::write;
+    using file_descriptor::seek;
     using file_descriptor::open;
     using file_descriptor::is_open;
     using file_descriptor::close;
Modified: branches/iostreams_dev/libs/iostreams/test/detail/verification.hpp
==============================================================================
--- branches/iostreams_dev/libs/iostreams/test/detail/verification.hpp	(original)
+++ branches/iostreams_dev/libs/iostreams/test/detail/verification.hpp	2007-12-23 21:20:17 EST (Sun, 23 Dec 2007)
@@ -8,6 +8,7 @@
 #ifndef BOOST_IOSTREAMS_TEST_VERIFICATION_HPP_INCLUDED
 #define BOOST_IOSTREAMS_TEST_VERIFICATION_HPP_INCLUDED
 
+#include <iostream>
 #include <exception>
 #include <string>
 #include <string.h>
@@ -137,7 +138,7 @@
     // Test seeking with ios::beg
     std::streamoff off = 0;
     io.seekp(0, BOOST_IOS::beg);
-    for (i = 0; i < data_reps; ++i, off+= chunk_size) {
+    for (i = 0; i < data_reps; ++i, off += chunk_size) {
         int j;
         for (j = 0; j < chunk_size; ++j)
             io.put(narrow_data()[j]);
@@ -173,7 +174,7 @@
 {
     int i;  // old 'for' scope workaround.
 
-    // Test seeking with ios::cu
+    // Test seeking with ios::cur
     for (i = 0; i < data_reps; ++i) {
         io.write(narrow_data(), chunk_size);
         io.seekp(-chunk_size, BOOST_IOS::cur);
@@ -188,7 +189,7 @@
     // Test seeking with ios::beg
     std::streamoff off = 0;
     io.seekp(0, BOOST_IOS::beg);
-    for (i = 0; i < data_reps; ++i) {
+    for (i = 0; i < data_reps; ++i, off += chunk_size) {
         io.write(narrow_data(), chunk_size);
         io.seekp(off, BOOST_IOS::beg);
         char buf[chunk_size];
@@ -203,7 +204,7 @@
     io.seekp(0, BOOST_IOS::end);
     off = io.tellp();
     io.seekp(-off, BOOST_IOS::end);
-    for (i = 0; i < data_reps; ++i) {
+    for (i = 0; i < data_reps; ++i, off -= chunk_size) {
         io.write(narrow_data(), chunk_size);
         io.seekp(-off, BOOST_IOS::end);
         char buf[chunk_size];
@@ -216,6 +217,88 @@
     return true;
 }
 
+bool test_input_seekable(std::istream& io)
+{
+    int i;  // old 'for' scope workaround.
+
+    // Test seeking with ios::cur
+    for (i = 0; i < data_reps; ++i) {
+        for (int j = 0; j < chunk_size; ++j)
+            if (io.get() != narrow_data()[j])
+               return false;
+        io.seekg(-chunk_size, BOOST_IOS::cur);
+        char buf[chunk_size];
+        io.read(buf, chunk_size);
+        if (strncmp(buf, narrow_data(), chunk_size) != 0)
+            return false;
+    }
+
+    // Test seeking with ios::beg
+    std::streamoff off = 0;
+    io.seekg(0, BOOST_IOS::beg);
+    for (i = 0; i < data_reps; ++i, off += chunk_size) {
+        for (int j = 0; j < chunk_size; ++j)
+            if (io.get() != narrow_data()[j])
+               return false;
+        io.seekg(off, BOOST_IOS::beg);
+        char buf[chunk_size];
+        io.read(buf, chunk_size);
+        if (strncmp(buf, narrow_data(), chunk_size) != 0)
+            return false;
+    }
+    
+    // Test seeking with ios::end
+    io.seekg(0, BOOST_IOS::end);
+    off = io.tellg();
+    io.seekg(-off, BOOST_IOS::end);
+    for (i = 0; i < data_reps; ++i, off -= chunk_size) {
+        for (int j = 0; j < chunk_size; ++j)
+            if (io.get() != narrow_data()[j])
+               return false;
+        io.seekg(-off, BOOST_IOS::end);
+        char buf[chunk_size];
+        io.read(buf, chunk_size);
+        if (strncmp(buf, narrow_data(), chunk_size) != 0)
+            return false;
+    }
+    return true;
+}
+
+bool test_output_seekable(std::ostream& io)
+{
+    int i;  // old 'for' scope workaround.
+
+    // Test seeking with ios::cur
+    for (i = 0; i < data_reps; ++i) {
+        for (int j = 0; j < chunk_size; ++j)
+            io.put(narrow_data()[j]);
+        io.seekp(-chunk_size, BOOST_IOS::cur);
+        io.write(narrow_data(), chunk_size);
+    }
+
+    // Test seeking with ios::beg
+    std::streamoff off = 0;
+    io.seekp(0, BOOST_IOS::beg);
+    for (i = 0; i < data_reps; ++i, off += chunk_size) {
+        for (int j = 0; j < chunk_size; ++j)
+            io.put(narrow_data()[j]);
+        io.seekp(off, BOOST_IOS::beg);
+        io.write(narrow_data(), chunk_size);
+    }
+    
+    // Test seeking with ios::end
+    io.seekp(0, BOOST_IOS::end);
+    off = io.tellp();
+    io.seekp(-off, BOOST_IOS::end);
+    for (i = 0; i < data_reps; ++i, off -= chunk_size) {
+        for (int j = 0; j < chunk_size; ++j)
+            io.put(narrow_data()[j]);
+        io.seekp(-off, BOOST_IOS::end);
+        io.write(narrow_data(), chunk_size);
+    }
+    return true;
+}
+
 } } } // End namespaces test, iostreams, boost.
 
 #if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
Modified: branches/iostreams_dev/libs/iostreams/test/file_descriptor_test.cpp
==============================================================================
--- branches/iostreams_dev/libs/iostreams/test/file_descriptor_test.cpp	(original)
+++ branches/iostreams_dev/libs/iostreams/test/file_descriptor_test.cpp	2007-12-23 21:20:17 EST (Sun, 23 Dec 2007)
@@ -142,6 +142,30 @@
         BOOST_CHECK(!file.is_open());
     }
 
+    //--Test seeking with file_descriptor_source and file_descriptor_sink-----//
+
+    {
+        file_descriptor_sink  sink(test1.name());
+        fdostream             out(sink);
+        BOOST_CHECK(out->is_open());
+        BOOST_CHECK_MESSAGE(
+            test_output_seekable(out),
+            "failed seeking within a file_descriptor_sink"
+        );
+        out->close();
+        BOOST_CHECK(!out->is_open());
+
+        file_descriptor_source  source(test1.name());
+        fdistream               in(source);
+        BOOST_CHECK(in->is_open());
+        BOOST_CHECK_MESSAGE(
+            test_input_seekable(in),
+            "failed seeking within a file_descriptor_source"
+        );
+        in->close();
+        BOOST_CHECK(!in->is_open());
+    }
+
     //--------------Test file_descriptor--------------------------------------//
 
     {