Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

177 lines
4.6 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: assert.cpp
  7. //
  8. // Contents: Assertion handling code for OleTest
  9. //
  10. // Classes:
  11. //
  12. // Functions: OleTestAssert
  13. // DlgAssertProc
  14. //
  15. // History: dd-mmm-yy Author Comment
  16. // 09-Dec-94 MikeW author
  17. //
  18. //--------------------------------------------------------------------------
  19. #include "oletest.h"
  20. #include "appwin.h"
  21. //+-------------------------------------------------------------------------
  22. //
  23. // Function: OleTestAssert
  24. //
  25. // Synopsis: Reports assertion failures to the user
  26. //
  27. // Effects:
  28. //
  29. // Arguments: [pszMessage] -- the assertion message
  30. // [pszFile] -- the file it occured in
  31. // [uLine] -- the line it occured at
  32. //
  33. // Requires:
  34. //
  35. // Returns: void
  36. //
  37. // Signals:
  38. //
  39. // Modifies:
  40. //
  41. // Algorithm: Format the message and then put up a dialog box for the user.
  42. // They can then choose to abort the test, break to the debugger,
  43. // or ignore the assertion.
  44. //
  45. // History: dd-mmm-yy Author Comment
  46. // 09-Dec-94 MikeW author
  47. //
  48. // Notes:
  49. //
  50. //--------------------------------------------------------------------------
  51. void OleTestAssert(char *pszMessage, char *pszFile, UINT uLine)
  52. {
  53. char szErrorMessage[3 * 80]; // room for 3 lines of info
  54. int cch;
  55. int nAction;
  56. OutputDebugString("OleTest -- Assertion Failure\r\n");
  57. //
  58. // format the message
  59. //
  60. cch = _snprintf(szErrorMessage,
  61. sizeof(szErrorMessage),
  62. "%s\r\nIn file: %s\r\nAt line: %u",
  63. pszMessage,
  64. pszFile,
  65. uLine);
  66. if (cch < 0)
  67. {
  68. //
  69. // the whole assertion message doesn't fit in the buffer so
  70. // just worry about the file name and line number
  71. //
  72. OutputDebugString(pszMessage); // send original text to the debugger
  73. OutputDebugString("\r\n");
  74. _snprintf(szErrorMessage,
  75. sizeof(szErrorMessage),
  76. "In file: %s\r\nAt line: %d",
  77. pszFile,
  78. uLine);
  79. szErrorMessage[sizeof(szErrorMessage) - 1] = '\0'; // just in case
  80. }
  81. OutputDebugString(szErrorMessage);
  82. OutputDebugString("\r\n");
  83. nAction = DialogBoxParam(vApp.m_hinst, // get the users choice
  84. MAKEINTRESOURCE(IDD_ASSERTIONFAILURE),
  85. vApp.m_hwndMain,
  86. DlgAssertProc,
  87. (LPARAM) szErrorMessage);
  88. switch (nAction)
  89. {
  90. case IDABORT: // abort the test
  91. RaiseException(E_ABORT, 0, 0, NULL);
  92. case IDB_BREAK: // break into the debugger
  93. DebugBreak();
  94. break;
  95. case IDIGNORE: // ignore the assertion
  96. break;
  97. default: // whoops
  98. RaiseException(E_UNEXPECTED, 0, 0, NULL);
  99. }
  100. }
  101. //+-------------------------------------------------------------------------
  102. //
  103. // Function: DlgAssertProc
  104. //
  105. // Synopsis: Window procedure for the assertion dialog box
  106. //
  107. // Effects:
  108. //
  109. // Arguments: [hWnd] -- dialog window
  110. // [uMsg] -- message
  111. // [wParam] -- wParam
  112. // [lParam] -- lParam (for INITDIALOG it points to assert text)
  113. //
  114. // Requires:
  115. //
  116. // Returns: BOOL
  117. //
  118. // Signals:
  119. //
  120. // Modifies:
  121. //
  122. // Algorithm: Just wait for a button to be pressed
  123. //
  124. // History: dd-mmm-yy Author Comment
  125. // 09-Dec-94 MikeW author
  126. //
  127. // Notes:
  128. //
  129. //--------------------------------------------------------------------------
  130. INT_PTR CALLBACK DlgAssertProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  131. {
  132. switch (uMsg)
  133. {
  134. case WM_INITDIALOG:
  135. DeleteMenu(GetSystemMenu(hWnd, FALSE), SC_CLOSE, MF_BYCOMMAND);
  136. DrawMenuBar(hWnd);
  137. SetDlgItemText(hWnd, IDC_EDIT, (LPCSTR) lParam);
  138. return TRUE;
  139. case WM_COMMAND:
  140. switch (LOWORD(wParam))
  141. {
  142. case IDABORT:
  143. case IDB_BREAK:
  144. case IDIGNORE:
  145. EndDialog(hWnd, LOWORD(wParam));
  146. return TRUE;
  147. default:
  148. return FALSE;
  149. }
  150. default:
  151. return FALSE;
  152. }
  153. }