20 #include "glog/logging.h" 21 #include "gtest/gtest.h" 27 std::string toString(
const std::vector<char>& data) {
28 return std::string(data.data(), data.size());
31 TEST(FakeFileWriter, Filename) {
32 auto content = std::make_shared<std::vector<char>>();
33 FakeFileWriter writer(
"file", content);
34 EXPECT_EQ(
"file", writer.GetFilename());
37 TEST(FakeFileWriter, CloseStream) {
38 auto content = std::make_shared<std::vector<char>>();
39 FakeFileWriter writer(
"file", content);
40 EXPECT_TRUE(writer.Close());
41 EXPECT_EQ(
"", toString(*content));
44 TEST(FakeFileWriter, WriteHeader) {
45 auto content = std::make_shared<std::vector<char>>();
46 const std::string header(
"dummy header");
47 const std::string header_2(
"dummy header 2");
48 FakeFileWriter writer(
"file", content);
50 EXPECT_TRUE(writer.WriteHeader(header.c_str(), header.size()));
51 EXPECT_EQ(
"dummy header", toString(*content));
53 EXPECT_TRUE(writer.WriteHeader(header_2.c_str(), header_2.size()));
54 EXPECT_EQ(
"dummy header 2", toString(*content));
56 EXPECT_TRUE(writer.Close());
57 EXPECT_EQ(
"dummy header 2", toString(*content));
60 TEST(FakeFileWriter, Write) {
61 auto content = std::make_shared<std::vector<char>>();
62 const std::vector<std::string> data_stream = {
"data 1",
"data 2"};
63 FakeFileWriter writer(
"file", content);
65 for (
const auto& data : data_stream) {
66 EXPECT_TRUE(writer.Write(data.c_str(), data.size()));
69 EXPECT_EQ(
"data 1data 2", toString(*content));
70 EXPECT_TRUE(writer.Close());
71 EXPECT_EQ(
"data 1data 2", toString(*content));
74 TEST(FakeFileWriter, HeaderAndWrite) {
75 auto content = std::make_shared<std::vector<char>>();
76 const std::string header(
"dummy header");
77 const std::vector<std::string> data_stream = {
"data 1",
"data 2"};
78 FakeFileWriter writer(
"file", content);
80 EXPECT_TRUE(writer.WriteHeader(header.c_str(), header.size()));
81 EXPECT_EQ(
"dummy header", toString(*content));
83 for (
const auto& data : data_stream) {
84 EXPECT_TRUE(writer.Write(data.c_str(), data.size()));
87 EXPECT_TRUE(writer.Close());
88 EXPECT_EQ(
"dummy headerdata 1data 2", toString(*content));
91 TEST(FakeFileWriter, WriteTerminatedString) {
92 auto content = std::make_shared<std::vector<char>>();
93 std::vector<char> data_stream = {
'd',
'a',
't',
'a',
'\0',
' ',
'1'};
94 FakeFileWriter writer(
"file", content);
95 EXPECT_TRUE(writer.Write(data_stream.data(), data_stream.size()));
96 EXPECT_EQ(data_stream, *content);
99 TEST(FakeFileWriter, WriteTerminatedHeaderString) {
100 auto content = std::make_shared<std::vector<char>>();
101 std::vector<char> header = {
'h',
'e',
'a',
'd',
'\0',
' ',
'e',
'r'};
102 FakeFileWriter writer(
"file", content);
103 EXPECT_TRUE(writer.WriteHeader(header.data(), header.size()));
104 EXPECT_EQ(header, *content);
107 TEST(FakeFileWriter, HeaderAndWriteTerminatedString) {
108 auto content = std::make_shared<std::vector<char>>();
109 std::vector<char> header = {
'd',
'a',
't',
'a',
'\0',
' ',
'1'};
110 std::vector<char> data = {
'h',
'e',
'a',
'd',
'\0',
' ',
'e',
'r'};
112 FakeFileWriter writer(
"file", content);
113 EXPECT_TRUE(writer.WriteHeader(header.data(), header.size()));
114 EXPECT_EQ(header, *content);
116 EXPECT_TRUE(writer.Write(data.data(), data.size()));
118 std::vector<char> expected_output = header;
119 expected_output.insert(expected_output.end(), data.begin(), data.end());
121 EXPECT_EQ(expected_output, *content);
123 EXPECT_TRUE(writer.Close());
124 EXPECT_EQ(expected_output, *content);
TEST(TrajectoryConnectivityStateTest, UnknownTrajectory)