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-400-gd


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. 0_9-400-gdc0439e
Date: Tue, 10 Nov 2009 22:37:52 +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  dc0439e55949fd7d4ce8d683562e957bd2d02508 (commit)
      from  510c8b8238b8cb4a2d5ccfbdda0058512d7913d5 (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 dc0439e55949fd7d4ce8d683562e957bd2d02508
Author: Domenico Chierico <address@hidden>
Date:   Tue Nov 10 21:04:08 2009 +0100

    Add a test for the gopher protocol.
    
    A new mock class MemorySocket is used to expose the socket interface.

diff --git a/myserver/tests/Makefile.am b/myserver/tests/Makefile.am
index 50c05a3..f634da8 100644
--- a/myserver/tests/Makefile.am
+++ b/myserver/tests/Makefile.am
@@ -1,5 +1,6 @@
 bin_PROGRAMS = tests_suite
 tests_suite_SOURCES =          main.cpp                                \
+                       memory_socket.h                 \
                        test_auth_domain.cpp                    \
                        test_auth_method.cpp                    \
                        test_base64.cpp                         \
@@ -17,6 +18,7 @@ tests_suite_SOURCES =         main.cpp                        
        \
                        test_filter_chain.cpp                   \
                        test_fork_server.cpp                    \
                        test_ftp.cpp                            \
+                       test_gopher_content.cpp                         \
                        test_gzip.cpp                           \
                        test_hashmap.cpp                        \
                        test_homedir.cpp                        \
@@ -30,6 +32,7 @@ tests_suite_SOURCES =         main.cpp                        
        \
                        test_mem_buff.cpp                       \
                        test_mem_stream.cpp                     \
                        test_membuf_file.cpp                    \
+                       test_mem_socket.cpp                     \
                        test_mime_manager.cpp                   \
                        test_multicast.cpp                      \
                        test_mutex.cpp                          \
diff --git a/myserver/tests/memory_socket.h b/myserver/tests/memory_socket.h
new file mode 100644
index 0000000..54bd531
--- /dev/null
+++ b/myserver/tests/memory_socket.h
@@ -0,0 +1,70 @@
+/*
+  MyServer
+  Copyright (C) 2008, 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/>.
+*/
+
+#include <include/base/socket/socket.h>
+#include <string.h>
+#include <include/base/mem_buff/mem_buff.h>
+
+
+class MemorySocket : public Socket
+{
+public:
+  MemorySocket (){};
+  ~MemorySocket (){};
+
+
+  virtual Handle getHandle () {return (Handle) -1;}
+
+  virtual int connect (MYSERVER_SOCKADDR*, int) {return 0;}
+  virtual int close (){return 0;}
+  virtual int shutdown (int){return 0;}
+  virtual int recv (char*, int, int, u_long){return 0;}
+  virtual int recv (char*, int, int) {return 0;}
+  virtual u_long bytesToRead () {return 0;}
+
+  virtual int dataOnRead (int sec = 0, int usec = 500){return 0;}
+
+  int read (char* buffer, u_long len, u_long *nbr)
+  {
+    return len;
+  }
+
+  int write (const char* buffer, u_long len, u_long *nbw)
+  {
+    interBuff << buffer;
+    return len;
+  }
+
+  int rawSend (const char* buffer, int len, int flags)
+  {
+    interBuff << buffer;
+    return len;
+  }
+
+  int getLength()
+  {
+    return interBuff.getLength();
+  }
+
+  operator const char *()
+  {
+    return interBuff.getBuffer ();
+  }
+
+private:
+  MemBuf interBuff;
+};
diff --git a/myserver/tests/test_gopher_content.cpp 
b/myserver/tests/test_gopher_content.cpp
new file mode 100644
index 0000000..548d8ea
--- /dev/null
+++ b/myserver/tests/test_gopher_content.cpp
@@ -0,0 +1,63 @@
+/*
+  MyServer
+  Copyright (C) 2008, 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/>.
+*/
+
+#include "stdafx.h"
+#include <include/protocol/gopher/gopher_content.h>
+#include "memory_socket.h"
+
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+
+class TestGopherContent : public CppUnit::TestFixture
+{
+  CPPUNIT_TEST_SUITE (TestGopherContent);
+  CPPUNIT_TEST (testGopherImageContent);
+  CPPUNIT_TEST_SUITE_END ();
+  MemorySocket *s;
+
+public:
+  void setUp ()
+  {
+    s = new MemorySocket ();
+    s->setThrottling (0);
+  }
+  void tearDown ()
+  {
+    delete s;
+  }
+
+  void testGopherImageContent ()
+  {
+    string fname = "test.jpg";
+    string path = "root/subdir/gopher";
+    string hostname = "localhost";
+    string port = "70";
+    string element  = "Itest.jpg\troot/subdir/gopher\tlocalhost\t70\t\n";
+    GopherImage i (fname.c_str (), path.c_str (), hostname.c_str (),
+                   port.c_str ());
+    i.toProtocol(s);
+
+    const char *buffer = *s;
+    CPPUNIT_ASSERT_EQUAL (strncmp (element.c_str (), buffer, element.length 
()),
+                          0);
+  }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION (TestGopherContent);
diff --git a/myserver/tests/test_mem_socket.cpp 
b/myserver/tests/test_mem_socket.cpp
new file mode 100644
index 0000000..f15992e
--- /dev/null
+++ b/myserver/tests/test_mem_socket.cpp
@@ -0,0 +1,65 @@
+/*
+  MyServer
+  Copyright (C) 2008, 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/>.
+*/
+
+#include "stdafx.h"
+#include "stdafx.h"
+#include "memory_socket.h"
+
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+/* Ensure the mock memory socket works.  */
+class TestMemorySocket : public CppUnit::TestFixture
+{
+  CPPUNIT_TEST_SUITE (TestMemorySocket);
+  CPPUNIT_TEST (testMemorySocketWrite);
+  CPPUNIT_TEST (testMemorySocketRead);
+  CPPUNIT_TEST_SUITE_END ();
+
+  MemorySocket *s;
+
+public:
+  void setUp ()
+  {
+    s = new MemorySocket ();
+    s->setThrottling (0);
+  }
+  void tearDown ()
+  {
+    delete s;
+  }
+
+  void testMemorySocketWrite ()
+  {
+    string temp = "foo bar foo bar foo bar";
+    s->send (temp.c_str (), temp.length (), 0);
+    const char* buffer = *s;
+    CPPUNIT_ASSERT_EQUAL (strncmp (temp.c_str (), buffer, temp.length ()), 0);
+    CPPUNIT_ASSERT_EQUAL (strncmp (temp.c_str (), buffer, s->getLength ()), 0);
+  }
+
+  void testMemorySocketRead ()
+  {
+    string temp = "foo bar foo bar foo bar";
+    s->send (temp.c_str (), temp.length (), 0);
+    CPPUNIT_ASSERT_EQUAL (strncmp (temp.c_str (), *s, temp.length ()), 0);
+  }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION (TestMemorySocket);

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

Summary of changes:
 myserver/tests/Makefile.am                         |    3 +
 myserver/tests/memory_socket.h                     |   70 ++++++++++++++++++++
 ..._stream_creator.cpp => test_gopher_content.cpp} |   60 +++++++----------
 ...cket_stream_creator.cpp => test_mem_socket.cpp} |   58 +++++++---------
 4 files changed, 123 insertions(+), 68 deletions(-)
 create mode 100644 myserver/tests/memory_socket.h
 copy myserver/tests/{test_socket_stream_creator.cpp => 
test_gopher_content.cpp} (52%)
 copy myserver/tests/{test_socket_stream_creator.cpp => test_mem_socket.cpp} 
(52%)


hooks/post-receive
-- 
GNU MyServer




reply via email to

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