home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / pascal / shdk_1.zip / TESTCRC.PAS < prev    next >
Pascal/Delphi Source File  |  1992-03-23  |  2KB  |  68 lines

  1. program TestCrc;
  2. {
  3.                        To test the ShCrcChk unit
  4.  
  5.                   Copyright 1991 Madison & Associates
  6.                           All Rights Reserved
  7.  
  8.          This program source file and the associated executable
  9.          file may be  used and distributed  only in  accordance
  10.          with the  provisions  described  on  the title page of
  11.                   the accompanying documentation file
  12.                               SKYHAWK.DOC
  13. }
  14.  
  15. uses
  16.   TpString,
  17.   TpCrt,
  18.   ShCrcChk;
  19.  
  20. var
  21.   OriginalCRC,
  22.   CopiedFileCRC,
  23.   ChangedFileCRC: word;
  24.   XXX           : file of byte;
  25.   T1            : longint;
  26.   B1            : byte;
  27. begin
  28.   WriteLn('Reads this program source file and calculates its CRC,');
  29.   WriteLn('makes a true copy and calculates its CRC, then makes a');
  30.   WriteLn('copy with one character at or near the mid-point of the');
  31.   WriteLn('file changed and calculates its CRC. At the completion the');
  32.   WriteLn('three CRC''s are displayed.');
  33.   WriteLn('');
  34.   WriteLn('Copying with CrcCopy...');
  35.   OriginalCRC := CrcCopy('TESTCRC.PAS', 'TESTCRC.CK1');
  36.   CopiedFileCRC := CrcCopy('TESTCRC.CK1', 'TESTCRC.CK2');
  37.   WriteLn('Changing one character in the second copy...');
  38.   {Now change one character in the second file, somewhere near the middle}
  39.   Assign(XXX, 'TESTCRC.CK2');
  40.   Reset(XXX);
  41.   T1 := FileSize(XXX) shr 1;
  42.   Seek(XXX, T1);
  43.   repeat
  44.     Read(XXX,B1);
  45.     inc(T1);
  46.     until (B1 >= 32); {Change only a readable character}
  47.   dec(T1);  {Put the pointer back where it belongs}
  48.   Write('':5,'A ''',char(B1),''' is being changed to a ''');
  49.   inc(B1);
  50.   WriteLn(char(B1),'''');
  51.   Seek(XXX, T1);
  52.   Write(XXX,B1);
  53.   Close(XXX);
  54.   WriteLn('Calculating CRC of modified copy with CrcCalc...');
  55.   ChangedFileCRC := CrcCalc('TESTCRC.CK2');
  56.   {Tests completed. Display the result.}
  57.   WriteLn('CRC of original file = ',HexW(OriginalCRC));
  58.   WriteLn('CRC of true copy     = ',HexW(CopiedFileCRC));
  59.   WriteLn('CRC of changed copy  = ',HexW(ChangedFileCRC));
  60.   WriteLn;
  61.   Write('Delete the copied test files (Y/n)? » ');
  62.   if not (UpCase(ReadKey) = 'N') then begin
  63.     Erase(XXX);
  64.     Assign(XXX, 'TESTCRC.CK1');
  65.     Erase(XXX);
  66.     end;
  67.   end.
  68.