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

  1. /*
  2.     File:        TestMoreOSUtils.c
  3.  
  4.     Contains:    Simple test program for the MoreOSUtils library.
  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.          <2>     16/3/99    Quinn   Added tests for InterfaceDisableLib.
  21.          <1>      1/3/99    Quinn   First checked in.
  22. */
  23.  
  24. /////////////////////////////////////////////////////////////////
  25.  
  26. // MoreIsBetter Setup
  27.  
  28. #include "MoreSetup.h"
  29.  
  30. // Standard Mac OS interfaces
  31.  
  32. #include <MacTypes.h>
  33.  
  34. // Standard C interfaces
  35.  
  36. #include <stdio.h>
  37.  
  38. // MIB Prototypes
  39.  
  40. #include "MoreOSUtils.h"
  41.  
  42. /////////////////////////////////////////////////////////////////
  43.  
  44. static UInt16 gCodeSnippet[16];
  45.  
  46. void main(void)
  47. {
  48.     OSStatus err;
  49.     
  50.     printf("Hello Cruel World!\n");
  51.     printf("TestMoreOSUtils\n");
  52.     printf("-- A simple test program for the MoreOSUtils library.\n");
  53.     
  54.     printf("Testing Cache Flushing...\n");
  55.     
  56.     err = MakeDataPowerPCExecutable(gCodeSnippet, sizeof(gCodeSnippet));
  57.     if (err == noErr) {
  58.         // In the classic 68K case, this second call exercises a different
  59.         // code path from the first.
  60.         err = MakeDataPowerPCExecutable(gCodeSnippet, sizeof(gCodeSnippet));
  61.     }
  62.     if (err == noErr) {
  63.         err = MakeData68KExecutable(gCodeSnippet, sizeof(gCodeSnippet));
  64.     }
  65.  
  66.     #if TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  67.         TermMoreOSUtils();
  68.     #endif
  69.     
  70.     printf("Testing Interrupt Disable/Enable...\n");
  71.     
  72.     {
  73.         UInt16 initialMask;
  74.         UInt16 maskIndex;
  75.         
  76.         // Save the initial interrupt mask for later restoration.
  77.         
  78.         initialMask = GetInterruptMask();
  79.         
  80.         // Set the interrupt mask to every legal value and make
  81.         // sure it sticks.
  82.         
  83.         for (maskIndex = 0; maskIndex <= 7; maskIndex++) {
  84.             (void) SetInterruptMask(maskIndex);
  85.             if (GetInterruptMask() != maskIndex) {
  86.                 printf("••• Failed to set mask to %d.\n", maskIndex);
  87.             }
  88.         }
  89.         
  90.         // Check that the "set returns old value" behaviour.
  91.         
  92.         SetInterruptMask(7);
  93.         if (SetInterruptMask(5) != 7) {
  94.             printf("••• SetInterruptMask failed to return old values.\n");
  95.         }
  96.         
  97.         // Restore the initial interrupt mask and make sure that works.
  98.         
  99.         SetInterruptMask(initialMask);
  100.         if (GetInterruptMask() != initialMask) {
  101.             printf("••• Failed to restore interrupt mask.\n");
  102.         }
  103.     }    
  104.     
  105.     if (err == noErr) {
  106.         printf("Success!\n");
  107.     } else {
  108.         printf("Failed with error %ld.\n", err);
  109.     }
  110. }
  111.