home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-11-19 | 6.8 KB | 289 lines | [TEXT/MPS ] |
- /*
- File: LibraryManagerTest.cp
-
- Contains: MPW Tool to test out the ASLM.
-
- 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 ASLM
-
- 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 __STDDEF__
- #include <stddef.h>
- #endif
- #ifndef __QUICKDRAW__
- #include <QuickDraw.h>
- #endif
- #ifndef __CTYPE__
- #include <ctype.h>
- #endif
- #ifndef __IOSTREAM__
- #include <iostream.h>
- #endif
- #ifndef __STDIO__
- #include <stdio.h>
- #endif
- #ifndef __EVENTS__
- #include <Events.h>
- #endif
-
- #ifndef __EXAMPLECLASS__
- #include "ExampleClass.h"
- #endif
- #ifndef __LIBRARYMANAGERUTILITIES__
- #include <LibraryManagerUtilities.h>
- #endif
-
- static int getIntArgument(char *arg);
- 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);
-
- void printUsage(char* progName)
- {
- fprintf(stderr, "# Usage - %s [-v] [-c numReps] [-t] [-s] [-l] [-i <classid>]\n", progName);
- fprintf(stderr, "-v verbose, -c repetitions, -t trace on, -s shutdown ASLM -l load ASLM -i <GetClassInfo test classid>\n");
- }
-
- main(int argc, char *argv[]) {
-
- int paramNdx;
- int theCount = 1;
- Boolean verbose = false;
- Boolean trace = false;
- Boolean debugging = false;
- char* testClassInfoClass = 0;
-
- for (paramNdx = 1; paramNdx < argc; paramNdx++) {
-
- if (tolower(*(argv[paramNdx])) == '-') { // found an option
-
- switch (tolower(*(argv[paramNdx]+1))) {
-
- case 'c':
-
- if (++paramNdx < argc) {
- theCount = getIntArgument(argv[paramNdx]);
- if (theCount == -1) {
- fprintf(stderr,
- "### option -c value is not a positive integer: %s\n",
- argv[paramNdx]);
- return 1;
- }
- }
- else {
- fprintf(stderr, "### Not enough arguments\n");
- return 1;
- }
- break;
-
- case 'l':
-
- LoadLibraryManager();
- return 0;
-
- case 'v':
-
- verbose = true;
- break;
-
- case 't':
-
- trace = true;
- break;
-
- case 'x':
-
- debugging = true;
- break;
-
- case 's':
-
- UnloadLibraryManager();
- if (paramNdx+1 < argc && tolower(*(argv[paramNdx+1]+1)) == 'l')
- LoadLibraryManager();
- return 0;
-
- case 'i':
-
- if (++paramNdx < argc) {
- testClassInfoClass = argv[paramNdx];
- }
- else {
- fprintf(stderr, "### Not enough arguments\n");
- printUsage(argv[0]);
- }
-
- break;
-
-
- default:
-
- fprintf(stderr,"### %s - \"%s\" is not an option.\n",
- argv[0], argv[paramNdx]);
- printUsage(argv[0]);
- return 1;
- }
- }
- }
-
-
- if (debugging)
- DebugStr("\p LibraryManagerTest");
-
- // Now, on with business
- if (verbose) cout << "Entering LibraryManagerTest" << endl;
-
- if (verbose) cout << "Calling InitLibraryManager" << endl;
-
- // Call InitLibraryManager
- InitLibraryManager(kTestPoolSize, kSystemZone);
- TLibraryManager* testMgr = GetLocalLibraryManager();
- if (testMgr == NULL) {
- cout << "Bad News: testMgr is NULL" << endl;
- return 1;
- }
-
- if (LoadLibraries() != kNoError)
- {
- cout << "Bad News: Couldn't preload libraries" << endl;
- CleanupLibraryManager();
- return 1;
- }
-
- // turn trace on or off according to -t option
- if (!trace)
- testMgr->TraceLogOff();
- else
- testMgr->TraceLogOn();
-
- testDynamicFunctions();
-
- // dump out TLibraryManager info
- //testMgr->Dump();
-
- // Create our test object
- if (verbose) cout << "***Creating object1" << endl;
-
- // Create object with classId = kTExampleClassID
- TExampleClass* object1 = (TExampleClass*) testMgr->NewObject(ClassID(kTExampleClassID));
- if (!object1)
- cout << "Could not create new object!!!" << endl;
-
- //testMgr->Dump();
-
- if (verbose) cout << "***Creating object2" << endl;
-
- // Create object with classId = kExampleClass
- // NOTE: We use the new (NULL) form of the new operator in case TExampleClass was compiled
- // with Symantec C++ and we were compiled with MPW CFront.
- //
- TExampleClass* object2 = new (NULL) TExampleClass;
- if (!object2)
- cout << "Could not create new object!!!" << endl;
-
- /* Call the code that will actually do the tests. */
-
- cout << ends;
- DoTests(object1, object2, theCount, trace, verbose, testClassInfoClass);
-
- if (verbose) cout << "***Disposing testMgr" << endl;
- CleanupLibraryManager(); // delete the TLibraryManager and its pool
-
- return 0;
- };
-
-
- static int getIntArgument(char *arg)
- {
- int theCount = -1;
-
- sscanf(arg, "%d", &theCount);
-
- return theCount;
- }
-
-
- void testDynamicFunctions()
- {
- // Try out some dynamically linked functions
- ulong startticks;
-
- cout << "Hello(ulong&):" << kHelloRef(startticks) << endl;
- cout << "startticks = " << startticks << endl;
-
- cout << "Hello(ulong*):" << kHelloPtr(&startticks) << endl;
- cout << "startticks = " << startticks << endl;
-
- cout << "HelloC(ulong*):" << HelloC(&startticks) << endl;
- cout << "startticks = " << startticks << endl;
-
- #ifdef THINK_CPLUS
- cout << "HelloPascal(ulong&):" << HELLOPASCAL(startticks) << endl;
- #else
- cout << "HelloPascal(ulong&):" << HelloPascal(startticks) << endl;
- #endif
- cout << "startticks = " << startticks << endl;
-
- // Now lets call Hello a bunch of times
- ulong startTestHelloCount;
- ulong helloCount = kTestHelloCount;
- kHelloRef(startTestHelloCount);
- while (helloCount-- > 0)
- {
- ulong theTicks;
- kHelloRef(theTicks);
- }
- ulong endTestHelloCount;
- kHelloRef(endTestHelloCount);
- cout << kTestHelloCount << " Iterations of Hello: " << endTestHelloCount - startTestHelloCount << endl;
-
- // Test the locally linked localHello() for a comparison
- localHello(startTestHelloCount);
- helloCount = kTestHelloCount;
- while (helloCount-- > 0)
- {
- ulong theTicks;
- localHello(theTicks);
- }
- localHello(endTestHelloCount);
- cout << kTestHelloCount << " Iterations of local Hello: " << endTestHelloCount - startTestHelloCount << endl;
-
- cout << "Elapsed ticks (according to 'C' interface): " << Goodbye() << endl;
- #ifdef THINK_CPLUS
- cout << "Elapsed ticks: (according to Pascal interface): " << GOODBYEPASCAL() << endl;
- #else
- cout << "Elapsed ticks: (according to Pascal interface): " << GoodbyePascal() << endl;
- #endif
- }
-
- char* localHello(ulong& theHelloTicks)
- {
- helloticks = TickCount();
- theHelloTicks = helloticks;
- return "Hello";
- }
-
-