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.
5 #include "base/mac/call_with_eh_frame.h"
7 #import <Foundation/Foundation.h>
9 #include "testing/gtest/include/gtest/gtest.h"
15 class CallWithEHFrameTest : public testing::Test {
17 void ThrowException() {
18 [NSArray arrayWithObject:nil];
22 // Catching from within the EHFrame is allowed.
23 TEST_F(CallWithEHFrameTest, CatchExceptionHigher) {
24 bool __block saw_exception = false;
25 base::mac::CallWithEHFrame(^{
28 } @catch (NSException* exception) {
32 EXPECT_TRUE(saw_exception);
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;
40 base::mac::CallWithEHFrame(^{
43 } @catch (NSException* exception) {
46 ASSERT_FALSE(saw_exception);
48 EXPECT_DEATH(catch_exception_lower(), "");