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-391-g5


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. 0_9-391-g5d7ee85
Date: Mon, 09 Nov 2009 10:40:01 +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  5d7ee855ce1a420c81922e9d6c53ed479fcdef5c (commit)
       via  ecf366a65e3c2c49a9731bb99b82d70e72aecfb2 (commit)
      from  2097cd7f32fbc307be958b8e3b154200fdbf230c (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 5d7ee855ce1a420c81922e9d6c53ed479fcdef5c
Author: Giuseppe Scrivano <address@hidden>
Date:   Mon Nov 9 11:38:37 2009 +0100

    Refactoring: divide a big test case in smaller tests.

diff --git a/myserver/tests/test_file.cpp b/myserver/tests/test_file.cpp
index 716191c..4a3fb43 100644
--- a/myserver/tests/test_file.cpp
+++ b/myserver/tests/test_file.cpp
@@ -1,19 +1,19 @@
 /*
- 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/>.
- */
+  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 <cppunit/CompilerOutputter.h>
@@ -37,14 +37,23 @@ class TestFile : public CppUnit::TestFixture
   File *tfile;
   string fname;
 
-  CPPUNIT_TEST_SUITE ( TestFile );
-
-  CPPUNIT_TEST ( testCreateTemporaryFile );
-  CPPUNIT_TEST ( testOnFile );
-  CPPUNIT_TEST ( testTruncate );
+  CPPUNIT_TEST_SUITE (TestFile);
 
+  CPPUNIT_TEST (testCreateTemporaryFile);
+  CPPUNIT_TEST (testOnFile);
+  CPPUNIT_TEST (testTruncate);
+  CPPUNIT_TEST (testCreationTime);
+  CPPUNIT_TEST (testLastAccessTime);
+  CPPUNIT_TEST (testLastModTime);
+  CPPUNIT_TEST (testSeek);
   CPPUNIT_TEST_SUITE_END ();
 
+  int openHelper ()
+  {
+   return  tfile->openFile (fname.c_str (), File::WRITE
+                            | File::READ
+                            | File::FILE_CREATE_ALWAYS);
+  }
 public:
   void setUp ()
   {
@@ -66,40 +75,56 @@ public:
 
   void testOnFile ()
   {
-    char buf[] = { 'H', 'e', 'l', 'l', 'o', ',', ' ', 'm', 'y', 'W', 'o', 'r', 
'l', 'd', 0 };
-    const int bufLen = sizeof (buf) / sizeof (char);
+    const char *buf = "HELLO myWORLD";
+    char readbuf[512];
+    size_t bufLen = strlen (buf);
     u_long nbw;
     u_long nbr;
 
-    CPPUNIT_ASSERT_EQUAL (tfile->openFile (fname.c_str (), File::WRITE |
-                                           File::READ |
-                                           File::FILE_CREATE_ALWAYS), 0);
+    CPPUNIT_ASSERT_EQUAL (openHelper (), 0);
 
     CPPUNIT_ASSERT_EQUAL (tfile->writeToFile (buf, bufLen, &nbw), 0);
 
-    memset (buf, 0, bufLen);
+    memset (readbuf, 0, bufLen);
 
     CPPUNIT_ASSERT_EQUAL (tfile->seek (0), 0);
 
-    CPPUNIT_ASSERT_EQUAL (tfile->read (buf, bufLen, &nbr), 0);
+    CPPUNIT_ASSERT_EQUAL (tfile->read (readbuf, bufLen, &nbr), 0);
 
     CPPUNIT_ASSERT (nbr > 0);
 
-    CPPUNIT_ASSERT (tfile->getCreationTime () != -1);
-
-    CPPUNIT_ASSERT (tfile->getLastAccTime () != -1);
+    for (size_t i = 0; i < bufLen; i++)
+      CPPUNIT_ASSERT_EQUAL (buf[i], readbuf[i]);
 
-    CPPUNIT_ASSERT (tfile->getLastModTime () != -1);
+    CPPUNIT_ASSERT_EQUAL (tfile->getFileSize (), nbr);
+    CPPUNIT_ASSERT_EQUAL (tfile->close (), 0);
 
-    CPPUNIT_ASSERT (tfile->getFileSize () != -1);
+    FilesUtility::deleteFile (fname.c_str ());
+  }
 
-    CPPUNIT_ASSERT_EQUAL (tfile->seek (1), 0);
+  void testCreationTime ()
+  {
+    CPPUNIT_ASSERT_EQUAL (openHelper (), 0);
+    CPPUNIT_ASSERT (tfile->getCreationTime () != -1);
+  }
 
-    CPPUNIT_ASSERT_EQUAL (tfile->getSeek (), 1ul);
+  void testLastAccessTime ()
+  {
+    CPPUNIT_ASSERT_EQUAL (openHelper (), 0);
+    CPPUNIT_ASSERT (tfile->getCreationTime () != -1);
+  }
 
-    CPPUNIT_ASSERT_EQUAL (tfile->close (), 0);
+  void testLastModTime ()
+  {
+    CPPUNIT_ASSERT_EQUAL (openHelper (), 0);
+    CPPUNIT_ASSERT (tfile->getCreationTime () != -1);
+  }
 
-    FilesUtility::deleteFile (fname.c_str ());
+  void testSeek ()
+  {
+    CPPUNIT_ASSERT_EQUAL (openHelper (), 0);
+    CPPUNIT_ASSERT_EQUAL (tfile->seek (1), 0);
+    CPPUNIT_ASSERT_EQUAL (tfile->getSeek (), 1ul);
   }
 
   void testTruncate ()
@@ -108,9 +133,7 @@ public:
 
     CPPUNIT_ASSERT_EQUAL (FilesUtility::deleteFile (fname.c_str ()), 0);
 
-    CPPUNIT_ASSERT_EQUAL (tfile->openFile (fname.c_str (), File::WRITE |
-                                           File::READ |
-                                           File::FILE_CREATE_ALWAYS), 0);
+    CPPUNIT_ASSERT_EQUAL (openHelper (), 0);
 
     CPPUNIT_ASSERT_EQUAL (tfile->getFileSize (), 0ul);
 



commit ecf366a65e3c2c49a9731bb99b82d70e72aecfb2
Author: Giuseppe Scrivano <address@hidden>
Date:   Mon Nov 9 11:22:34 2009 +0100

    Add new class MemBufFile and relative tests.
    
    It wraps the File interface around a MemBuf object.

diff --git a/myserver/include/base/files_cache/Makefile.am 
b/myserver/include/base/files_cache/Makefile.am
index fb3abf4..9b53545 100644
--- a/myserver/include/base/files_cache/Makefile.am
+++ b/myserver/include/base/files_cache/Makefile.am
@@ -1,4 +1,5 @@
 files_cacheincludedir=$(includedir)/myserver/include/base/files_cache
-files_cacheinclude_HEADERS = cached_file_buffer.h cached_file_factory.h 
cached_file.h
+files_cacheinclude_HEADERS = cached_file_buffer.h cached_file_factory.h \
+                            cached_file.h membuf_file.h
 SUBDIRS =
 
diff --git a/myserver/include/base/files_cache/cached_file.h 
b/myserver/include/base/files_cache/cached_file.h
index 8530d02..596e6e0 100644
--- a/myserver/include/base/files_cache/cached_file.h
+++ b/myserver/include/base/files_cache/cached_file.h
@@ -1,19 +1,19 @@
 /* -*- mode: c++ -*- */
 /*
-MyServer
-Copyright (C) 2006, 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/>.
+  MyServer
+  Copyright (C) 2006, 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/>.
 */
 
 #ifndef CACHED_FILE_H
@@ -30,29 +30,29 @@ using namespace std;
 class CachedFile : public File
 {
 public:
-       CachedFile (CachedFileBuffer* buffer);
-       virtual Handle getHandle ();
-       virtual int setHandle (Handle);
-       virtual int read (char* ,u_long ,u_long* );
-       virtual int writeToFile (const char* ,u_long ,u_long* );
-       virtual int createTemporaryFile (const char* );
-
-       virtual int openFile (const char*, u_long );
+  CachedFile (CachedFileBuffer* buffer);
+  virtual Handle getHandle ();
+  virtual int setHandle (Handle);
+  virtual int read (char* ,u_long ,u_long* );
+  virtual int writeToFile (const char* ,u_long ,u_long* );
+  virtual int createTemporaryFile (const char* );
+
+  virtual int openFile (const char*, u_long );
   virtual int openFile (string const &file, u_long opt)
-    {return openFile (file.c_str (), opt);}
+  {return openFile (file.c_str (), opt);}
 
-       virtual u_long getFileSize ();
-       virtual int seek (u_long);
+  virtual u_long getFileSize ();
+  virtual int seek (u_long);
 
-       virtual int operator =(CachedFile);
-       virtual int close ();
+  virtual int operator =(CachedFile);
+  virtual int close ();
 
   virtual int fastCopyToSocket (Socket *dest, u_long offset,
                                 MemBuf *buf, u_long *nbw);
 
   virtual int write (const char* buffer, u_long len, u_long *nbw);
 protected:
-       u_long fseek;
-       CachedFileBuffer* buffer;
+  u_long fseek;
+  CachedFileBuffer* buffer;
 };
 #endif
diff --git a/myserver/include/base/files_cache/membuf_file.h 
b/myserver/include/base/files_cache/membuf_file.h
new file mode 100644
index 0000000..6fc4a27
--- /dev/null
+++ b/myserver/include/base/files_cache/membuf_file.h
@@ -0,0 +1,59 @@
+/* -*- mode: c++ -*- */
+/*
+  MyServer
+  Copyright (C) 2006, 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/>.
+*/
+
+#ifndef MEMBUF_FILE_H
+# define MEMBUF_FILE_H
+
+# include "stdafx.h"
+# include <include/filter/stream.h>
+# include <include/base/file/file.h>
+# include <string>
+
+# include <include/base/mem_buff/mem_buff.h>
+
+using namespace std;
+
+class MemBufFile : public File
+{
+public:
+  MemBufFile (MemBuf* buffer);
+  virtual Handle getHandle ();
+  virtual int setHandle (Handle);
+  virtual int read (char* ,u_long ,u_long*);
+  virtual int writeToFile (const char* ,u_long ,u_long*);
+  virtual int createTemporaryFile (const char*);
+
+  virtual int openFile (const char*, u_long);
+  virtual int openFile (string const &file, u_long opt)
+  {return openFile (file.c_str (), opt);}
+
+  virtual u_long getFileSize ();
+  virtual int seek (u_long);
+
+  virtual int close ();
+
+  virtual int fastCopyToSocket (Socket *dest, u_long offset,
+                                MemBuf *buf, u_long *nbw);
+
+  virtual u_long getSeek ();
+  virtual int write (const char* buffer, u_long len, u_long *nbw);
+protected:
+  u_long fseek;
+  MemBuf *buffer;
+};
+#endif
diff --git a/myserver/src/base/files_cache/Makefile.am 
b/myserver/src/base/files_cache/Makefile.am
index 0e78be2..10e9526 100644
--- a/myserver/src/base/files_cache/Makefile.am
+++ b/myserver/src/base/files_cache/Makefile.am
@@ -1,5 +1,6 @@
 lib_LIBRARIES = libfiles_cache.a
-libfiles_cache_a_SOURCES = cached_file_buffer.cpp cached_file.cpp 
cached_file_factory.cpp
+libfiles_cache_a_SOURCES = cached_file_buffer.cpp cached_file.cpp \
+                          cached_file_factory.cpp membuf_file.cpp
 SUBDIRS =
 AM_CPPFLAGS = $(all_includes)
 
diff --git a/myserver/src/base/files_cache/cached_file.cpp 
b/myserver/src/base/files_cache/cached_file.cpp
index c640298..70fa57f 100644
--- a/myserver/src/base/files_cache/cached_file.cpp
+++ b/myserver/src/base/files_cache/cached_file.cpp
@@ -1,18 +1,18 @@
 /*
-MyServer
-Copyright (C) 2006, 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/>.
+  MyServer
+  Copyright (C) 2006, 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/>.
 */
 
 
diff --git a/myserver/src/base/files_cache/membuf_file.cpp 
b/myserver/src/base/files_cache/membuf_file.cpp
new file mode 100644
index 0000000..560ac39
--- /dev/null
+++ b/myserver/src/base/files_cache/membuf_file.cpp
@@ -0,0 +1,165 @@
+/*
+  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/>.
+*/
+
+
+#include "stdafx.h"
+#include <include/base/utility.h>
+#include <include/base/string/stringutils.h>
+#include <include/base/file/files_utility.h>
+#include <include/base/files_cache/membuf_file.h>
+
+#ifndef WIN32
+extern "C"
+{
+# include <fcntl.h>
+# include <unistd.h>
+# include <sys/types.h>
+# include <sys/stat.h>
+# include <errno.h>
+# include <stdio.h>
+# include <fcntl.h>
+# include <stdlib.h>
+# include <string.h>
+# include <math.h>
+# include <time.h>
+}
+#endif
+
+#include <string>
+#include <sstream>
+
+using namespace std;
+
+MemBufFile::MemBufFile (MemBuf* buffer)
+{
+  this->buffer = buffer;
+  fseek = 0;
+}
+
+/*!
+  \see File#getHandle.
+*/
+Handle MemBufFile::getHandle ()
+{
+  return (Handle) -1;
+}
+
+/*!
+  \see File#setHandle.
+*/
+int MemBufFile::setHandle (Handle)
+{
+  return -1;
+}
+
+/*!
+  \see File#read.
+*/
+int MemBufFile::read (char *data, u_long len, u_long *nbr)
+{
+  const char *buf = buffer->getBuffer ();
+
+  *nbr = min (len, buffer->getLength () - fseek);
+  if (*nbr)
+    memcpy (data, buf, *nbr);
+
+  fseek += *nbr;
+
+  return 0;
+}
+
+/*!
+  \see File#writeToFile.
+*/
+int MemBufFile::writeToFile (const char *data, u_long len, u_long *nbw)
+{
+  u_long initialSize = buffer->getLength ();
+  buffer->addBuffer (data, len);
+
+  fseek += *nbw = buffer->getLength () - initialSize;
+  return 0;
+}
+
+/*!
+  \see File#createTemporaryFile.
+*/
+int MemBufFile::createTemporaryFile (const char*)
+{
+  return -1;
+}
+
+
+/*!
+  \see File#openFile.
+*/
+int MemBufFile::openFile (const char*, u_long)
+{
+  return -1;
+}
+
+/*!
+  \see File#getFileSize.
+*/
+u_long MemBufFile::getFileSize ()
+{
+  return buffer->getLength ();
+}
+
+/*!
+  \see File#seek.
+*/
+int MemBufFile::seek (u_long newSeek)
+{
+  fseek = newSeek;
+  return 0;
+}
+
+/*!
+  \see File#close.
+*/
+int MemBufFile::close ()
+{
+  return 0;
+}
+
+/*!
+  \see File#fastCopyToSocket.
+*/
+int MemBufFile::fastCopyToSocket (Socket *dest, u_long offset,
+                                  MemBuf *buf, u_long *nbw)
+{
+  const char *data = buffer->getBuffer ();
+  u_long toWrite = buffer->getLength () - offset;
+
+  return dest->write (data, toWrite, nbw);
+}
+
+/*!
+  \see File#write.
+*/
+int MemBufFile::write (const char* buffer, u_long len, u_long *nbw)
+{
+  return writeToFile (buffer, len, nbw);
+}
+
+/*!
+  \see File#getSeek.
+*/
+u_long MemBufFile::getSeek ()
+{
+  return fseek;
+}
diff --git a/myserver/tests/Makefile.am b/myserver/tests/Makefile.am
index da07db4..50c05a3 100644
--- a/myserver/tests/Makefile.am
+++ b/myserver/tests/Makefile.am
@@ -1,26 +1,65 @@
-# makefile for MyServer tests suite driver program
-#
-
 bin_PROGRAMS = tests_suite
-tests_suite_SOURCES = main.cpp test_auth_domain.cpp test_auth_method.cpp \
-  test_base64.cpp test_bitvec.cpp test_cached_file_buffer.cpp \
-       test_cached_file.cpp test_cached_file_factory.cpp 
test_crypt_algo_manager.cpp \
-       test_connection.cpp test_connections_scheduler.cpp test_file.cpp \
-       test_file_stream.cpp test_file_stream_creator.cpp 
test_files_utility.cpp \
-       test_filter_chain.cpp test_fork_server.cpp test_ftp.cpp test_gzip.cpp \
-       test_hashmap.cpp test_homedir.cpp test_http_req_security_domain.cpp \
-       test_http_request.cpp test_http_response.cpp test_ip.cpp \
-       test_log_manager.cpp test_log_stream_factory.cpp test_md5.cpp \
-       test_mem_buff.cpp test_mem_stream.cpp test_mime_manager.cpp \
-       test_multicast.cpp test_mutex.cpp test_nodetree.cpp test_pipe.cpp \
-       test_plugin_info.cpp test_read_directory.cpp test_recursive_mutex.cpp \
-       test_regex.cpp test_safetime.cpp test_security_cache.cpp \
-       test_security_domain.cpp test_security_manager.cpp \
-       test_security_token.cpp test_sha1.cpp test_semaphore.cpp test_slab.cpp \
-       test_socket.cpp test_socket_pair.cpp test_socket_stream_creator.cpp \
-       test_ssl_socket.cpp test_thread.cpp test_unix_socket.cpp test_url.cpp \
-       test_utility.cpp test_validator.cpp test_validator_factory.cpp \
-       test_xml.cpp test_xml_main_configuration.cpp test_xml_validator.cpp 
+tests_suite_SOURCES =          main.cpp                                \
+                       test_auth_domain.cpp                    \
+                       test_auth_method.cpp                    \
+                       test_base64.cpp                         \
+                       test_bitvec.cpp                         \
+                       test_cached_file.cpp                    \
+                       test_cached_file_buffer.cpp             \
+                       test_cached_file_factory.cpp            \
+                       test_connection.cpp                     \
+                       test_connections_scheduler.cpp          \
+                       test_crypt_algo_manager.cpp             \
+                       test_file.cpp                           \
+                       test_file_stream.cpp                    \
+                       test_file_stream_creator.cpp            \
+                       test_files_utility.cpp                  \
+                       test_filter_chain.cpp                   \
+                       test_fork_server.cpp                    \
+                       test_ftp.cpp                            \
+                       test_gzip.cpp                           \
+                       test_hashmap.cpp                        \
+                       test_homedir.cpp                        \
+                       test_http_req_security_domain.cpp       \
+                       test_http_request.cpp                   \
+                       test_http_response.cpp                  \
+                       test_ip.cpp                             \
+                       test_log_manager.cpp                    \
+                       test_log_stream_factory.cpp             \
+                       test_md5.cpp                            \
+                       test_mem_buff.cpp                       \
+                       test_mem_stream.cpp                     \
+                       test_membuf_file.cpp                    \
+                       test_mime_manager.cpp                   \
+                       test_multicast.cpp                      \
+                       test_mutex.cpp                          \
+                       test_nodetree.cpp                       \
+                       test_pipe.cpp                           \
+                       test_plugin_info.cpp                    \
+                       test_read_directory.cpp                 \
+                       test_recursive_mutex.cpp                \
+                       test_regex.cpp                          \
+                       test_safetime.cpp                       \
+                       test_security_cache.cpp                 \
+                       test_security_domain.cpp                \
+                       test_security_manager.cpp               \
+                       test_security_token.cpp                 \
+                       test_semaphore.cpp                      \
+                       test_sha1.cpp                           \
+                       test_slab.cpp                           \
+                       test_socket.cpp                         \
+                       test_socket_pair.cpp                    \
+                       test_socket_stream_creator.cpp          \
+                       test_ssl_socket.cpp                     \
+                       test_thread.cpp                         \
+                       test_unix_socket.cpp                    \
+                       test_url.cpp                            \
+                       test_utility.cpp                        \
+                       test_validator.cpp                      \
+                       test_validator_factory.cpp              \
+                       test_xml.cpp                            \
+                       test_xml_main_configuration.cpp         \
+                       test_xml_validator.cpp
 
 tests_suite_LDADD = ../src/libmyserver.a  ../lib/libgnu.a $(CPPUNIT_LDFLAGS) \
        $(PTHREAD_LIB)  $(IDN_LIB) $(XNET_LIB) $(EVENT_LIB) $(DL_LIB) 
$(SSL_LIB) \
diff --git a/myserver/tests/test_membuf_file.cpp 
b/myserver/tests/test_membuf_file.cpp
new file mode 100644
index 0000000..922b721
--- /dev/null
+++ b/myserver/tests/test_membuf_file.cpp
@@ -0,0 +1,129 @@
+/*
+ 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 <cppunit/CompilerOutputter.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+
+#include "../include/base/utility.h"
+#include "../include/base/file/file.h"
+#include "../include/base/file/files_utility.h"
+#include "include/base/files_cache/membuf_file.h"
+
+#include <string.h>
+#include <unistd.h>
+#include <string>
+
+using namespace std;
+
+class TestMembufFile : public CppUnit::TestFixture
+{
+  MemBuf *memBuf;
+  MemBufFile *tfile;
+
+  CPPUNIT_TEST_SUITE ( TestMembufFile );
+  CPPUNIT_TEST (testCreateTemporaryMembufFile);
+  CPPUNIT_TEST (testClose);
+  CPPUNIT_TEST (testOpenFile);
+  CPPUNIT_TEST (testWrite);
+  CPPUNIT_TEST (testRead);
+  CPPUNIT_TEST (testHandle);
+  CPPUNIT_TEST (testSeek);
+  CPPUNIT_TEST_SUITE_END ();
+
+public:
+  void setUp ()
+  {
+    memBuf = new MemBuf ();
+    tfile = new MemBufFile (memBuf);
+  }
+
+  void tearDown ()
+  {
+    delete tfile;
+    delete memBuf;
+  }
+
+  void testHandle ()
+  {
+    Handle handle = (Handle) 1;
+    CPPUNIT_ASSERT_EQUAL (tfile->getHandle (), -1);
+    CPPUNIT_ASSERT_EQUAL (tfile->setHandle (handle), -1);
+    CPPUNIT_ASSERT_EQUAL (tfile->getHandle (), -1);
+  }
+
+  void testCreateTemporaryMembufFile ()
+  {
+    CPPUNIT_ASSERT_EQUAL (tfile->createTemporaryFile ("foo.dat"), -1);
+  }
+
+  void testClose ()
+  {
+    CPPUNIT_ASSERT_EQUAL (tfile->close (), 0);
+  }
+
+  void testOpenFile ()
+  {
+    const char *file = "tmp.dat";
+    CPPUNIT_ASSERT_EQUAL (tfile->openFile (file, File::WRITE
+                                           | File::READ
+                                           | File::FILE_CREATE_ALWAYS), -1);
+  }
+
+  void testWrite ()
+  {
+    const char *data = "hello dudes";
+    u_long len = strlen (data);
+    u_long nbw;
+
+    CPPUNIT_ASSERT_EQUAL (tfile->getSeek (), 0UL);
+    CPPUNIT_ASSERT_EQUAL (tfile->write (data, len, &nbw), 0);
+    CPPUNIT_ASSERT_EQUAL (len, nbw);
+    CPPUNIT_ASSERT_EQUAL (tfile->getSeek (), nbw);
+  }
+
+  void testRead ()
+  {
+    char buffer[512];
+    const char *data = "hello dudes";
+    u_long len = strlen (data);
+    u_long nbw, nbr;
+
+    tfile->read (buffer, len, &nbr);
+    CPPUNIT_ASSERT_EQUAL (nbr, 0UL);
+    CPPUNIT_ASSERT_EQUAL (tfile->write (data, len, &nbw), 0);
+    CPPUNIT_ASSERT_EQUAL (tfile->getSeek (), nbw);
+
+    CPPUNIT_ASSERT_EQUAL (tfile->seek (0), 0);
+    CPPUNIT_ASSERT_EQUAL (tfile->read (buffer, 512, &nbr), 0);
+    CPPUNIT_ASSERT_EQUAL (nbr, nbw);
+  }
+
+  void testSeek ()
+  {
+    u_long seek = 12L;
+    CPPUNIT_ASSERT_EQUAL (tfile->getSeek (), 0UL);
+    CPPUNIT_ASSERT_EQUAL (tfile->seek (seek), 0);
+    CPPUNIT_ASSERT_EQUAL (tfile->getSeek (), seek);
+  }
+
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION (TestMembufFile);

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

Summary of changes:
 myserver/include/base/files_cache/Makefile.am   |    3 +-
 myserver/include/base/files_cache/cached_file.h |   58 ++++----
 myserver/include/base/files_cache/membuf_file.h |   59 ++++++++
 myserver/src/base/files_cache/Makefile.am       |    3 +-
 myserver/src/base/files_cache/cached_file.cpp   |   28 ++--
 myserver/src/base/files_cache/membuf_file.cpp   |  165 +++++++++++++++++++++++
 myserver/tests/Makefile.am                      |   83 +++++++++---
 myserver/tests/test_file.cpp                    |  101 +++++++++------
 myserver/tests/test_membuf_file.cpp             |  129 ++++++++++++++++++
 9 files changed, 523 insertions(+), 106 deletions(-)
 create mode 100644 myserver/include/base/files_cache/membuf_file.h
 create mode 100644 myserver/src/base/files_cache/membuf_file.cpp
 create mode 100644 myserver/tests/test_membuf_file.cpp


hooks/post-receive
-- 
GNU MyServer




reply via email to

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