chromium/third_party/perfetto/src/base/scoped_file_unittest.cc


/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "perfetto/ext/base/scoped_file.h"
#include "perfetto/base/build_config.h"

#include <fcntl.h>

#if PERFETTO_BUILDFLAG(PERFETTO_OS_WIN)
#include <io.h>
#elif PERFETTO_BUILDFLAG(PERFETTO_OS_FUCHSIA)
#include <lib/fdio/fdio.h>
#else
#include <unistd.h>
// Double closing of file handles on Windows leads to invocation of the invalid
// parameter handler or asserts and therefore it cannot be tested, but it can
// be tested on other platforms.
#define TEST_INVALID_CLOSE
#endif

#include "test/gtest_and_gmock.h"

namespace perfetto {
namespace base {
namespace {

int OpenDevNull() {}

FILE* OpenDevNullStream() {}

// Returns a file descriptor to some file. On Fuchsia: returns a descriptor of a
// file in /tmp. On other platforms: returns a descriptor of /dev/zero.
int MakeSecondFileDescriptor() {}

#if !PERFETTO_BUILDFLAG(PERFETTO_OS_WIN)
TEST(ScopedDirTest, CloseOutOfScope) {}
#endif

TEST(ScopedFileTest, CloseOutOfScope) {}

TEST(ScopedFstreamTest, CloseOutOfScope) {}

TEST(ScopedFileTest, Reset) {}

TEST(ScopedFileTest, Release) {}

TEST(ScopedFileTest, MoveCtor) {}

TEST(ScopedFileTest, MoveAssignment) {}

// File descriptors are capabilities and hence can be security critical. A
// failed close() suggests the memory ownership of the file is wrong and we
// might have leaked a capability.
#ifdef TEST_INVALID_CLOSE
TEST(ScopedFileTest, CloseFailureIsFatal) {}
#endif

}  // namespace
}  // namespace base
}  // namespace perfetto