OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/mac/call_with_eh_frame.h" | |
6 | |
7 #import <Foundation/Foundation.h> | |
8 | |
9 #include "testing/gtest/include/gtest/gtest.h" | |
10 | |
11 namespace base { | |
12 namespace mac { | |
13 namespace { | |
14 | |
15 class CallWithEHFrameTest : public testing::Test { | |
16 protected: | |
17 void ThrowException() { | |
18 [NSArray arrayWithObject:nil]; | |
19 } | |
20 }; | |
21 | |
22 // Catching from within the EHFrame is allowed. | |
23 TEST_F(CallWithEHFrameTest, CatchExceptionHigher) { | |
24 bool __block saw_exception = false; | |
25 base::mac::CallWithEHFrame(^{ | |
26 @try { | |
27 ThrowException(); | |
28 } @catch (NSException* exception) { | |
29 saw_exception = true; | |
30 } | |
31 }); | |
32 EXPECT_TRUE(saw_exception); | |
33 } | |
34 | |
35 // Trying to catch an exception outside the EHFrame is blocked. | |
36 TEST_F(CallWithEHFrameTest, CatchExceptionLower) { | |
37 auto catch_exception_lower = ^{ | |
38 bool saw_exception = false; | |
39 @try { | |
40 base::mac::CallWithEHFrame(^{ | |
41 ThrowException(); | |
42 }); | |
43 } @catch (NSException* exception) { | |
44 saw_exception = true; | |
45 } | |
46 ASSERT_FALSE(saw_exception); | |
Scott Hess - ex-Googler
2015/07/06 22:34:04
Should this code crash by failing this assertion,
Robert Sesek
2015/07/07 22:26:17
It should crash by throwing the excpetion.
Scott Hess - ex-Googler
2015/07/07 22:34:31
To be clear, what I meant was that this snippet ca
Robert Sesek
2015/07/07 22:35:55
No, I don't think so. One is a crash and the other
| |
47 }; | |
48 EXPECT_DEATH(catch_exception_lower(), ""); | |
49 } | |
50 | |
51 } // namespace | |
52 } // namespace mac | |
53 } // namespace base | |
OLD | NEW |