Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
file_descriptor_unittest.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <fcntl.h>
6#include <sys/types.h>
7
8#include <string>
9#include <vector>
10
11#include "filesystem/scoped_temp_dir.h"
12#include "filesystem/unique_fd.h"
13#include "gtest/gtest.h"
14
15namespace filesystem {
16
17TEST(FileDescriptor, WriteAndRead) {
18 files::ScopedTempDir temp_dir;
19 std::string path;
20 ASSERT_TRUE(temp_dir.NewTempFile(&path));
21
22 fxl::UniqueFD fd(open(path.c_str(), O_RDWR));
23 ASSERT_TRUE(fd.is_valid());
24
25 std::string string = "one, two, three";
26 EXPECT_TRUE(WriteFileDescriptor(fd.get(), string.data(), string.size()));
27 EXPECT_EQ(0, lseek(fd.get(), 0, SEEK_SET));
28
29 std::vector<char> buffer;
30 buffer.resize(1024);
31 ssize_t read = ReadFileDescriptor(fd.get(), buffer.data(), 1024);
32 EXPECT_EQ(static_cast<ssize_t>(string.size()), read);
33 EXPECT_EQ(string, buffer.data());
34}
35
36} // namespace filesystem
#define TEST(S, s, D, expected)
static bool read(SkStream *stream, void *buffer, size_t amount)
static const uint8_t buffer[]
#define EXPECT_TRUE(handle)
Definition unit_test.h:685