stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r709780 - /stdcxx/branches/4.2.x/tests/iostream/27.filebuf.cpp
Date Sat, 01 Nov 2008 21:26:26 GMT
Author: sebor
Date: Sat Nov  1 14:26:25 2008
New Revision: 709780

URL: http://svn.apache.org/viewvc?rev=709780&view=rev
Log:
2008-11-01  Martin Sebor  <sebor@roguewave.com>

	* tests/iostream/27.filebuf.cpp (test_open): Verified that
	the filebuf::open((char*)0) extension doesn't leak file
	descriptors.

Modified:
    stdcxx/branches/4.2.x/tests/iostream/27.filebuf.cpp

Modified: stdcxx/branches/4.2.x/tests/iostream/27.filebuf.cpp
URL: http://svn.apache.org/viewvc/stdcxx/branches/4.2.x/tests/iostream/27.filebuf.cpp?rev=709780&r1=709779&r2=709780&view=diff
==============================================================================
--- stdcxx/branches/4.2.x/tests/iostream/27.filebuf.cpp (original)
+++ stdcxx/branches/4.2.x/tests/iostream/27.filebuf.cpp Sat Nov  1 14:26:25 2008
@@ -870,6 +870,11 @@
         BEGIN_MODE (std::ios::in | iomodes [minx],
                     ", file name = 0 [extension]");
 
+        int fdcount [2];
+        int next_fd [2];
+
+        next_fd [0] = rw_nextfd (fdcount + 0);
+
         // verify that open() succeeds when the first argument
         // is the null pointer (the call creates a temporary
         // file and opens it for reading -- such a file may not
@@ -882,8 +887,27 @@
         rw_assert (fb.is_open (), __FILE__, __LINE__,
                    "basic_filebuf<%s>::is_open()", tname);
 
-        // FIXME: verify that the call to close removes the file
+        // verify that a single file descriptor has been allocated
+        next_fd [1] = rw_nextfd (fdcount + 1);
+
+        rw_assert (   next_fd [0] + 1 == next_fd [1]
+                   && fdcount [0] + 1 == fdcount [1],
+                   __FILE__, __LINE__,
+                   "%d file descriptor leak(s) detected after construction",
+                   fdcount [1] - fdcount [0]);
+
         fb.close ();
+
+        // verify that a single file descriptor has been deallocated
+        next_fd [1] = rw_nextfd (fdcount + 1);
+
+        rw_assert (next_fd [0] == next_fd [1] && fdcount [0] == fdcount [1],
+                   __FILE__, __LINE__,
+                   "%d file descriptor leak(s) detected after close()",
+                   fdcount [1] - fdcount [0]);
+
+        // FIXME: verify that the temporary file has been deleted
+        //        from the file system
     }
 
     //////////////////////////////////////////////////////////////////
@@ -894,6 +918,11 @@
         BEGIN_MODE (std::ios::out | iomodes [minx],
                     ", file name = 0 [extension]");
 
+        int fdcount [2];
+        int next_fd [2];
+
+        next_fd [0] = rw_nextfd (fdcount + 0);
+
         // verify that open() succeeds when the first argument
         // is the null pointer (the call creates a temporary
         // file and opens it for writing)
@@ -904,8 +933,27 @@
         rw_assert (fb.is_open (), __FILE__, __LINE__,
                    "basic_filebuf<%s>::is_open()", tname);
 
-        // FIXME: verify that the call to close removes the file
+        // verify that a single file descriptor has been allocated
+        next_fd [1] = rw_nextfd (fdcount + 1);
+
+        rw_assert (   next_fd [0] + 1 == next_fd [1]
+                   && fdcount [0] + 1 == fdcount [1],
+                   __FILE__, __LINE__,
+                   "%d file descriptor leak(s) detected after construction",
+                   fdcount [1] - fdcount [0]);
+
         fb.close ();
+
+        // verify that a single file descriptor has been deallocated
+        next_fd [1] = rw_nextfd (fdcount + 1);
+
+        rw_assert (next_fd [0] == next_fd [1] && fdcount [0] == fdcount [1],
+                   __FILE__, __LINE__,
+                   "%d file descriptor leak(s) detected after close()",
+                   fdcount [1] - fdcount [0]);
+
+        // FIXME: verify that the temporary file has been deleted
+        //        from the file system
     }
 
     //////////////////////////////////////////////////////////////////
@@ -916,14 +964,38 @@
         BEGIN_MODE (std::ios::in | std::ios::out | iomodes [minx],
                     ", file name = 0 [extension]");
 
+        int fdcount [2];
+        int next_fd [2];
+
+        next_fd [0] = rw_nextfd (fdcount + 0);
+
         Filebuf fb;
         fb.open ((const char*)0, mode);
 
         rw_assert (fb.is_open (), __FILE__, __LINE__,
                    "basic_filebuf<%s>::is_open()", tname);
 
-        // FIXME: verify that the call to close removes the file
+        // verify that a single file descriptor has been allocated
+        next_fd [1] = rw_nextfd (fdcount + 1);
+
+        rw_assert (   next_fd [0] + 1 == next_fd [1]
+                   && fdcount [0] + 1 == fdcount [1],
+                   __FILE__, __LINE__,
+                   "%d file descriptor leak(s) detected after construction",
+                   fdcount [1] - fdcount [0]);
+
         fb.close ();
+
+        // verify that a single file descriptor has been deallocated
+        next_fd [1] = rw_nextfd (fdcount + 1);
+
+        rw_assert (next_fd [0] == next_fd [1] && fdcount [0] == fdcount [1],
+                   __FILE__, __LINE__,
+                   "%d file descriptor leak(s) detected after close()",
+                   fdcount [1] - fdcount [0]);
+
+        // FIXME: verify that the temporary file has been deleted
+        //        from the file system
     }
 
 
@@ -2801,4 +2873,3 @@
                     "",   // no comment
                     run_test, "", 0);
 }
-



Mime
View raw message