blob: 1b73dd3bd3e85460e4f4e5cf98005b81a3a9a888 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
#include "cru/common/io/OpenFileFlag.hpp"
#include "cru/common/io/UnixFileStream.hpp"
#include <gtest/gtest.h>
#include <cstdio>
#include <filesystem>
TEST(UnixFileStream, Work) {
using namespace cru;
using namespace cru::io;
auto temp_file_path =
(std::filesystem::temp_directory_path() / "cru_test_temp.XXXXXX")
.generic_string();
mktemp(temp_file_path.data());
String path = String::FromUtf8(temp_file_path);
UnixFileStream file(path, OpenFileFlags::Write | OpenFileFlags::Create);
file.Write("abc", 3);
file.Close();
UnixFileStream file2(path, OpenFileFlags::Read);
auto buffer = std::make_unique<std::byte[]>(3);
file2.Read(buffer.get(), 3);
ASSERT_EQ(std::string_view(reinterpret_cast<const char*>(buffer.get()), 3),
"abc");
file2.Close();
std::filesystem::remove(temp_file_path);
}
|