1998-12-08 05:22:54 +03:00
|
|
|
#include "nsFileSpec.h"
|
|
|
|
#include "nsFileStream.h"
|
|
|
|
|
1998-12-16 01:45:09 +03:00
|
|
|
#ifdef NS_USING_STL
|
1998-12-12 02:05:24 +03:00
|
|
|
#include <iostream>
|
|
|
|
using namespace std;
|
|
|
|
#else
|
|
|
|
#include <iostream.h>
|
|
|
|
#endif
|
|
|
|
|
1998-12-09 11:47:30 +03:00
|
|
|
NS_NAMESPACE FileTest
|
1998-12-08 05:22:54 +03:00
|
|
|
{
|
1998-12-16 01:45:09 +03:00
|
|
|
NS_NAMESPACE_PROTOTYPE void WriteStuff(ostream& s);
|
1998-12-09 11:47:30 +03:00
|
|
|
} NS_NAMESPACE_END
|
1998-12-08 05:22:54 +03:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
void FileTest::WriteStuff(ostream& s)
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
|
|
|
// Initialize a URL from a string without suffix. Change the path to suit your machine.
|
|
|
|
nsFileURL fileURL("file:///Development/MPW/MPW%20Shell");
|
1998-12-09 11:47:30 +03:00
|
|
|
s << "File URL initialized to: \"" << fileURL << "\""<< endl;
|
1998-12-08 05:22:54 +03:00
|
|
|
|
|
|
|
// Initialize a Unix path from a URL
|
1998-12-09 01:45:42 +03:00
|
|
|
nsFilePath filePath(fileURL);
|
1998-12-09 11:47:30 +03:00
|
|
|
s << "As a unix path: \"" << (const char*)filePath << "\""<< endl;
|
1998-12-08 05:22:54 +03:00
|
|
|
|
|
|
|
// Initialize a native file spec from a URL
|
|
|
|
nsNativeFileSpec fileSpec(fileURL);
|
|
|
|
s << "As a file spec: " << fileSpec << endl;
|
|
|
|
|
|
|
|
// Make the spec unique (this one has no suffix).
|
|
|
|
fileSpec.MakeUnique();
|
|
|
|
s << "Unique file spec: " << fileSpec << endl;
|
|
|
|
|
|
|
|
// Assign the spec to a URL
|
|
|
|
fileURL = fileSpec;
|
1998-12-09 11:47:30 +03:00
|
|
|
s << "File URL assigned from spec: \"" << fileURL << "\""<< endl;
|
1998-12-08 05:22:54 +03:00
|
|
|
|
|
|
|
// Assign a unix path using a string with a suffix.
|
|
|
|
filePath = "/Development/MPW/SysErrs.err";
|
1998-12-09 11:47:30 +03:00
|
|
|
s << "File path reassigned to: \"" << (const char*)filePath << "\""<< endl;
|
1998-12-08 05:22:54 +03:00
|
|
|
|
|
|
|
// Assign to a file spec using a unix path.
|
|
|
|
fileSpec = filePath;
|
|
|
|
s << "File spec reassigned to: " << fileSpec << endl;
|
|
|
|
|
|
|
|
// Make this unique (this one has a suffix).
|
|
|
|
fileSpec.MakeUnique();
|
|
|
|
s << "File spec made unique: " << fileSpec << endl;
|
|
|
|
} // WriteStuff
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
void main()
|
|
|
|
// For use with DEBUG defined.
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
{
|
|
|
|
|
|
|
|
// Test of nsFileSpec
|
|
|
|
|
|
|
|
cout << "WRITING TEST OUTPUT TO cout" << endl << endl;
|
|
|
|
FileTest::WriteStuff(cout);
|
|
|
|
cout << endl << endl;
|
|
|
|
|
|
|
|
// Test of nsOutputFileStream
|
|
|
|
|
1998-12-09 01:45:42 +03:00
|
|
|
nsFilePath myTextFilePath("/Development/iotest.txt");
|
|
|
|
|
|
|
|
{
|
1998-12-09 11:47:30 +03:00
|
|
|
cout << "WRITING IDENTICAL OUTPUT TO " << (const char*)myTextFilePath << endl << endl;
|
1998-12-09 01:45:42 +03:00
|
|
|
nsOutputFileStream testStream(myTextFilePath);
|
|
|
|
FileTest::WriteStuff(testStream);
|
|
|
|
} // <-- Scope closes the stream (and the file).
|
1998-12-08 05:22:54 +03:00
|
|
|
|
|
|
|
// Test of nsInputFileStream
|
|
|
|
|
|
|
|
{
|
1998-12-09 11:47:30 +03:00
|
|
|
cout << "READING BACK DATA FROM " << (const char*)myTextFilePath << endl << endl;
|
1998-12-09 01:45:42 +03:00
|
|
|
nsInputFileStream testStream2(myTextFilePath);
|
|
|
|
char line[1000];
|
1998-12-12 02:52:31 +03:00
|
|
|
|
|
|
|
testStream2.seekg(0); // check that the seek template compiles
|
1998-12-09 01:45:42 +03:00
|
|
|
while (!testStream2.eof())
|
|
|
|
{
|
|
|
|
testStream2.getline(line, sizeof(line), '\n');
|
|
|
|
cout << line << endl;
|
|
|
|
}
|
1998-12-08 05:22:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
} // main
|