• 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 <optional>
8
9#include "testing/gtest/include/gtest/gtest.h"
10
11namespace base::apple {
12
13#if DCHECK_IS_ON()
14TEST(ScopedNSAutoreleasePoolTest, DieOutOfOrder) {
15  std::optional<ScopedNSAutoreleasePool> pool1;
16  std::optional<ScopedNSAutoreleasePool> pool2;
17
18  // Instantiate the pools in the order 1, then 2.
19  pool1.emplace();
20  pool2.emplace();
21
22  // Destroy in the wrong order; ensure death.
23  ASSERT_DEATH(pool1.reset(), "autorelease");
24}
25#endif
26
27}  // namespace base::apple
28