Replaced usage of gtest's internal scoped_ptr with unique_ptr.

scoped_ptr was removed in with gtest google/googletest@e857f9cdd9.
This commit is contained in:
Michael Winterberg 2019-01-02 10:03:04 -08:00 committed by Victor Zverovich
parent ae1de3a8d3
commit 39623a7400
3 changed files with 14 additions and 16 deletions

View File

@ -7,8 +7,9 @@
#include "gtest-extra.h"
#include <cstring>
#include <algorithm>
#include <cstring>
#include <memory>
#include <stdexcept>
#include <gtest/gtest-spi.h>
@ -18,8 +19,6 @@
#include "util.h"
using testing::internal::scoped_ptr;
namespace {
// This is used to suppress coverity warnings about untrusted values.
@ -340,7 +339,7 @@ TEST(OutputRedirectTest, FlushErrorInCtor) {
// Put a character in a file buffer.
EXPECT_EQ('x', fputc('x', f.get()));
FMT_POSIX(close(write_fd));
scoped_ptr<OutputRedirect> redir{FMT_NULL};
std::unique_ptr<OutputRedirect> redir{FMT_NULL};
EXPECT_SYSTEM_ERROR_NOASSERT(redir.reset(new OutputRedirect(f.get())),
EBADF, "cannot flush stream");
redir.reset(FMT_NULL);
@ -352,7 +351,7 @@ TEST(OutputRedirectTest, DupErrorInCtor) {
int fd = (f.fileno)();
file copy = file::dup(fd);
FMT_POSIX(close(fd));
scoped_ptr<OutputRedirect> redir{FMT_NULL};
std::unique_ptr<OutputRedirect> redir{FMT_NULL};
EXPECT_SYSTEM_ERROR_NOASSERT(redir.reset(new OutputRedirect(f.get())),
EBADF, fmt::format("cannot duplicate file descriptor {}", fd));
copy.dup2(fd); // "undo" close or dtor will fail
@ -394,7 +393,7 @@ TEST(OutputRedirectTest, ErrorInDtor) {
int write_fd = write_end.descriptor();
file write_copy = write_end.dup(write_fd);
buffered_file f = write_end.fdopen("w");
scoped_ptr<OutputRedirect> redir(new OutputRedirect(f.get()));
std::unique_ptr<OutputRedirect> redir(new OutputRedirect(f.get()));
// Put a character in a file buffer.
EXPECT_EQ('x', fputc('x', f.get()));
EXPECT_WRITE(stderr, {

View File

@ -13,9 +13,10 @@
#include "posix-mock.h"
#include "../src/posix.cc"
#include <climits>
#include <errno.h>
#include <fcntl.h>
#include <climits>
#include <memory>
#ifdef _WIN32
# include <io.h>
@ -31,7 +32,6 @@ using fmt::buffered_file;
using fmt::error_code;
using fmt::file;
using testing::internal::scoped_ptr;
using testing::_;
using testing::StrEq;
using testing::Return;
@ -216,7 +216,7 @@ TEST(UtilTest, GetPageSize) {
TEST(FileTest, OpenRetry) {
write_file("test", "there must be something here");
scoped_ptr<file> f{FMT_NULL};
std::unique_ptr<file> f{FMT_NULL};
EXPECT_RETRY(f.reset(new file("test", file::RDONLY)),
open, "cannot open file test");
#ifndef _WIN32
@ -228,7 +228,7 @@ TEST(FileTest, OpenRetry) {
TEST(FileTest, CloseNoRetryInDtor) {
file read_end, write_end;
file::pipe(read_end, write_end);
scoped_ptr<file> f(new file(std::move(read_end)));
std::unique_ptr<file> f(new file(std::move(read_end)));
int saved_close_count = 0;
EXPECT_WRITE(stderr, {
close_count = 1;
@ -385,7 +385,7 @@ TEST(FileTest, FdopenNoRetry) {
TEST(BufferedFileTest, OpenRetry) {
write_file("test", "there must be something here");
scoped_ptr<buffered_file> f{FMT_NULL};
std::unique_ptr<buffered_file> f{FMT_NULL};
EXPECT_RETRY(f.reset(new buffered_file("test", "r")),
fopen, "cannot open file test");
#ifndef _WIN32
@ -398,7 +398,7 @@ TEST(BufferedFileTest, OpenRetry) {
TEST(BufferedFileTest, CloseNoRetryInDtor) {
file read_end, write_end;
file::pipe(read_end, write_end);
scoped_ptr<buffered_file> f(new buffered_file(read_end.fdopen("r")));
std::unique_ptr<buffered_file> f(new buffered_file(read_end.fdopen("r")));
int saved_fclose_count = 0;
EXPECT_WRITE(stderr, {
fclose_count = 1;

View File

@ -7,6 +7,7 @@
#include <cstdlib> // std::exit
#include <cstring>
#include <memory>
#include "fmt/posix.h"
#include "gtest-extra.h"
@ -20,8 +21,6 @@ using fmt::buffered_file;
using fmt::error_code;
using fmt::file;
using testing::internal::scoped_ptr;
// Checks if the file is open by reading one character from it.
static bool isopen(int fd) {
char buffer;
@ -119,7 +118,7 @@ TEST(BufferedFileTest, CloseFileInDtor) {
}
TEST(BufferedFileTest, CloseErrorInDtor) {
scoped_ptr<buffered_file> f(new buffered_file(open_buffered_file()));
std::unique_ptr<buffered_file> f(new buffered_file(open_buffered_file()));
EXPECT_WRITE(stderr, {
// The close function must be called inside EXPECT_WRITE, otherwise
// the system may recycle closed file descriptor when redirecting the
@ -246,7 +245,7 @@ TEST(FileTest, CloseFileInDtor) {
}
TEST(FileTest, CloseErrorInDtor) {
scoped_ptr<file> f(new file(open_file()));
std::unique_ptr<file> f(new file(open_file()));
EXPECT_WRITE(stderr, {
// The close function must be called inside EXPECT_WRITE, otherwise
// the system may recycle closed file descriptor when redirecting the