chromium/base/files/scoped_file_linux_unittest.cc

// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/files/scoped_file.h"

#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace base {
namespace {

class ScopedFDOwnershipTrackingTest : public testing::Test {};

TEST_F(ScopedFDOwnershipTrackingTest, BasicTracking) {}

#if defined(GTEST_HAS_DEATH_TEST) && !defined(COMPONENT_BUILD)

TEST_F(ScopedFDOwnershipTrackingTest, NoDoubleOwnership) {
  ScopedFD fd = OpenFD();
  subtle::EnableFDOwnershipEnforcement(true);
  EXPECT_DEATH(ScopedFD(fd.get()), "");
}

TEST_F(ScopedFDOwnershipTrackingTest, CrashOnUnownedClose) {
  ScopedFD fd = OpenFD();
  subtle::EnableFDOwnershipEnforcement(true);
  EXPECT_DEATH(close(fd.get()), "");
}

#endif  // defined(GTEST_HAS_DEATH_TEST) && !defined(COMPONENT_BUILD)

}  // namespace
}  // namespace base