Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
Sources/FileClassTest.cp
/* |
File: FileClassTest.cp |
Contains: TFile is a simple object that does file manipulations |
TFileTest.cp contains the TFile class and subclass test functions. |
Written by: Kent Sandvik |
Copyright: Copyright © 1992-1999 by Apple Computer, Inc., All Rights Reserved. |
You may incorporate this Apple sample source code into your program(s) without |
restriction. This Apple sample source code has been provided "AS IS" and the |
responsibility for its operation is yours. You are not permitted to redistribute |
this Apple sample source code as "Apple sample source code" after having made |
changes. If you're going to re-distribute the source, we require that you make |
it clear in the source that the code was descended from Apple sample source |
code, but that you've made changes. |
Change History (most recent first): |
8/18/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1 |
*/ |
#ifndef _FILECLASS_ |
#include "FileClass.h" |
#endif |
const short kSize = 5; |
// This is a simple test that will try to create, open, store and retrieve data |
// from files. |
void main(void) |
{ |
char myString[255]="Test File 1"; |
cout << "Start of the TFile object testÉ\n"; |
cout << "\nTest x: Create File and get File info (FInfo)É\n"; |
TDataFile myFile(myString); |
myFile.Create(); |
FInfo myInfo = myFile.GetFileInfo(); |
cout << "File signature is " << myInfo.fdCreator << "\n"; |
cout << "\nTest x:Rename and open the fileÉ\n"; |
strcpy(myString,"Test File 2"); |
myFile.Rename(myString); |
myFile.Open(); |
cout << "\nTest x: Write and Read handles to fileÉ\n"; |
Handle myH = ::NewHandle(kSize); // handle |
(**myH) = '!'; // set a value inside the handle |
myFile.WriteHandle(myH); // write it down to disk |
Handle result = myFile.ReadHandle(); // read the handle back |
cout << "The character stored isÉ " << (**result) << " and it should be ! \n"; |
::DisposeHandle(result); |
::DisposeHandle(myH); |
cout << "\nTest x: Write and Read buffers to fileÉ\n"; |
Ptr myBuffer = ::NewPtr(kSize); // 100 byte buffer |
for (short i = 0; i < kSize; i++) |
myBuffer[i] = 'P'; // stuff the buffer full of 'P's |
myFile.Reset(); // set mark to beginning of file |
myFile.Write(myBuffer, kSize); // write the buffer to disk |
Ptr otherBuffer = ::NewPtr(kSize); // create another buffer |
myFile.Reset(); // reset to beginning of file |
myFile.Read(otherBuffer, kSize); // read the bytes |
for (int i = 0; i < kSize; i++) |
cout << otherBuffer[i]; |
::DisposePtr(otherBuffer); |
::DisposePtr(myBuffer); |
cout << "\nTest x: Create a Resource file, and write into it, and read the resourceÉ\n"; |
strcpy(myString,"Resource File"); |
TResourceFile myResourceFile(myString); |
myResourceFile.Create(); |
myResourceFile.Open(); |
if (myResourceFile.HasResourceFork()) |
cout << "We have a resource fork in the resource file created\n"; |
else |
cout << "We don't have a resource fork in the resource file created.\n"; |
myResourceFile.Update(); |
myResourceFile.Assign(); |
cout << "\nTest x:Close and delete the filesÉ\n"; |
myFile.Close(); |
myResourceFile.Close(); |
myFile.Delete(); |
myResourceFile.Delete(); |
cout << "\nEnd of the TFile object test!\n"; |
} |
// _________________________________________________________________________________________________________ // |
/* Change History (most recent last): |
No Init. Date Comment |
1 khs 12/27/92 New file |
2 khs 1/14/93 Cleanup |
*/ |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-01-14