Utils: Removed ErrnoException and implemented generic Exception base-class
[senf.git] / Socket / FileHandle.test.cc
index 262bf0c..6835f15 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 //
 // Copyright (C) 2006
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
-//     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+//     Stefan Bund <g0dil@berlios.de>
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
@@ -31,7 +31,7 @@
 #include <unistd.h>
 #include "FileHandle.hh"
 
-#include <boost/test/auto_unit_test.hpp>
+#include "../Utils/auto_unit_test.hh"
 #include <boost/test/test_tools.hpp>
 
 #define prefix_
@@ -41,16 +41,17 @@ namespace {
     class FHandle : public senf::FileHandle
     {
     public:
-        FHandle(int fd=-1)
+        FHandle() {}
+        FHandle(int fd)
             : senf::FileHandle(std::auto_ptr<senf::FileBody>(
                                           new senf::FileBody(fd))) {}
-        FHandle(std::string name)
+        FHandle(std::string const & name)
             : senf::FileHandle(std::auto_ptr<senf::FileBody>(
                                           new senf::FileBody()))
             {
                 int rv = ::open(name.c_str(),O_RDWR|O_NONBLOCK) ;
                 if (rv<0)
-                    throw senf::SystemException(errno);
+                    throw senf::SystemException();
                 fd(rv);
             }
     };
@@ -66,7 +67,9 @@ BOOST_AUTO_UNIT_TEST(fileHandle)
             BOOST_CHECK(fh);
             BOOST_CHECK(!!fh);
 
-            FHandle fh2(fh);
+            FHandle fh2;
+            BOOST_CHECK( ! fh2.valid() );
+            fh2 = fh;
             BOOST_CHECK_EQUAL(fh.fd(), fh2.fd());
 
             BOOST_CHECK(fh.writeable());
@@ -94,6 +97,7 @@ BOOST_AUTO_UNIT_TEST(fileHandle)
             if (fcntl(fds[1],F_SETFL,flags|O_NONBLOCK) == -1)
                 BOOST_FAIL(strerror(errno));
             char buffer[1024];
+            ::memset(buffer, 0, sizeof(buffer));
             while (write(fds[1],buffer,1024) == 1024) ;
 
             FHandle fh2(fds[1]);
@@ -115,4 +119,6 @@ BOOST_AUTO_UNIT_TEST(fileHandle)
 // c-file-style: "senf"
 // indent-tabs-mode: nil
 // ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// comment-column: 40
 // End: