home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 April: Mac OS SDK / Dev.CD Apr 99 SDK1.toast / Development Kits / Apple Shared Library Manager / ASLM Examples / TestTools / Sources / TestLibrary.cp < prev    next >
Encoding:
Text File  |  1996-11-19  |  3.1 KB  |  154 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        TestLibrary.cp
  3.  
  4.     Contains:    Files for the test library
  5.  
  6.     Copyright:    © 1991-1994 by Apple Computer, Inc., all rights reserved.
  7.  
  8. */
  9.  
  10.  
  11. #ifndef __TESTCLASS__
  12. #include "TestClass.h"
  13. #endif
  14. #ifndef __OSUTILS__
  15. #include <OSUtils.h>
  16. #endif
  17. #ifndef __STDARG__
  18. #include <stdarg.h>
  19. #endif
  20.  
  21. /**********************************************************************
  22. ** TTestTool methods
  23. ***********************************************************************/
  24.  
  25. TTestTool::TTestTool()
  26. {
  27. #ifndef USEMPW
  28.     fPrint = NULL;
  29.     fPrintWorld = NULL;
  30. #endif
  31.     fPool = NULL;
  32. }
  33.  
  34. TTestTool::TTestTool(TStandardPool* thePool)
  35. {
  36. #ifndef USEMPW
  37.     fPrint = NULL;
  38.     fPrintWorld = NULL;
  39. #endif
  40.     SetPool(thePool);
  41. }
  42.  
  43. TTestTool::~TTestTool()
  44. {}
  45.  
  46. #ifndef USEMPW
  47.     void TTestTool::SetPrintf(PrintfFunc func)
  48.     {
  49.         fPrintWorld = (Ptr) SetCurrentA5();
  50.         fPrint = func;
  51.     }
  52. #endif
  53.  
  54. void TTestTool::Printf(const char* str, ...) const
  55. {
  56.     va_list    args;
  57.     
  58. #ifdef USEMPW
  59.     va_start(args, str);
  60.     vprintf(str, args);
  61.     fflush(stdout);
  62. #else
  63.     if (fPrint)
  64.     {
  65.         Ptr oldWorld = (Ptr) SetA5((long)fPrintWorld);            // Set up the fPrint's world
  66.         va_start(args, str);    
  67.         (*fPrint)(str, args);
  68.         SetA5((long)oldWorld);                            // restore the world
  69.     }
  70. #endif
  71. }
  72.  
  73. /**********************************************************************
  74. ** TNumber methods
  75. ***********************************************************************/
  76.  
  77. TNumber::TNumber(short num)
  78. {
  79.     fNumber = num;
  80. }
  81.  
  82. TNumber::~TNumber()
  83. {}
  84.  
  85. Boolean TNumber::IsEqual(const void* obj) const
  86. {
  87.     return (fNumber == ((const TNumber*)obj)->fNumber) ? true : false;
  88. }
  89.  
  90. unsigned long TNumber::Hash() const
  91. {
  92.     return fNumber;
  93. }
  94.  
  95. /**********************************************************************
  96. ** TNumberHasher methods
  97. ***********************************************************************/
  98.  
  99. TNumberHasher::TNumberHasher()
  100. {}
  101.  
  102. TNumberHasher::~TNumberHasher()
  103. {}
  104.  
  105. unsigned long TNumberHasher::Hash(const void* obj) const
  106. {
  107.     return ((const TNumber*)obj)->Hash();
  108. }
  109.  
  110. /*******************************************************************************
  111. ** Some Constants
  112. ********************************************************************************/
  113.  
  114. const size_t    kFastIMValue    = 1771875;
  115. const size_t    kFastIAValue    = 2416;
  116. const size_t    kFastICValue    = 374441;
  117.  
  118. size_t    gSeed = 0;
  119.  
  120. size_t RandomNumber(size_t lo, size_t hi)
  121. {
  122.     gSeed = (gSeed*kFastIAValue + kFastICValue) % kFastIMValue;
  123.     return lo + ((hi - lo + 1)*gSeed)/kFastIMValue;
  124. }
  125.  
  126. size_t StringToNum(char* str)
  127. {
  128.     size_t num = 0;
  129.     while (*str >= '0' && *str <= '9')
  130.         num = num*10 + (*str++) - '0';
  131.     return num;
  132. }
  133.  
  134. /**********************************************************************
  135. ** Load other test tools
  136. ***********************************************************************/
  137.  
  138. #include "TestLinkedList.cp"
  139. #include "TestAllocLinkedList.cp"
  140. #include "TestPriorityList.cp"
  141. #include "TestTimeScheduler.cp"
  142. #include "TestTaskScheduler.cp"
  143. #include "TestArbitrator.cp"
  144. #include "TestTimeStamp.cp"
  145. #include "TestRandom.cp"
  146. #include "TestHashList.cp"
  147. #include "TestStandardPool.cp"
  148. #include "TestFSet.cp"
  149. #include "TestNoVTable.cp"
  150. #include "TestTimings.cp"
  151. #include "TestExceptions.cp"
  152. #include "TestMisc.cp"
  153.     
  154.