home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-11-19 | 5.5 KB | 229 lines | [TEXT/MPS ] |
- /*
- File: LibraryManagerTest.cp
-
- Contains: MPW Tool to test out LibraryManager.
-
- Description:
-
- LibraryManagerTest1 [-v] [-t 0|1] [-c nReps]
-
- -v turns verbose mode on (progress messages in MPW window), it is off by default
- -t turns tracing on (tracing to the Trace Monitor), it is off by default
- -c nReps nReps must be a positive integer for number of times through the test while loop
- -s shutdown the LibraryManager
-
- This test program can be modified to test any class you develop and do simple stress
- testing by changing what is inside the test while loop.
-
- Caveats:
-
- Command-period will leave some things dangling that will never be disposed.
-
-
- Copyright: © 1991-1994 by Apple Computer, Inc., all rights reserved.
-
- */
-
-
- #ifndef __EXAMPLECLASS__
- #include "ExampleClass.h"
- #endif
- #ifndef __LIBRARYMANAGERUTILITIES__
- #include <LibraryManagerUtilities.h>
- #endif
-
- #ifndef __CTYPE__
- #include <ctype.h>
- #endif
- #ifndef __EVENTS__
- #include <Events.h>
- #endif
-
- #include <MixedMode.h>
-
-
- extern "C" void DoTests(TExampleClass* object1, TExampleClass* object2, int count, Boolean trace, Boolean verbose, char* testClassInfoClass);
-
- const kTestPoolSize = 0; // set to 0 to test autogrow pools
- const ulong kTestHelloCount = 100000;
-
- ulong helloticks = 0;
-
- void testDynamicFunctions();
- char* localHello(ulong& theHelloTicks);
-
- short sub[2] = { 0xD080, 0x4E75 };
-
- main() {
-
- int paramNdx;
- int theCount = 1;
- Boolean verbose = true;
- Boolean trace = true;
- Boolean debugging = false;
- char* testClassInfoClass = 0;
-
- DebugStr((unsigned char *)"\pTo get us into the Nub\n");
- if (debugging)
- DebugStr((unsigned char *)"\p ExampleClassTest\n");
-
- // Get our LibraryManager
- InitLibraryManager(kTestPoolSize, kSystemZone);
- TLibraryManager* testMgr = GetLocalLibraryManager();
- if (testMgr == NULL) {
- return 1;
- }
-
- if (LoadLibraries() != kNoError)
- {
- Trace("Bad News: Couldn't preload libraries\n");
- CleanupLibraryManager();
- return 1;
- }
-
- // turn trace on or off according to -t option
- if (!trace)
- testMgr->TraceLogOff();
- else
- testMgr->TraceLogOn();
-
- testDynamicFunctions();
-
- // dump out LibraryManager info
- //testMgr->Dump();
-
- // Create our test object
- if (verbose) Trace("***Creating object1\n");
-
- SetSelfAsClient();
-
- // Create object with classId = kTExampleClassID
- TExampleClass* object1 = (TExampleClass*) testMgr->NewObject(ClassID(kTExampleClassID));
- if (!object1)
- Trace("Could not create new object!!!\n");
-
- //testMgr->Dump();
-
- if (verbose) Trace("***Creating object2\n");
-
- // Create object with classId = kExampleClass
- TExampleClass* object2 = (TExampleClass*) testMgr->NewObject(ClassID(kTExampleClassID));
- if (!object2)
- Trace("Could not create new object!!!\n");
-
- /* Call the code that will actually do the tests. */
-
- DoTests(object1, object2, theCount, trace, verbose, testClassInfoClass);
-
- if (verbose) Trace("***Disposing testMgr\n");
- CleanupLibraryManager(); // delete the LibraryManager and its pool
-
- return 0;
- };
-
-
- void testDynamicFunctions()
- {
- // Try out some dynamically linked functions
-
- // Now lets call Hello a bunch of times
- ulong startTestHelloCount;
- ulong helloCount = kTestHelloCount;
- Hello(startTestHelloCount);
- while (helloCount-- > 0)
- {
- ulong theTicks;
- Hello(theTicks);
- }
- ulong endTestHelloCount;
- Hello(endTestHelloCount);
- Trace(" Iterations of Hello: \n");
-
- // Test the locally linked localHello() for a comparison
- localHello(startTestHelloCount);
- helloCount = kTestHelloCount;
- while (helloCount-- > 0)
- {
- ulong theTicks;
- localHello(theTicks);
- }
- localHello(endTestHelloCount);
- }
-
- char* localHello(ulong& theHelloTicks)
- {
- helloticks = TickCount();
- theHelloTicks = helloticks;
- return "Hello";
- }
-
- extern "C"
- void DoTests(TExampleClass* object1, TExampleClass* object2, int count, Boolean trace, Boolean /*verbose*/, char* testClassInfoClass)
- {
- unsigned long endTicks, startTicks;
- unsigned long saveCount = count;
-
- if (object1 && object2)
- {
- startTicks = TickCount();
- object1->SetObjectName("object1");
- object2->SetObjectName("object2");
-
- while (count-- > 0) // <-- here is the test while loop
- { // we put calls to DoThisAndThat in here
- object1->DoThisAndThat(); // here we test DoThisAndThat for object1
- object2->DoThisAndThat(); // here we test DoThisAndThat for object2
- }
-
- // test accessing globals
- object1->SetGlobalInt(42); // set the global using object1
-
- // get the global using object2
- // since object1 and object2 share the same A5 world this will return
- // 42!
-
- // Test the dynamically linked non-virtual member function GetGlobalRef
- long* theGlobal;
- object1->GetGlobalRef(theGlobal);
- // Now theGlobal is the address of a global variable in the example library,
- // whose value should still be 42
-
- endTicks = TickCount();
-
- // Lets try TExampleClass::Test(char*),
- // note that this is a dynamically linked static member function
- // it will return true since there are 2 instances of TExampleClass
- Boolean hey = TExampleClass::Test("2");
- Boolean hoo = TExampleClass::Test(2);
- Boolean hee = TExampleClass::Test(3);
- }
-
- if (object1)
- {
- delete object1;
- }
-
- if (object2) {
- delete object2;
- }
-
- // Now its time to really do something
- if (testClassInfoClass)
- {
- TClassInfo* theInfo = GetLocalLibraryManager()->GetClassInfo(ClassID(testClassInfoClass));
- if (theInfo)
- {
- do
- {
- char nameBuffer[256]; // for calls to GetVerboseName
- if (trace)
- {
- Trace("\nClass ID: %s\n", (char*) theInfo->GetClassID());
- }
- } while (theInfo->Next());
-
- delete theInfo;
- }
- }
- }
-