home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-01-14 | 2.9 KB | 90 lines | [TEXT/MPS ] |
- /* _________________________________________________________________________________________________________ //
- Copyright © 1992-93 Apple Computer, Inc. All rights reserved.
- Macintosh Developer Technical Support.C++ Macintosh Toolbox Framework.
- Programmer: Kent Sandvik
- Date: 12/27/92
- Revision comments are at the end of this file.
- ---
- TFile is a simple object that does file manipulations
- TFileTest.cp contains the TFile class and subclass test functions.
- _________________________________________________________________________________________________________ */
-
- #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)
- {
- cout << "Start of the TFile object test…\n";
-
- cout << "\nTest x: Create File and get File info (FInfo)…\n";
- TDataFile myFile("Test File 1");
- myFile.Create();
- FInfo myInfo = myFile.GetFileInfo();
- cout << "File signature is " << myInfo.fdCreator << "\n";
-
-
- cout << "\nTest x:Rename and open the file…\n";
- myFile.Rename("Test File 2");
- 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 (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";
- TResourceFile myResourceFile("Resource File");
- 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
- */
-