myserver-commit
[Top][All Lists]
Advanced

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

[myserver-commit] [3090] Added `File::getSeek ()' function.


From: Giuseppe Scrivano
Subject: [myserver-commit] [3090] Added `File::getSeek ()' function.
Date: Fri, 22 May 2009 20:21:25 +0000

Revision: 3090
          http://svn.sv.gnu.org/viewvc/?view=rev&root=myserver&revision=3090
Author:   gscrivano
Date:     2009-05-22 20:21:23 +0000 (Fri, 22 May 2009)
Log Message:
-----------
Added `File::getSeek ()' function.

Modified Paths:
--------------
    trunk/myserver/include/base/file/file.h
    trunk/myserver/src/base/file/file.cpp
    trunk/myserver/tests/test_file.cpp

Modified: trunk/myserver/include/base/file/file.h
===================================================================
--- trunk/myserver/include/base/file/file.h     2009-05-22 20:21:08 UTC (rev 
3089)
+++ trunk/myserver/include/base/file/file.h     2009-05-22 20:21:23 UTC (rev 
3090)
@@ -1,7 +1,7 @@
 /* -*- mode: c++ -*- */
 /*
 MyServer
-Copyright (C) 2002, 2003, 2004, 2008 Free Software Foundation, Inc.
+Copyright (C) 2002, 2003, 2004, 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
@@ -31,40 +31,41 @@
 class File : public Stream
 {
 public:
-       static const u_long MYSERVER_OPEN_READ;
-       static const u_long MYSERVER_OPEN_WRITE;
-       static const u_long MYSERVER_OPEN_TEMPORARY;
-       static const u_long MYSERVER_OPEN_HIDDEN;
-       static const u_long MYSERVER_OPEN_ALWAYS;
-       static const u_long MYSERVER_OPEN_IFEXISTS;
-       static const u_long MYSERVER_OPEN_APPEND;
-       static const u_long MYSERVER_CREATE_ALWAYS;
-       static const u_long MYSERVER_NO_INHERIT;
+  static const u_long MYSERVER_OPEN_READ;
+  static const u_long MYSERVER_OPEN_WRITE;
+  static const u_long MYSERVER_OPEN_TEMPORARY;
+  static const u_long MYSERVER_OPEN_HIDDEN;
+  static const u_long MYSERVER_OPEN_ALWAYS;
+  static const u_long MYSERVER_OPEN_IFEXISTS;
+  static const u_long MYSERVER_OPEN_APPEND;
+  static const u_long MYSERVER_CREATE_ALWAYS;
+  static const u_long MYSERVER_NO_INHERIT;
 
-       File();
+  File();
   File(char *,int);
-       virtual FileHandle getHandle();
-       virtual int setHandle(FileHandle);
-       virtual int writeToFile(const char* ,u_long ,u_long* );
-       virtual int createTemporaryFile(const char* );
+  virtual FileHandle getHandle();
+  virtual int setHandle(FileHandle);
+  virtual int writeToFile(const char* ,u_long ,u_long* );
+  virtual int createTemporaryFile(const char* );
 
-       virtual int openFile(const char*, u_long );
+  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 u_long getFileSize();
+  virtual int seek (u_long);
+  virtual u_long getSeek ();
 
-       virtual time_t getLastModTime();
-       virtual time_t getCreationTime();
-       virtual time_t getLastAccTime();
-       virtual const char *getFilename();
-       virtual int setFilename(const char*);
+  virtual time_t getLastModTime();
+  virtual time_t getCreationTime();
+  virtual time_t getLastAccTime();
+  virtual const char *getFilename();
+  virtual int setFilename(const char*);
   virtual int setFilename(string const &name)
     {return setFilename(name.c_str());}
 
-       virtual int operator =(File);
-       virtual int close();
+  virtual int operator =(File);
+  virtual int close();
 
   /*! Inherithed from Stream. */
   virtual int read(char* buffer, u_long len, u_long *nbr);
@@ -73,7 +74,7 @@
   virtual int fastCopyToSocket (Socket *dest, u_long offset, 
                                 MemBuf *buf, u_long *nbw);
 protected:
-       FileHandle handle;
-       string filename;
+  FileHandle handle;
+  string filename;
 };
 #endif

Modified: trunk/myserver/src/base/file/file.cpp
===================================================================
--- trunk/myserver/src/base/file/file.cpp       2009-05-22 20:21:08 UTC (rev 
3089)
+++ trunk/myserver/src/base/file/file.cpp       2009-05-22 20:21:23 UTC (rev 
3090)
@@ -406,6 +406,20 @@
 }
 
 /*!
+ * Get the current file pointer position.
+ *
+ *\return The current file pointer position.
+ */
+u_long File::getSeek ()
+{
+#ifdef WIN32
+  return SetFilePointer ((HANDLE)handle, 0, NULL, FILE_CURRENT);
+#else
+  return lseek (handle, 0, SEEK_CUR);
+#endif
+}
+
+/*!
  *Get the time of the last modifify did to the file.
  */
 time_t File::getLastModTime()

Modified: trunk/myserver/tests/test_file.cpp
===================================================================
--- trunk/myserver/tests/test_file.cpp  2009-05-22 20:21:08 UTC (rev 3089)
+++ trunk/myserver/tests/test_file.cpp  2009-05-22 20:21:23 UTC (rev 3090)
@@ -36,63 +36,69 @@
   File *tfile;
   string fname;
   
-  CPPUNIT_TEST_SUITE( TestFile );
+  CPPUNIT_TEST_SUITE ( TestFile );
   
-  CPPUNIT_TEST( testCreateTemporaryFile );
-  CPPUNIT_TEST( testOnFile );
+  CPPUNIT_TEST ( testCreateTemporaryFile );
+  CPPUNIT_TEST ( testOnFile );
   
-  CPPUNIT_TEST_SUITE_END();
+  CPPUNIT_TEST_SUITE_END ();
 
 public:
-  void setUp ( )
+  void setUp ()
   {
     setcwdBuffer ();/* Be sure the cwd buffer is initialized.  */
-    FilesUtility::temporaryFileName ( 0, fname );
+    FilesUtility::temporaryFileName (0, fname);
     tfile = new File;
   }
   
-  void tearDown ( )
+  void tearDown ()
   {
     delete tfile;
   }
   
-  void testCreateTemporaryFile ( )
+  void testCreateTemporaryFile ()
   {
-    CPPUNIT_ASSERT_EQUAL( tfile->createTemporaryFile ( fname.c_str() ), 0 );
+    CPPUNIT_ASSERT_EQUAL (tfile->createTemporaryFile (fname.c_str()), 0);
     
-    CPPUNIT_ASSERT_EQUAL( tfile->close ( ), 0 );
+    CPPUNIT_ASSERT_EQUAL (tfile->close (), 0);
   }
   
-  void testOnFile ( )
+  void testOnFile ()
   {
     char buf[] = { 'H', 'e', 'l', 'l', 'o', ',', ' ', 'm', 'y', 'W', 'o', 'r', 
'l', 'd', 0 };
     const int bufLen = sizeof (buf) / sizeof (char);
     u_long nbw;
     u_long nbr;
     
-    CPPUNIT_ASSERT_EQUAL( tfile->openFile( fname.c_str(), 
File::MYSERVER_OPEN_WRITE | 
-                                           File::MYSERVER_OPEN_READ | 
File::MYSERVER_CREATE_ALWAYS ), 0 );
+    CPPUNIT_ASSERT_EQUAL (tfile->openFile( fname.c_str (), 
File::MYSERVER_OPEN_WRITE | 
+                                           File::MYSERVER_OPEN_READ | 
+                                           File::MYSERVER_CREATE_ALWAYS ), 0);
     
-    CPPUNIT_ASSERT_EQUAL( tfile->writeToFile ( buf, bufLen, &nbw ), 0 );
+    CPPUNIT_ASSERT_EQUAL (tfile->writeToFile ( buf, bufLen, &nbw ), 0);
     
-    memset ( buf, 0, bufLen );
+    memset (buf, 0, bufLen);
     
-    CPPUNIT_ASSERT_EQUAL( tfile->seek ( 0 ), 0 );
+    CPPUNIT_ASSERT_EQUAL (tfile->seek (0), 0);
     
-    CPPUNIT_ASSERT_EQUAL( tfile->read ( buf, bufLen, &nbr ), 0 );
+    CPPUNIT_ASSERT_EQUAL (tfile->read (buf, bufLen, &nbr), 0);
     
-    CPPUNIT_ASSERT( nbr > 0 );
+    CPPUNIT_ASSERT (nbr > 0);
     
-    CPPUNIT_ASSERT( tfile->getCreationTime ( ) != -1 );
+    CPPUNIT_ASSERT (tfile->getCreationTime () != -1);
     
-    CPPUNIT_ASSERT( tfile->getLastAccTime ( ) != -1 );
+    CPPUNIT_ASSERT (tfile->getLastAccTime () != -1);
     
-    CPPUNIT_ASSERT( tfile->getLastModTime ( ) != -1 );
+    CPPUNIT_ASSERT (tfile->getLastModTime () != -1);
     
-    CPPUNIT_ASSERT( tfile->getFileSize ( ) != -1 );
+    CPPUNIT_ASSERT (tfile->getFileSize () != -1);
+
+    CPPUNIT_ASSERT_EQUAL (tfile->seek (1), 0);
+
+    CPPUNIT_ASSERT_EQUAL (tfile->getSeek (), 1ul);
+
     
-    CPPUNIT_ASSERT_EQUAL( tfile->close ( ), 0 );
+    CPPUNIT_ASSERT_EQUAL (tfile->close (), 0);
   }
 };
 
-CPPUNIT_TEST_SUITE_REGISTRATION( TestFile );
+CPPUNIT_TEST_SUITE_REGISTRATION (TestFile);





reply via email to

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