fake_file_writer.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2018 The Cartographer Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #include "glog/logging.h"
20 #include "gtest/gtest.h"
21 
22 namespace cartographer {
23 namespace io {
24 
25 FakeFileWriter::FakeFileWriter(const std::string& filename,
26  std::shared_ptr<std::vector<char>> content)
27  : is_closed_(false), content_(content), filename_(filename) {
28  CHECK(content != nullptr);
29 }
30 
31 bool FakeFileWriter::Write(const char* const data, const size_t len) {
32  EXPECT_FALSE(is_closed_);
33  content_->insert(content_->end(), data, data + len);
34  return true;
35 }
36 
38  EXPECT_FALSE(is_closed_);
39  is_closed_ = true;
40  return true;
41 }
42 
43 bool FakeFileWriter::WriteHeader(const char* const data, const size_t len) {
44  EXPECT_FALSE(is_closed_);
45  if (content_->size() < len) {
46  content_->resize(len);
47  }
48  std::copy(data, data + len, content_->begin());
49  return true;
50 }
51 
52 std::string FakeFileWriter::GetFilename() { return filename_; }
53 
54 } // namespace io
55 } // namespace cartographer
FakeFileWriter(const std::string &filename, std::shared_ptr< std::vector< char >> content)
std::shared_ptr< std::vector< char > > content_
bool Write(const char *data, size_t len) override
bool WriteHeader(const char *data, size_t len) override
std::string GetFilename() override


cartographer
Author(s): The Cartographer Authors
autogenerated on Mon Feb 28 2022 22:00:58