home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1994 June / NEBULA_SE.ISO / SourceCode / MiscKit / Examples / MiscLockFile / LockFileTest.m next >
Encoding:
Text File  |  1994-01-06  |  2.4 KB  |  62 lines

  1. //
  2. // LockFileTest.m -- test out the lock file class
  3. //        Written by Don Yacktman (c) 1993 by Don Yacktman.
  4. //                Version 1.0.  All rights reserved.
  5. //
  6. //        This notice may not be removed from this source code.
  7. //
  8. //    This program is included in the MiscKit by permission from the author
  9. //    and its use is governed by the MiscKit license, found in the file
  10. //    "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
  11. //    for a list of all applicable permissions and restrictions.
  12. //    
  13.  
  14. #import <misckit/misckit.h>
  15. #import <appkit/appkit.h>
  16. #import <stdio.h>
  17.  
  18. void main()
  19. {
  20.     id lockFile1 = [[MiscLockFile alloc] init];
  21.     id lockFile2 = [[MiscLockFile alloc] init];
  22.  
  23.     printf("Standard lock/unlock test...");
  24.     [lockFile1 setFileName:[[MiscString alloc] initString:"lock1"]];
  25.     if (![lockFile1 lock]) { printf("failed on lock.\n"); exit(1); }
  26.     printf("\n");
  27.     system("ls -alsFg lock1");
  28.     system("cat lock1"); printf("\n");
  29.     if (![lockFile1 haveLock]) { printf("haveLock is wrong.\n"); exit(1); }
  30.     if (![lockFile1 unlock]) { printf("failed on unlock.\n"); exit(1); }
  31.     system("ls -alsFg lock1");
  32.     printf("passed.\n");
  33.  
  34.     printf("Attempt to obtain lock when someone else has it...");
  35.     [lockFile2 setFileName:[[MiscString alloc] initString:"lock1"]];
  36.     if (![lockFile1 lock]) { printf("failed on initial lock.\n"); exit(1); }
  37.     if ([lockFile2 lock]) { printf("second client got lock.\n"); exit(1); }
  38.     if (![lockFile1 haveLock]) { printf("haveLock #1 is wrong.\n"); exit(1); }
  39.     if ([lockFile2 haveLock]) { printf("haveLock #2 is wrong.\n"); exit(1); }
  40.     if (![lockFile1 unlock]) { printf("failed on unlock.\n"); exit(1); }
  41.     if ([lockFile2 unlock]) { printf("lock #2 unlocked.\n"); exit(1); }
  42.     printf("passed.\n");
  43.  
  44.     printf("Dual lock/unlock test...");
  45.     [lockFile1 setFileName:[[MiscString alloc] initString:"lock1"]];
  46.     [lockFile2 setFileName:[[MiscString alloc] initString:"lock2"]];
  47.     if (![lockFile1 lock]) { printf("failed on lock #1.\n"); exit(1); }
  48.     if (![lockFile2 lock]) { printf("failed on lock #2.\n"); exit(1); }
  49.     printf("\n");
  50.     system("ls -alsFg lock1 lock2");
  51.     system("cat lock1"); printf("\n");
  52.     system("cat lock2"); printf("\n");
  53.     if (![lockFile1 haveLock]) { printf("haveLock #1 is wrong.\n"); exit(1); }
  54.     if (![lockFile2 haveLock]) { printf("haveLock #2 is wrong.\n"); exit(1); }
  55.     if (![lockFile1 unlock]) { printf("failed on unlock #1.\n"); exit(1); }
  56.     if (![lockFile2 unlock]) { printf("failed on unlock #2.\n"); exit(1); }
  57.     system("ls -alsFg lock1 lock2");
  58.     printf("passed.\n");
  59.  
  60.     exit(0);
  61. }
  62.