home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-01-28 | 8.1 KB | 200 lines | [TEXT/CWIE] |
- /*
- HASTest.c from Hsoi's App Shell © 1995-1997 John C. Daub. All rights reserved.
-
- This file is fairly empty...this is because there really isn't anything to do
- here. This is merely meant for you to have an easy place to insert test code.
-
- Ever have a time when you wanted to try something? a little bit of code or
- just an idea or something? a way to try before you actually impliment it throughout
- the code or something? well, usually I found this to be difficult to do. why?
- well, if i wanted to test something, I needed a way to test it, usually this
- meant some form or degree of a full running Mac application. Now, sometimes for
- some things I was just able to get away with writing some sort of ANSI C
- thing that followed the same logic...but it'd just be all command line and text.
-
- Now, that was fine for some things (like i remember one time i way playing a MUD
- and wanted to figure out my weapon's average damage...so I just wrote a nice
- ANSI C routine to do this). But what if i wanted to test something with the
- Mac interface? little way to do that without writing some sort of a Mac skeleton
- application. until now!
-
- now here's all you have to do....edit this file...change HsoiDoTest() as you
- need (add/remove return type, add/remove arguments, etc...don't forget to
- also change the function prototype in HASTest.h and the call(s) to HsoiDoTest
- wherever in your code you make it/them (right now, it's just called in HASMenus.c
- in HsoiDoMenuCommand())). You'll also need to change any HsoiAdjustMenuTestWindow()
- stuff as necessary to enable/disable the Test menu/items.
-
- (an easy way to see what you might need to change (tho you may need to do more
- than this depending on what you're testing) is enter HAS_DEBUG into the Find
- dialog of the CW IDE and search all the source for where this is. At least by
- doing this, you can see what is done and what you might need to modify to
- make sure your test code works).
-
- Then, add your code in here in the body of HsoiDoTest to do whatever sorts
- of testing things you want.
-
- When you select "Do Test" from the menu, your test routines will run, and away
- you can go.
-
- For your convenience, there is a message window (gTestWindow). This little
- window isn't something that you'll normally want to use in the functioning
- of the application, but say you need a little window to draw your test results
- in (like if all your testing does is compute some number or want to display the
- value of some variable), then this window works for that.
-
- The window is implimented and checked for throughout the appliction so that the
- ability to close, call IsXXX() (e.g. HsoiIsDocumentWindow), and everything else
- in HAS will function properly and happily with the window. (again, Find all
- instances of HAS_DEBUG in the code for some ideas of how things conditionally work).
-
- I've also tried to do things with the shell to allow for ease of transition between
- coding/testing versions of your application and final release shipping versions
- of the application. Basically, I've tried to isolate these "testing" related
- functions, code, and resources from the rest of the app by putting relevant
- functions and things into their own files. All you have to do is this to go
- from a testing version of your app to a final shipping version:
-
- in HASMain.h (which is included in almost every HAS source file), make sure to
- #define the correct macros for things (testing/final). See HASMain.h for
- more information.
-
- and remove the related testing source/header files from the project. (but
- don't remove the "placeholder" file...this is there to help you manage
- the project file...no need to create/recreate the segment for testing each
- time to add/remove the testing files. good for not having to constantly reset
- segment flags and other such things).
-
- That's it!
-
- Now, give a look over the testing code: the source files, the header files, the
- resource files. Also, look in the rest of the shell's code for where testing
- checks are made (do a Find for those preprocessor macros). See how it all works.
-
- And remember, if you do make any changes to things (the source, the resources, etc)
- be sure that not only your "regular" file(s) change, but also the testings ones
- (at least, check to ensure no conflicts...like you don't create a WIND resource
- with the same ID as the message window).
-
- hope you find this of some use!
-
- Oh, I should note this to you (cause i think i'm a little obscure above). There
- are 4 files (right now) involved in the test code:
-
- HASTest.c
- HASUtilTest.c
- HASTestPlaceholder.c
- HASTest.rsrc
-
- (and of course, associated header files).
-
- HASTest.c (this file) is where you will want to actually stick in your test code.
-
- HASUtilTest.c contains various utility functions that you can use with the
- gTestWindow (and other things to help make all this testing stuff work right
- with the rest of the shell, e.g. menu updating). If you write any sort of
- utility function, you probalby will want to stick it in here, especially if this
- code could be of general use in other testing situations.
-
- HASTestPlaceholder.c is just a blank file that does nothing but keep the
- test segment in your project file so, as stated above, you don't have to keep
- creating a new project segment every time and keep having to reset the segment
- flags.
-
- HASTest.rsrc contains any resources specifically for testing, and that you
- wouldn't want included in your final product. For example, in the file as it
- is now, there is the WIND for the test window, a MENU for the test menu, an
- MBAR similar to the "normal" MBAR for the project but this one allows for
- the test menu to be in the menu bar (see HsoiSetupMenus() for how this works).
-
- When you make the final release of your product, there might be other "better"
- ways to do this, but i find it just easy enough to make sure in HASMain.h
- that i #define HAS_DEBUG to zero (0), then remove HASTest.c, HASUtilTest.c,
- and HASTest.rsrc from my project file and off i go!
- */
-
- #pragma mark -
- #pragma mark ••• #includes •••
-
- // include any header files you need
- #ifndef __HSOIS_APP_SHELL__
- #include "HASMain.h"
- #endif
- #include "HASTest.h"
- #include "HASUtilTest.h"
- #include "WASTE_Objects.h"
-
-
- #pragma mark -
- #pragma mark ••• Globals •••
-
- // declare any global variables you need (and if they need to be accessed by the rest
- // of HAS, remember the extern declaration in HASTest.h. For example, look at
- // gTestWindow's declaration. Also, don't forget then to #include "HASTest.h"
- // in any other source files that might need it (and when doing so, be sure to watch
- // for and set properly the testing preprocessor macros (as laid out in HASMain.h)
-
- WindowRef gTestWindow = nil; // pointer to the debugger message window
-
- #pragma mark -
- #pragma mark ••• Public Call •••
-
-
-
- void HsoiDoTest( void )
- {
-
- // right now, it does nothing! add your own test code in here!
- // but just in case, here's a sample of how you can use it...
-
- WindowRef window;
-
- // if we have a sound playing, stop it. this might not always be something
- // that you want to do. it'll depend on your testing routines. but more than
- // likely, if in doubt, leave this in here to stop any currently playing sounds.
-
- if ( SoundIsPlaying() )
- StopCurrentSound();
-
- // get our test window, make it visible, bring it to the front, adjust the menus
- // note how we bring the window to the front before we do anything on it...this
- // is because we have no updating routines for this window...this is an important
- // factor..i don't deem it really necessary to have updating routines, but if you
- // do, feel free to write your own!
-
- window = HsoiGetTestWindow();
-
- // lame error handling
-
- if ( window == nil )
- {
- SysBeep( 5 );
- return;
- }
-
- // set the port
-
- SetPortWindowPort( window );
-
- // erase whatever's there
-
- EraseRect( &GetWindowPort(window)->portRect );
-
- // move the pen
-
- MoveTo( 10, 20 );
-
- // and write something!
-
- // DrawString( (StringPtr)"\pInsert your test code here." );
- HsoiPrintString( "\pInsert your test code here." );
-
- return;
- }
-
- #pragma mark -
- #pragma mark ••• Whatever Else •••
-
- // nothing else here, just wanted to have the #pragma for you for anything else
- // that you later add in here.
-