home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-11-19 | 3.3 KB | 130 lines | [TEXT/MPS ] |
- /*
- File: TestTaskScheduler.cp
-
- Contains: Tester for the TTaskScheduler class
-
- Copyright: © 1991-1994 by Apple Computer, Inc., all rights reserved.
-
- */
-
- #ifndef __TESTTASKSCHEDULER__
- #include "TestTaskScheduler.h"
- #endif
-
- #ifndef __LIBRARYMANAGERUTILITIES__
- #include <LibraryManagerUtilities.h>
- #endif
-
- #ifndef __DESK__
- #include <Desk.h>
- #endif
-
- /**********************************************************************
- ** TTaskOperation methods
- ***********************************************************************/
-
- TTaskOperation::TTaskOperation()
- {
- fCount = 0;
- }
-
- TTaskOperation::~TTaskOperation()
- {}
-
- void TTaskOperation::Process()
- {
- ++fCount;
- }
-
- /**********************************************************************
- ** PUBLIC Constructor/Destructor
- ***********************************************************************/
-
- Constructor(TaskScheduler)
- Destructor(TaskScheduler)
-
- /**********************************************************************
- ** PUBLIC InitTest
- ***********************************************************************/
-
- void TTestTaskScheduler :: InitTest(BooleanParm, BooleanParm, int, char**)
- {
- TStandardPool* pool = GetPool();
-
- if (pool == NULL)
- {
- Printf("### ERROR: There is no global pool\n");
- return;
- }
-
- if ((fTest = new (pool) TTaskScheduler) == NULL)
- {
- Printf("ERROR: Couldn't created a Task Scheduler\n");
- }
- }
-
- /**********************************************************************
- ** PUBLIC RunTestIteration
- ***********************************************************************/
-
- void TTestTaskScheduler :: RunTestIteration(BooleanParm verbose, BooleanParm)
- {
- if (verbose)
- Printf(" INFO: Creating 3 TTaskOperation objects\n");
- TTaskOperation* op1 = new TTaskOperation;
- TTaskOperation* op2 = new TTaskOperation;
- TTaskOperation* op3 = new TTaskOperation;
-
- if (verbose)
- Printf(" INFO: Scheduling 3 TTaskOperation objects\n");
- fTest->Schedule(op1);
- fTest->Schedule(op2);
- fTest->Schedule(op3);
-
- if (fTest->IsEmpty())
- Printf("ERROR: TTaskScheduler::IsEmpty() returned true, but things are scheduled!\n");
-
- if (verbose)
- Printf(" INFO: Waiting for 5 seconds to be sure they don't fire\n");
-
- TStopwatch watch;
- while ((&watch)->ElapsedSeconds() < 5)
- ;
-
- if (op1->fCount)
- Printf("ERROR: Operation #1 fired before we invoked System Task\n");
- if (op2->fCount)
- Printf("ERROR: Operation #2 fired before we invoked System Task\n");
- if (op3->fCount)
- Printf("ERROR: Operation #3 fired before we invoked System Task\n");
- if (verbose)
- Printf(" INFO: Invoking System Task\n");
- SystemTask();
- if (op1->fCount != 1)
- Printf("ERROR: Operation #1's count is %u instead of 1\n", op1->fCount);
- if (op2->fCount != 1)
- Printf("ERROR: Operation #2's count is %u instead of 1\n", op2->fCount);
- if (op3->fCount != 1)
- Printf("ERROR: Operation #3's count is %u instead of 1\n", op3->fCount);
-
- if (verbose)
- Printf(" INFO: Test complete. Deleting 3 TTaskOperation objects\n");
-
- if (!fTest->IsEmpty())
- Printf("ERROR: IsEmpty is not set for the TTaskScheduler\n");
-
- delete op1;
- delete op2;
- delete op3;
- }
-
- /**********************************************************************
- ** PUBLIC EndTest
- ***********************************************************************/
-
- void TTestTaskScheduler :: EndTest(BooleanParm, BooleanParm)
- {
- delete fTest;
- fTest = NULL;
- }
-