myserver-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myserver-commit] [SCM] GNU MyServer branch, master, updated. 0_9-392-g0


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. 0_9-392-g0230b18
Date: Mon, 09 Nov 2009 11:56:32 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU MyServer".

The branch, master has been updated
       via  0230b189f7ef5e8b8869c756f3648b081a017816 (commit)
      from  5d7ee855ce1a420c81922e9d6c53ed479fcdef5c (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------


commit 0230b189f7ef5e8b8869c756f3648b081a017816
Author: Giuseppe Scrivano <address@hidden>
Date:   Mon Nov 9 12:56:26 2009 +0100

    Add test case for `File::fastCopyToSocket'.

diff --git a/myserver/include/base/socket_pair/socket_pair.h 
b/myserver/include/base/socket_pair/socket_pair.h
index 68d7703..94e5e86 100644
--- a/myserver/include/base/socket_pair/socket_pair.h
+++ b/myserver/include/base/socket_pair/socket_pair.h
@@ -1,19 +1,19 @@
 /* -*- mode: c++ -*- */
 /*
-MyServer
-Copyright (C) 2009 Free Software Foundation, Inc.
-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
-the Free Software Foundation; either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program.  If not, see <http://www.gnu.org/licenses/>.
+  MyServer
+  Copyright (C) 2009 Free Software Foundation, Inc.
+  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
+  the Free Software Foundation; either version 3 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #ifndef SOCKET_PAIR_H
@@ -30,21 +30,21 @@ using namespace std;
 class SocketPair : public Socket
 {
 public:
-       SocketPair ();
-       int create ();
-       SocketHandle getFirstHandle ();
-       SocketHandle getSecondHandle ();
-
-       void inverted (SocketPair&);
-       virtual int close ();
-       void closeFirstHandle ();
-       void closeSecondHandle ();
+  SocketPair ();
+  int create ();
+  SocketHandle getFirstHandle ();
+  SocketHandle getSecondHandle ();
+
+  void inverted (SocketPair&);
+  virtual int close ();
+  void closeFirstHandle ();
+  void closeSecondHandle ();
   void setNonBlocking (bool blocking);
 
   int readHandle (Handle*);
   int writeHandle (Handle);
 
 protected:
-       SocketHandle handles[2];
+  SocketHandle handles[2];
 };
 #endif
diff --git a/myserver/tests/test_socket_pair.cpp 
b/myserver/tests/test_socket_pair.cpp
index fbde66b..fbae256 100644
--- a/myserver/tests/test_socket_pair.cpp
+++ b/myserver/tests/test_socket_pair.cpp
@@ -23,8 +23,13 @@
 #include <cppunit/ui/text/TestRunner.h>
 #include <cppunit/extensions/HelperMacros.h>
 
+#include "../include/base/file/file.h"
+#include "../include/base/file/files_utility.h"
+
 #include <string.h>
 
+using namespace std;
+
 class TestSocketPair : public CppUnit::TestFixture
 {
   CPPUNIT_TEST_SUITE ( TestSocketPair );
@@ -55,6 +60,47 @@ public:
 
     sp.close ();
   }
+  /* FIXME: generalize for other classes that inherit from File.  */
+  void testFastCopyToSocket ()
+  {
+    const u_long bsize = 512UL;
+    SocketPair sp;
+    SocketPair inverted;
+    sp.create ();
+    sp.inverted (inverted);
+
+    char inputBuffer[bsize];
+    char outputBuffer[bsize];
+    File file;
+    string fname;
+    u_long nbw;
+
+    for (int i = 0; i < bsize; i++)
+      {
+        inputBuffer[i] = '\0';
+        outputBuffer[i] = i + 1;
+      }
+
+    FilesUtility::temporaryFileName (0, fname);
+    file.openFile (fname.c_str (), File::WRITE | File::READ
+                   | File::FILE_CREATE_ALWAYS);
+    file.writeToFile (outputBuffer, bsize, &nbw);
+    file.seek (0);
+
+    MemBuf buf;
+    CPPUNIT_ASSERT_EQUAL (file.fastCopyToSocket (&sp, 0, &buf, &nbw), 0);
+    CPPUNIT_ASSERT_EQUAL (nbw, bsize);
+
+    u_long nbr;
+    inverted.read (inputBuffer, bsize, &nbr);
+    CPPUNIT_ASSERT_EQUAL (nbr, bsize);
+
+    for (int i = 0; i < bsize; i++)
+      CPPUNIT_ASSERT_EQUAL (inputBuffer[i], outputBuffer[i]);
+
+    file.close ();
+    sp.close ();
+  }
 
   void testCreateClose ()
   {

-----------------------------------------------------------------------

Summary of changes:
 myserver/include/base/socket_pair/socket_pair.h |   48 +++++++++++-----------
 myserver/tests/test_socket_pair.cpp             |   46 ++++++++++++++++++++++
 2 files changed, 70 insertions(+), 24 deletions(-)


hooks/post-receive
-- 
GNU MyServer




reply via email to

[Prev in Thread] Current Thread [Next in Thread]