home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / DockStrip / MoreInterfaceLib / TestMoreInterfaceLib / TestMoreInterfaceLib.c next >
Encoding:
C/C++ Source or Header  |  2000-06-24  |  5.7 KB  |  233 lines

  1. /*
  2.     File:        TestMoreInterfaceLib.c
  3.  
  4.     Contains:    Test rig for MoreInterfaceLib.
  5.  
  6.     Written by:    Quinn
  7.  
  8.     Copyright:    Copyright © 1999 by Apple Computer, Inc., all rights reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.  
  20.          <3>     16/9/99    Quinn   Add real code to test the FSM FCB accessors.
  21.          <2>     15/6/99    Quinn   Link with the Extended Disk Init Package routines, just to test
  22.                                     their linkage.
  23.          <1>     20/4/99    Quinn   First checked in.
  24. */
  25.  
  26. /////////////////////////////////////////////////////////////////
  27. // MoreIsBetter Setup
  28.  
  29. #include "MoreSetup.h"
  30.  
  31. /////////////////////////////////////////////////////////////////
  32. // Mac OS Interfaces
  33.  
  34. #include <MacTypes.h>
  35. #include <Devices.h>
  36. #include <Gestalt.h>
  37. #include <TextUtils.h>
  38.  
  39. /////////////////////////////////////////////////////////////////
  40. // ANSI C Interfaces
  41.  
  42. #include <stdio.h>
  43.  
  44. /////////////////////////////////////////////////////////////////
  45. // MIB Interfaces
  46.  
  47. #include "MoreInterfaceLib.h"
  48.  
  49. /////////////////////////////////////////////////////////////////
  50.  
  51. static void DoTestGestaltValue(void)
  52. {
  53.     OSStatus err;
  54.     SInt32 tmp;
  55.     
  56.     err = MoreNewGestaltValue('Foo!', 666);
  57.     if (err == noErr) {
  58.         err = Gestalt('Foo!', &tmp);
  59.         if (err == noErr && tmp != 666) {
  60.             err = -1;
  61.         }
  62.     }
  63.     if (err == noErr) {
  64.         err = MoreReplaceGestaltValue('Foo!', 667);
  65.         if (err == noErr) {
  66.             err = Gestalt('Foo!', &tmp);
  67.             if (err == noErr && tmp != 667) {
  68.                 err = -2;
  69.             }
  70.         }
  71.     }
  72.     if (err == noErr) {
  73.         err = MoreSetGestaltValue ('Foo!', 668);
  74.         if (err == noErr) {
  75.             err = Gestalt('Foo!', &tmp);
  76.             if (err == noErr && tmp != 668) {
  77.                 err = -2;
  78.             }
  79.         }
  80.     }
  81.     if (err == noErr) {
  82.         err = MoreDeleteGestaltValue('Foo!');
  83.         if (err == noErr) {
  84.             if ( Gestalt('Foo!', &tmp) == noErr) {
  85.                 err = -3;
  86.             }
  87.         }
  88.     }
  89.     
  90.     if (err == noErr) {
  91.         printf("Success!\n");
  92.     } else {
  93.         printf("Failed with error %ld.\n", err);
  94.     }
  95. }
  96.  
  97. /////////////////////////////////////////////////////////////////
  98.  
  99. static void DoTestExtendedDiskInit(Boolean mustBeFalse)
  100. {
  101.     printf("The purpose of this test is simple to test the linkage.\n");
  102.     if (mustBeFalse) {
  103.         OSStatus err;
  104.         
  105.         err = MoreDIXFormat(1, false, 0, nil);
  106.         err = MoreDIXZero(1, nil, 0, 0, 0, 0, nil);
  107.         err = MoreDIReformat(1, 0, nil, nil);
  108.     }
  109. }
  110.  
  111. /////////////////////////////////////////////////////////////////
  112.  
  113. static void DoTestFSM()
  114. {
  115.     // MoreUTFindDrive
  116.     {
  117.         SInt16 firstDriveNum;
  118.         DrvQElPtr foundDrive;
  119.     
  120.         firstDriveNum = ((DrvQElPtr) GetDrvQHdr()->qHead)->dQDrive;
  121.         
  122.         if ( MoreUTFindDrive(firstDriveNum, &foundDrive) != noErr ||
  123.                     foundDrive->dQDrive != firstDriveNum) {
  124.             printf("•••MoreUTFindDrive failed.\n");
  125.         }
  126.     }
  127.     
  128.     // MoreUTLocateFCB
  129.     {
  130.         VCBPtr firstVCB;
  131.         SInt16 foundRefNum;
  132.         FCBRecPtr foundFCB;
  133.         OSStatus junk;
  134.         OSStatus err;
  135.         UInt32 sysVersion;
  136.                 
  137.         // We're assuming that the boot volume is first in the VCB,
  138.         // that the system file is named "System", and that it's
  139.         // file reference number is 2.  All of this is not guaranteed
  140.         // to be true, but it's good enough for this test tool..
  141.         
  142.         firstVCB = ((VCBPtr) GetVCBQHdr()->qHead);
  143.         if ( MoreUTLocateFCB(firstVCB, 0, "\pSystem", &foundRefNum, &foundFCB) == noErr
  144.                     && foundRefNum == 2
  145.                     && EqualString(foundFCB->fcbCName, "\pSystem", false, true)) {
  146.  
  147.             // Get system version.
  148.             
  149.             junk = Gestalt(gestaltSystemVersion, (SInt32 *) &sysVersion);
  150.             MoreAssertQ(junk == noErr);
  151.             
  152.             // We now search for the second file called' "System".  We
  153.             // find it on Mac OS 8.5 and later (because the data fork
  154.             // of the System file is open) but not on Mac OS 8.1 or earlier.
  155.             
  156.             err = MoreUTLocateNextFCB(firstVCB, 0, "\pSystem", &foundRefNum, &foundFCB);
  157.             if ( err == noErr && sysVersion < 0x0850
  158.                     || err != noErr && sysVersion >= 0x0850 ) {
  159.                 printf("•••MoreUTLocateNextFCB failed.\n");
  160.             }            
  161.         } else {
  162.             printf("•••MoreUTLocateFCB failed.\n");
  163.         }
  164.     }
  165.     
  166.     // MoreUTIndexFCB
  167.     {
  168.         OSErr err;
  169.         Boolean found;
  170.         VCBPtr firstVCB;
  171.         SInt16 foundRefNum;
  172.         FCBRecPtr foundFCB;
  173.  
  174.         firstVCB = ((VCBPtr) GetVCBQHdr()->qHead);
  175.         found = false;
  176.         foundRefNum = 0;
  177.         do {
  178.             err = MoreUTIndexFCB(firstVCB, &foundRefNum, &foundFCB);
  179.             if (err == noErr) {
  180.                 found = EqualString(foundFCB->fcbCName, "\pSystem", false, true);
  181.             }
  182.         } while ( err == noErr && ! found );
  183.         if ( ! found ) {
  184.             printf("•••MoreUTIndexFCB failed.\n");
  185.         }
  186.     }
  187.     
  188.     // MoreUTResolveFCB
  189.     {
  190.         FCBRecPtr foundFCB;
  191.  
  192.         if ( MoreUTResolveFCB(2, &foundFCB) != noErr || ! EqualString(foundFCB->fcbCName, "\pSystem", false, true)) {
  193.             printf("•••MoreUTResolveFCB failed.\n");
  194.         }
  195.     }
  196.     
  197.     printf("FSM test done.\n");
  198. }
  199.  
  200. /////////////////////////////////////////////////////////////////
  201.  
  202. void main(void)
  203. {
  204.     char commandStr[256];
  205.     
  206.     printf("Hello Cruel World!\n");
  207.     printf("TestMoreInterfaceLib\n");
  208.     printf("-- A simple test program for the MoreInterfaceLib library.\n");
  209.     
  210.     printf("What test would you like to run?\n");
  211.     printf("a) Gestalt Value\n");
  212.     printf("X) Extended Disk Init\n");
  213.     printf("f) FSM test\n");
  214.     printf("Enter a command:\n");
  215.     gets(commandStr);
  216.     switch (commandStr[0]) {
  217.         case 'a':
  218.             DoTestGestaltValue();
  219.             break;
  220.         case 'X':
  221.             DoTestExtendedDiskInit(false);
  222.             break;
  223.         case 'f':
  224.             DoTestFSM();
  225.             break;
  226.         default:
  227.             printf("Huh?\n");
  228.             break;
  229.     }
  230.  
  231.     printf("Done.  Press Q to Quit.\n");
  232. }
  233.