| OLD | NEW |
| (Empty) |
| 1 // Copyright 2003-2009 Google Inc. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 // ======================================================================== | |
| 15 // | |
| 16 // Debug unittest | |
| 17 | |
| 18 #include <stdexcept> | |
| 19 | |
| 20 #include "omaha/base/debug.h" | |
| 21 #include "omaha/base/test.h" | |
| 22 #include "omaha/base/time.h" | |
| 23 | |
| 24 namespace omaha { | |
| 25 | |
| 26 // test what happens when we hit an exception | |
| 27 int SEHExceptionTest(int level, int reserved) { | |
| 28 const uint32 kflags = MB_SETFOREGROUND | | |
| 29 MB_TOPMOST | | |
| 30 MB_ICONWARNING | | |
| 31 MB_OKCANCEL; | |
| 32 if (::MessageBox(NULL, | |
| 33 L"do exception?", | |
| 34 L"exception test", | |
| 35 kflags) == IDOK) { | |
| 36 int *a1 = static_cast<int *>(1); | |
| 37 *a1 = 2; | |
| 38 | |
| 39 // if that does not work try: | |
| 40 // simulate a divide by zero | |
| 41 int a = 10; | |
| 42 int b2 = a; | |
| 43 b2 /= 2; | |
| 44 b2 -= 5; | |
| 45 // int c = a/b2; | |
| 46 int c = 0; | |
| 47 TCHAR *s = 0; | |
| 48 s++; | |
| 49 *s = 0; | |
| 50 | |
| 51 RaiseException(EXCEPTION_BREAKPOINT, 0, 0, NULL); | |
| 52 } | |
| 53 | |
| 54 return 0; | |
| 55 } | |
| 56 | |
| 57 int SEHCatchExceptionTest(int level, int reserved) { | |
| 58 __try { | |
| 59 SEHExceptionTest(level, reserved); | |
| 60 } __except (SehSendMinidump(GetExceptionCode(), | |
| 61 GetExceptionInformation(), | |
| 62 kMinsTo100ns)) { | |
| 63 } | |
| 64 | |
| 65 return 0; | |
| 66 } | |
| 67 | |
| 68 #pragma warning(push) | |
| 69 #pragma warning(disable:4702) | |
| 70 // test what happens when we do a C++ exception | |
| 71 int CppExceptionTest(int level, int reserved) { | |
| 72 _TRY_BEGIN | |
| 73 #if 0 | |
| 74 _THROW(std::logic_error, "throwing a fake logic_error"); | |
| 75 #else | |
| 76 // std::logic_error e("throwing a fake logic_error"); | |
| 77 // e._Raise(); | |
| 78 std::runtime_error(std::string("throwing a fake logic_error"))._Raise(); | |
| 79 #endif | |
| 80 _CATCH(std::logic_error e) | |
| 81 ASSERT(false, (L"caught exception")); | |
| 82 _CATCH_END | |
| 83 return 0; | |
| 84 } | |
| 85 #pragma warning(pop) | |
| 86 | |
| 87 // test what happens when we do a REPORT | |
| 88 int ReportTest(int level, int reserved) { | |
| 89 REPORT(false, R_ERROR, (L"test REPORT"), 592854117); | |
| 90 return 0; | |
| 91 } | |
| 92 | |
| 93 // test what happens when we hit an ASSERT | |
| 94 int AssertTest(int level, int reserved) { | |
| 95 ASSERT(false, (L"test ASSERT")); | |
| 96 return 0; | |
| 97 } | |
| 98 | |
| 99 // test what happens when we hit an ABORT | |
| 100 int AbortTest(int level, int reserved) { | |
| 101 ABORT((L"test ABORT")); | |
| 102 ASSERT(false, (L"returned from ABORT")); | |
| 103 return 0; | |
| 104 } | |
| 105 | |
| 106 } // namespace omaha | |
| 107 | |
| OLD | NEW |