home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / mac / oop / macapp3 / 182 < prev    next >
Encoding:
Text File  |  1992-12-13  |  8.0 KB  |  313 lines

  1. Path: sparky!uunet!stanford.edu!apple!applelink.apple.com
  2. From: MAILER-DAEMON@alink-gw.apple.COM (Mail Delivery Subsystem)
  3. Newsgroups: comp.sys.mac.oop.macapp3
  4. Subject: Returned mail: Unable to deliver mail
  5. Message-ID: <9212132011.AB11338@alink-gw.apple.com>
  6. Date: 13 Dec 92 20:11:52 GMT
  7. Sender: daemon@Apple.COM
  8. Organization: AppleLink Gateway
  9. Lines: 302
  10.  
  11.  
  12.    ----- Transcript of session follows -----
  13. 554 POST-MACAPP-BETA-3... Recipient names must be specified
  14.  
  15.    ----- Unsent message follows -----
  16. Received: by alink-gw.apple.com (5.65/27-Sep-1991-eef)
  17.     id AA11338; Sun, 13 Dec 92 12:11:52 -0800
  18.     for 
  19. Date: 12 Dec 92 23:25 GMT
  20. From: Gateway@AppleLink.Apple.COM (to Internet/BITNET/UUCP)
  21. Subject: Re: TAppl.InstallCohandler mo
  22. To: MACAPP3TECH$@AppleLink.Apple.COM (MacApp 3 Technical Discussion)
  23. Message-Id: <9212131953.AA24322@apple.com>
  24. X-Original-Document-Id: <9212131953.AA24322@apple.com>
  25.  
  26. From:
  27. References: , ,, <724097388.6934764@AppleLink.Apple.COM>
  28. Organization: (Evil Eye Creature from Mars, Inc.)
  29. Sender: macapp.admin@applelink.apple.com
  30. To: MacApp3Tech$@Applelink.apple.com
  31.  
  32. In article <724097388.6934764@AppleLink.Apple.COM>,
  33. DEWAELE.W@AppleLink.Apple.COM (De Waele Willy - Gent,BE,IHD) wrote:
  34. >
  35. >
  36. >
  37. > Indeed, Mark, debug versions (of frameworks and our own applications - MacApp
  38. > and others) should be defensive programmed (which save a lot of time), i use
  39. > the following technique taking your example:
  40. >
  41. > TFoo::Something()
  42. > {...
  43. > #if qDebug
  44. >    if (!IsObject(aCohandler)) {
  45. >      SysBreakStr("TFoo::Something - aCohandler is invalid!");
  46. >     return; }
  47. > #endif
  48. > ...
  49. > }
  50. > SADE must be started up, but i think this is no problem because when working
  51. > with MacApp 3.x, we need a lot of meg's (i don't like limited resources! -
  52. *The
  53. > sky's the limit!*).
  54.  
  55. SysBreakStr are kind of evil, unless SADE is running you usually get a
  56. System crash. Here's an ASSERT package I worked a little bit on two
  57. weeks ago, it's not yet complete but it could provide material for
  58. someone else writing similar stuff. Yes, I know of the Assertion MacApp
  59. version, but I wanted more flexibility in my ASSERT package. Note that
  60. this is not a full example, you need to add an Alert resource and a couple
  61. of other small things -- but the main thing was to stimulate the idea
  62. of writing similar flexible ASSERT packages. And this one should be ready
  63. within a month or so (and will then be available on the developer CD).
  64.  
  65. Kent
  66. ---- snippet stuff starts here ----
  67.  
  68. // TESTING, used for flagging that we use test code inside the classes and
  69. frameworks
  70. // TESTLEVEL0           - user friendly alerts as part of the application
  71. // TESTLEVEL1   - minor test level (detailed error message in alert box)
  72. // TESTLEVEL2   - semi-major test level (high level debuggers)
  73. // TESTLEVEL3   - major test level (low level debuggers)
  74. // TESTLOG1             - trigger a file log of information
  75. // TESTLOG2             - trigger a file log of information from a low level
  76. debugger
  77.  
  78. #define TESTLEVEL3
  79.  
  80. //
  81. _____________________________________________________________________________
  82. ____________________________
  83. //
  84. //      2. STRING FUNCTIONS
  85.  
  86. // return the len of a C string
  87. inline short clen(char *cptr)
  88. {
  89.         short   i;
  90.  
  91.         for (i = 0; cptr[i]; ++i)
  92.                 ;
  93.         return(i);
  94. }
  95.  
  96.  
  97. // Convert a c-string to a pascal-string
  98.  
  99. inline void     c2p(char *cptr)
  100. {
  101.         char    len;
  102.  
  103.         BlockMove(cptr, cptr + 1, len = clen(cptr));
  104.         *cptr = len;
  105. }
  106.  
  107.  
  108. // Convert a pascal-string to a c-string
  109. inline void     p2c(StringPtr cptr)
  110. {
  111.         char    len;
  112.  
  113.         BlockMove(cptr + 1, cptr, len = *cptr);
  114.         cptr[len] = 0;
  115. }
  116.  
  117.  
  118. // Copy two Pascal strings
  119. inline void     Pstrcpy(StringPtr d, StringPtr s)
  120. {
  121.         short   i;
  122.  
  123.         i = *s;
  124.         do {
  125.                 d[i] = s[i];
  126.         } while (i--);
  127. }
  128.  
  129.  
  130. // Concatenate two Pascal strings
  131. inline void ConcatPStrings(Str255 first,
  132.                                                    Str255 second)
  133. {
  134.         short charsToCopy;
  135.  
  136.         // Truncate if concatenated string would be longer than 255 chars
  137.         charsToCopy = Min(second[0], 255 - first[0]);
  138.         BlockMove(second + 1, first + first[0] + 1, (long)charsToCopy);
  139.         first[0] += charsToCopy;
  140. }
  141.  
  142.  
  143. //
  144. _____________________________________________________________________________
  145. ____________________________
  146. //
  147. // MACROS AND DEBUGGING
  148. // ASSERT Function, used for testing conditions and flagging error states.
  149. // Example: vdebugstr("The error message from Foo is %i", fError);
  150.  
  151. // We need to load in certain include files if we want to use the alert
  152. boxes for
  153. // high level ASSERT functions (we also need to include the
  154. GUIApplication.r file
  155. // into the project).
  156.  
  157. #if (defined TESTLEVEL0 || defined TESTLEVEL1)
  158. #include "ApplicationResources.h"
  159. #endif
  160.  
  161.  
  162. //  Define this flag if you want file and line information as part of the
  163. message.
  164. #define FILELINEINFO
  165.  
  166.  
  167. //      fileinfo will keep track of the current file and line in a global.
  168. static char fileNameArray[32];
  169. static char lineNumberArray[32];
  170.  
  171.  
  172. #if (defined TESTLEVEL0 || defined TESTLEVEL1)
  173. inline void AlertUser(Str255 theMessage)
  174. {
  175.         short itemHit;
  176.  
  177.         if(!(AEInteractWithUser(kNoTimeOut, nil, nil)))
  178.    // could we interact
  179. with the user?
  180.         {
  181.                 ParamText(theMessage, 0, 0,0);
  182.                 itemHit = Alert(kUserAlert, nil);
  183.         }
  184. }
  185. #endif
  186.  
  187. inline void fileinfo(char *file, int line)
  188. {
  189.         sprintf(fileNameArray, "File %s ", file);
  190.         sprintf(lineNumberArray, " Line %d  #", line);
  191. }
  192.  
  193.  
  194. //      vxdebugstr that also prints out by default __FILE__ and __LINE__
  195. information
  196. inline void vxdebugstr(char* format,...)
  197. {
  198.         char buff[255];
  199.         char final[255];
  200.  
  201.         va_list arglist;
  202.         va_start(arglist,format);
  203.         vsprintf(buff,format,arglist);
  204.         va_end(arglist);
  205.  
  206. #ifdef FILELINEINFO
  207.         strcat(final,fileNameArray);
  208. #ifdef TESTLEVEL2
  209.         strcat(final, " ;");
  210.    // MacsBug does not like embedded ;s
  211. #endif
  212.         strcat(final, lineNumberArray);
  213. #endif
  214.  
  215.         strcat(final, buff);
  216.         c2p(final);
  217.  
  218.         // Print out the message, based on the testing level
  219. #ifdef TESTLEVEL1
  220.         AlertUser((Str255)final);
  221. #endif
  222. #ifdef TESTLEVEL2
  223.         SysBreakStr((Str255)final);
  224.    // for high level debuggers
  225. #endif
  226. #ifdef TESTLEVEL3
  227.         DebugStr((Str255)final);
  228. #endif
  229. }
  230.  
  231.  
  232. //      ASSERT MACROS
  233.  
  234. //      ASSERT, small (and quick assert),  if assertion is false it will print
  235. out
  236. //      a message
  237. //      Use: ASSERT(false, "Problems with TSoundRecorder");
  238.  
  239. #if (defined TESTLEVEL0 || defined TESTLEVEL1)
  240. #define ASSERT(condition,debugMsg) do {
  241.    \
  242.         if(condition == 0)
  243.                    \
  244.         {
  245.                            \
  246.                 AlertUser(debugMsg);
  247.            \
  248.         }
  249.                            \
  250.    } while (0)
  251.                    \
  252.  
  253. #elif (defined TESTLEVEL2 || defined TESTLEVEL3)
  254. #define ASSERT(condition,debugMsg) do {
  255.    \
  256.         if(condition == 0)
  257.                    \
  258.         {
  259.                            \
  260.                 DebugStr(debugMsg);
  261.            \
  262.         }
  263.                            \
  264.    } while (0)
  265. #else
  266. #define ASSERT(condition,debugMsg) ((void) 0)
  267. #endif
  268.  
  269.  
  270. //      VASSERT, if assertion is false it will print out file, line, message
  271. and
  272. possible variable
  273. //      Use: VASSERT(false,("Problems with %d", anErr));
  274.  
  275. #if (defined TESTLEVEL0)
  276. ##define VASSERT(condition,debugMsg) do {
  277.    \
  278.         if(condition == 0)
  279.                    \
  280.         {
  281.                            \
  282.                 vxdebugstr  debugMsg;
  283.            \
  284.         }
  285.                            \
  286.    } while (0)
  287.  
  288. #elif (defined TESTLEVEL1 || defined TESTLEVEL2 ||  defined TESTLEVEL3)
  289. #define VASSERT(condition,debugMsg) do {
  290.    \
  291.         if(condition == 0)
  292.                    \
  293.         {
  294.                            \
  295.                 fileinfo(__FILE__, __LINE__);
  296.            \
  297.                 vxdebugstr  debugMsg;
  298.            \
  299.         }
  300.                            \
  301.    } while (0)
  302.  
  303. #else
  304. #define (condition,debugMsg) ((void) 0)
  305. #endif
  306.  
  307.  
  308.  
  309.  
  310. -------------------
  311. Kent Sandvik (UUCP: ....!apple!ksand; INTERNET: ksand@apple.com)
  312. DISCLAIMER: Private activities on the Net.
  313.