Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2009, Google Inc. | 1 // Copyright 2009, Google Inc. |
| 2 // All rights reserved. | 2 // All rights reserved. |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 6 // met: | 6 // met: |
| 7 // | 7 // |
| 8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
| 9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
| 10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 BOOL DoesPathExist(const TCHAR *path_name); | 46 BOOL DoesPathExist(const TCHAR *path_name); |
| 47 | 47 |
| 48 class ExceptionHandlerDeathTest : public ::testing::Test { | 48 class ExceptionHandlerDeathTest : public ::testing::Test { |
| 49 protected: | 49 protected: |
| 50 // Member variable for each test that they can use | 50 // Member variable for each test that they can use |
| 51 // for temporary storage. | 51 // for temporary storage. |
| 52 TCHAR temp_path_[MAX_PATH]; | 52 TCHAR temp_path_[MAX_PATH]; |
| 53 // Actually constructs a temp path name. | 53 // Actually constructs a temp path name. |
| 54 virtual void SetUp(); | 54 virtual void SetUp(); |
| 55 // A helper method that tests can use to crash. | 55 // A helper method that tests can use to crash. |
| 56 void DoCrash(); | 56 void DoCrashAccessViolation(); |
| 57 void DoCrashPureVirtualCall(); | |
| 57 }; | 58 }; |
| 58 | 59 |
| 59 void ExceptionHandlerDeathTest::SetUp() { | 60 void ExceptionHandlerDeathTest::SetUp() { |
| 60 const ::testing::TestInfo* const test_info = | 61 const ::testing::TestInfo* const test_info = |
| 61 ::testing::UnitTest::GetInstance()->current_test_info(); | 62 ::testing::UnitTest::GetInstance()->current_test_info(); |
| 62 TCHAR temp_path[MAX_PATH] = { '\0' }; | 63 TCHAR temp_path[MAX_PATH] = { '\0' }; |
| 63 TCHAR test_name_wide[MAX_PATH] = { '\0' }; | 64 TCHAR test_name_wide[MAX_PATH] = { '\0' }; |
| 64 // We want the temporary directory to be what the OS returns | 65 // We want the temporary directory to be what the OS returns |
| 65 // to us, + the test case name. | 66 // to us, + the test case name. |
| 66 GetTempPath(MAX_PATH, temp_path); | 67 GetTempPath(MAX_PATH, temp_path); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 } | 120 } |
| 120 | 121 |
| 121 static bool gDumpCallbackCalled = false; | 122 static bool gDumpCallbackCalled = false; |
| 122 | 123 |
| 123 void clientDumpCallback(void *dump_context, | 124 void clientDumpCallback(void *dump_context, |
| 124 const google_breakpad::ClientInfo *client_info, | 125 const google_breakpad::ClientInfo *client_info, |
| 125 const std::wstring *dump_path) { | 126 const std::wstring *dump_path) { |
| 126 gDumpCallbackCalled = true; | 127 gDumpCallbackCalled = true; |
| 127 } | 128 } |
| 128 | 129 |
| 129 void ExceptionHandlerDeathTest::DoCrash() { | 130 void ExceptionHandlerDeathTest::DoCrashAccessViolation() { |
| 130 google_breakpad::ExceptionHandler *exc = | 131 google_breakpad::ExceptionHandler *exc = |
| 131 new google_breakpad::ExceptionHandler( | 132 new google_breakpad::ExceptionHandler( |
| 132 temp_path_, NULL, NULL, NULL, | 133 temp_path_, NULL, NULL, NULL, |
| 133 google_breakpad::ExceptionHandler::HANDLER_ALL, MiniDumpNormal, kPipeName, | 134 google_breakpad::ExceptionHandler::HANDLER_ALL, MiniDumpNormal, kPipeName, |
| 134 NULL); | 135 NULL); |
| 135 // Although this is executing in the child process of the death test, | 136 // Although this is executing in the child process of the death test, |
| 136 // if it's not true we'll still get an error rather than the crash | 137 // if it's not true we'll still get an error rather than the crash |
| 137 // being expected. | 138 // being expected. |
| 138 ASSERT_TRUE(exc->IsOutOfProcess()); | 139 ASSERT_TRUE(exc->IsOutOfProcess()); |
| 139 int *i = NULL; | 140 int *i = NULL; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 153 std::wstring dump_path(temp_path_); | 154 std::wstring dump_path(temp_path_); |
| 154 google_breakpad::CrashGenerationServer server( | 155 google_breakpad::CrashGenerationServer server( |
| 155 kPipeName, NULL, NULL, NULL, &clientDumpCallback, NULL, NULL, NULL, true, | 156 kPipeName, NULL, NULL, NULL, &clientDumpCallback, NULL, NULL, NULL, true, |
| 156 &dump_path); | 157 &dump_path); |
| 157 | 158 |
| 158 // This HAS to be EXPECT_, because when this test case is executed in the | 159 // This HAS to be EXPECT_, because when this test case is executed in the |
| 159 // child process, the server registration will fail due to the named pipe | 160 // child process, the server registration will fail due to the named pipe |
| 160 // being the same. | 161 // being the same. |
| 161 EXPECT_TRUE(server.Start()); | 162 EXPECT_TRUE(server.Start()); |
| 162 EXPECT_FALSE(gDumpCallbackCalled); | 163 EXPECT_FALSE(gDumpCallbackCalled); |
| 163 ASSERT_DEATH(this->DoCrash(), ""); | 164 ASSERT_DEATH(this->DoCrashAccessViolation(), ""); |
| 164 EXPECT_TRUE(gDumpCallbackCalled); | 165 EXPECT_TRUE(gDumpCallbackCalled); |
| 165 } | 166 } |
| 166 | 167 |
| 167 TEST_F(ExceptionHandlerDeathTest, InvalidParameterTest) { | 168 TEST_F(ExceptionHandlerDeathTest, InvalidParameterTest) { |
| 168 using google_breakpad::ExceptionHandler; | 169 using google_breakpad::ExceptionHandler; |
| 169 | 170 |
| 170 ASSERT_TRUE(DoesPathExist(temp_path_)); | 171 ASSERT_TRUE(DoesPathExist(temp_path_)); |
| 171 ExceptionHandler handler(temp_path_, NULL, NULL, NULL, | 172 ExceptionHandler handler(temp_path_, NULL, NULL, NULL, |
| 172 ExceptionHandler::HANDLER_INVALID_PARAMETER); | 173 ExceptionHandler::HANDLER_INVALID_PARAMETER); |
| 173 | 174 |
| 174 // Disable the message box for assertions | 175 // Disable the message box for assertions |
| 175 _CrtSetReportMode(_CRT_ASSERT, 0); | 176 _CrtSetReportMode(_CRT_ASSERT, 0); |
| 176 | 177 |
| 177 // Call with a bad argument. The invalid parameter will be swallowed | 178 // Call with a bad argument. The invalid parameter will be swallowed |
| 178 // and a dump will be generated, the process will exit(0). | 179 // and a dump will be generated, the process will exit(0). |
| 179 ASSERT_EXIT(printf(NULL), ::testing::ExitedWithCode(0), ""); | 180 ASSERT_EXIT(printf(NULL), ::testing::ExitedWithCode(0), ""); |
| 180 } | 181 } |
| 182 | |
| 183 | |
| 184 struct PureVirtualCallBase { | |
| 185 PureVirtualCallBase() { | |
| 186 // We have to reinterpret so the linker doesn't get confused because the | |
| 187 // method isn't defined. | |
| 188 reinterpret_cast<PureVirtualCallBase*>(this)->PureFunction(); | |
|
Sigurður Ásgeirsson
2010/05/13 20:57:10
Really? How weird.
| |
| 189 } | |
| 190 virtual ~PureVirtualCallBase() {} | |
| 191 virtual void PureFunction() const = 0; | |
| 192 }; | |
| 193 struct PureVirtualCall : public PureVirtualCallBase { | |
| 194 PureVirtualCall() { PureFunction(); } | |
| 195 virtual void PureFunction() const {} | |
| 196 }; | |
| 197 | |
| 198 void ExceptionHandlerDeathTest::DoCrashPureVirtualCall() { | |
| 199 PureVirtualCall instance; | |
| 181 } | 200 } |
| 201 | |
| 202 TEST_F(ExceptionHandlerDeathTest, PureVirtualCallTest) { | |
| 203 using google_breakpad::ExceptionHandler; | |
| 204 | |
| 205 ASSERT_TRUE(DoesPathExist(temp_path_)); | |
| 206 ExceptionHandler handler(temp_path_, NULL, NULL, NULL, | |
| 207 ExceptionHandler::HANDLER_PURECALL); | |
| 208 | |
| 209 // Disable the message box for assertions | |
| 210 _CrtSetReportMode(_CRT_ASSERT, 0); | |
| 211 | |
| 212 // Calls a pure virtual function. | |
| 213 EXPECT_EXIT(DoCrashPureVirtualCall(), ::testing::ExitedWithCode(0), ""); | |
| 214 } | |
| 215 } | |
| OLD | NEW |