Rewrote the stream stuff to be simple, since Unix build environment cannot even handle ostream and istream. This builds and runs correctly on Linux and Macintosh now.
git-svn-id: svn://10.0.0.236/trunk@16688 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -1,53 +1,46 @@
|
||||
#include "nsFileSpec.h"
|
||||
#include "nsFileStream.h"
|
||||
|
||||
#ifdef NS_USING_STL
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
#else
|
||||
#include <iostream.h>
|
||||
#endif
|
||||
|
||||
NS_NAMESPACE FileTest
|
||||
{
|
||||
NS_NAMESPACE_PROTOTYPE void WriteStuff(ostream& s);
|
||||
NS_NAMESPACE_PROTOTYPE void WriteStuff(nsOutputFileStream& s);
|
||||
} NS_NAMESPACE_END
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void FileTest::WriteStuff(ostream& s)
|
||||
void FileTest::WriteStuff(nsOutputFileStream& s)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
// Initialize a URL from a string without suffix. Change the path to suit your machine.
|
||||
nsFileURL fileURL("file:///Development/MPW/MPW%20Shell");
|
||||
s << "File URL initialized to: \"" << fileURL << "\""<< endl;
|
||||
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 << "\""<< endl;
|
||||
s << "As a unix path: \"" << (const char*)filePath << "\""<< nsEndl;
|
||||
|
||||
// Initialize a native file spec from a URL
|
||||
nsNativeFileSpec fileSpec(fileURL);
|
||||
s << "As a file spec: " << fileSpec << endl;
|
||||
s << "As a file spec: " << fileSpec << nsEndl;
|
||||
|
||||
// Make the spec unique (this one has no suffix).
|
||||
fileSpec.MakeUnique();
|
||||
s << "Unique file spec: " << fileSpec << endl;
|
||||
s << "Unique file spec: " << fileSpec << nsEndl;
|
||||
|
||||
// Assign the spec to a URL
|
||||
fileURL = fileSpec;
|
||||
s << "File URL assigned from spec: \"" << fileURL << "\""<< endl;
|
||||
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 << "\""<< endl;
|
||||
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 << endl;
|
||||
s << "File spec reassigned to: " << fileSpec << nsEndl;
|
||||
|
||||
// Make this unique (this one has a suffix).
|
||||
fileSpec.MakeUnique();
|
||||
s << "File spec made unique: " << fileSpec << endl;
|
||||
s << "File spec made unique: " << fileSpec << nsEndl;
|
||||
} // WriteStuff
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
@@ -58,33 +51,36 @@ void main()
|
||||
|
||||
// Test of nsFileSpec
|
||||
|
||||
cout << "WRITING TEST OUTPUT TO cout" << endl << endl;
|
||||
FileTest::WriteStuff(cout);
|
||||
cout << endl << endl;
|
||||
nsOutputFileStream nsOut(cout);
|
||||
nsOut << "WRITING TEST OUTPUT TO cout" << nsEndl << nsEndl;
|
||||
|
||||
FileTest::WriteStuff(nsOut);
|
||||
nsOut << nsEndl << nsEndl;
|
||||
|
||||
// Test of nsOutputFileStream
|
||||
|
||||
nsFilePath myTextFilePath("/Development/iotest.txt");
|
||||
|
||||
{
|
||||
cout << "WRITING IDENTICAL OUTPUT TO " << (const char*)myTextFilePath << endl << endl;
|
||||
nsOut << "WRITING IDENTICAL OUTPUT TO " << (const char*)myTextFilePath << nsEndl << nsEndl;
|
||||
nsOutputFileStream testStream(myTextFilePath);
|
||||
NS_ASSERTION(testStream.is_open(), "File could not be opened");
|
||||
FileTest::WriteStuff(testStream);
|
||||
} // <-- Scope closes the stream (and the file).
|
||||
|
||||
// Test of nsInputFileStream
|
||||
|
||||
{
|
||||
cout << "READING BACK DATA FROM " << (const char*)myTextFilePath << endl << endl;
|
||||
nsOut << "READING BACK DATA FROM " << (const char*)myTextFilePath << nsEndl << nsEndl;
|
||||
nsInputFileStream testStream2(myTextFilePath);
|
||||
NS_ASSERTION(testStream2.is_open(), "File could not be opened");
|
||||
char line[1000];
|
||||
|
||||
testStream2.seekg(0); // check that the seek template compiles
|
||||
testStream2.seek(0); // check that the seek compiles
|
||||
while (!testStream2.eof())
|
||||
{
|
||||
testStream2.getline(line, sizeof(line), '\n');
|
||||
cout << line << endl;
|
||||
testStream2.readline(line, sizeof(line));
|
||||
nsOut << line << nsEndl;
|
||||
}
|
||||
}
|
||||
|
||||
} // main
|
||||
|
||||
Reference in New Issue
Block a user