Removed the offset parameter from the base stream interfaces. Implemented string streams.
git-svn-id: svn://10.0.0.236/trunk@22964 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
Binary file not shown.
@@ -401,6 +401,8 @@ class NS_BASE nsFileURL
|
||||
void operator = (const nsFilePath& inOther);
|
||||
void operator = (const nsFileSpec& inOther);
|
||||
|
||||
operator const char* const () { return mURL; }
|
||||
|
||||
friend NS_BASE nsOutputStream& operator << (
|
||||
nsOutputStream& s, const nsFileURL& spec);
|
||||
|
||||
@@ -411,7 +413,6 @@ class NS_BASE nsFileURL
|
||||
private:
|
||||
// Should not be defined (only nsFilePath is to be treated as strings.
|
||||
operator char* ();
|
||||
operator const char* const ();
|
||||
private:
|
||||
friend class nsFilePath; // to allow construction of nsFilePath
|
||||
char* mURL;
|
||||
|
||||
@@ -35,15 +35,10 @@
|
||||
// the handy << or >> notation can be yours.
|
||||
//
|
||||
// nsInputFileStream, nsOutputFileStream
|
||||
// These are the STATICALLY LINKED versions of the file i/o streams,
|
||||
// which wrap the NSPR file i/o plus console i/o.
|
||||
//
|
||||
// Related files:
|
||||
// prio.h the NSPR file i/o C API), which is wrapped by
|
||||
// THIS FILE statically linked C++ wrappers, which in turn are wrapped by
|
||||
// nsIFileStream.h COM wrappers for this file, which are wrapped by
|
||||
// nsAutoFileStream.h more easily used, nicer syntax wrappers for the
|
||||
// COMified ones. Wrapper of a wrapper of a wrapper.
|
||||
// These are the STATICALLY LINKED wrappers for the file-related
|
||||
// versions of the above.
|
||||
// nsIOFileStream
|
||||
// An input and output file stream attached to the same file.
|
||||
//
|
||||
// This suite provide the following services:
|
||||
//
|
||||
@@ -91,12 +86,14 @@
|
||||
#include "prio.h"
|
||||
#endif
|
||||
|
||||
#include "nsIFileStream.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIFileStream.h"
|
||||
|
||||
// Defined elsewhere
|
||||
class nsFileSpec;
|
||||
class nsInputFileStream;
|
||||
class nsOutputFileStream;
|
||||
class nsString;
|
||||
class nsIInputStream;
|
||||
class nsIOutputStream;
|
||||
|
||||
//========================================================================================
|
||||
// Compiler-specific macros, as needed
|
||||
@@ -180,16 +177,7 @@ public:
|
||||
{
|
||||
mInputStream->Close();
|
||||
}
|
||||
PRInt32 read(void* s, PRInt32 n)
|
||||
{
|
||||
if (!mInputStream)
|
||||
return 0;
|
||||
PRInt32 result = 0;
|
||||
mInputStream->Read((char*)s, 0, n, (PRUint32*)&result);
|
||||
if (result < n)
|
||||
set_at_eof(PR_TRUE);
|
||||
return result;
|
||||
}
|
||||
PRInt32 read(void* s, PRInt32 n);
|
||||
|
||||
// Input streamers. Add more as needed (int&, unsigned int& etc). (but you have to
|
||||
// add delegators to the derived classes, too, because these operators don't inherit).
|
||||
@@ -250,14 +238,7 @@ public:
|
||||
mOutputStream->Close();
|
||||
}
|
||||
void put(char c);
|
||||
PRInt32 write(const void* s, PRInt32 n)
|
||||
{
|
||||
if (!mOutputStream)
|
||||
return 0;
|
||||
PRInt32 result = 0;
|
||||
mOutputStream->Write((char*)s, 0, n, (PRUint32*)&result);
|
||||
return result;
|
||||
}
|
||||
PRInt32 write(const void* s, PRInt32 n);
|
||||
virtual void flush();
|
||||
|
||||
// Output streamers. Add more as needed (but you have to add delegators to the derived
|
||||
@@ -282,29 +263,41 @@ protected:
|
||||
|
||||
typedef nsOutputStream nsBasicOutStream; // Historic support for this name
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsErrorProne
|
||||
// Common (virtual) base class for remembering errors on demand
|
||||
//========================================================================================
|
||||
{
|
||||
public:
|
||||
nsErrorProne() // for delayed opening
|
||||
: mResult(NS_OK)
|
||||
{
|
||||
}
|
||||
PRBool failed() const
|
||||
{
|
||||
return NS_FAILED(mResult);
|
||||
}
|
||||
|
||||
// DATA
|
||||
protected:
|
||||
nsresult mResult;
|
||||
}; // class nsErrorProne
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsFileClient
|
||||
// Because COM does not allow us to write functions which return a boolean value etc,
|
||||
// this class is here to take care of the tedious "declare variable then call with
|
||||
// the address of the variable" chores.
|
||||
//========================================================================================
|
||||
: public virtual nsErrorProne
|
||||
{
|
||||
public:
|
||||
nsFileClient() // for delayed opening
|
||||
: mResult(NS_OK)
|
||||
{
|
||||
}
|
||||
nsFileClient(const nsCOMPtr<nsIFile>& inFile)
|
||||
: mFile(do_QueryInterface(inFile))
|
||||
, mResult(NS_OK)
|
||||
{
|
||||
}
|
||||
virtual ~nsFileClient() {}
|
||||
|
||||
PRBool is_file() const
|
||||
{
|
||||
return mFile ? PR_TRUE : PR_FALSE;
|
||||
}
|
||||
|
||||
void open(
|
||||
const nsFileSpec& inFile,
|
||||
int nsprMode,
|
||||
@@ -320,10 +313,39 @@ public:
|
||||
mFile->GetIsOpen(&result);
|
||||
return result;
|
||||
}
|
||||
PRBool failed() const
|
||||
PRBool is_file() const
|
||||
{
|
||||
return NS_FAILED(mResult);
|
||||
return mFile ? PR_TRUE : PR_FALSE;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
nsFileClient() // for delayed opening
|
||||
{
|
||||
}
|
||||
// DATA
|
||||
protected:
|
||||
nsCOMPtr<nsIFile> mFile;
|
||||
}; // class nsFileClient
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsRandomAccessStoreClient
|
||||
// Because COM does not allow us to write functions which return a boolean value etc,
|
||||
// this class is here to take care of the tedious "declare variable then call with
|
||||
// the address of the variable" chores.
|
||||
//========================================================================================
|
||||
: public virtual nsErrorProne
|
||||
{
|
||||
public:
|
||||
nsRandomAccessStoreClient() // for delayed opening
|
||||
{
|
||||
}
|
||||
nsRandomAccessStoreClient(const nsCOMPtr<nsIRandomAccessStore>& inStore)
|
||||
: mStore(do_QueryInterface(inStore))
|
||||
{
|
||||
}
|
||||
virtual ~nsRandomAccessStoreClient() {}
|
||||
|
||||
void seek(PRInt32 offset)
|
||||
{
|
||||
seek(PR_SEEK_SET, offset);
|
||||
@@ -332,49 +354,109 @@ public:
|
||||
void seek(PRSeekWhence whence, PRInt32 offset)
|
||||
{
|
||||
set_at_eof(PR_FALSE);
|
||||
if (mFile)
|
||||
mResult = mFile->Seek(whence, offset);
|
||||
if (mStore)
|
||||
mResult = mStore->Seek(whence, offset);
|
||||
}
|
||||
PRIntn tell()
|
||||
{
|
||||
PRIntn result = -1;
|
||||
if (mFile)
|
||||
mResult = mFile->Tell(&result);
|
||||
if (mStore)
|
||||
mResult = mStore->Tell(&result);
|
||||
return result;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
virtual PRBool get_at_eof() const
|
||||
{
|
||||
PRBool result;
|
||||
if (mFile)
|
||||
mFile->GetAtEOF(&result);
|
||||
PRBool result = PR_TRUE;
|
||||
if (mStore)
|
||||
mStore->GetAtEOF(&result);
|
||||
return result;
|
||||
}
|
||||
|
||||
virtual void set_at_eof(PRBool atEnd)
|
||||
{
|
||||
if (mFile)
|
||||
mFile->SetAtEOF(atEnd);
|
||||
if (mStore)
|
||||
mStore->SetAtEOF(atEnd);
|
||||
}
|
||||
|
||||
// DATA
|
||||
protected:
|
||||
nsCOMPtr<nsIFile> mFile;
|
||||
PRBool mResult;
|
||||
}; // class nsFileClient
|
||||
nsCOMPtr<nsIRandomAccessStore> mStore;
|
||||
}; // class nsRandomAccessStoreClient
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsRandomAccessInputStream
|
||||
// Please read the comments at the top of this file
|
||||
//========================================================================================
|
||||
: public nsRandomAccessStoreClient
|
||||
, public nsInputStream
|
||||
{
|
||||
public:
|
||||
nsRandomAccessInputStream(nsIInputStream* inStream)
|
||||
: nsRandomAccessStoreClient(do_QueryInterface(inStream))
|
||||
, nsInputStream(inStream)
|
||||
{
|
||||
}
|
||||
PRBool readline(char* s, PRInt32 n);
|
||||
// Result always null-terminated.
|
||||
// Check eof() before each call.
|
||||
// CAUTION: false result only indicates line was truncated
|
||||
// to fit buffer, or an error occurred (OTHER THAN eof).
|
||||
|
||||
// Input streamers. Unfortunately, they don't inherit!
|
||||
nsInputStream& operator >> (char& ch)
|
||||
{ return nsInputStream::operator >>(ch); }
|
||||
nsInputStream& operator >> (nsInputStream& (*pf)(nsInputStream&))
|
||||
{ return nsInputStream::operator >>(pf); }
|
||||
|
||||
protected:
|
||||
nsRandomAccessInputStream()
|
||||
: nsInputStream(nsnull)
|
||||
{
|
||||
}
|
||||
|
||||
virtual PRBool get_at_eof() const
|
||||
{
|
||||
return nsRandomAccessStoreClient::get_at_eof();
|
||||
}
|
||||
|
||||
virtual void set_at_eof(PRBool atEnd)
|
||||
{
|
||||
nsRandomAccessStoreClient::set_at_eof(atEnd);
|
||||
}
|
||||
|
||||
}; // class nsRandomAccessInputStream
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsInputStringStream
|
||||
//========================================================================================
|
||||
: public nsRandomAccessInputStream
|
||||
{
|
||||
public:
|
||||
nsInputStringStream(const char* stringToRead);
|
||||
nsInputStringStream(const nsString& stringToRead);
|
||||
|
||||
// Input streamers. Unfortunately, they don't inherit!
|
||||
nsInputStream& operator >> (char& ch)
|
||||
{ return nsInputStream::operator >>(ch); }
|
||||
nsInputStream& operator >> (nsInputStream& (*pf)(nsInputStream&))
|
||||
{ return nsInputStream::operator >>(pf); }
|
||||
|
||||
}; // class nsInputStringStream
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsInputFileStream
|
||||
// Please read the comments at the top of this file
|
||||
//========================================================================================
|
||||
: public nsInputStream
|
||||
, public nsFileClient
|
||||
: public nsRandomAccessInputStream
|
||||
, public nsFileClient
|
||||
{
|
||||
public:
|
||||
enum { kDefaultMode = PR_RDONLY };
|
||||
nsInputFileStream(nsIInputStream* inStream)
|
||||
: nsInputStream(inStream)
|
||||
: nsRandomAccessInputStream(inStream)
|
||||
, nsFileClient(do_QueryInterface(inStream))
|
||||
, mFileInputStream(do_QueryInterface(inStream))
|
||||
{
|
||||
@@ -382,29 +464,12 @@ public:
|
||||
nsInputFileStream(
|
||||
const nsFileSpec& inFile,
|
||||
int nsprMode = kDefaultMode,
|
||||
PRIntn accessMode = 00700) // <- OCTAL
|
||||
: nsInputStream(nsnull)
|
||||
{
|
||||
nsISupports* stream;
|
||||
NS_NewIOFileStream(
|
||||
&stream,
|
||||
inFile, nsprMode, accessMode);
|
||||
mFile = nsQueryInterface(stream);
|
||||
mInputStream = nsQueryInterface(stream);
|
||||
mFileInputStream = nsQueryInterface(stream);
|
||||
NS_RELEASE(stream);
|
||||
}
|
||||
|
||||
PRBool readline(char* s, PRInt32 n);
|
||||
// Result always null-terminated.
|
||||
// Check eof() before each call.
|
||||
// CAUTION: false result only indicates line was truncated
|
||||
// to fit buffer, or an error occurred (OTHER THAN eof).
|
||||
PRIntn accessMode = 00700); // <- OCTAL
|
||||
|
||||
void Open(
|
||||
const nsFileSpec& inFile,
|
||||
int nsprMode = kDefaultMode,
|
||||
PRIntn accessMode = 00700) // <- OCTAL
|
||||
const nsFileSpec& inFile,
|
||||
int nsprMode = kDefaultMode,
|
||||
PRIntn accessMode = 00700) // <- OCTAL
|
||||
{
|
||||
if (mFile)
|
||||
mFile->Open(inFile, nsprMode, accessMode);
|
||||
@@ -416,47 +481,91 @@ public:
|
||||
nsInputStream& operator >> (nsInputStream& (*pf)(nsInputStream&))
|
||||
{ return nsInputStream::operator >>(pf); }
|
||||
|
||||
protected:
|
||||
|
||||
virtual PRBool get_at_eof() const
|
||||
{
|
||||
return nsFileClient::get_at_eof();
|
||||
}
|
||||
|
||||
virtual void set_at_eof(PRBool atEnd)
|
||||
{
|
||||
nsFileClient::set_at_eof(atEnd);
|
||||
}
|
||||
|
||||
|
||||
// DATA
|
||||
protected:
|
||||
nsCOMPtr<nsIFileInputStream> mFileInputStream;
|
||||
}; // class nsInputFileStream
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsRandomAccessOutputStream
|
||||
// Please read the comments at the top of this file
|
||||
//========================================================================================
|
||||
: public nsRandomAccessStoreClient
|
||||
, public nsOutputStream
|
||||
{
|
||||
public:
|
||||
nsRandomAccessOutputStream(nsIOutputStream* inStream)
|
||||
: nsRandomAccessStoreClient(do_QueryInterface(inStream))
|
||||
, nsOutputStream(inStream)
|
||||
{
|
||||
}
|
||||
|
||||
// Output streamers. Unfortunately, they don't inherit!
|
||||
nsOutputStream& operator << (const char* buf)
|
||||
{ return nsOutputStream::operator << (buf); }
|
||||
nsOutputStream& operator << (char ch)
|
||||
{ return nsOutputStream::operator << (ch); }
|
||||
nsOutputStream& operator << (short val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (unsigned short val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (long val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (unsigned long val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (nsOutputStream& (*pf)(nsOutputStream&))
|
||||
{ return nsOutputStream::operator << (pf); }
|
||||
|
||||
protected:
|
||||
nsRandomAccessOutputStream()
|
||||
: nsOutputStream(nsnull)
|
||||
{
|
||||
}
|
||||
}; // class nsRandomAccessOutputStream
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsOutputStringStream
|
||||
//========================================================================================
|
||||
: public nsRandomAccessOutputStream
|
||||
{
|
||||
public:
|
||||
nsOutputStringStream(char*& stringToChange);
|
||||
nsOutputStringStream(nsString& stringToChange);
|
||||
|
||||
// Output streamers. Unfortunately, they don't inherit!
|
||||
nsOutputStream& operator << (const char* buf)
|
||||
{ return nsOutputStream::operator << (buf); }
|
||||
nsOutputStream& operator << (char ch)
|
||||
{ return nsOutputStream::operator << (ch); }
|
||||
nsOutputStream& operator << (short val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (unsigned short val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (long val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (unsigned long val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (nsOutputStream& (*pf)(nsOutputStream&))
|
||||
{ return nsOutputStream::operator << (pf); }
|
||||
|
||||
}; // class nsOutputStringStream
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsOutputFileStream
|
||||
// Please read the comments at the top of this file
|
||||
//========================================================================================
|
||||
: public nsOutputStream
|
||||
: public nsRandomAccessOutputStream
|
||||
, public nsFileClient
|
||||
{
|
||||
public:
|
||||
enum { kDefaultMode = (PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE) };
|
||||
|
||||
nsOutputFileStream() {}
|
||||
nsOutputFileStream(nsIOutputStream* inStream)
|
||||
: nsOutputStream(inStream)
|
||||
, nsFileClient(do_QueryInterface(inStream))
|
||||
, mFileOutputStream(do_QueryInterface(inStream))
|
||||
{
|
||||
}
|
||||
nsOutputFileStream(
|
||||
const nsFileSpec& inFile,
|
||||
int nsprMode = kDefaultMode,
|
||||
PRIntn accessMode = 00700) // <- OCTAL
|
||||
: nsOutputStream(nsnull)
|
||||
{
|
||||
{
|
||||
nsISupports* stream;
|
||||
if (NS_FAILED(NS_NewIOFileStream(
|
||||
&stream,
|
||||
@@ -464,6 +573,7 @@ public:
|
||||
return;
|
||||
mFile = nsQueryInterface(stream);
|
||||
mOutputStream = nsQueryInterface(stream);
|
||||
mStore = nsQueryInterface(stream);
|
||||
mFileOutputStream = nsQueryInterface(stream);
|
||||
NS_RELEASE(stream);
|
||||
}
|
||||
@@ -486,18 +596,6 @@ public:
|
||||
nsOutputStream& operator << (nsOutputStream& (*pf)(nsOutputStream&))
|
||||
{ return nsOutputStream::operator << (pf); }
|
||||
|
||||
protected:
|
||||
|
||||
virtual PRBool get_at_eof() const
|
||||
{
|
||||
return nsFileClient::get_at_eof();
|
||||
}
|
||||
|
||||
virtual void set_at_eof(PRBool atEnd)
|
||||
{
|
||||
nsFileClient::set_at_eof(atEnd);
|
||||
}
|
||||
|
||||
// DATA
|
||||
protected:
|
||||
nsCOMPtr<nsIFileOutputStream> mFileOutputStream;
|
||||
@@ -571,6 +669,7 @@ public:
|
||||
inFile, nsprMode, accessMode)))
|
||||
return;
|
||||
mFile = nsQueryInterface(stream);
|
||||
mStore = nsQueryInterface(stream);
|
||||
mInputStream = nsQueryInterface(stream);
|
||||
mOutputStream = nsQueryInterface(stream);
|
||||
mFileInputStream = nsQueryInterface(stream);
|
||||
|
||||
@@ -31,7 +31,7 @@ class nsFileSpec;
|
||||
|
||||
//========================================================================================
|
||||
class nsIFile
|
||||
// Represents a file, and supports Open, Tell etc.
|
||||
// Represents a file, and supports Open.
|
||||
//========================================================================================
|
||||
: public nsISupports
|
||||
{
|
||||
@@ -44,14 +44,30 @@ public:
|
||||
// Note: Open() is only needed after
|
||||
// an explicit Close(). All file streams
|
||||
// are automatically opened on construction.
|
||||
NS_IMETHOD Seek(PRSeekWhence whence, PRInt32 offset) = 0;
|
||||
NS_IMETHOD GetIsOpen(PRBool* outOpen) = 0;
|
||||
|
||||
}; // class nsIFile
|
||||
|
||||
/* a6cf90e8-15b3-11d2-932e-00805f8add32 */
|
||||
#define NS_IRANDOMACCESS_IID \
|
||||
{ 0xa6cf90eb, 0x15b3, 0x11d2, \
|
||||
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }
|
||||
|
||||
//========================================================================================
|
||||
class nsIRandomAccessStore
|
||||
// Supports Seek, Tell etc.
|
||||
//========================================================================================
|
||||
: public nsISupports
|
||||
{
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IRANDOMACCESS_IID; return iid; }
|
||||
NS_IMETHOD Seek(PRSeekWhence whence, PRInt32 offset) = 0;
|
||||
NS_IMETHOD Tell(PRIntn* outWhere) = 0;
|
||||
|
||||
/* "PROTECTED" */
|
||||
NS_IMETHOD GetAtEOF(PRBool* outAtEOF) = 0;
|
||||
NS_IMETHOD SetAtEOF(PRBool inAtEOF) = 0;
|
||||
}; // class nsIFile
|
||||
}; // class nsIRandomAccessStore
|
||||
|
||||
/* a6cf90e6-15b3-11d2-932e-00805f8add32 */
|
||||
#define NS_IFILEINPUTSTREAM_IID \
|
||||
@@ -64,7 +80,7 @@ class nsIFileInputStream
|
||||
// nsIInputStream supports. The current implementation supports both
|
||||
// interfaces.
|
||||
//========================================================================================
|
||||
: public nsISupports
|
||||
: public nsIInputStream
|
||||
{
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IFILEINPUTSTREAM_IID; return iid; }
|
||||
@@ -81,7 +97,7 @@ class nsIFileOutputStream
|
||||
// nsIOutputStream supports. The current implementation supports both
|
||||
// interfaces.
|
||||
//========================================================================================
|
||||
: public nsISupports
|
||||
: public nsIOutputStream
|
||||
{
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IFILEOUTPUTSTREAM_IID; return iid; }
|
||||
|
||||
@@ -112,9 +112,8 @@ PRInt32 ByteBufferImpl::Fill(nsresult* aErrorCode, nsIInputStream* aStream,
|
||||
|
||||
// Read in some new data
|
||||
mLength = aKeep;
|
||||
PRUint32 amount = mSpace - aKeep;
|
||||
PRUint32 nb;
|
||||
*aErrorCode = aStream->Read(mBuffer, aKeep, amount, &nb);
|
||||
*aErrorCode = aStream->Read(mBuffer + aKeep, mSpace - aKeep, &nb);
|
||||
if (NS_SUCCEEDED(*aErrorCode)) {
|
||||
mLength += nb;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include "nsFileStream.h"
|
||||
|
||||
#include "nsIStringStream.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
@@ -46,6 +47,19 @@ char nsInputStream::get()
|
||||
return c;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
PRInt32 nsInputStream::read(void* s, PRInt32 n)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (!mInputStream)
|
||||
return 0;
|
||||
PRInt32 result = 0;
|
||||
mInputStream->Read((char*)s, n, (PRUint32*)&result);
|
||||
if (result < n)
|
||||
set_at_eof(PR_TRUE);
|
||||
return result;
|
||||
} // nsInputStream::read
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
static void TidyEndOfLine(char*& cp)
|
||||
// Assumes that cp is pointing at \n or \r. Nulls out the character, checks for
|
||||
@@ -84,6 +98,17 @@ void nsOutputStream::put(char c)
|
||||
write(&c, sizeof(c));
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
PRInt32 nsOutputStream::write(const void* s, PRInt32 n)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (!mOutputStream)
|
||||
return 0;
|
||||
PRInt32 result = 0;
|
||||
mOutputStream->Write((char*)s, n, (PRUint32*)&result);
|
||||
return result;
|
||||
} // nsOutputStream::write
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void nsOutputStream::flush()
|
||||
//----------------------------------------------------------------------------------------
|
||||
@@ -143,11 +168,11 @@ nsOutputStream& nsOutputStream::operator << (unsigned long val)
|
||||
}
|
||||
|
||||
//========================================================================================
|
||||
// nsInputFileStream
|
||||
// nsRandomAccessInputStream
|
||||
//========================================================================================
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
PRBool nsInputFileStream::readline(char* s, PRInt32 n)
|
||||
PRBool nsRandomAccessInputStream::readline(char* s, PRInt32 n)
|
||||
// This will truncate if the buffer is too small. Result will always be null-terminated.
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
@@ -173,7 +198,84 @@ PRBool nsInputFileStream::readline(char* s, PRInt32 n)
|
||||
position += bytesRead;
|
||||
seek(position);
|
||||
return bufferLargeEnough;
|
||||
} // nsInputStream::readline
|
||||
} // nsRandomAccessInputStream::readline
|
||||
|
||||
//========================================================================================
|
||||
// nsInputStringStream
|
||||
//========================================================================================
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsInputStringStream::nsInputStringStream(const char* stringToRead)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsISupports* stream;
|
||||
if (NS_FAILED(NS_NewCharInputStream(&stream, stringToRead)))
|
||||
return;
|
||||
mInputStream = nsQueryInterface(stream);
|
||||
mStore = nsQueryInterface(stream);
|
||||
NS_RELEASE(stream);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsInputStringStream::nsInputStringStream(const nsString& stringToRead)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsISupports* stream;
|
||||
if (NS_FAILED(NS_NewStringInputStream(&stream, stringToRead)))
|
||||
return;
|
||||
mInputStream = nsQueryInterface(stream);
|
||||
mStore = nsQueryInterface(stream);
|
||||
NS_RELEASE(stream);
|
||||
}
|
||||
|
||||
//========================================================================================
|
||||
// nsOutputStringStream
|
||||
//========================================================================================
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsOutputStringStream::nsOutputStringStream(char*& stringToChange)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsISupports* stream;
|
||||
if (NS_FAILED(NS_NewCharOutputStream(&stream, &stringToChange)))
|
||||
return;
|
||||
mOutputStream = nsQueryInterface(stream);
|
||||
mStore = nsQueryInterface(stream);
|
||||
NS_RELEASE(stream);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsOutputStringStream::nsOutputStringStream(nsString& stringToChange)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsISupports* stream;
|
||||
if (NS_FAILED(NS_NewStringOutputStream(&stream, stringToChange)))
|
||||
return;
|
||||
mOutputStream = nsQueryInterface(stream);
|
||||
mStore = nsQueryInterface(stream);
|
||||
NS_RELEASE(stream);
|
||||
}
|
||||
|
||||
//========================================================================================
|
||||
// nsInputFileStream
|
||||
//========================================================================================
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsInputFileStream::nsInputFileStream(
|
||||
const nsFileSpec& inFile,
|
||||
int nsprMode,
|
||||
PRIntn accessMode)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsISupports* stream;
|
||||
if (NS_FAILED(NS_NewIOFileStream(&stream, inFile, nsprMode, accessMode)))
|
||||
return;
|
||||
mFile = nsQueryInterface(stream);
|
||||
mInputStream = nsQueryInterface(stream);
|
||||
mStore = nsQueryInterface(stream);
|
||||
mFileInputStream = nsQueryInterface(stream);
|
||||
NS_RELEASE(stream);
|
||||
} // nsInputFileStream::nsInputFileStream
|
||||
|
||||
//========================================================================================
|
||||
// nsOutputFileStream
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
//========================================================================================
|
||||
class FileImpl
|
||||
: public nsIOutputStream
|
||||
, public nsIInputStream
|
||||
: public nsIRandomAccessStore
|
||||
, public nsIFileOutputStream
|
||||
, public nsIFileInputStream
|
||||
, public nsIFile
|
||||
@@ -78,7 +77,6 @@ class FileImpl
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHOD Read(char* aBuf,
|
||||
PRUint32 aOffset,
|
||||
PRUint32 aCount,
|
||||
PRUint32 *aReadCount)
|
||||
{
|
||||
@@ -92,8 +90,6 @@ class FileImpl
|
||||
return NS_FILE_RESULT(PR_BAD_DESCRIPTOR_ERROR);
|
||||
if (mFailed)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (aOffset)
|
||||
PR_Seek(mFileDesc, aOffset, PR_SEEK_CUR);
|
||||
PRInt32 bytesRead = PR_Read(mFileDesc, aBuf, aCount);
|
||||
if (bytesRead < 0)
|
||||
{
|
||||
@@ -106,7 +102,6 @@ class FileImpl
|
||||
}
|
||||
// nsIOutputStream interface
|
||||
NS_IMETHOD Write(const char* aBuf,
|
||||
PRUint32 aOffset,
|
||||
PRUint32 aCount,
|
||||
PRUint32 *aWriteCount)
|
||||
{
|
||||
@@ -127,8 +122,6 @@ class FileImpl
|
||||
return NS_FILE_RESULT(PR_BAD_DESCRIPTOR_ERROR);
|
||||
if (mFailed)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (aOffset)
|
||||
PR_Seek(mFileDesc, aOffset, PR_SEEK_CUR);
|
||||
PRInt32 bytesWrit = PR_Write(mFileDesc, aBuf, aCount);
|
||||
if (bytesWrit != aCount)
|
||||
{
|
||||
@@ -154,19 +147,19 @@ class FileImpl
|
||||
|
||||
protected:
|
||||
|
||||
PRFileDesc* mFileDesc;
|
||||
int mNSPRMode;
|
||||
PRBool mFailed;
|
||||
PRBool mEOF;
|
||||
PRInt32 mLength;
|
||||
PRFileDesc* mFileDesc;
|
||||
int mNSPRMode;
|
||||
PRBool mFailed;
|
||||
PRBool mEOF;
|
||||
PRInt32 mLength;
|
||||
}; // class FileImpl
|
||||
|
||||
#define SAY_I_IMPLEMENT(classname) \
|
||||
if (aIID.Equals(classname::GetIID())) \
|
||||
{ \
|
||||
#define SAY_I_IMPLEMENT(classname) \
|
||||
if (aIID.Equals(classname::GetIID())) \
|
||||
{ \
|
||||
*aInstancePtr = (void*)((classname*)this); \
|
||||
NS_ADDREF_THIS(); \
|
||||
return NS_OK; \
|
||||
NS_ADDREF_THIS(); \
|
||||
return NS_OK; \
|
||||
}
|
||||
|
||||
NS_IMPL_RELEASE(FileImpl)
|
||||
@@ -182,6 +175,7 @@ NS_IMETHODIMP FileImpl::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
*aInstancePtr = nsnull;
|
||||
|
||||
SAY_I_IMPLEMENT(nsIFile)
|
||||
SAY_I_IMPLEMENT(nsIRandomAccessStore)
|
||||
SAY_I_IMPLEMENT(nsIOutputStream)
|
||||
SAY_I_IMPLEMENT(nsIInputStream)
|
||||
SAY_I_IMPLEMENT(nsIFileInputStream)
|
||||
@@ -319,7 +313,7 @@ NS_IMETHODIMP FileImpl::Seek(PRSeekWhence whence, PRInt32 offset)
|
||||
newPosition = 0;
|
||||
mFailed = PR_TRUE;
|
||||
}
|
||||
else if (newPosition >= fileSize)
|
||||
if (newPosition >= fileSize) // nb: not "else if".
|
||||
{
|
||||
newPosition = fileSize;
|
||||
mEOF = PR_TRUE;
|
||||
|
||||
@@ -42,7 +42,6 @@ public:
|
||||
/** Read data from the stream.
|
||||
* @param aErrorCode the error code if an error occurs
|
||||
* @param aBuf the buffer into which the data is read
|
||||
* @param aOffset the start offset of the data
|
||||
* @param aCount the maximum number of bytes to read
|
||||
* @param aReadCount out parameter to hold the number of
|
||||
* bytes read, eof if 0. if an error occurs, the
|
||||
@@ -50,7 +49,7 @@ public:
|
||||
* @return error status
|
||||
*/
|
||||
NS_IMETHOD
|
||||
Read(char* aBuf, PRUint32 aOffset, PRUint32 aCount, PRUint32 *aReadCount) = 0;
|
||||
Read(char* aBuf, PRUint32 aCount, PRUint32 *aReadCount) = 0;
|
||||
};
|
||||
|
||||
#endif /* nsInputStream_h___ */
|
||||
|
||||
@@ -33,7 +33,6 @@ public:
|
||||
|
||||
/** Write data into the stream.
|
||||
* @param aBuf the buffer into which the data is read
|
||||
* @param aOffset the start offset of the data
|
||||
* @param aCount the maximum number of bytes to read
|
||||
* @param aWriteCount out parameter to hold the number of
|
||||
* bytes written. if an error occurs, the writecount
|
||||
@@ -41,7 +40,7 @@ public:
|
||||
* @return error status
|
||||
*/
|
||||
NS_IMETHOD
|
||||
Write(const char* aBuf, PRUint32 aOffset, PRUint32 aCount, PRUint32 *aWriteCount) = 0;
|
||||
Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -26,35 +26,37 @@
|
||||
|
||||
struct FilesTest
|
||||
{
|
||||
FilesTest() : mConsole() {}
|
||||
FilesTest() : mConsole() {}
|
||||
|
||||
int RunAllTests();
|
||||
|
||||
void WriteStuff(nsOutputFileStream& s);
|
||||
int InputStream(const char* relativePath);
|
||||
int OutputStream(const char* relativePath);
|
||||
int IOStream(const char* relativePath);
|
||||
int Parent(const char* relativePath, nsFileSpec& outParent);
|
||||
int Delete(nsFileSpec& victim);
|
||||
int CreateDirectory(nsFileSpec& victim);
|
||||
int RunAllTests();
|
||||
|
||||
void WriteStuff(nsOutputStream& s);
|
||||
int InputStream(const char* relativePath);
|
||||
int OutputStream(const char* relativePath);
|
||||
int IOStream(const char* relativePath);
|
||||
int StringStream();
|
||||
int Parent(const char* relativePath, nsFileSpec& outParent);
|
||||
int Delete(nsFileSpec& victim);
|
||||
int CreateDirectory(nsFileSpec& victim);
|
||||
int CreateDirectoryRecursive(const char* aPath);
|
||||
int IterateDirectoryChildren(nsFileSpec& startChild);
|
||||
int CanonicalPath(const char* relativePath);
|
||||
int Persistence(const char* relativePath);
|
||||
int IterateDirectoryChildren(nsFileSpec& startChild);
|
||||
int CanonicalPath(const char* relativePath);
|
||||
int Persistence(const char* relativePath);
|
||||
|
||||
int Copy(const char* sourceFile, const char* targDir);
|
||||
int Move(const char* sourceFile, const char* targDir);
|
||||
int Rename(const char* sourceFile, const char* newName);
|
||||
|
||||
int Execute(const char* appName, const char* args);
|
||||
|
||||
#if WHEN_MCMULLEN_REVIEWS
|
||||
int SpecialSystemDirectories();
|
||||
#endif
|
||||
void Banner(const char* bannerString);
|
||||
void Passed();
|
||||
void Failed();
|
||||
void Inspect();
|
||||
|
||||
void Banner(const char* bannerString);
|
||||
void Passed();
|
||||
int Failed();
|
||||
void Inspect();
|
||||
|
||||
nsOutputConsoleStream mConsole;
|
||||
};
|
||||
|
||||
@@ -62,293 +64,323 @@ struct FilesTest
|
||||
void FilesTest::Banner(const char* bannerString)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
mConsole
|
||||
<< nsEndl
|
||||
<< "---------------------------" << nsEndl
|
||||
<< bannerString << " Test" << nsEndl
|
||||
<< "---------------------------" << nsEndl;
|
||||
mConsole
|
||||
<< nsEndl
|
||||
<< "---------------------------" << nsEndl
|
||||
<< bannerString << " Test" << nsEndl
|
||||
<< "---------------------------" << nsEndl;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void FilesTest::Passed()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
((nsOutputStream&)mConsole) << "Test passed.";
|
||||
mConsole << nsEndl;
|
||||
((nsOutputStream&)mConsole) << "Test passed.";
|
||||
mConsole << nsEndl;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void FilesTest::Failed()
|
||||
int FilesTest::Failed()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
mConsole << "ERROR: Test failed." << nsEndl;
|
||||
mConsole << "ERROR: Test failed." << nsEndl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void FilesTest::Inspect()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
mConsole << nsEndl << "^^^^^^^^^^ PLEASE INSPECT OUTPUT FOR ERRORS" << nsEndl;
|
||||
mConsole << nsEndl << "^^^^^^^^^^ PLEASE INSPECT OUTPUT FOR ERRORS" << nsEndl;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void FilesTest::WriteStuff(nsOutputFileStream& s)
|
||||
void FilesTest::WriteStuff(nsOutputStream& s)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
// Initialize a URL from a string without suffix. Change the path to suit your machine.
|
||||
nsFileURL fileURL("file:///Development/MPW/MPW%20Shell", PR_FALSE);
|
||||
s << "File URL initialized to: \"" << fileURL << "\""<< nsEndl;
|
||||
|
||||
// Initialize a Unix path from a URL
|
||||
nsFilePath filePath(fileURL);
|
||||
s << "As a unix path: \"" << (const char*)filePath << "\""<< nsEndl;
|
||||
|
||||
// Initialize a native file spec from a URL
|
||||
nsFileSpec fileSpec(fileURL);
|
||||
s << "As a file spec: " << fileSpec << nsEndl;
|
||||
|
||||
// Make the spec unique (this one has no suffix).
|
||||
fileSpec.MakeUnique();
|
||||
s << "Unique file spec: " << fileSpec << nsEndl;
|
||||
|
||||
// Assign the spec to a URL
|
||||
fileURL = fileSpec;
|
||||
s << "File URL assigned from spec: \"" << fileURL << "\""<< nsEndl;
|
||||
|
||||
// Assign a unix path using a string with a suffix.
|
||||
filePath = "/Development/MPW/SysErrs.err";
|
||||
s << "File path reassigned to: \"" << (const char*)filePath << "\""<< nsEndl;
|
||||
|
||||
// Assign to a file spec using a unix path.
|
||||
fileSpec = filePath;
|
||||
s << "File spec reassigned to: " << fileSpec << nsEndl;
|
||||
|
||||
// Make this unique (this one has a suffix).
|
||||
fileSpec.MakeUnique();
|
||||
s << "File spec made unique: " << fileSpec << nsEndl;
|
||||
// Initialize a URL from a string without suffix. Change the path to suit your machine.
|
||||
nsFileURL fileURL("file:///Development/MPW/MPW%20Shell", PR_FALSE);
|
||||
s << "File URL initialized to: \"" << fileURL << "\""<< nsEndl;
|
||||
|
||||
// Initialize a Unix path from a URL
|
||||
nsFilePath filePath(fileURL);
|
||||
s << "As a unix path: \"" << (const char*)filePath << "\""<< nsEndl;
|
||||
|
||||
// Initialize a native file spec from a URL
|
||||
nsFileSpec fileSpec(fileURL);
|
||||
s << "As a file spec: " << fileSpec << nsEndl;
|
||||
|
||||
// Make the spec unique (this one has no suffix).
|
||||
fileSpec.MakeUnique();
|
||||
s << "Unique file spec: " << fileSpec << nsEndl;
|
||||
|
||||
// Assign the spec to a URL
|
||||
fileURL = fileSpec;
|
||||
s << "File URL assigned from spec: \"" << fileURL << "\""<< nsEndl;
|
||||
|
||||
// Assign a unix path using a string with a suffix.
|
||||
filePath = "/Development/MPW/SysErrs.err";
|
||||
s << "File path reassigned to: \"" << (const char*)filePath << "\""<< nsEndl;
|
||||
|
||||
// Assign to a file spec using a unix path.
|
||||
fileSpec = filePath;
|
||||
s << "File spec reassigned to: " << fileSpec << nsEndl;
|
||||
|
||||
// Make this unique (this one has a suffix).
|
||||
fileSpec.MakeUnique();
|
||||
s << "File spec made unique: " << fileSpec << nsEndl;
|
||||
} // WriteStuff
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
int FilesTest::OutputStream(const char* relativePath)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsFilePath myTextFilePath(relativePath, PR_TRUE); // relative path.
|
||||
const char* pathAsString = (const char*)myTextFilePath;
|
||||
nsFileSpec mySpec(myTextFilePath);
|
||||
{
|
||||
mConsole << "WRITING IDENTICAL OUTPUT TO " << pathAsString << nsEndl << nsEndl;
|
||||
nsOutputFileStream testStream(mySpec);
|
||||
if (!testStream.is_open())
|
||||
{
|
||||
mConsole
|
||||
<< "ERROR: File "
|
||||
<< pathAsString
|
||||
<< " could not be opened for output"
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
FilesTest::WriteStuff(testStream);
|
||||
} // <-- Scope closes the stream (and the file).
|
||||
nsFilePath myTextFilePath(relativePath, PR_TRUE); // relative path.
|
||||
const char* pathAsString = (const char*)myTextFilePath;
|
||||
nsFileSpec mySpec(myTextFilePath);
|
||||
{
|
||||
mConsole << "WRITING IDENTICAL OUTPUT TO " << pathAsString << nsEndl << nsEndl;
|
||||
nsOutputFileStream testStream(mySpec);
|
||||
if (!testStream.is_open())
|
||||
{
|
||||
mConsole
|
||||
<< "ERROR: File "
|
||||
<< pathAsString
|
||||
<< " could not be opened for output"
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
FilesTest::WriteStuff(testStream);
|
||||
} // <-- Scope closes the stream (and the file).
|
||||
|
||||
if (!mySpec.Exists() || mySpec.IsDirectory() || !mySpec.IsFile())
|
||||
{
|
||||
mConsole
|
||||
<< "ERROR: File "
|
||||
<< pathAsString
|
||||
<< " is not a file (cela n'est pas un pipe)"
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
Passed();
|
||||
return 0;
|
||||
if (!mySpec.Exists() || mySpec.IsDirectory() || !mySpec.IsFile())
|
||||
{
|
||||
mConsole
|
||||
<< "ERROR: File "
|
||||
<< pathAsString
|
||||
<< " is not a file (cela n'est pas un pipe)"
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
Passed();
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
int FilesTest::StringStream()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
char* string1 = nsnull, *string2 = nsnull;
|
||||
{
|
||||
mConsole << "WRITING USUAL STUFF TO string1" << nsEndl << nsEndl;
|
||||
nsOutputStringStream streamout(string1);
|
||||
FilesTest::WriteStuff(streamout);
|
||||
}
|
||||
{
|
||||
nsInputStringStream streamin(string1);
|
||||
nsOutputStringStream streamout2(string2);
|
||||
mConsole << "READING LINES FROM string1, writing to string2"
|
||||
<< nsEndl << nsEndl;
|
||||
while (!streamin.eof())
|
||||
{
|
||||
char line[5000]; // Use a buffer longer than the file!
|
||||
streamin.readline(line, sizeof(line));
|
||||
streamout2 << line << nsEndl;
|
||||
}
|
||||
if (strcmp(string1, string2) != 0)
|
||||
{
|
||||
mConsole << "Results disagree!" << nsEndl;
|
||||
mConsole << "First string is:" << nsEndl;
|
||||
mConsole << string1 << nsEndl << nsEndl;
|
||||
mConsole << "Second string is:" << nsEndl;
|
||||
mConsole << string2 << nsEndl << nsEndl;
|
||||
return Failed();
|
||||
}
|
||||
}
|
||||
Passed();
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
int FilesTest::IOStream(const char* relativePath)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsFilePath myTextFilePath(relativePath, PR_TRUE); // relative path.
|
||||
const char* pathAsString = (const char*)myTextFilePath;
|
||||
nsFileSpec mySpec(myTextFilePath);
|
||||
mConsole
|
||||
<< "Replacing \"path\" by \"ZUUL\" in " << pathAsString << nsEndl << nsEndl;
|
||||
nsIOFileStream testStream(mySpec);
|
||||
if (!testStream.is_open())
|
||||
{
|
||||
mConsole
|
||||
<< "ERROR: File "
|
||||
<< pathAsString
|
||||
<< " could not be opened for input+output"
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
char line[5000]; // Use a buffer longer than the file!
|
||||
testStream.seek(0); // check that the seek compiles
|
||||
while (!testStream.eof())
|
||||
{
|
||||
PRInt32 pos = testStream.tell();
|
||||
testStream.readline(line, sizeof(line));
|
||||
char* replacementSubstring = strstr(line, "path");
|
||||
if (replacementSubstring)
|
||||
{
|
||||
testStream.seek(pos + (replacementSubstring - line));
|
||||
testStream << "ZUUL";
|
||||
testStream.seek(pos); // back to the start of the line
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
nsFilePath myTextFilePath(relativePath, PR_TRUE); // relative path.
|
||||
const char* pathAsString = (const char*)myTextFilePath;
|
||||
nsFileSpec mySpec(myTextFilePath);
|
||||
mConsole
|
||||
<< "Replacing \"path\" by \"ZUUL\" in " << pathAsString << nsEndl << nsEndl;
|
||||
nsIOFileStream testStream(mySpec);
|
||||
if (!testStream.is_open())
|
||||
{
|
||||
mConsole
|
||||
<< "ERROR: File "
|
||||
<< pathAsString
|
||||
<< " could not be opened for input+output"
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
char line[5000]; // Use a buffer longer than the file!
|
||||
testStream.seek(0); // check that the seek compiles
|
||||
while (!testStream.eof())
|
||||
{
|
||||
PRInt32 pos = testStream.tell();
|
||||
testStream.readline(line, sizeof(line));
|
||||
char* replacementSubstring = strstr(line, "path");
|
||||
if (replacementSubstring)
|
||||
{
|
||||
testStream.seek(pos + (replacementSubstring - line));
|
||||
testStream << "ZUUL";
|
||||
testStream.seek(pos); // back to the start of the line
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
int FilesTest::Persistence(
|
||||
const char* relativePathToWrite)
|
||||
const char* relativePathToWrite)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsFilePath myTextFilePath(relativePathToWrite, PR_TRUE);
|
||||
const char* pathAsString = (const char*)myTextFilePath;
|
||||
nsFileSpec mySpec(myTextFilePath);
|
||||
nsFilePath myTextFilePath(relativePathToWrite, PR_TRUE);
|
||||
const char* pathAsString = (const char*)myTextFilePath;
|
||||
nsFileSpec mySpec(myTextFilePath);
|
||||
|
||||
nsIOFileStream testStream(mySpec, (PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE));
|
||||
if (!testStream.is_open())
|
||||
{
|
||||
mConsole
|
||||
<< "ERROR: File "
|
||||
<< pathAsString
|
||||
<< " could not be opened for input+output"
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
nsPersistentFileDescriptor myPersistent(mySpec);
|
||||
mConsole
|
||||
<< "Writing persistent file data " << pathAsString << nsEndl << nsEndl;
|
||||
|
||||
testStream.seek(0); // check that the seek compiles
|
||||
testStream << myPersistent;
|
||||
|
||||
testStream.seek(0);
|
||||
|
||||
nsPersistentFileDescriptor mySecondPersistent;
|
||||
testStream >> mySecondPersistent;
|
||||
|
||||
mySpec = mySecondPersistent;
|
||||
nsIOFileStream testStream(mySpec, (PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE));
|
||||
if (!testStream.is_open())
|
||||
{
|
||||
mConsole
|
||||
<< "ERROR: File "
|
||||
<< pathAsString
|
||||
<< " could not be opened for input+output"
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
nsPersistentFileDescriptor myPersistent(mySpec);
|
||||
mConsole
|
||||
<< "Writing persistent file data " << pathAsString << nsEndl << nsEndl;
|
||||
|
||||
testStream.seek(0); // check that the seek compiles
|
||||
testStream << myPersistent;
|
||||
|
||||
testStream.seek(0);
|
||||
|
||||
nsPersistentFileDescriptor mySecondPersistent;
|
||||
testStream >> mySecondPersistent;
|
||||
|
||||
mySpec = mySecondPersistent;
|
||||
#ifdef XP_MAC
|
||||
if (mySpec.Error())
|
||||
{
|
||||
Failed();
|
||||
return -1;
|
||||
}
|
||||
return Failed();
|
||||
#endif
|
||||
|
||||
if (!mySpec.Exists())
|
||||
{
|
||||
Failed();
|
||||
return -1;
|
||||
}
|
||||
return Failed();
|
||||
|
||||
Passed();
|
||||
return 0;
|
||||
Passed();
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
int FilesTest::InputStream(const char* relativePath)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsFilePath myTextFilePath(relativePath, PR_TRUE);
|
||||
const char* pathAsString = (const char*)myTextFilePath;
|
||||
mConsole << "READING BACK DATA FROM " << pathAsString << nsEndl << nsEndl;
|
||||
nsFileSpec mySpec(myTextFilePath);
|
||||
nsInputFileStream testStream2(mySpec);
|
||||
if (!testStream2.is_open())
|
||||
{
|
||||
mConsole
|
||||
<< "ERROR: File "
|
||||
<< pathAsString
|
||||
<< " could not be opened for input"
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
char line[1000];
|
||||
|
||||
testStream2.seek(0); // check that the seek compiles
|
||||
while (!testStream2.eof())
|
||||
{
|
||||
testStream2.readline(line, sizeof(line));
|
||||
mConsole << line << nsEndl;
|
||||
}
|
||||
Inspect();
|
||||
return 0;
|
||||
nsFilePath myTextFilePath(relativePath, PR_TRUE);
|
||||
const char* pathAsString = (const char*)myTextFilePath;
|
||||
mConsole << "READING BACK DATA FROM " << pathAsString << nsEndl << nsEndl;
|
||||
nsFileSpec mySpec(myTextFilePath);
|
||||
nsInputFileStream testStream2(mySpec);
|
||||
if (!testStream2.is_open())
|
||||
{
|
||||
mConsole
|
||||
<< "ERROR: File "
|
||||
<< pathAsString
|
||||
<< " could not be opened for input"
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
char line[1000];
|
||||
|
||||
testStream2.seek(0); // check that the seek compiles
|
||||
while (!testStream2.eof())
|
||||
{
|
||||
testStream2.readline(line, sizeof(line));
|
||||
mConsole << line << nsEndl;
|
||||
}
|
||||
Inspect();
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
int FilesTest::Parent(
|
||||
const char* relativePath,
|
||||
nsFileSpec& outParent)
|
||||
const char* relativePath,
|
||||
nsFileSpec& outParent)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsFilePath myTextFilePath(relativePath, PR_TRUE);
|
||||
const char* pathAsString = (const char*)myTextFilePath;
|
||||
nsFileSpec mySpec(myTextFilePath);
|
||||
nsFilePath myTextFilePath(relativePath, PR_TRUE);
|
||||
const char* pathAsString = (const char*)myTextFilePath;
|
||||
nsFileSpec mySpec(myTextFilePath);
|
||||
|
||||
mySpec.GetParent(outParent);
|
||||
nsFilePath parentPath(outParent);
|
||||
mConsole
|
||||
<< "GetParent() on "
|
||||
<< "\n\t" << pathAsString
|
||||
<< "\n yields "
|
||||
<< "\n\t" << (const char*)parentPath
|
||||
<< nsEndl;
|
||||
Inspect();
|
||||
return 0;
|
||||
mConsole
|
||||
<< "GetParent() on "
|
||||
<< "\n\t" << pathAsString
|
||||
<< "\n yields "
|
||||
<< "\n\t" << (const char*)parentPath
|
||||
<< nsEndl;
|
||||
Inspect();
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
int FilesTest::Delete(nsFileSpec& victim)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
// - Test of non-recursive delete
|
||||
// - Test of non-recursive delete
|
||||
|
||||
nsFilePath victimPath(victim);
|
||||
mConsole
|
||||
<< "Attempting to delete "
|
||||
<< "\n\t" << (const char*)victimPath
|
||||
<< "\n without recursive option (should fail)"
|
||||
<< nsEndl;
|
||||
victim.Delete(PR_FALSE);
|
||||
if (victim.Exists())
|
||||
Passed();
|
||||
else
|
||||
{
|
||||
mConsole
|
||||
<< "ERROR: File "
|
||||
<< "\n\t" << (const char*)victimPath
|
||||
<< "\n has been deleted without the recursion option,"
|
||||
<< "\n and is a nonempty directory!"
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
mConsole
|
||||
<< "Attempting to delete "
|
||||
<< "\n\t" << (const char*)victimPath
|
||||
<< "\n without recursive option (should fail)"
|
||||
<< nsEndl;
|
||||
victim.Delete(PR_FALSE);
|
||||
if (victim.Exists())
|
||||
Passed();
|
||||
else
|
||||
{
|
||||
mConsole
|
||||
<< "ERROR: File "
|
||||
<< "\n\t" << (const char*)victimPath
|
||||
<< "\n has been deleted without the recursion option,"
|
||||
<< "\n and is a nonempty directory!"
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// - Test of recursive delete
|
||||
// - Test of recursive delete
|
||||
|
||||
mConsole
|
||||
<< nsEndl
|
||||
<< "Deleting "
|
||||
<< "\n\t" << (const char*)victimPath
|
||||
<< "\n with recursive option"
|
||||
<< nsEndl;
|
||||
victim.Delete(PR_TRUE);
|
||||
if (victim.Exists())
|
||||
{
|
||||
mConsole
|
||||
<< "ERROR: Directory "
|
||||
<< "\n\t" << (const char*)victimPath
|
||||
<< "\n has NOT been deleted despite the recursion option!"
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
Passed();
|
||||
return 0;
|
||||
mConsole
|
||||
<< nsEndl
|
||||
<< "Deleting "
|
||||
<< "\n\t" << (const char*)victimPath
|
||||
<< "\n with recursive option"
|
||||
<< nsEndl;
|
||||
victim.Delete(PR_TRUE);
|
||||
if (victim.Exists())
|
||||
{
|
||||
mConsole
|
||||
<< "ERROR: Directory "
|
||||
<< "\n\t" << (const char*)victimPath
|
||||
<< "\n has NOT been deleted despite the recursion option!"
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
Passed();
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
@@ -394,7 +426,7 @@ int FilesTest::CreateDirectoryRecursive(const char* aPath)
|
||||
int FilesTest::IterateDirectoryChildren(nsFileSpec& startChild)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
// - Test of directory iterator
|
||||
// - Test of directory iterator
|
||||
|
||||
nsFileSpec grandparent;
|
||||
startChild.GetParent(grandparent); // should be the original default directory.
|
||||
@@ -403,41 +435,41 @@ int FilesTest::IterateDirectoryChildren(nsFileSpec& startChild)
|
||||
mConsole << "Forwards listing of " << (const char*)grandparentPath << ":" << nsEndl;
|
||||
for (nsDirectoryIterator i(grandparent, +1); i.Exists(); i++)
|
||||
{
|
||||
char* itemName = ((nsFileSpec&)i).GetLeafName();
|
||||
mConsole << '\t' << itemName << nsEndl;
|
||||
delete [] itemName;
|
||||
char* itemName = ((nsFileSpec&)i).GetLeafName();
|
||||
mConsole << '\t' << itemName << nsEndl;
|
||||
delete [] itemName;
|
||||
}
|
||||
|
||||
mConsole << "Backwards listing of " << (const char*)grandparentPath << ":" << nsEndl;
|
||||
for (nsDirectoryIterator j(grandparent, -1); j.Exists(); j--)
|
||||
{
|
||||
char* itemName = ((nsFileSpec&)j).GetLeafName();
|
||||
mConsole << '\t' << itemName << nsEndl;
|
||||
delete [] itemName;
|
||||
char* itemName = ((nsFileSpec&)j).GetLeafName();
|
||||
mConsole << '\t' << itemName << nsEndl;
|
||||
delete [] itemName;
|
||||
}
|
||||
Inspect();
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
int FilesTest::CanonicalPath(
|
||||
const char* relativePath)
|
||||
const char* relativePath)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsFilePath myTextFilePath(relativePath, PR_TRUE);
|
||||
const char* pathAsString = (const char*)myTextFilePath;
|
||||
if (*pathAsString != '/')
|
||||
{
|
||||
mConsole
|
||||
<< "ERROR: after initializing the path object with a relative path,"
|
||||
<< "\n the path consisted of the string "
|
||||
<< "\n\t" << pathAsString
|
||||
<< "\n which is not a canonical full path!"
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
Passed();
|
||||
return 0;
|
||||
nsFilePath myTextFilePath(relativePath, PR_TRUE);
|
||||
const char* pathAsString = (const char*)myTextFilePath;
|
||||
if (*pathAsString != '/')
|
||||
{
|
||||
mConsole
|
||||
<< "ERROR: after initializing the path object with a relative path,"
|
||||
<< "\n the path consisted of the string "
|
||||
<< "\n\t" << pathAsString
|
||||
<< "\n which is not a canonical full path!"
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
Passed();
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
@@ -445,36 +477,27 @@ int FilesTest::Copy(const char* file, const char* dir)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsFileSpec dirPath(dir, PR_TRUE);
|
||||
|
||||
dirPath.CreateDirectory();
|
||||
|
||||
dirPath.CreateDirectory();
|
||||
if (! dirPath.Exists())
|
||||
{
|
||||
Failed();
|
||||
return -1;
|
||||
}
|
||||
return Failed();
|
||||
|
||||
|
||||
nsFileSpec mySpec(file, PR_TRUE); // relative path.
|
||||
{
|
||||
nsIOFileStream testStream(mySpec); // creates the file
|
||||
// Scope ends here, file gets closed
|
||||
nsIOFileStream testStream(mySpec); // creates the file
|
||||
// Scope ends here, file gets closed
|
||||
}
|
||||
|
||||
nsFileSpec filePath(file);
|
||||
if (! filePath.Exists())
|
||||
{
|
||||
Failed();
|
||||
return -1;
|
||||
}
|
||||
return Failed();
|
||||
|
||||
nsresult error = filePath.Copy(dirPath);
|
||||
|
||||
dirPath += filePath.GetLeafName();
|
||||
if (! dirPath.Exists() || ! filePath.Exists() || NS_FAILED(error))
|
||||
{
|
||||
Failed();
|
||||
return -1;
|
||||
}
|
||||
return Failed();
|
||||
|
||||
Passed();
|
||||
|
||||
@@ -486,13 +509,10 @@ int FilesTest::Move(const char* file, const char* dir)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsFileSpec dirPath(dir, PR_TRUE);
|
||||
|
||||
dirPath.CreateDirectory();
|
||||
|
||||
dirPath.CreateDirectory();
|
||||
if (! dirPath.Exists())
|
||||
{
|
||||
Failed();
|
||||
return -1;
|
||||
}
|
||||
return Failed();
|
||||
|
||||
|
||||
nsFileSpec srcSpec(file, PR_TRUE); // relative path.
|
||||
@@ -502,20 +522,14 @@ int FilesTest::Move(const char* file, const char* dir)
|
||||
};
|
||||
|
||||
if (! srcSpec.Exists())
|
||||
{
|
||||
Failed();
|
||||
return -1;
|
||||
}
|
||||
return Failed();
|
||||
|
||||
nsresult error = srcSpec.Move(dirPath);
|
||||
|
||||
|
||||
dirPath += srcSpec.GetLeafName();
|
||||
if (! dirPath.Exists() || srcSpec.Exists() || NS_FAILED(error))
|
||||
{
|
||||
Failed();
|
||||
return -1;
|
||||
}
|
||||
return Failed();
|
||||
|
||||
Passed();
|
||||
return 0;
|
||||
@@ -527,17 +541,11 @@ int FilesTest::Execute(const char* appName, const char* args)
|
||||
{
|
||||
nsFileSpec appPath(appName, PR_FALSE);
|
||||
if (!appPath.Exists())
|
||||
{
|
||||
Failed();
|
||||
return -1;
|
||||
}
|
||||
|
||||
return Failed();
|
||||
|
||||
nsresult error = appPath.Execute(args);
|
||||
if (NS_FAILED(error))
|
||||
{
|
||||
Failed();
|
||||
return -1;
|
||||
}
|
||||
return Failed();
|
||||
|
||||
Passed();
|
||||
|
||||
@@ -545,7 +553,9 @@ int FilesTest::Execute(const char* appName, const char* args)
|
||||
}
|
||||
|
||||
#if WHEN_MCMULLEN_REVIEWS
|
||||
//----------------------------------------------------------------------------------------
|
||||
int FilesTest::SpecialSystemDirectories()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
mConsole << "Please verify that these are the paths to various system directories:" << nsEndl;
|
||||
|
||||
@@ -775,7 +785,7 @@ int FilesTest::SpecialSystemDirectories()
|
||||
Passed();
|
||||
return 0;
|
||||
|
||||
}
|
||||
} // FilesTest::SpecialSystemDirectories
|
||||
#endif
|
||||
|
||||
|
||||
@@ -812,6 +822,10 @@ int FilesTest::RunAllTests()
|
||||
if (InputStream("mumble/iotest.txt") != 0)
|
||||
return -1;
|
||||
|
||||
Banner("StringStream");
|
||||
if (StringStream() != 0)
|
||||
return -1;
|
||||
|
||||
Banner("Parent");
|
||||
nsFileSpec parent;
|
||||
if (Parent("mumble/iotest.txt", parent) != 0)
|
||||
@@ -848,9 +862,9 @@ int FilesTest::RunAllTests()
|
||||
|
||||
Banner("Execute");
|
||||
#ifdef XP_MAC
|
||||
// This path is hard-coded to test on jrm's machine. Finding an app
|
||||
// on an arbitrary Macintosh would cost more trouble than it's worth.
|
||||
// Change path to suit.
|
||||
// This path is hard-coded to test on jrm's machine. Finding an app
|
||||
// on an arbitrary Macintosh would cost more trouble than it's worth.
|
||||
// Change path to suit.
|
||||
if NS_FAILED(Execute("/Projects/Nav45_BRANCH/ns/cmd/macfe/"\
|
||||
"projects/client45/Client45PPC", ""))
|
||||
#elif XP_PC
|
||||
@@ -859,17 +873,13 @@ int FilesTest::RunAllTests()
|
||||
if NS_FAILED(Execute("/bin/ls", "/"))
|
||||
#endif
|
||||
return -1;
|
||||
|
||||
#if WHEN_MCMULLEN_REVIEWS
|
||||
Banner("Special System Directories");
|
||||
if (SpecialSystemDirectories() != 0)
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
Banner("Move");
|
||||
if (Move("mumble/moveFile.txt", "mumble/move") != 0)
|
||||
return -1;
|
||||
|
||||
|
||||
Banner("Persistence");
|
||||
if (Persistence("mumble/filedesc.dat") != 0)
|
||||
return -1;
|
||||
@@ -879,14 +889,13 @@ int FilesTest::RunAllTests()
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
} // FilesTest::RunAllTests
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
int main()
|
||||
// For use with DEBUG defined.
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
FilesTest tester;
|
||||
return tester.RunAllTests();
|
||||
FilesTest tester;
|
||||
return tester.RunAllTests();
|
||||
} // main
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
/* Some build-wide Mac-related defines */
|
||||
#define macintosh /* macintosh is defined for GUSI */
|
||||
#define XP_MAC 1
|
||||
#define JRM_Debug
|
||||
|
||||
/* We have to do this here because ConditionalMacros.h will be included from
|
||||
* within OpenTptInternet.h and will stupidly define these to 1 if they
|
||||
|
||||
@@ -281,16 +281,16 @@ nsTransactionItem::Write(nsIOutputStream *aOutputStream)
|
||||
if (mTransaction)
|
||||
mTransaction->Write(aOutputStream);
|
||||
|
||||
aOutputStream->Write(" ItemUndoStack:\n", 0, 19, &len);
|
||||
aOutputStream->Write(" ItemUndoStack:\n", 19, &len);
|
||||
if (mUndoStack) {
|
||||
mUndoStack->Write(aOutputStream);
|
||||
}
|
||||
|
||||
aOutputStream->Write("\n ItemRedoStack:\n", 0, 20, &len);
|
||||
aOutputStream->Write("\n ItemRedoStack:\n", 20, &len);
|
||||
if (mRedoStack) {
|
||||
mRedoStack->Write(aOutputStream);
|
||||
}
|
||||
aOutputStream->Write("\n", 0, 1, &len);
|
||||
aOutputStream->Write("\n", 1, &len);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -475,10 +475,10 @@ nsTransactionManager::Write(nsIOutputStream *aOutputStream)
|
||||
if (!aOutputStream)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
aOutputStream->Write("UndoStack:\n\n", 0, 12, &len);
|
||||
aOutputStream->Write("UndoStack:\n\n", 12, &len);
|
||||
mUndoStack.Write(aOutputStream);
|
||||
|
||||
aOutputStream->Write("\nRedoStack:\n\n", 0, 13, &len);
|
||||
aOutputStream->Write("\nRedoStack:\n\n", 13, &len);
|
||||
mRedoStack.Write(aOutputStream);
|
||||
|
||||
return NS_OK;
|
||||
|
||||
@@ -205,7 +205,7 @@ ImageConsumer::OnDataAvailable(nsIURL* aURL, nsIInputStream *pIStream, PRUint32
|
||||
max_read = IMAGE_BUF_SIZE;
|
||||
}
|
||||
|
||||
err = pIStream->Read(mBuffer, 0,
|
||||
err = pIStream->Read(mBuffer,
|
||||
max_read, &nb);
|
||||
if (err != NS_OK) {
|
||||
break;
|
||||
|
||||
@@ -189,7 +189,7 @@ ImageNetContextSyncImpl::GetURL(ilIURL* aURL,
|
||||
nsresult result;
|
||||
PRBool first = PR_TRUE;
|
||||
|
||||
result = stream->Read(buf, 0, sizeof(buf), &count);
|
||||
result = stream->Read(buf, sizeof(buf), &count);
|
||||
while (NS_SUCCEEDED(result) && (count > 0)) {
|
||||
if (first == PR_TRUE) {
|
||||
PRInt32 ilErr;
|
||||
@@ -206,7 +206,7 @@ ImageNetContextSyncImpl::GetURL(ilIURL* aURL,
|
||||
aReader->Write((const unsigned char *)buf, (int32)count);
|
||||
|
||||
// Get the next block
|
||||
result = stream->Read(buf, 0, sizeof(buf), &count);
|
||||
result = stream->Read(buf, sizeof(buf), &count);
|
||||
}
|
||||
|
||||
if (NS_FAILED(result)) {
|
||||
|
||||
@@ -845,7 +845,7 @@ nsresult nsParser::OnDataAvailable(nsIURL* aURL, nsIInputStream *pIStream, PRUin
|
||||
nsresult result=NS_OK;
|
||||
|
||||
while ((theNumRead>0) && (aLength>theTotalRead) && (NS_OK==result)) {
|
||||
result = pIStream->Read(mParserContext->mTransferBuffer, 0, aLength, &theNumRead);
|
||||
result = pIStream->Read(mParserContext->mTransferBuffer, aLength, &theNumRead);
|
||||
if((result == NS_OK) && (theNumRead>0)) {
|
||||
theTotalRead+=theNumRead;
|
||||
if(mParserFilter)
|
||||
|
||||
@@ -539,7 +539,7 @@ ns4xPlugin::_write(NPP npp, NPStream *pstream, int32 len, void *buffer)
|
||||
nsIOutputStream* stream = wrapper->GetStream();
|
||||
|
||||
PRUint32 count = 0;
|
||||
nsresult rv = stream->Write((char *)buffer, 0, len, &count);
|
||||
nsresult rv = stream->Write((char *)buffer, len, &count);
|
||||
|
||||
NS_RELEASE(stream);
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ ns4xPluginStreamListener::OnStartBinding(const char* url, nsIPluginStreamInfo* p
|
||||
|
||||
NS_IMETHODIMP
|
||||
ns4xPluginStreamListener::OnDataAvailable(const char* url, nsIInputStream* input,
|
||||
PRUint32 offset, PRUint32 length, nsIPluginStreamInfo* pluginInfo)
|
||||
PRUint32 /*offset*/, PRUint32 length, nsIPluginStreamInfo* pluginInfo)
|
||||
{
|
||||
const NPPluginFuncs *callbacks;
|
||||
NPP npp;
|
||||
@@ -154,7 +154,7 @@ ns4xPluginStreamListener::OnDataAvailable(const char* url, nsIInputStream* input
|
||||
// Get the data from the input stream
|
||||
char* buffer = new char[length];
|
||||
if (buffer)
|
||||
input->Read(buffer, offset, length, &amountRead);
|
||||
input->Read(buffer, length, &amountRead);
|
||||
|
||||
// amountRead tells us how many bytes were put in the buffer
|
||||
// WriteReady returns to us how many bytes the plugin is
|
||||
|
||||
@@ -23,7 +23,9 @@
|
||||
#include "prmem.h"
|
||||
#include "plstr.h"
|
||||
#include "prprf.h"
|
||||
#include "nsIOutputStream.h"
|
||||
#include "nsIFileStream.h"
|
||||
#include "nsFileSpec.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#ifdef XP_PC
|
||||
#include "windows.h"
|
||||
@@ -147,7 +149,7 @@ public:
|
||||
// nsIOutputStream interface
|
||||
|
||||
NS_IMETHOD
|
||||
Write(const char* aBuf, PRUint32 aOffset, PRUint32 aCount, PRUint32 *aWriteCount);
|
||||
Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount);
|
||||
|
||||
// nsIBaseStream interface
|
||||
|
||||
@@ -157,24 +159,24 @@ public:
|
||||
protected:
|
||||
|
||||
char* mTarget;
|
||||
char* mFileURL;
|
||||
char* mFilename;
|
||||
FILE* mStreamFile;
|
||||
nsFileURL mFileURL;
|
||||
nsFileSpec mFileSpec;
|
||||
nsCOMPtr<nsIFileOutputStream> mFileThing;
|
||||
nsIPluginInstanceOwner* mOwner;
|
||||
};
|
||||
|
||||
nsPluginStreamToFile::nsPluginStreamToFile(const char* target, nsIPluginInstanceOwner* owner)
|
||||
: mTarget(PL_strdup(target))
|
||||
, mFileURL(nsnull)
|
||||
, mOwner(owner)
|
||||
{
|
||||
mTarget = PL_strdup(target);
|
||||
mOwner = owner;
|
||||
|
||||
// open the file and prepare it for writing
|
||||
char buf[400], tpath[300];
|
||||
#ifdef XP_PC
|
||||
::GetTempPath(sizeof(tpath), tpath);
|
||||
PRInt32 len = PL_strlen(tpath);
|
||||
|
||||
if((len > 0) && (tpath[len-1] != '\\'))
|
||||
if ((len > 0) && (tpath[len-1] != '\\'))
|
||||
{
|
||||
tpath[len] = '\\';
|
||||
tpath[len+1] = 0;
|
||||
@@ -185,43 +187,35 @@ nsPluginStreamToFile::nsPluginStreamToFile(const char* target, nsIPluginInstance
|
||||
tpath[0] = 0;
|
||||
#endif // XP_PC
|
||||
|
||||
// create the file
|
||||
PR_snprintf(buf, sizeof(buf), "%s%08X.html", tpath, this);
|
||||
mStreamFile = fopen(buf, "w");
|
||||
fclose(mStreamFile);
|
||||
|
||||
mFilename = PL_strdup(buf);
|
||||
|
||||
// construct the URL we'll use later in calls to GetURL()
|
||||
mFileURL = (char*)PR_Malloc((PL_strlen(buf)+PL_strlen("file://")+1) * sizeof(char));
|
||||
if(mFileURL == nsnull)
|
||||
// Create and validate the file spec object. (When we have a constructor for the temp
|
||||
// directory, we should use this instead of the per-platform hack above).
|
||||
mFileSpec = buf;
|
||||
if (mFileSpec.Error())
|
||||
return;
|
||||
|
||||
PL_strcpy(mFileURL, "file://");
|
||||
PL_strcat(mFileURL, buf);
|
||||
// create the file
|
||||
nsISupports* ourStream;
|
||||
if (NS_FAILED(NS_NewTypicalOutputFileStream(&ourStream, mFileSpec)))
|
||||
return;
|
||||
mFileThing = do_QueryInterface(ourStream);
|
||||
NS_RELEASE(ourStream);
|
||||
|
||||
mFileThing->Close();
|
||||
|
||||
// swap \ with / for the file URL
|
||||
PRInt32 i = 0;
|
||||
while(mFileURL[i] != 0)
|
||||
{
|
||||
if(mFileURL[i] == '\\')
|
||||
mFileURL[i] = '/';
|
||||
++i;
|
||||
}
|
||||
// construct the URL we'll use later in calls to GetURL()
|
||||
mFileURL = mFileSpec;
|
||||
|
||||
printf("File URL = %s\n", mFileURL);
|
||||
printf("File URL = %s\n", (const char*)mFileURL);
|
||||
}
|
||||
|
||||
nsPluginStreamToFile::~nsPluginStreamToFile()
|
||||
{
|
||||
if(nsnull != mTarget)
|
||||
if (nsnull != mTarget)
|
||||
PL_strfree(mTarget);
|
||||
|
||||
if(nsnull != mFileURL)
|
||||
PL_strfree(mFileURL);
|
||||
|
||||
if(nsnull != mFilename)
|
||||
PL_strfree(mFilename);
|
||||
}
|
||||
|
||||
|
||||
@@ -247,16 +241,14 @@ nsresult nsPluginStreamToFile::QueryInterface(const nsIID& aIID,
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPluginStreamToFile::Write(const char* aBuf, PRUint32 aOffset, PRUint32 aCount, PRUint32 *aWriteCount)
|
||||
nsPluginStreamToFile::Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount)
|
||||
{
|
||||
// write the data to the file and update the target
|
||||
if(nsnull != mFilename)
|
||||
{
|
||||
mStreamFile = fopen(mFilename, "a");
|
||||
fwrite(aBuf, 1, aCount, mStreamFile);
|
||||
fclose(mStreamFile);
|
||||
mOwner->GetURL(mFileURL, mTarget, nsnull);
|
||||
}
|
||||
nsCOMPtr<nsIFile>(do_QueryInterface(mFileThing))->Open(mFileSpec, (PR_RDWR|PR_APPEND), 0700);
|
||||
PRUint32 actualCount;
|
||||
mFileThing->Write(aBuf, aCount, &actualCount);
|
||||
mFileThing->Close();
|
||||
mOwner->GetURL(mFileURL, mTarget, nsnull);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -539,7 +539,7 @@ ns4xPlugin::_write(NPP npp, NPStream *pstream, int32 len, void *buffer)
|
||||
nsIOutputStream* stream = wrapper->GetStream();
|
||||
|
||||
PRUint32 count = 0;
|
||||
nsresult rv = stream->Write((char *)buffer, 0, len, &count);
|
||||
nsresult rv = stream->Write((char *)buffer, len, &count);
|
||||
|
||||
NS_RELEASE(stream);
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ ns4xPluginStreamListener::OnStartBinding(const char* url, nsIPluginStreamInfo* p
|
||||
|
||||
NS_IMETHODIMP
|
||||
ns4xPluginStreamListener::OnDataAvailable(const char* url, nsIInputStream* input,
|
||||
PRUint32 offset, PRUint32 length, nsIPluginStreamInfo* pluginInfo)
|
||||
PRUint32 /*offset*/, PRUint32 length, nsIPluginStreamInfo* pluginInfo)
|
||||
{
|
||||
const NPPluginFuncs *callbacks;
|
||||
NPP npp;
|
||||
@@ -154,7 +154,7 @@ ns4xPluginStreamListener::OnDataAvailable(const char* url, nsIInputStream* input
|
||||
// Get the data from the input stream
|
||||
char* buffer = new char[length];
|
||||
if (buffer)
|
||||
input->Read(buffer, offset, length, &amountRead);
|
||||
input->Read(buffer, length, &amountRead);
|
||||
|
||||
// amountRead tells us how many bytes were put in the buffer
|
||||
// WriteReady returns to us how many bytes the plugin is
|
||||
|
||||
@@ -23,7 +23,9 @@
|
||||
#include "prmem.h"
|
||||
#include "plstr.h"
|
||||
#include "prprf.h"
|
||||
#include "nsIOutputStream.h"
|
||||
#include "nsIFileStream.h"
|
||||
#include "nsFileSpec.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#ifdef XP_PC
|
||||
#include "windows.h"
|
||||
@@ -147,7 +149,7 @@ public:
|
||||
// nsIOutputStream interface
|
||||
|
||||
NS_IMETHOD
|
||||
Write(const char* aBuf, PRUint32 aOffset, PRUint32 aCount, PRUint32 *aWriteCount);
|
||||
Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount);
|
||||
|
||||
// nsIBaseStream interface
|
||||
|
||||
@@ -157,24 +159,24 @@ public:
|
||||
protected:
|
||||
|
||||
char* mTarget;
|
||||
char* mFileURL;
|
||||
char* mFilename;
|
||||
FILE* mStreamFile;
|
||||
nsFileURL mFileURL;
|
||||
nsFileSpec mFileSpec;
|
||||
nsCOMPtr<nsIFileOutputStream> mFileThing;
|
||||
nsIPluginInstanceOwner* mOwner;
|
||||
};
|
||||
|
||||
nsPluginStreamToFile::nsPluginStreamToFile(const char* target, nsIPluginInstanceOwner* owner)
|
||||
: mTarget(PL_strdup(target))
|
||||
, mFileURL(nsnull)
|
||||
, mOwner(owner)
|
||||
{
|
||||
mTarget = PL_strdup(target);
|
||||
mOwner = owner;
|
||||
|
||||
// open the file and prepare it for writing
|
||||
char buf[400], tpath[300];
|
||||
#ifdef XP_PC
|
||||
::GetTempPath(sizeof(tpath), tpath);
|
||||
PRInt32 len = PL_strlen(tpath);
|
||||
|
||||
if((len > 0) && (tpath[len-1] != '\\'))
|
||||
if ((len > 0) && (tpath[len-1] != '\\'))
|
||||
{
|
||||
tpath[len] = '\\';
|
||||
tpath[len+1] = 0;
|
||||
@@ -185,43 +187,35 @@ nsPluginStreamToFile::nsPluginStreamToFile(const char* target, nsIPluginInstance
|
||||
tpath[0] = 0;
|
||||
#endif // XP_PC
|
||||
|
||||
// create the file
|
||||
PR_snprintf(buf, sizeof(buf), "%s%08X.html", tpath, this);
|
||||
mStreamFile = fopen(buf, "w");
|
||||
fclose(mStreamFile);
|
||||
|
||||
mFilename = PL_strdup(buf);
|
||||
|
||||
// construct the URL we'll use later in calls to GetURL()
|
||||
mFileURL = (char*)PR_Malloc((PL_strlen(buf)+PL_strlen("file://")+1) * sizeof(char));
|
||||
if(mFileURL == nsnull)
|
||||
// Create and validate the file spec object. (When we have a constructor for the temp
|
||||
// directory, we should use this instead of the per-platform hack above).
|
||||
mFileSpec = buf;
|
||||
if (mFileSpec.Error())
|
||||
return;
|
||||
|
||||
PL_strcpy(mFileURL, "file://");
|
||||
PL_strcat(mFileURL, buf);
|
||||
// create the file
|
||||
nsISupports* ourStream;
|
||||
if (NS_FAILED(NS_NewTypicalOutputFileStream(&ourStream, mFileSpec)))
|
||||
return;
|
||||
mFileThing = do_QueryInterface(ourStream);
|
||||
NS_RELEASE(ourStream);
|
||||
|
||||
mFileThing->Close();
|
||||
|
||||
// swap \ with / for the file URL
|
||||
PRInt32 i = 0;
|
||||
while(mFileURL[i] != 0)
|
||||
{
|
||||
if(mFileURL[i] == '\\')
|
||||
mFileURL[i] = '/';
|
||||
++i;
|
||||
}
|
||||
// construct the URL we'll use later in calls to GetURL()
|
||||
mFileURL = mFileSpec;
|
||||
|
||||
printf("File URL = %s\n", mFileURL);
|
||||
printf("File URL = %s\n", (const char*)mFileURL);
|
||||
}
|
||||
|
||||
nsPluginStreamToFile::~nsPluginStreamToFile()
|
||||
{
|
||||
if(nsnull != mTarget)
|
||||
if (nsnull != mTarget)
|
||||
PL_strfree(mTarget);
|
||||
|
||||
if(nsnull != mFileURL)
|
||||
PL_strfree(mFileURL);
|
||||
|
||||
if(nsnull != mFilename)
|
||||
PL_strfree(mFilename);
|
||||
}
|
||||
|
||||
|
||||
@@ -247,16 +241,14 @@ nsresult nsPluginStreamToFile::QueryInterface(const nsIID& aIID,
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPluginStreamToFile::Write(const char* aBuf, PRUint32 aOffset, PRUint32 aCount, PRUint32 *aWriteCount)
|
||||
nsPluginStreamToFile::Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount)
|
||||
{
|
||||
// write the data to the file and update the target
|
||||
if(nsnull != mFilename)
|
||||
{
|
||||
mStreamFile = fopen(mFilename, "a");
|
||||
fwrite(aBuf, 1, aCount, mStreamFile);
|
||||
fclose(mStreamFile);
|
||||
mOwner->GetURL(mFileURL, mTarget, nsnull);
|
||||
}
|
||||
nsCOMPtr<nsIFile>(do_QueryInterface(mFileThing))->Open(mFileSpec, (PR_RDWR|PR_APPEND), 0700);
|
||||
PRUint32 actualCount;
|
||||
mFileThing->Write(aBuf, aCount, &actualCount);
|
||||
mFileThing->Close();
|
||||
mOwner->GetURL(mFileURL, mTarget, nsnull);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ plugin_stream_write(NET_StreamClass *stream, const char* str, int32 len)
|
||||
nsresult res;
|
||||
int32 written;
|
||||
|
||||
res = instance_stream->Write(str, (unsigned int)0, (unsigned int)len, (unsigned int *)&written);
|
||||
res = instance_stream->Write(str, (unsigned int)len, (unsigned int *)&written);
|
||||
if (res == NS_OK)
|
||||
{
|
||||
return written;
|
||||
|
||||
@@ -125,7 +125,7 @@ nsresult nsNetConverterStream :: WriteReady(PRUint32 *aReadyCount)
|
||||
}
|
||||
|
||||
|
||||
nsresult nsNetConverterStream :: Write(const char* aBuf, PRUint32 aOffset, PRUint32 aCount, PRUint32 *aWriteCount)
|
||||
nsresult nsNetConverterStream :: Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount)
|
||||
{
|
||||
NET_StreamClass *stream;
|
||||
|
||||
@@ -134,7 +134,7 @@ nsresult nsNetConverterStream :: Write(const char* aBuf, PRUint32 aOffset, PRUin
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = stream->put_block(stream, (char *)(aBuf + aOffset), aCount);
|
||||
ret = stream->put_block(stream, (char *)aBuf, aCount);
|
||||
|
||||
*aWriteCount = aCount;
|
||||
return NS_OK;
|
||||
|
||||
@@ -45,7 +45,6 @@ public:
|
||||
// nsIOutputStream interface
|
||||
|
||||
NS_IMETHOD Write(const char *aBuf,
|
||||
PRUint32 aOffset,
|
||||
PRUint32 aLen,
|
||||
PRUint32 *aWriteLength);
|
||||
|
||||
|
||||
@@ -239,7 +239,6 @@ nsresult nsBufferedStream::GetLength(PRUint32 *aLength)
|
||||
|
||||
|
||||
nsresult nsBufferedStream::Write(const char *aBuf,
|
||||
PRUint32 aOffset,
|
||||
PRUint32 aLen,
|
||||
PRUint32 *aWriteCount)
|
||||
{
|
||||
@@ -282,11 +281,6 @@ nsresult nsBufferedStream::Write(const char *aBuf,
|
||||
}
|
||||
}
|
||||
|
||||
/* Skip the appropriate number of bytes in the input buffer... */
|
||||
if (aOffset) {
|
||||
aBuf += aOffset;
|
||||
}
|
||||
|
||||
memcpy(&m_Buffer[m_WriteOffset], aBuf, aLen);
|
||||
m_WriteOffset += aLen;
|
||||
|
||||
@@ -302,7 +296,6 @@ done:
|
||||
|
||||
|
||||
nsresult nsBufferedStream::Read(char *aBuf,
|
||||
PRUint32 aOffset,
|
||||
PRUint32 aCount,
|
||||
PRUint32 *aReadCount)
|
||||
{
|
||||
@@ -325,10 +318,6 @@ nsresult nsBufferedStream::Read(char *aBuf,
|
||||
}
|
||||
|
||||
if (m_Buffer && m_DataLength) {
|
||||
/* Skip the appropriate number of bytes in the input buffer... */
|
||||
if (aOffset) {
|
||||
aBuf += aOffset;
|
||||
}
|
||||
|
||||
/* Do not read more data than there is available... */
|
||||
if (aCount > m_DataLength) {
|
||||
@@ -407,7 +396,6 @@ nsresult nsAsyncStream::GetLength(PRUint32 *aLength)
|
||||
|
||||
|
||||
nsresult nsAsyncStream::Write(const char *aBuf,
|
||||
PRUint32 aOffset,
|
||||
PRUint32 aLen,
|
||||
PRUint32 *aWriteCount)
|
||||
{
|
||||
@@ -428,10 +416,6 @@ nsresult nsAsyncStream::Write(const char *aBuf,
|
||||
}
|
||||
|
||||
if (!m_bIsClosed && aBuf) {
|
||||
/* Skip the appropriate number of bytes in the input buffer... */
|
||||
if (aOffset) {
|
||||
aBuf += aOffset;
|
||||
}
|
||||
|
||||
/* Do not store more data than there is space for... */
|
||||
NS_ASSERTION(m_BufferLength >= m_DataLength, "unsigned madness");
|
||||
@@ -468,7 +452,6 @@ done:
|
||||
|
||||
|
||||
nsresult nsAsyncStream::Read(char *aBuf,
|
||||
PRUint32 aOffset,
|
||||
PRUint32 aCount,
|
||||
PRUint32 *aReadCount)
|
||||
{
|
||||
@@ -490,10 +473,6 @@ nsresult nsAsyncStream::Read(char *aBuf,
|
||||
}
|
||||
|
||||
if (m_Buffer && m_DataLength) {
|
||||
/* Skip the appropriate number of bytes in the input buffer... */
|
||||
if (aOffset) {
|
||||
aBuf += aOffset;
|
||||
}
|
||||
|
||||
/* Do not read more data than there is available... */
|
||||
if (aCount > m_DataLength) {
|
||||
@@ -608,7 +587,6 @@ nsresult nsBlockingStream::GetLength(PRUint32 *aLength)
|
||||
|
||||
|
||||
nsresult nsBlockingStream::Write(const char *aBuf,
|
||||
PRUint32 aOffset,
|
||||
PRUint32 aLen,
|
||||
PRUint32 *aWriteCount)
|
||||
{
|
||||
@@ -629,10 +607,6 @@ nsresult nsBlockingStream::Write(const char *aBuf,
|
||||
}
|
||||
|
||||
if (!m_bIsClosed && aBuf) {
|
||||
/* Skip the appropriate number of bytes in the input buffer... */
|
||||
if (aOffset) {
|
||||
aBuf += aOffset;
|
||||
}
|
||||
|
||||
/* Do not store more data than there is space for... */
|
||||
NS_ASSERTION(m_BufferLength >= m_DataLength, "unsigned madness");
|
||||
@@ -675,7 +649,6 @@ done:
|
||||
|
||||
|
||||
nsresult nsBlockingStream::Read(char *aBuf,
|
||||
PRUint32 aOffset,
|
||||
PRUint32 aCount,
|
||||
PRUint32 *aReadCount)
|
||||
{
|
||||
@@ -697,10 +670,6 @@ nsresult nsBlockingStream::Read(char *aBuf,
|
||||
}
|
||||
|
||||
if (m_Buffer) {
|
||||
/* Skip the appropriate number of bytes in the input buffer... */
|
||||
if (aOffset) {
|
||||
aBuf += aOffset;
|
||||
}
|
||||
|
||||
/*
|
||||
* There is either enough data, or some data left in the stream
|
||||
|
||||
@@ -103,13 +103,11 @@ public:
|
||||
NS_IMETHOD GetLength(PRUint32 *aLength);
|
||||
|
||||
NS_IMETHOD Read(char *aBuf,
|
||||
PRUint32 aOffset,
|
||||
PRUint32 aCount,
|
||||
PRUint32 *aReadCount);
|
||||
|
||||
/* nsIOutputStream interface */
|
||||
NS_IMETHOD Write(const char *aBuf,
|
||||
PRUint32 aOffset,
|
||||
PRUint32 aLen,
|
||||
PRUint32 *aWriteCount);
|
||||
|
||||
@@ -141,13 +139,11 @@ public:
|
||||
NS_IMETHOD GetLength(PRUint32 *aLength);
|
||||
|
||||
NS_IMETHOD Read(char *aBuf,
|
||||
PRUint32 aOffset,
|
||||
PRUint32 aCount,
|
||||
PRUint32 *aReadLength);
|
||||
|
||||
/* nsIOutputStream interface */
|
||||
NS_IMETHOD Write(const char *aBuf,
|
||||
PRUint32 aOffset,
|
||||
PRUint32 aLen,
|
||||
PRUint32 *aWriteLength);
|
||||
|
||||
@@ -181,13 +177,11 @@ public:
|
||||
NS_IMETHOD GetLength(PRUint32 *aLength);
|
||||
|
||||
NS_IMETHOD Read(char *aBuf,
|
||||
PRUint32 aOffset,
|
||||
PRUint32 aCount,
|
||||
PRUint32 *aReadLength);
|
||||
|
||||
/* nsIOutputStream interface */
|
||||
NS_IMETHOD Write(const char *aBuf,
|
||||
PRUint32 aOffset,
|
||||
PRUint32 aLen,
|
||||
PRUint32 *aWriteLength);
|
||||
|
||||
|
||||
@@ -186,7 +186,7 @@ nsUnicharStreamLoader::OnDataAvailable(nsIURL* aURL,
|
||||
lenRead = BUF_SIZE;
|
||||
}
|
||||
|
||||
rv = aIStream->Read(buffer, 0, lenRead, &lenRead);
|
||||
rv = aIStream->Read(buffer, lenRead, &lenRead);
|
||||
if (NS_OK != rv) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -252,7 +252,7 @@ nsSocketTransport::OnDataAvailable(nsIURL* pURL,
|
||||
lenRead = NET_SOCKSTUB_BUF_SIZE;
|
||||
}
|
||||
|
||||
rv = aIStream->Read(m_buffer, 0, lenRead, &lenRead);
|
||||
rv = aIStream->Read(m_buffer, lenRead, &lenRead);
|
||||
if (NS_OK != rv) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -636,7 +636,7 @@ int stub_put_block(NET_StreamClass *stream, const char *buffer, int32 length)
|
||||
* with the string "Transfer Interrupted!"
|
||||
*/
|
||||
NS_ASSERTION(length >= 0, "negative length");
|
||||
errorCode = pConn->pNetStream->Write(buffer, 0, (PRUint32)length, &bytesWritten);
|
||||
errorCode = pConn->pNetStream->Write(buffer, (PRUint32)length, &bytesWritten);
|
||||
|
||||
/* Abort the connection... */
|
||||
if (NS_BASE_STREAM_EOF == errorCode) {
|
||||
|
||||
@@ -845,7 +845,7 @@ nsresult nsParser::OnDataAvailable(nsIURL* aURL, nsIInputStream *pIStream, PRUin
|
||||
nsresult result=NS_OK;
|
||||
|
||||
while ((theNumRead>0) && (aLength>theTotalRead) && (NS_OK==result)) {
|
||||
result = pIStream->Read(mParserContext->mTransferBuffer, 0, aLength, &theNumRead);
|
||||
result = pIStream->Read(mParserContext->mTransferBuffer, aLength, &theNumRead);
|
||||
if((result == NS_OK) && (theNumRead>0)) {
|
||||
theTotalRead+=theNumRead;
|
||||
if(mParserFilter)
|
||||
|
||||
@@ -127,9 +127,8 @@ public:
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD Read(char* aBuf, PRUint32 aOffset, PRUint32 aCount, PRUint32 *aReadCount) {
|
||||
NS_IMETHOD Read(char* aBuf, PRUint32 aCount, PRUint32 *aReadCount) {
|
||||
PRUint32 readCount = 0;
|
||||
aBuf += aOffset;
|
||||
while (mIndex < mSize && aCount > 0) {
|
||||
*aBuf = mBuffer[mIndex];
|
||||
aBuf++;
|
||||
@@ -469,7 +468,7 @@ rdf_BlockingParse(nsIURL* aURL, nsIStreamListener* aConsumer)
|
||||
char buf[1024];
|
||||
PRUint32 readCount;
|
||||
|
||||
if (NS_FAILED(rv = in->Read(buf, 0, sizeof(buf), &readCount)))
|
||||
if (NS_FAILED(rv = in->Read(buf, sizeof(buf), &readCount)))
|
||||
break; // error or eof
|
||||
|
||||
if (readCount == 0)
|
||||
@@ -889,7 +888,7 @@ rdf_BlockingWrite(nsIOutputStream* stream, const char* buf, PRUint32 size)
|
||||
nsresult rv;
|
||||
PRUint32 cb;
|
||||
|
||||
if (NS_FAILED(rv = stream->Write(buf, written, remaining, &cb)))
|
||||
if (NS_FAILED(rv = stream->Write(buf + written, remaining, &cb)))
|
||||
return rv;
|
||||
|
||||
written += cb;
|
||||
|
||||
@@ -112,9 +112,8 @@ PRInt32 ByteBufferImpl::Fill(nsresult* aErrorCode, nsIInputStream* aStream,
|
||||
|
||||
// Read in some new data
|
||||
mLength = aKeep;
|
||||
PRUint32 amount = mSpace - aKeep;
|
||||
PRUint32 nb;
|
||||
*aErrorCode = aStream->Read(mBuffer, aKeep, amount, &nb);
|
||||
*aErrorCode = aStream->Read(mBuffer + aKeep, mSpace - aKeep, &nb);
|
||||
if (NS_SUCCEEDED(*aErrorCode)) {
|
||||
mLength += nb;
|
||||
}
|
||||
|
||||
@@ -401,6 +401,8 @@ class NS_BASE nsFileURL
|
||||
void operator = (const nsFilePath& inOther);
|
||||
void operator = (const nsFileSpec& inOther);
|
||||
|
||||
operator const char* const () { return mURL; }
|
||||
|
||||
friend NS_BASE nsOutputStream& operator << (
|
||||
nsOutputStream& s, const nsFileURL& spec);
|
||||
|
||||
@@ -411,7 +413,6 @@ class NS_BASE nsFileURL
|
||||
private:
|
||||
// Should not be defined (only nsFilePath is to be treated as strings.
|
||||
operator char* ();
|
||||
operator const char* const ();
|
||||
private:
|
||||
friend class nsFilePath; // to allow construction of nsFilePath
|
||||
char* mURL;
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include "nsFileStream.h"
|
||||
|
||||
#include "nsIStringStream.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
@@ -46,6 +47,19 @@ char nsInputStream::get()
|
||||
return c;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
PRInt32 nsInputStream::read(void* s, PRInt32 n)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (!mInputStream)
|
||||
return 0;
|
||||
PRInt32 result = 0;
|
||||
mInputStream->Read((char*)s, n, (PRUint32*)&result);
|
||||
if (result < n)
|
||||
set_at_eof(PR_TRUE);
|
||||
return result;
|
||||
} // nsInputStream::read
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
static void TidyEndOfLine(char*& cp)
|
||||
// Assumes that cp is pointing at \n or \r. Nulls out the character, checks for
|
||||
@@ -84,6 +98,17 @@ void nsOutputStream::put(char c)
|
||||
write(&c, sizeof(c));
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
PRInt32 nsOutputStream::write(const void* s, PRInt32 n)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (!mOutputStream)
|
||||
return 0;
|
||||
PRInt32 result = 0;
|
||||
mOutputStream->Write((char*)s, n, (PRUint32*)&result);
|
||||
return result;
|
||||
} // nsOutputStream::write
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void nsOutputStream::flush()
|
||||
//----------------------------------------------------------------------------------------
|
||||
@@ -143,11 +168,11 @@ nsOutputStream& nsOutputStream::operator << (unsigned long val)
|
||||
}
|
||||
|
||||
//========================================================================================
|
||||
// nsInputFileStream
|
||||
// nsRandomAccessInputStream
|
||||
//========================================================================================
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
PRBool nsInputFileStream::readline(char* s, PRInt32 n)
|
||||
PRBool nsRandomAccessInputStream::readline(char* s, PRInt32 n)
|
||||
// This will truncate if the buffer is too small. Result will always be null-terminated.
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
@@ -173,7 +198,84 @@ PRBool nsInputFileStream::readline(char* s, PRInt32 n)
|
||||
position += bytesRead;
|
||||
seek(position);
|
||||
return bufferLargeEnough;
|
||||
} // nsInputStream::readline
|
||||
} // nsRandomAccessInputStream::readline
|
||||
|
||||
//========================================================================================
|
||||
// nsInputStringStream
|
||||
//========================================================================================
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsInputStringStream::nsInputStringStream(const char* stringToRead)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsISupports* stream;
|
||||
if (NS_FAILED(NS_NewCharInputStream(&stream, stringToRead)))
|
||||
return;
|
||||
mInputStream = nsQueryInterface(stream);
|
||||
mStore = nsQueryInterface(stream);
|
||||
NS_RELEASE(stream);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsInputStringStream::nsInputStringStream(const nsString& stringToRead)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsISupports* stream;
|
||||
if (NS_FAILED(NS_NewStringInputStream(&stream, stringToRead)))
|
||||
return;
|
||||
mInputStream = nsQueryInterface(stream);
|
||||
mStore = nsQueryInterface(stream);
|
||||
NS_RELEASE(stream);
|
||||
}
|
||||
|
||||
//========================================================================================
|
||||
// nsOutputStringStream
|
||||
//========================================================================================
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsOutputStringStream::nsOutputStringStream(char*& stringToChange)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsISupports* stream;
|
||||
if (NS_FAILED(NS_NewCharOutputStream(&stream, &stringToChange)))
|
||||
return;
|
||||
mOutputStream = nsQueryInterface(stream);
|
||||
mStore = nsQueryInterface(stream);
|
||||
NS_RELEASE(stream);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsOutputStringStream::nsOutputStringStream(nsString& stringToChange)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsISupports* stream;
|
||||
if (NS_FAILED(NS_NewStringOutputStream(&stream, stringToChange)))
|
||||
return;
|
||||
mOutputStream = nsQueryInterface(stream);
|
||||
mStore = nsQueryInterface(stream);
|
||||
NS_RELEASE(stream);
|
||||
}
|
||||
|
||||
//========================================================================================
|
||||
// nsInputFileStream
|
||||
//========================================================================================
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsInputFileStream::nsInputFileStream(
|
||||
const nsFileSpec& inFile,
|
||||
int nsprMode,
|
||||
PRIntn accessMode)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsISupports* stream;
|
||||
if (NS_FAILED(NS_NewIOFileStream(&stream, inFile, nsprMode, accessMode)))
|
||||
return;
|
||||
mFile = nsQueryInterface(stream);
|
||||
mInputStream = nsQueryInterface(stream);
|
||||
mStore = nsQueryInterface(stream);
|
||||
mFileInputStream = nsQueryInterface(stream);
|
||||
NS_RELEASE(stream);
|
||||
} // nsInputFileStream::nsInputFileStream
|
||||
|
||||
//========================================================================================
|
||||
// nsOutputFileStream
|
||||
|
||||
@@ -35,15 +35,10 @@
|
||||
// the handy << or >> notation can be yours.
|
||||
//
|
||||
// nsInputFileStream, nsOutputFileStream
|
||||
// These are the STATICALLY LINKED versions of the file i/o streams,
|
||||
// which wrap the NSPR file i/o plus console i/o.
|
||||
//
|
||||
// Related files:
|
||||
// prio.h the NSPR file i/o C API), which is wrapped by
|
||||
// THIS FILE statically linked C++ wrappers, which in turn are wrapped by
|
||||
// nsIFileStream.h COM wrappers for this file, which are wrapped by
|
||||
// nsAutoFileStream.h more easily used, nicer syntax wrappers for the
|
||||
// COMified ones. Wrapper of a wrapper of a wrapper.
|
||||
// These are the STATICALLY LINKED wrappers for the file-related
|
||||
// versions of the above.
|
||||
// nsIOFileStream
|
||||
// An input and output file stream attached to the same file.
|
||||
//
|
||||
// This suite provide the following services:
|
||||
//
|
||||
@@ -91,12 +86,14 @@
|
||||
#include "prio.h"
|
||||
#endif
|
||||
|
||||
#include "nsIFileStream.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIFileStream.h"
|
||||
|
||||
// Defined elsewhere
|
||||
class nsFileSpec;
|
||||
class nsInputFileStream;
|
||||
class nsOutputFileStream;
|
||||
class nsString;
|
||||
class nsIInputStream;
|
||||
class nsIOutputStream;
|
||||
|
||||
//========================================================================================
|
||||
// Compiler-specific macros, as needed
|
||||
@@ -180,16 +177,7 @@ public:
|
||||
{
|
||||
mInputStream->Close();
|
||||
}
|
||||
PRInt32 read(void* s, PRInt32 n)
|
||||
{
|
||||
if (!mInputStream)
|
||||
return 0;
|
||||
PRInt32 result = 0;
|
||||
mInputStream->Read((char*)s, 0, n, (PRUint32*)&result);
|
||||
if (result < n)
|
||||
set_at_eof(PR_TRUE);
|
||||
return result;
|
||||
}
|
||||
PRInt32 read(void* s, PRInt32 n);
|
||||
|
||||
// Input streamers. Add more as needed (int&, unsigned int& etc). (but you have to
|
||||
// add delegators to the derived classes, too, because these operators don't inherit).
|
||||
@@ -250,14 +238,7 @@ public:
|
||||
mOutputStream->Close();
|
||||
}
|
||||
void put(char c);
|
||||
PRInt32 write(const void* s, PRInt32 n)
|
||||
{
|
||||
if (!mOutputStream)
|
||||
return 0;
|
||||
PRInt32 result = 0;
|
||||
mOutputStream->Write((char*)s, 0, n, (PRUint32*)&result);
|
||||
return result;
|
||||
}
|
||||
PRInt32 write(const void* s, PRInt32 n);
|
||||
virtual void flush();
|
||||
|
||||
// Output streamers. Add more as needed (but you have to add delegators to the derived
|
||||
@@ -282,29 +263,41 @@ protected:
|
||||
|
||||
typedef nsOutputStream nsBasicOutStream; // Historic support for this name
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsErrorProne
|
||||
// Common (virtual) base class for remembering errors on demand
|
||||
//========================================================================================
|
||||
{
|
||||
public:
|
||||
nsErrorProne() // for delayed opening
|
||||
: mResult(NS_OK)
|
||||
{
|
||||
}
|
||||
PRBool failed() const
|
||||
{
|
||||
return NS_FAILED(mResult);
|
||||
}
|
||||
|
||||
// DATA
|
||||
protected:
|
||||
nsresult mResult;
|
||||
}; // class nsErrorProne
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsFileClient
|
||||
// Because COM does not allow us to write functions which return a boolean value etc,
|
||||
// this class is here to take care of the tedious "declare variable then call with
|
||||
// the address of the variable" chores.
|
||||
//========================================================================================
|
||||
: public virtual nsErrorProne
|
||||
{
|
||||
public:
|
||||
nsFileClient() // for delayed opening
|
||||
: mResult(NS_OK)
|
||||
{
|
||||
}
|
||||
nsFileClient(const nsCOMPtr<nsIFile>& inFile)
|
||||
: mFile(do_QueryInterface(inFile))
|
||||
, mResult(NS_OK)
|
||||
{
|
||||
}
|
||||
virtual ~nsFileClient() {}
|
||||
|
||||
PRBool is_file() const
|
||||
{
|
||||
return mFile ? PR_TRUE : PR_FALSE;
|
||||
}
|
||||
|
||||
void open(
|
||||
const nsFileSpec& inFile,
|
||||
int nsprMode,
|
||||
@@ -320,10 +313,39 @@ public:
|
||||
mFile->GetIsOpen(&result);
|
||||
return result;
|
||||
}
|
||||
PRBool failed() const
|
||||
PRBool is_file() const
|
||||
{
|
||||
return NS_FAILED(mResult);
|
||||
return mFile ? PR_TRUE : PR_FALSE;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
nsFileClient() // for delayed opening
|
||||
{
|
||||
}
|
||||
// DATA
|
||||
protected:
|
||||
nsCOMPtr<nsIFile> mFile;
|
||||
}; // class nsFileClient
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsRandomAccessStoreClient
|
||||
// Because COM does not allow us to write functions which return a boolean value etc,
|
||||
// this class is here to take care of the tedious "declare variable then call with
|
||||
// the address of the variable" chores.
|
||||
//========================================================================================
|
||||
: public virtual nsErrorProne
|
||||
{
|
||||
public:
|
||||
nsRandomAccessStoreClient() // for delayed opening
|
||||
{
|
||||
}
|
||||
nsRandomAccessStoreClient(const nsCOMPtr<nsIRandomAccessStore>& inStore)
|
||||
: mStore(do_QueryInterface(inStore))
|
||||
{
|
||||
}
|
||||
virtual ~nsRandomAccessStoreClient() {}
|
||||
|
||||
void seek(PRInt32 offset)
|
||||
{
|
||||
seek(PR_SEEK_SET, offset);
|
||||
@@ -332,49 +354,109 @@ public:
|
||||
void seek(PRSeekWhence whence, PRInt32 offset)
|
||||
{
|
||||
set_at_eof(PR_FALSE);
|
||||
if (mFile)
|
||||
mResult = mFile->Seek(whence, offset);
|
||||
if (mStore)
|
||||
mResult = mStore->Seek(whence, offset);
|
||||
}
|
||||
PRIntn tell()
|
||||
{
|
||||
PRIntn result = -1;
|
||||
if (mFile)
|
||||
mResult = mFile->Tell(&result);
|
||||
if (mStore)
|
||||
mResult = mStore->Tell(&result);
|
||||
return result;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
virtual PRBool get_at_eof() const
|
||||
{
|
||||
PRBool result;
|
||||
if (mFile)
|
||||
mFile->GetAtEOF(&result);
|
||||
PRBool result = PR_TRUE;
|
||||
if (mStore)
|
||||
mStore->GetAtEOF(&result);
|
||||
return result;
|
||||
}
|
||||
|
||||
virtual void set_at_eof(PRBool atEnd)
|
||||
{
|
||||
if (mFile)
|
||||
mFile->SetAtEOF(atEnd);
|
||||
if (mStore)
|
||||
mStore->SetAtEOF(atEnd);
|
||||
}
|
||||
|
||||
// DATA
|
||||
protected:
|
||||
nsCOMPtr<nsIFile> mFile;
|
||||
PRBool mResult;
|
||||
}; // class nsFileClient
|
||||
nsCOMPtr<nsIRandomAccessStore> mStore;
|
||||
}; // class nsRandomAccessStoreClient
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsRandomAccessInputStream
|
||||
// Please read the comments at the top of this file
|
||||
//========================================================================================
|
||||
: public nsRandomAccessStoreClient
|
||||
, public nsInputStream
|
||||
{
|
||||
public:
|
||||
nsRandomAccessInputStream(nsIInputStream* inStream)
|
||||
: nsRandomAccessStoreClient(do_QueryInterface(inStream))
|
||||
, nsInputStream(inStream)
|
||||
{
|
||||
}
|
||||
PRBool readline(char* s, PRInt32 n);
|
||||
// Result always null-terminated.
|
||||
// Check eof() before each call.
|
||||
// CAUTION: false result only indicates line was truncated
|
||||
// to fit buffer, or an error occurred (OTHER THAN eof).
|
||||
|
||||
// Input streamers. Unfortunately, they don't inherit!
|
||||
nsInputStream& operator >> (char& ch)
|
||||
{ return nsInputStream::operator >>(ch); }
|
||||
nsInputStream& operator >> (nsInputStream& (*pf)(nsInputStream&))
|
||||
{ return nsInputStream::operator >>(pf); }
|
||||
|
||||
protected:
|
||||
nsRandomAccessInputStream()
|
||||
: nsInputStream(nsnull)
|
||||
{
|
||||
}
|
||||
|
||||
virtual PRBool get_at_eof() const
|
||||
{
|
||||
return nsRandomAccessStoreClient::get_at_eof();
|
||||
}
|
||||
|
||||
virtual void set_at_eof(PRBool atEnd)
|
||||
{
|
||||
nsRandomAccessStoreClient::set_at_eof(atEnd);
|
||||
}
|
||||
|
||||
}; // class nsRandomAccessInputStream
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsInputStringStream
|
||||
//========================================================================================
|
||||
: public nsRandomAccessInputStream
|
||||
{
|
||||
public:
|
||||
nsInputStringStream(const char* stringToRead);
|
||||
nsInputStringStream(const nsString& stringToRead);
|
||||
|
||||
// Input streamers. Unfortunately, they don't inherit!
|
||||
nsInputStream& operator >> (char& ch)
|
||||
{ return nsInputStream::operator >>(ch); }
|
||||
nsInputStream& operator >> (nsInputStream& (*pf)(nsInputStream&))
|
||||
{ return nsInputStream::operator >>(pf); }
|
||||
|
||||
}; // class nsInputStringStream
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsInputFileStream
|
||||
// Please read the comments at the top of this file
|
||||
//========================================================================================
|
||||
: public nsInputStream
|
||||
, public nsFileClient
|
||||
: public nsRandomAccessInputStream
|
||||
, public nsFileClient
|
||||
{
|
||||
public:
|
||||
enum { kDefaultMode = PR_RDONLY };
|
||||
nsInputFileStream(nsIInputStream* inStream)
|
||||
: nsInputStream(inStream)
|
||||
: nsRandomAccessInputStream(inStream)
|
||||
, nsFileClient(do_QueryInterface(inStream))
|
||||
, mFileInputStream(do_QueryInterface(inStream))
|
||||
{
|
||||
@@ -382,29 +464,12 @@ public:
|
||||
nsInputFileStream(
|
||||
const nsFileSpec& inFile,
|
||||
int nsprMode = kDefaultMode,
|
||||
PRIntn accessMode = 00700) // <- OCTAL
|
||||
: nsInputStream(nsnull)
|
||||
{
|
||||
nsISupports* stream;
|
||||
NS_NewIOFileStream(
|
||||
&stream,
|
||||
inFile, nsprMode, accessMode);
|
||||
mFile = nsQueryInterface(stream);
|
||||
mInputStream = nsQueryInterface(stream);
|
||||
mFileInputStream = nsQueryInterface(stream);
|
||||
NS_RELEASE(stream);
|
||||
}
|
||||
|
||||
PRBool readline(char* s, PRInt32 n);
|
||||
// Result always null-terminated.
|
||||
// Check eof() before each call.
|
||||
// CAUTION: false result only indicates line was truncated
|
||||
// to fit buffer, or an error occurred (OTHER THAN eof).
|
||||
PRIntn accessMode = 00700); // <- OCTAL
|
||||
|
||||
void Open(
|
||||
const nsFileSpec& inFile,
|
||||
int nsprMode = kDefaultMode,
|
||||
PRIntn accessMode = 00700) // <- OCTAL
|
||||
const nsFileSpec& inFile,
|
||||
int nsprMode = kDefaultMode,
|
||||
PRIntn accessMode = 00700) // <- OCTAL
|
||||
{
|
||||
if (mFile)
|
||||
mFile->Open(inFile, nsprMode, accessMode);
|
||||
@@ -416,47 +481,91 @@ public:
|
||||
nsInputStream& operator >> (nsInputStream& (*pf)(nsInputStream&))
|
||||
{ return nsInputStream::operator >>(pf); }
|
||||
|
||||
protected:
|
||||
|
||||
virtual PRBool get_at_eof() const
|
||||
{
|
||||
return nsFileClient::get_at_eof();
|
||||
}
|
||||
|
||||
virtual void set_at_eof(PRBool atEnd)
|
||||
{
|
||||
nsFileClient::set_at_eof(atEnd);
|
||||
}
|
||||
|
||||
|
||||
// DATA
|
||||
protected:
|
||||
nsCOMPtr<nsIFileInputStream> mFileInputStream;
|
||||
}; // class nsInputFileStream
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsRandomAccessOutputStream
|
||||
// Please read the comments at the top of this file
|
||||
//========================================================================================
|
||||
: public nsRandomAccessStoreClient
|
||||
, public nsOutputStream
|
||||
{
|
||||
public:
|
||||
nsRandomAccessOutputStream(nsIOutputStream* inStream)
|
||||
: nsRandomAccessStoreClient(do_QueryInterface(inStream))
|
||||
, nsOutputStream(inStream)
|
||||
{
|
||||
}
|
||||
|
||||
// Output streamers. Unfortunately, they don't inherit!
|
||||
nsOutputStream& operator << (const char* buf)
|
||||
{ return nsOutputStream::operator << (buf); }
|
||||
nsOutputStream& operator << (char ch)
|
||||
{ return nsOutputStream::operator << (ch); }
|
||||
nsOutputStream& operator << (short val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (unsigned short val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (long val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (unsigned long val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (nsOutputStream& (*pf)(nsOutputStream&))
|
||||
{ return nsOutputStream::operator << (pf); }
|
||||
|
||||
protected:
|
||||
nsRandomAccessOutputStream()
|
||||
: nsOutputStream(nsnull)
|
||||
{
|
||||
}
|
||||
}; // class nsRandomAccessOutputStream
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsOutputStringStream
|
||||
//========================================================================================
|
||||
: public nsRandomAccessOutputStream
|
||||
{
|
||||
public:
|
||||
nsOutputStringStream(char*& stringToChange);
|
||||
nsOutputStringStream(nsString& stringToChange);
|
||||
|
||||
// Output streamers. Unfortunately, they don't inherit!
|
||||
nsOutputStream& operator << (const char* buf)
|
||||
{ return nsOutputStream::operator << (buf); }
|
||||
nsOutputStream& operator << (char ch)
|
||||
{ return nsOutputStream::operator << (ch); }
|
||||
nsOutputStream& operator << (short val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (unsigned short val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (long val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (unsigned long val)
|
||||
{ return nsOutputStream::operator << (val); }
|
||||
nsOutputStream& operator << (nsOutputStream& (*pf)(nsOutputStream&))
|
||||
{ return nsOutputStream::operator << (pf); }
|
||||
|
||||
}; // class nsOutputStringStream
|
||||
|
||||
//========================================================================================
|
||||
class NS_BASE nsOutputFileStream
|
||||
// Please read the comments at the top of this file
|
||||
//========================================================================================
|
||||
: public nsOutputStream
|
||||
: public nsRandomAccessOutputStream
|
||||
, public nsFileClient
|
||||
{
|
||||
public:
|
||||
enum { kDefaultMode = (PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE) };
|
||||
|
||||
nsOutputFileStream() {}
|
||||
nsOutputFileStream(nsIOutputStream* inStream)
|
||||
: nsOutputStream(inStream)
|
||||
, nsFileClient(do_QueryInterface(inStream))
|
||||
, mFileOutputStream(do_QueryInterface(inStream))
|
||||
{
|
||||
}
|
||||
nsOutputFileStream(
|
||||
const nsFileSpec& inFile,
|
||||
int nsprMode = kDefaultMode,
|
||||
PRIntn accessMode = 00700) // <- OCTAL
|
||||
: nsOutputStream(nsnull)
|
||||
{
|
||||
{
|
||||
nsISupports* stream;
|
||||
if (NS_FAILED(NS_NewIOFileStream(
|
||||
&stream,
|
||||
@@ -464,6 +573,7 @@ public:
|
||||
return;
|
||||
mFile = nsQueryInterface(stream);
|
||||
mOutputStream = nsQueryInterface(stream);
|
||||
mStore = nsQueryInterface(stream);
|
||||
mFileOutputStream = nsQueryInterface(stream);
|
||||
NS_RELEASE(stream);
|
||||
}
|
||||
@@ -486,18 +596,6 @@ public:
|
||||
nsOutputStream& operator << (nsOutputStream& (*pf)(nsOutputStream&))
|
||||
{ return nsOutputStream::operator << (pf); }
|
||||
|
||||
protected:
|
||||
|
||||
virtual PRBool get_at_eof() const
|
||||
{
|
||||
return nsFileClient::get_at_eof();
|
||||
}
|
||||
|
||||
virtual void set_at_eof(PRBool atEnd)
|
||||
{
|
||||
nsFileClient::set_at_eof(atEnd);
|
||||
}
|
||||
|
||||
// DATA
|
||||
protected:
|
||||
nsCOMPtr<nsIFileOutputStream> mFileOutputStream;
|
||||
@@ -571,6 +669,7 @@ public:
|
||||
inFile, nsprMode, accessMode)))
|
||||
return;
|
||||
mFile = nsQueryInterface(stream);
|
||||
mStore = nsQueryInterface(stream);
|
||||
mInputStream = nsQueryInterface(stream);
|
||||
mOutputStream = nsQueryInterface(stream);
|
||||
mFileInputStream = nsQueryInterface(stream);
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
//========================================================================================
|
||||
class FileImpl
|
||||
: public nsIOutputStream
|
||||
, public nsIInputStream
|
||||
: public nsIRandomAccessStore
|
||||
, public nsIFileOutputStream
|
||||
, public nsIFileInputStream
|
||||
, public nsIFile
|
||||
@@ -78,7 +77,6 @@ class FileImpl
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHOD Read(char* aBuf,
|
||||
PRUint32 aOffset,
|
||||
PRUint32 aCount,
|
||||
PRUint32 *aReadCount)
|
||||
{
|
||||
@@ -92,8 +90,6 @@ class FileImpl
|
||||
return NS_FILE_RESULT(PR_BAD_DESCRIPTOR_ERROR);
|
||||
if (mFailed)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (aOffset)
|
||||
PR_Seek(mFileDesc, aOffset, PR_SEEK_CUR);
|
||||
PRInt32 bytesRead = PR_Read(mFileDesc, aBuf, aCount);
|
||||
if (bytesRead < 0)
|
||||
{
|
||||
@@ -106,7 +102,6 @@ class FileImpl
|
||||
}
|
||||
// nsIOutputStream interface
|
||||
NS_IMETHOD Write(const char* aBuf,
|
||||
PRUint32 aOffset,
|
||||
PRUint32 aCount,
|
||||
PRUint32 *aWriteCount)
|
||||
{
|
||||
@@ -127,8 +122,6 @@ class FileImpl
|
||||
return NS_FILE_RESULT(PR_BAD_DESCRIPTOR_ERROR);
|
||||
if (mFailed)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (aOffset)
|
||||
PR_Seek(mFileDesc, aOffset, PR_SEEK_CUR);
|
||||
PRInt32 bytesWrit = PR_Write(mFileDesc, aBuf, aCount);
|
||||
if (bytesWrit != aCount)
|
||||
{
|
||||
@@ -154,19 +147,19 @@ class FileImpl
|
||||
|
||||
protected:
|
||||
|
||||
PRFileDesc* mFileDesc;
|
||||
int mNSPRMode;
|
||||
PRBool mFailed;
|
||||
PRBool mEOF;
|
||||
PRInt32 mLength;
|
||||
PRFileDesc* mFileDesc;
|
||||
int mNSPRMode;
|
||||
PRBool mFailed;
|
||||
PRBool mEOF;
|
||||
PRInt32 mLength;
|
||||
}; // class FileImpl
|
||||
|
||||
#define SAY_I_IMPLEMENT(classname) \
|
||||
if (aIID.Equals(classname::GetIID())) \
|
||||
{ \
|
||||
#define SAY_I_IMPLEMENT(classname) \
|
||||
if (aIID.Equals(classname::GetIID())) \
|
||||
{ \
|
||||
*aInstancePtr = (void*)((classname*)this); \
|
||||
NS_ADDREF_THIS(); \
|
||||
return NS_OK; \
|
||||
NS_ADDREF_THIS(); \
|
||||
return NS_OK; \
|
||||
}
|
||||
|
||||
NS_IMPL_RELEASE(FileImpl)
|
||||
@@ -182,6 +175,7 @@ NS_IMETHODIMP FileImpl::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
*aInstancePtr = nsnull;
|
||||
|
||||
SAY_I_IMPLEMENT(nsIFile)
|
||||
SAY_I_IMPLEMENT(nsIRandomAccessStore)
|
||||
SAY_I_IMPLEMENT(nsIOutputStream)
|
||||
SAY_I_IMPLEMENT(nsIInputStream)
|
||||
SAY_I_IMPLEMENT(nsIFileInputStream)
|
||||
@@ -319,7 +313,7 @@ NS_IMETHODIMP FileImpl::Seek(PRSeekWhence whence, PRInt32 offset)
|
||||
newPosition = 0;
|
||||
mFailed = PR_TRUE;
|
||||
}
|
||||
else if (newPosition >= fileSize)
|
||||
if (newPosition >= fileSize) // nb: not "else if".
|
||||
{
|
||||
newPosition = fileSize;
|
||||
mEOF = PR_TRUE;
|
||||
|
||||
@@ -31,7 +31,7 @@ class nsFileSpec;
|
||||
|
||||
//========================================================================================
|
||||
class nsIFile
|
||||
// Represents a file, and supports Open, Tell etc.
|
||||
// Represents a file, and supports Open.
|
||||
//========================================================================================
|
||||
: public nsISupports
|
||||
{
|
||||
@@ -44,14 +44,30 @@ public:
|
||||
// Note: Open() is only needed after
|
||||
// an explicit Close(). All file streams
|
||||
// are automatically opened on construction.
|
||||
NS_IMETHOD Seek(PRSeekWhence whence, PRInt32 offset) = 0;
|
||||
NS_IMETHOD GetIsOpen(PRBool* outOpen) = 0;
|
||||
|
||||
}; // class nsIFile
|
||||
|
||||
/* a6cf90e8-15b3-11d2-932e-00805f8add32 */
|
||||
#define NS_IRANDOMACCESS_IID \
|
||||
{ 0xa6cf90eb, 0x15b3, 0x11d2, \
|
||||
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }
|
||||
|
||||
//========================================================================================
|
||||
class nsIRandomAccessStore
|
||||
// Supports Seek, Tell etc.
|
||||
//========================================================================================
|
||||
: public nsISupports
|
||||
{
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IRANDOMACCESS_IID; return iid; }
|
||||
NS_IMETHOD Seek(PRSeekWhence whence, PRInt32 offset) = 0;
|
||||
NS_IMETHOD Tell(PRIntn* outWhere) = 0;
|
||||
|
||||
/* "PROTECTED" */
|
||||
NS_IMETHOD GetAtEOF(PRBool* outAtEOF) = 0;
|
||||
NS_IMETHOD SetAtEOF(PRBool inAtEOF) = 0;
|
||||
}; // class nsIFile
|
||||
}; // class nsIRandomAccessStore
|
||||
|
||||
/* a6cf90e6-15b3-11d2-932e-00805f8add32 */
|
||||
#define NS_IFILEINPUTSTREAM_IID \
|
||||
@@ -64,7 +80,7 @@ class nsIFileInputStream
|
||||
// nsIInputStream supports. The current implementation supports both
|
||||
// interfaces.
|
||||
//========================================================================================
|
||||
: public nsISupports
|
||||
: public nsIInputStream
|
||||
{
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IFILEINPUTSTREAM_IID; return iid; }
|
||||
@@ -81,7 +97,7 @@ class nsIFileOutputStream
|
||||
// nsIOutputStream supports. The current implementation supports both
|
||||
// interfaces.
|
||||
//========================================================================================
|
||||
: public nsISupports
|
||||
: public nsIOutputStream
|
||||
{
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IFILEOUTPUTSTREAM_IID; return iid; }
|
||||
|
||||
@@ -42,7 +42,6 @@ public:
|
||||
/** Read data from the stream.
|
||||
* @param aErrorCode the error code if an error occurs
|
||||
* @param aBuf the buffer into which the data is read
|
||||
* @param aOffset the start offset of the data
|
||||
* @param aCount the maximum number of bytes to read
|
||||
* @param aReadCount out parameter to hold the number of
|
||||
* bytes read, eof if 0. if an error occurs, the
|
||||
@@ -50,7 +49,7 @@ public:
|
||||
* @return error status
|
||||
*/
|
||||
NS_IMETHOD
|
||||
Read(char* aBuf, PRUint32 aOffset, PRUint32 aCount, PRUint32 *aReadCount) = 0;
|
||||
Read(char* aBuf, PRUint32 aCount, PRUint32 *aReadCount) = 0;
|
||||
};
|
||||
|
||||
#endif /* nsInputStream_h___ */
|
||||
|
||||
@@ -33,7 +33,6 @@ public:
|
||||
|
||||
/** Write data into the stream.
|
||||
* @param aBuf the buffer into which the data is read
|
||||
* @param aOffset the start offset of the data
|
||||
* @param aCount the maximum number of bytes to read
|
||||
* @param aWriteCount out parameter to hold the number of
|
||||
* bytes written. if an error occurs, the writecount
|
||||
@@ -41,7 +40,7 @@ public:
|
||||
* @return error status
|
||||
*/
|
||||
NS_IMETHOD
|
||||
Write(const char* aBuf, PRUint32 aOffset, PRUint32 aCount, PRUint32 *aWriteCount) = 0;
|
||||
Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -26,35 +26,37 @@
|
||||
|
||||
struct FilesTest
|
||||
{
|
||||
FilesTest() : mConsole() {}
|
||||
FilesTest() : mConsole() {}
|
||||
|
||||
int RunAllTests();
|
||||
|
||||
void WriteStuff(nsOutputFileStream& s);
|
||||
int InputStream(const char* relativePath);
|
||||
int OutputStream(const char* relativePath);
|
||||
int IOStream(const char* relativePath);
|
||||
int Parent(const char* relativePath, nsFileSpec& outParent);
|
||||
int Delete(nsFileSpec& victim);
|
||||
int CreateDirectory(nsFileSpec& victim);
|
||||
int RunAllTests();
|
||||
|
||||
void WriteStuff(nsOutputStream& s);
|
||||
int InputStream(const char* relativePath);
|
||||
int OutputStream(const char* relativePath);
|
||||
int IOStream(const char* relativePath);
|
||||
int StringStream();
|
||||
int Parent(const char* relativePath, nsFileSpec& outParent);
|
||||
int Delete(nsFileSpec& victim);
|
||||
int CreateDirectory(nsFileSpec& victim);
|
||||
int CreateDirectoryRecursive(const char* aPath);
|
||||
int IterateDirectoryChildren(nsFileSpec& startChild);
|
||||
int CanonicalPath(const char* relativePath);
|
||||
int Persistence(const char* relativePath);
|
||||
int IterateDirectoryChildren(nsFileSpec& startChild);
|
||||
int CanonicalPath(const char* relativePath);
|
||||
int Persistence(const char* relativePath);
|
||||
|
||||
int Copy(const char* sourceFile, const char* targDir);
|
||||
int Move(const char* sourceFile, const char* targDir);
|
||||
int Rename(const char* sourceFile, const char* newName);
|
||||
|
||||
int Execute(const char* appName, const char* args);
|
||||
|
||||
#if WHEN_MCMULLEN_REVIEWS
|
||||
int SpecialSystemDirectories();
|
||||
#endif
|
||||
void Banner(const char* bannerString);
|
||||
void Passed();
|
||||
void Failed();
|
||||
void Inspect();
|
||||
|
||||
void Banner(const char* bannerString);
|
||||
void Passed();
|
||||
int Failed();
|
||||
void Inspect();
|
||||
|
||||
nsOutputConsoleStream mConsole;
|
||||
};
|
||||
|
||||
@@ -62,293 +64,323 @@ struct FilesTest
|
||||
void FilesTest::Banner(const char* bannerString)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
mConsole
|
||||
<< nsEndl
|
||||
<< "---------------------------" << nsEndl
|
||||
<< bannerString << " Test" << nsEndl
|
||||
<< "---------------------------" << nsEndl;
|
||||
mConsole
|
||||
<< nsEndl
|
||||
<< "---------------------------" << nsEndl
|
||||
<< bannerString << " Test" << nsEndl
|
||||
<< "---------------------------" << nsEndl;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void FilesTest::Passed()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
((nsOutputStream&)mConsole) << "Test passed.";
|
||||
mConsole << nsEndl;
|
||||
((nsOutputStream&)mConsole) << "Test passed.";
|
||||
mConsole << nsEndl;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void FilesTest::Failed()
|
||||
int FilesTest::Failed()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
mConsole << "ERROR: Test failed." << nsEndl;
|
||||
mConsole << "ERROR: Test failed." << nsEndl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void FilesTest::Inspect()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
mConsole << nsEndl << "^^^^^^^^^^ PLEASE INSPECT OUTPUT FOR ERRORS" << nsEndl;
|
||||
mConsole << nsEndl << "^^^^^^^^^^ PLEASE INSPECT OUTPUT FOR ERRORS" << nsEndl;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void FilesTest::WriteStuff(nsOutputFileStream& s)
|
||||
void FilesTest::WriteStuff(nsOutputStream& s)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
// Initialize a URL from a string without suffix. Change the path to suit your machine.
|
||||
nsFileURL fileURL("file:///Development/MPW/MPW%20Shell", PR_FALSE);
|
||||
s << "File URL initialized to: \"" << fileURL << "\""<< nsEndl;
|
||||
|
||||
// Initialize a Unix path from a URL
|
||||
nsFilePath filePath(fileURL);
|
||||
s << "As a unix path: \"" << (const char*)filePath << "\""<< nsEndl;
|
||||
|
||||
// Initialize a native file spec from a URL
|
||||
nsFileSpec fileSpec(fileURL);
|
||||
s << "As a file spec: " << fileSpec << nsEndl;
|
||||
|
||||
// Make the spec unique (this one has no suffix).
|
||||
fileSpec.MakeUnique();
|
||||
s << "Unique file spec: " << fileSpec << nsEndl;
|
||||
|
||||
// Assign the spec to a URL
|
||||
fileURL = fileSpec;
|
||||
s << "File URL assigned from spec: \"" << fileURL << "\""<< nsEndl;
|
||||
|
||||
// Assign a unix path using a string with a suffix.
|
||||
filePath = "/Development/MPW/SysErrs.err";
|
||||
s << "File path reassigned to: \"" << (const char*)filePath << "\""<< nsEndl;
|
||||
|
||||
// Assign to a file spec using a unix path.
|
||||
fileSpec = filePath;
|
||||
s << "File spec reassigned to: " << fileSpec << nsEndl;
|
||||
|
||||
// Make this unique (this one has a suffix).
|
||||
fileSpec.MakeUnique();
|
||||
s << "File spec made unique: " << fileSpec << nsEndl;
|
||||
// Initialize a URL from a string without suffix. Change the path to suit your machine.
|
||||
nsFileURL fileURL("file:///Development/MPW/MPW%20Shell", PR_FALSE);
|
||||
s << "File URL initialized to: \"" << fileURL << "\""<< nsEndl;
|
||||
|
||||
// Initialize a Unix path from a URL
|
||||
nsFilePath filePath(fileURL);
|
||||
s << "As a unix path: \"" << (const char*)filePath << "\""<< nsEndl;
|
||||
|
||||
// Initialize a native file spec from a URL
|
||||
nsFileSpec fileSpec(fileURL);
|
||||
s << "As a file spec: " << fileSpec << nsEndl;
|
||||
|
||||
// Make the spec unique (this one has no suffix).
|
||||
fileSpec.MakeUnique();
|
||||
s << "Unique file spec: " << fileSpec << nsEndl;
|
||||
|
||||
// Assign the spec to a URL
|
||||
fileURL = fileSpec;
|
||||
s << "File URL assigned from spec: \"" << fileURL << "\""<< nsEndl;
|
||||
|
||||
// Assign a unix path using a string with a suffix.
|
||||
filePath = "/Development/MPW/SysErrs.err";
|
||||
s << "File path reassigned to: \"" << (const char*)filePath << "\""<< nsEndl;
|
||||
|
||||
// Assign to a file spec using a unix path.
|
||||
fileSpec = filePath;
|
||||
s << "File spec reassigned to: " << fileSpec << nsEndl;
|
||||
|
||||
// Make this unique (this one has a suffix).
|
||||
fileSpec.MakeUnique();
|
||||
s << "File spec made unique: " << fileSpec << nsEndl;
|
||||
} // WriteStuff
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
int FilesTest::OutputStream(const char* relativePath)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsFilePath myTextFilePath(relativePath, PR_TRUE); // relative path.
|
||||
const char* pathAsString = (const char*)myTextFilePath;
|
||||
nsFileSpec mySpec(myTextFilePath);
|
||||
{
|
||||
mConsole << "WRITING IDENTICAL OUTPUT TO " << pathAsString << nsEndl << nsEndl;
|
||||
nsOutputFileStream testStream(mySpec);
|
||||
if (!testStream.is_open())
|
||||
{
|
||||
mConsole
|
||||
<< "ERROR: File "
|
||||
<< pathAsString
|
||||
<< " could not be opened for output"
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
FilesTest::WriteStuff(testStream);
|
||||
} // <-- Scope closes the stream (and the file).
|
||||
nsFilePath myTextFilePath(relativePath, PR_TRUE); // relative path.
|
||||
const char* pathAsString = (const char*)myTextFilePath;
|
||||
nsFileSpec mySpec(myTextFilePath);
|
||||
{
|
||||
mConsole << "WRITING IDENTICAL OUTPUT TO " << pathAsString << nsEndl << nsEndl;
|
||||
nsOutputFileStream testStream(mySpec);
|
||||
if (!testStream.is_open())
|
||||
{
|
||||
mConsole
|
||||
<< "ERROR: File "
|
||||
<< pathAsString
|
||||
<< " could not be opened for output"
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
FilesTest::WriteStuff(testStream);
|
||||
} // <-- Scope closes the stream (and the file).
|
||||
|
||||
if (!mySpec.Exists() || mySpec.IsDirectory() || !mySpec.IsFile())
|
||||
{
|
||||
mConsole
|
||||
<< "ERROR: File "
|
||||
<< pathAsString
|
||||
<< " is not a file (cela n'est pas un pipe)"
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
Passed();
|
||||
return 0;
|
||||
if (!mySpec.Exists() || mySpec.IsDirectory() || !mySpec.IsFile())
|
||||
{
|
||||
mConsole
|
||||
<< "ERROR: File "
|
||||
<< pathAsString
|
||||
<< " is not a file (cela n'est pas un pipe)"
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
Passed();
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
int FilesTest::StringStream()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
char* string1 = nsnull, *string2 = nsnull;
|
||||
{
|
||||
mConsole << "WRITING USUAL STUFF TO string1" << nsEndl << nsEndl;
|
||||
nsOutputStringStream streamout(string1);
|
||||
FilesTest::WriteStuff(streamout);
|
||||
}
|
||||
{
|
||||
nsInputStringStream streamin(string1);
|
||||
nsOutputStringStream streamout2(string2);
|
||||
mConsole << "READING LINES FROM string1, writing to string2"
|
||||
<< nsEndl << nsEndl;
|
||||
while (!streamin.eof())
|
||||
{
|
||||
char line[5000]; // Use a buffer longer than the file!
|
||||
streamin.readline(line, sizeof(line));
|
||||
streamout2 << line << nsEndl;
|
||||
}
|
||||
if (strcmp(string1, string2) != 0)
|
||||
{
|
||||
mConsole << "Results disagree!" << nsEndl;
|
||||
mConsole << "First string is:" << nsEndl;
|
||||
mConsole << string1 << nsEndl << nsEndl;
|
||||
mConsole << "Second string is:" << nsEndl;
|
||||
mConsole << string2 << nsEndl << nsEndl;
|
||||
return Failed();
|
||||
}
|
||||
}
|
||||
Passed();
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
int FilesTest::IOStream(const char* relativePath)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsFilePath myTextFilePath(relativePath, PR_TRUE); // relative path.
|
||||
const char* pathAsString = (const char*)myTextFilePath;
|
||||
nsFileSpec mySpec(myTextFilePath);
|
||||
mConsole
|
||||
<< "Replacing \"path\" by \"ZUUL\" in " << pathAsString << nsEndl << nsEndl;
|
||||
nsIOFileStream testStream(mySpec);
|
||||
if (!testStream.is_open())
|
||||
{
|
||||
mConsole
|
||||
<< "ERROR: File "
|
||||
<< pathAsString
|
||||
<< " could not be opened for input+output"
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
char line[5000]; // Use a buffer longer than the file!
|
||||
testStream.seek(0); // check that the seek compiles
|
||||
while (!testStream.eof())
|
||||
{
|
||||
PRInt32 pos = testStream.tell();
|
||||
testStream.readline(line, sizeof(line));
|
||||
char* replacementSubstring = strstr(line, "path");
|
||||
if (replacementSubstring)
|
||||
{
|
||||
testStream.seek(pos + (replacementSubstring - line));
|
||||
testStream << "ZUUL";
|
||||
testStream.seek(pos); // back to the start of the line
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
nsFilePath myTextFilePath(relativePath, PR_TRUE); // relative path.
|
||||
const char* pathAsString = (const char*)myTextFilePath;
|
||||
nsFileSpec mySpec(myTextFilePath);
|
||||
mConsole
|
||||
<< "Replacing \"path\" by \"ZUUL\" in " << pathAsString << nsEndl << nsEndl;
|
||||
nsIOFileStream testStream(mySpec);
|
||||
if (!testStream.is_open())
|
||||
{
|
||||
mConsole
|
||||
<< "ERROR: File "
|
||||
<< pathAsString
|
||||
<< " could not be opened for input+output"
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
char line[5000]; // Use a buffer longer than the file!
|
||||
testStream.seek(0); // check that the seek compiles
|
||||
while (!testStream.eof())
|
||||
{
|
||||
PRInt32 pos = testStream.tell();
|
||||
testStream.readline(line, sizeof(line));
|
||||
char* replacementSubstring = strstr(line, "path");
|
||||
if (replacementSubstring)
|
||||
{
|
||||
testStream.seek(pos + (replacementSubstring - line));
|
||||
testStream << "ZUUL";
|
||||
testStream.seek(pos); // back to the start of the line
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
int FilesTest::Persistence(
|
||||
const char* relativePathToWrite)
|
||||
const char* relativePathToWrite)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsFilePath myTextFilePath(relativePathToWrite, PR_TRUE);
|
||||
const char* pathAsString = (const char*)myTextFilePath;
|
||||
nsFileSpec mySpec(myTextFilePath);
|
||||
nsFilePath myTextFilePath(relativePathToWrite, PR_TRUE);
|
||||
const char* pathAsString = (const char*)myTextFilePath;
|
||||
nsFileSpec mySpec(myTextFilePath);
|
||||
|
||||
nsIOFileStream testStream(mySpec, (PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE));
|
||||
if (!testStream.is_open())
|
||||
{
|
||||
mConsole
|
||||
<< "ERROR: File "
|
||||
<< pathAsString
|
||||
<< " could not be opened for input+output"
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
nsPersistentFileDescriptor myPersistent(mySpec);
|
||||
mConsole
|
||||
<< "Writing persistent file data " << pathAsString << nsEndl << nsEndl;
|
||||
|
||||
testStream.seek(0); // check that the seek compiles
|
||||
testStream << myPersistent;
|
||||
|
||||
testStream.seek(0);
|
||||
|
||||
nsPersistentFileDescriptor mySecondPersistent;
|
||||
testStream >> mySecondPersistent;
|
||||
|
||||
mySpec = mySecondPersistent;
|
||||
nsIOFileStream testStream(mySpec, (PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE));
|
||||
if (!testStream.is_open())
|
||||
{
|
||||
mConsole
|
||||
<< "ERROR: File "
|
||||
<< pathAsString
|
||||
<< " could not be opened for input+output"
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
nsPersistentFileDescriptor myPersistent(mySpec);
|
||||
mConsole
|
||||
<< "Writing persistent file data " << pathAsString << nsEndl << nsEndl;
|
||||
|
||||
testStream.seek(0); // check that the seek compiles
|
||||
testStream << myPersistent;
|
||||
|
||||
testStream.seek(0);
|
||||
|
||||
nsPersistentFileDescriptor mySecondPersistent;
|
||||
testStream >> mySecondPersistent;
|
||||
|
||||
mySpec = mySecondPersistent;
|
||||
#ifdef XP_MAC
|
||||
if (mySpec.Error())
|
||||
{
|
||||
Failed();
|
||||
return -1;
|
||||
}
|
||||
return Failed();
|
||||
#endif
|
||||
|
||||
if (!mySpec.Exists())
|
||||
{
|
||||
Failed();
|
||||
return -1;
|
||||
}
|
||||
return Failed();
|
||||
|
||||
Passed();
|
||||
return 0;
|
||||
Passed();
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
int FilesTest::InputStream(const char* relativePath)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsFilePath myTextFilePath(relativePath, PR_TRUE);
|
||||
const char* pathAsString = (const char*)myTextFilePath;
|
||||
mConsole << "READING BACK DATA FROM " << pathAsString << nsEndl << nsEndl;
|
||||
nsFileSpec mySpec(myTextFilePath);
|
||||
nsInputFileStream testStream2(mySpec);
|
||||
if (!testStream2.is_open())
|
||||
{
|
||||
mConsole
|
||||
<< "ERROR: File "
|
||||
<< pathAsString
|
||||
<< " could not be opened for input"
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
char line[1000];
|
||||
|
||||
testStream2.seek(0); // check that the seek compiles
|
||||
while (!testStream2.eof())
|
||||
{
|
||||
testStream2.readline(line, sizeof(line));
|
||||
mConsole << line << nsEndl;
|
||||
}
|
||||
Inspect();
|
||||
return 0;
|
||||
nsFilePath myTextFilePath(relativePath, PR_TRUE);
|
||||
const char* pathAsString = (const char*)myTextFilePath;
|
||||
mConsole << "READING BACK DATA FROM " << pathAsString << nsEndl << nsEndl;
|
||||
nsFileSpec mySpec(myTextFilePath);
|
||||
nsInputFileStream testStream2(mySpec);
|
||||
if (!testStream2.is_open())
|
||||
{
|
||||
mConsole
|
||||
<< "ERROR: File "
|
||||
<< pathAsString
|
||||
<< " could not be opened for input"
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
char line[1000];
|
||||
|
||||
testStream2.seek(0); // check that the seek compiles
|
||||
while (!testStream2.eof())
|
||||
{
|
||||
testStream2.readline(line, sizeof(line));
|
||||
mConsole << line << nsEndl;
|
||||
}
|
||||
Inspect();
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
int FilesTest::Parent(
|
||||
const char* relativePath,
|
||||
nsFileSpec& outParent)
|
||||
const char* relativePath,
|
||||
nsFileSpec& outParent)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsFilePath myTextFilePath(relativePath, PR_TRUE);
|
||||
const char* pathAsString = (const char*)myTextFilePath;
|
||||
nsFileSpec mySpec(myTextFilePath);
|
||||
nsFilePath myTextFilePath(relativePath, PR_TRUE);
|
||||
const char* pathAsString = (const char*)myTextFilePath;
|
||||
nsFileSpec mySpec(myTextFilePath);
|
||||
|
||||
mySpec.GetParent(outParent);
|
||||
nsFilePath parentPath(outParent);
|
||||
mConsole
|
||||
<< "GetParent() on "
|
||||
<< "\n\t" << pathAsString
|
||||
<< "\n yields "
|
||||
<< "\n\t" << (const char*)parentPath
|
||||
<< nsEndl;
|
||||
Inspect();
|
||||
return 0;
|
||||
mConsole
|
||||
<< "GetParent() on "
|
||||
<< "\n\t" << pathAsString
|
||||
<< "\n yields "
|
||||
<< "\n\t" << (const char*)parentPath
|
||||
<< nsEndl;
|
||||
Inspect();
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
int FilesTest::Delete(nsFileSpec& victim)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
// - Test of non-recursive delete
|
||||
// - Test of non-recursive delete
|
||||
|
||||
nsFilePath victimPath(victim);
|
||||
mConsole
|
||||
<< "Attempting to delete "
|
||||
<< "\n\t" << (const char*)victimPath
|
||||
<< "\n without recursive option (should fail)"
|
||||
<< nsEndl;
|
||||
victim.Delete(PR_FALSE);
|
||||
if (victim.Exists())
|
||||
Passed();
|
||||
else
|
||||
{
|
||||
mConsole
|
||||
<< "ERROR: File "
|
||||
<< "\n\t" << (const char*)victimPath
|
||||
<< "\n has been deleted without the recursion option,"
|
||||
<< "\n and is a nonempty directory!"
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
mConsole
|
||||
<< "Attempting to delete "
|
||||
<< "\n\t" << (const char*)victimPath
|
||||
<< "\n without recursive option (should fail)"
|
||||
<< nsEndl;
|
||||
victim.Delete(PR_FALSE);
|
||||
if (victim.Exists())
|
||||
Passed();
|
||||
else
|
||||
{
|
||||
mConsole
|
||||
<< "ERROR: File "
|
||||
<< "\n\t" << (const char*)victimPath
|
||||
<< "\n has been deleted without the recursion option,"
|
||||
<< "\n and is a nonempty directory!"
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// - Test of recursive delete
|
||||
// - Test of recursive delete
|
||||
|
||||
mConsole
|
||||
<< nsEndl
|
||||
<< "Deleting "
|
||||
<< "\n\t" << (const char*)victimPath
|
||||
<< "\n with recursive option"
|
||||
<< nsEndl;
|
||||
victim.Delete(PR_TRUE);
|
||||
if (victim.Exists())
|
||||
{
|
||||
mConsole
|
||||
<< "ERROR: Directory "
|
||||
<< "\n\t" << (const char*)victimPath
|
||||
<< "\n has NOT been deleted despite the recursion option!"
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
Passed();
|
||||
return 0;
|
||||
mConsole
|
||||
<< nsEndl
|
||||
<< "Deleting "
|
||||
<< "\n\t" << (const char*)victimPath
|
||||
<< "\n with recursive option"
|
||||
<< nsEndl;
|
||||
victim.Delete(PR_TRUE);
|
||||
if (victim.Exists())
|
||||
{
|
||||
mConsole
|
||||
<< "ERROR: Directory "
|
||||
<< "\n\t" << (const char*)victimPath
|
||||
<< "\n has NOT been deleted despite the recursion option!"
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
Passed();
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
@@ -394,7 +426,7 @@ int FilesTest::CreateDirectoryRecursive(const char* aPath)
|
||||
int FilesTest::IterateDirectoryChildren(nsFileSpec& startChild)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
// - Test of directory iterator
|
||||
// - Test of directory iterator
|
||||
|
||||
nsFileSpec grandparent;
|
||||
startChild.GetParent(grandparent); // should be the original default directory.
|
||||
@@ -403,41 +435,41 @@ int FilesTest::IterateDirectoryChildren(nsFileSpec& startChild)
|
||||
mConsole << "Forwards listing of " << (const char*)grandparentPath << ":" << nsEndl;
|
||||
for (nsDirectoryIterator i(grandparent, +1); i.Exists(); i++)
|
||||
{
|
||||
char* itemName = ((nsFileSpec&)i).GetLeafName();
|
||||
mConsole << '\t' << itemName << nsEndl;
|
||||
delete [] itemName;
|
||||
char* itemName = ((nsFileSpec&)i).GetLeafName();
|
||||
mConsole << '\t' << itemName << nsEndl;
|
||||
delete [] itemName;
|
||||
}
|
||||
|
||||
mConsole << "Backwards listing of " << (const char*)grandparentPath << ":" << nsEndl;
|
||||
for (nsDirectoryIterator j(grandparent, -1); j.Exists(); j--)
|
||||
{
|
||||
char* itemName = ((nsFileSpec&)j).GetLeafName();
|
||||
mConsole << '\t' << itemName << nsEndl;
|
||||
delete [] itemName;
|
||||
char* itemName = ((nsFileSpec&)j).GetLeafName();
|
||||
mConsole << '\t' << itemName << nsEndl;
|
||||
delete [] itemName;
|
||||
}
|
||||
Inspect();
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
int FilesTest::CanonicalPath(
|
||||
const char* relativePath)
|
||||
const char* relativePath)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsFilePath myTextFilePath(relativePath, PR_TRUE);
|
||||
const char* pathAsString = (const char*)myTextFilePath;
|
||||
if (*pathAsString != '/')
|
||||
{
|
||||
mConsole
|
||||
<< "ERROR: after initializing the path object with a relative path,"
|
||||
<< "\n the path consisted of the string "
|
||||
<< "\n\t" << pathAsString
|
||||
<< "\n which is not a canonical full path!"
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
Passed();
|
||||
return 0;
|
||||
nsFilePath myTextFilePath(relativePath, PR_TRUE);
|
||||
const char* pathAsString = (const char*)myTextFilePath;
|
||||
if (*pathAsString != '/')
|
||||
{
|
||||
mConsole
|
||||
<< "ERROR: after initializing the path object with a relative path,"
|
||||
<< "\n the path consisted of the string "
|
||||
<< "\n\t" << pathAsString
|
||||
<< "\n which is not a canonical full path!"
|
||||
<< nsEndl;
|
||||
return -1;
|
||||
}
|
||||
Passed();
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
@@ -445,36 +477,27 @@ int FilesTest::Copy(const char* file, const char* dir)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsFileSpec dirPath(dir, PR_TRUE);
|
||||
|
||||
dirPath.CreateDirectory();
|
||||
|
||||
dirPath.CreateDirectory();
|
||||
if (! dirPath.Exists())
|
||||
{
|
||||
Failed();
|
||||
return -1;
|
||||
}
|
||||
return Failed();
|
||||
|
||||
|
||||
nsFileSpec mySpec(file, PR_TRUE); // relative path.
|
||||
{
|
||||
nsIOFileStream testStream(mySpec); // creates the file
|
||||
// Scope ends here, file gets closed
|
||||
nsIOFileStream testStream(mySpec); // creates the file
|
||||
// Scope ends here, file gets closed
|
||||
}
|
||||
|
||||
nsFileSpec filePath(file);
|
||||
if (! filePath.Exists())
|
||||
{
|
||||
Failed();
|
||||
return -1;
|
||||
}
|
||||
return Failed();
|
||||
|
||||
nsresult error = filePath.Copy(dirPath);
|
||||
|
||||
dirPath += filePath.GetLeafName();
|
||||
if (! dirPath.Exists() || ! filePath.Exists() || NS_FAILED(error))
|
||||
{
|
||||
Failed();
|
||||
return -1;
|
||||
}
|
||||
return Failed();
|
||||
|
||||
Passed();
|
||||
|
||||
@@ -486,13 +509,10 @@ int FilesTest::Move(const char* file, const char* dir)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsFileSpec dirPath(dir, PR_TRUE);
|
||||
|
||||
dirPath.CreateDirectory();
|
||||
|
||||
dirPath.CreateDirectory();
|
||||
if (! dirPath.Exists())
|
||||
{
|
||||
Failed();
|
||||
return -1;
|
||||
}
|
||||
return Failed();
|
||||
|
||||
|
||||
nsFileSpec srcSpec(file, PR_TRUE); // relative path.
|
||||
@@ -502,20 +522,14 @@ int FilesTest::Move(const char* file, const char* dir)
|
||||
};
|
||||
|
||||
if (! srcSpec.Exists())
|
||||
{
|
||||
Failed();
|
||||
return -1;
|
||||
}
|
||||
return Failed();
|
||||
|
||||
nsresult error = srcSpec.Move(dirPath);
|
||||
|
||||
|
||||
dirPath += srcSpec.GetLeafName();
|
||||
if (! dirPath.Exists() || srcSpec.Exists() || NS_FAILED(error))
|
||||
{
|
||||
Failed();
|
||||
return -1;
|
||||
}
|
||||
return Failed();
|
||||
|
||||
Passed();
|
||||
return 0;
|
||||
@@ -527,17 +541,11 @@ int FilesTest::Execute(const char* appName, const char* args)
|
||||
{
|
||||
nsFileSpec appPath(appName, PR_FALSE);
|
||||
if (!appPath.Exists())
|
||||
{
|
||||
Failed();
|
||||
return -1;
|
||||
}
|
||||
|
||||
return Failed();
|
||||
|
||||
nsresult error = appPath.Execute(args);
|
||||
if (NS_FAILED(error))
|
||||
{
|
||||
Failed();
|
||||
return -1;
|
||||
}
|
||||
return Failed();
|
||||
|
||||
Passed();
|
||||
|
||||
@@ -545,7 +553,9 @@ int FilesTest::Execute(const char* appName, const char* args)
|
||||
}
|
||||
|
||||
#if WHEN_MCMULLEN_REVIEWS
|
||||
//----------------------------------------------------------------------------------------
|
||||
int FilesTest::SpecialSystemDirectories()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
mConsole << "Please verify that these are the paths to various system directories:" << nsEndl;
|
||||
|
||||
@@ -775,7 +785,7 @@ int FilesTest::SpecialSystemDirectories()
|
||||
Passed();
|
||||
return 0;
|
||||
|
||||
}
|
||||
} // FilesTest::SpecialSystemDirectories
|
||||
#endif
|
||||
|
||||
|
||||
@@ -812,6 +822,10 @@ int FilesTest::RunAllTests()
|
||||
if (InputStream("mumble/iotest.txt") != 0)
|
||||
return -1;
|
||||
|
||||
Banner("StringStream");
|
||||
if (StringStream() != 0)
|
||||
return -1;
|
||||
|
||||
Banner("Parent");
|
||||
nsFileSpec parent;
|
||||
if (Parent("mumble/iotest.txt", parent) != 0)
|
||||
@@ -848,9 +862,9 @@ int FilesTest::RunAllTests()
|
||||
|
||||
Banner("Execute");
|
||||
#ifdef XP_MAC
|
||||
// This path is hard-coded to test on jrm's machine. Finding an app
|
||||
// on an arbitrary Macintosh would cost more trouble than it's worth.
|
||||
// Change path to suit.
|
||||
// This path is hard-coded to test on jrm's machine. Finding an app
|
||||
// on an arbitrary Macintosh would cost more trouble than it's worth.
|
||||
// Change path to suit.
|
||||
if NS_FAILED(Execute("/Projects/Nav45_BRANCH/ns/cmd/macfe/"\
|
||||
"projects/client45/Client45PPC", ""))
|
||||
#elif XP_PC
|
||||
@@ -859,17 +873,13 @@ int FilesTest::RunAllTests()
|
||||
if NS_FAILED(Execute("/bin/ls", "/"))
|
||||
#endif
|
||||
return -1;
|
||||
|
||||
#if WHEN_MCMULLEN_REVIEWS
|
||||
Banner("Special System Directories");
|
||||
if (SpecialSystemDirectories() != 0)
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
Banner("Move");
|
||||
if (Move("mumble/moveFile.txt", "mumble/move") != 0)
|
||||
return -1;
|
||||
|
||||
|
||||
Banner("Persistence");
|
||||
if (Persistence("mumble/filedesc.dat") != 0)
|
||||
return -1;
|
||||
@@ -879,14 +889,13 @@ int FilesTest::RunAllTests()
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
} // FilesTest::RunAllTests
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
int main()
|
||||
// For use with DEBUG defined.
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
FilesTest tester;
|
||||
return tester.RunAllTests();
|
||||
FilesTest tester;
|
||||
return tester.RunAllTests();
|
||||
} // main
|
||||
|
||||
Reference in New Issue
Block a user