home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Frameworks / Hsoi's App Shell 1.0a4 / Hsoi's App Shell Source / HASTest.c < prev    next >
Encoding:
Text File  |  1997-01-28  |  8.1 KB  |  200 lines  |  [TEXT/CWIE]

  1. /*
  2.     HASTest.c from Hsoi's App Shell © 1995-1997 John C. Daub.  All rights reserved.
  3.     
  4.     This file is fairly empty...this is because there really isn't anything to do
  5.     here.  This is merely meant for you to have an easy place to insert test code.
  6.     
  7.     Ever have a time when you wanted to try something?  a little bit of code or
  8.     just an idea or something?  a way to try before you actually impliment it throughout
  9.     the code or something?  well, usually I found this to be difficult to do.  why?
  10.     well, if i wanted to test something, I needed a way to test it, usually this
  11.     meant some form or degree of a full running Mac application.  Now, sometimes for
  12.     some things I was just able to get away with writing some sort of ANSI C
  13.     thing that followed the same logic...but it'd just be all command line and text.
  14.     
  15.     Now, that was fine for some things (like i remember one time i way playing a MUD
  16.     and wanted to figure out my weapon's average damage...so I just wrote a nice
  17.     ANSI C routine to do this).  But what if i wanted to test something with the
  18.     Mac interface?  little way to do that without writing some sort of a Mac skeleton
  19.     application.  until now!
  20.     
  21.     now here's all you have to do....edit this file...change HsoiDoTest() as you
  22.     need (add/remove return type, add/remove arguments, etc...don't forget to
  23.     also change the function prototype in HASTest.h and the call(s) to HsoiDoTest
  24.     wherever in your code you make it/them (right now, it's just called in HASMenus.c
  25.     in HsoiDoMenuCommand())).  You'll also need to change any HsoiAdjustMenuTestWindow()
  26.     stuff as necessary to enable/disable the Test menu/items.
  27.     
  28.     (an easy way to see what you might need to change (tho you may need to do more
  29.     than this depending on what you're testing) is enter HAS_DEBUG into the Find
  30.     dialog of the CW IDE and search all the source for where this is.  At least by
  31.     doing this, you can see what is done and what you might need to modify to
  32.     make sure your test code works).
  33.     
  34.     Then, add your code in here in the body of HsoiDoTest to do whatever sorts
  35.     of testing things you want.
  36.     
  37.     When you select "Do Test" from the menu, your test routines will run, and away
  38.     you can go.
  39.     
  40.     For your convenience, there is a message window (gTestWindow).  This little
  41.     window isn't something that you'll normally want to use in the functioning
  42.     of the application, but say you need a little window to draw your test results
  43.     in (like if all your testing does is compute some number or want to display the
  44.     value of some variable), then this window works for that.
  45.     
  46.     The window is implimented and checked for throughout the appliction so that the
  47.     ability to close, call IsXXX() (e.g. HsoiIsDocumentWindow), and everything else
  48.     in HAS will function properly and happily with the window.  (again, Find all
  49.     instances of HAS_DEBUG in the code for some ideas of how things conditionally work).
  50.     
  51.     I've also tried to do things with the shell to allow for ease of transition between
  52.     coding/testing versions of your application and final release shipping versions
  53.     of the application.  Basically, I've tried to isolate these "testing" related
  54.     functions, code, and resources from the rest of the app by putting relevant
  55.     functions and things into their own files.  All you have to do is this to go
  56.     from a testing version of your app to a final shipping version:
  57.     
  58.     in HASMain.h (which is included in almost every HAS source file), make sure to
  59.     #define the correct macros for things (testing/final).  See HASMain.h for
  60.     more information.
  61.     
  62.     and remove the related testing source/header files from the project.  (but
  63.     don't remove the "placeholder" file...this is there to help you manage
  64.     the project file...no need to create/recreate the segment for testing each
  65.     time to add/remove the testing files.  good for not having to constantly reset
  66.     segment flags and other such things).
  67.     
  68.     That's it!
  69.     
  70.     Now, give a look over the testing code:  the source files, the header files, the
  71.     resource files.  Also, look in the rest of the shell's code for where testing
  72.     checks are made (do a Find for those preprocessor macros).  See how it all works.
  73.     
  74.     And remember, if you do make any changes to things (the source, the resources, etc)
  75.     be sure that not only your "regular" file(s) change, but also the testings ones
  76.     (at least, check to ensure no conflicts...like you don't create a WIND resource
  77.     with the same ID as the message window).
  78.     
  79.     hope you find this of some use!
  80.     
  81.     Oh, I should note this to you (cause i think i'm a little obscure above).  There
  82.     are 4 files (right now) involved in the test code:
  83.     
  84.     HASTest.c
  85.     HASUtilTest.c
  86.     HASTestPlaceholder.c
  87.     HASTest.rsrc
  88.     
  89.     (and of course, associated header files).
  90.     
  91.     HASTest.c (this file) is where you will want to actually stick in your test code.
  92.     
  93.     HASUtilTest.c contains various utility functions that you can use with the
  94.     gTestWindow (and other things to help make all this testing stuff work right
  95.     with the rest of the shell, e.g. menu updating).  If you write any sort of
  96.     utility function, you probalby will want to stick it in here, especially if this
  97.     code could be of general use in other testing situations.
  98.     
  99.     HASTestPlaceholder.c is just a blank file that does nothing but keep the
  100.     test segment in your project file so, as stated above, you don't have to keep
  101.     creating a new project segment every time and keep having to reset the segment
  102.     flags.
  103.     
  104.     HASTest.rsrc contains any resources specifically for testing, and that you
  105.     wouldn't want included in your final product.  For example, in the file as it
  106.     is now, there is the WIND for the test window, a MENU for the test menu, an
  107.     MBAR similar to the "normal" MBAR for the project but this one allows for
  108.     the test menu to be in the menu bar (see HsoiSetupMenus() for how this works).
  109.     
  110.     When you make the final release of your product, there might be other "better"
  111.     ways to do this, but i find it just easy enough to make sure in HASMain.h
  112.     that i #define HAS_DEBUG to zero (0), then remove HASTest.c, HASUtilTest.c,
  113.     and HASTest.rsrc from my project file and off i go!
  114. */
  115.  
  116. #pragma mark -
  117. #pragma mark ••• #includes •••
  118.  
  119. // include any header files you need
  120. #ifndef __HSOIS_APP_SHELL__
  121. #include "HASMain.h"
  122. #endif
  123. #include "HASTest.h"
  124. #include "HASUtilTest.h"
  125. #include "WASTE_Objects.h"
  126.  
  127.  
  128. #pragma mark -
  129. #pragma mark ••• Globals •••
  130.  
  131. // declare any global variables you need (and if they need to be accessed by the rest
  132. // of HAS, remember the extern declaration in HASTest.h.  For example, look at
  133. // gTestWindow's declaration.  Also, don't forget then to #include "HASTest.h"
  134. // in any other source files that might need it (and when doing so, be sure to watch
  135. // for and set properly the testing preprocessor macros (as laid out in HASMain.h)
  136.  
  137. WindowRef    gTestWindow = nil;        //    pointer to the debugger message window
  138.  
  139. #pragma mark -
  140. #pragma mark ••• Public Call •••
  141.  
  142.  
  143.  
  144. void    HsoiDoTest( void )
  145. {
  146.  
  147.     // right now, it does nothing!  add your own test code in here!
  148.     // but just in case, here's a sample of how you can use it...
  149.     
  150.     WindowRef    window;
  151.     
  152.     // if we have a sound playing, stop it.  this might not always be something
  153.     // that you want to do.  it'll depend on your testing routines.  but more than
  154.     // likely, if in doubt, leave this in here to stop any currently playing sounds.
  155.     
  156.     if ( SoundIsPlaying() )
  157.         StopCurrentSound();
  158.     
  159.     // get our test window, make it visible, bring it to the front, adjust the menus
  160.     // note how we bring the window to the front before we do anything on it...this
  161.     // is because we have no updating routines for this window...this is an important
  162.     // factor..i don't deem it really necessary to have updating routines, but if you
  163.     // do, feel free to write your own!
  164.     
  165.     window = HsoiGetTestWindow();
  166.     
  167.     // lame error handling
  168.     
  169.     if ( window == nil )
  170.     {
  171.         SysBeep( 5 );
  172.         return;
  173.     }
  174.     
  175.     // set the port
  176.     
  177.     SetPortWindowPort( window );
  178.     
  179.     // erase whatever's there
  180.     
  181.     EraseRect( &GetWindowPort(window)->portRect );
  182.     
  183.     // move the pen
  184.     
  185.     MoveTo( 10, 20 );
  186.     
  187.     // and write something!
  188.     
  189. //    DrawString( (StringPtr)"\pInsert your test code here." );
  190.     HsoiPrintString( "\pInsert your test code here." );
  191.     
  192.     return;
  193. }
  194.  
  195. #pragma mark -
  196. #pragma mark ••• Whatever Else •••
  197.  
  198. // nothing else here, just wanted to have the #pragma for you for anything else
  199. // that you later add in here.
  200.