Style/readability clean-up for certificate reporting code
[chromium-blink-merge.git] / base / mac / call_with_eh_frame_unittest.mm
blob46bf285c2cd957c3ce763f2b2cbf7d1f7caed411
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"
11 namespace base {
12 namespace mac {
13 namespace {
15 class CallWithEHFrameTest : public testing::Test {
16  protected:
17   void ThrowException() {
18     [NSArray arrayWithObject:nil];
19   }
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);
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);
47   };
48   EXPECT_DEATH(catch_exception_lower(), "");
51 }  // namespace
52 }  // namespace mac
53 }  // namespace base