• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2023 The Chromium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#import "base/apple/scoped_nsautorelease_pool.h"
6
7#include "testing/gtest/include/gtest/gtest.h"
8#include "third_party/abseil-cpp/absl/types/optional.h"
9
10namespace base::apple {
11
12#if DCHECK_IS_ON()
13TEST(ScopedNSAutoreleasePoolTest, DieOutOfOrder) {
14  absl::optional<ScopedNSAutoreleasePool> pool1;
15  absl::optional<ScopedNSAutoreleasePool> pool2;
16
17  // Instantiate the pools in the order 1, then 2.
18  pool1.emplace();
19  pool2.emplace();
20
21  // Destroy in the wrong order; ensure death.
22  ASSERT_DEATH(pool1.reset(), "autorelease");
23}
24#endif
25
26}  // namespace base::apple
27