5 #include <gtest/gtest.h> 18 if (path == file_name)
20 out_size =
uint16_t(file_data.length());
21 out_type.flags |= EntryType::FLAG_FILE;
22 out_type.flags |= EntryType::FLAG_READABLE;
27 return Error::NOT_FOUND;
33 if (path == file_name)
35 if (offset < file_data.length())
37 inout_size =
uint16_t(file_data.length() - offset);
38 std::memcpy(out_buffer, file_data.c_str() + offset, inout_size);
48 return Error::NOT_FOUND;
56 TEST(BasicFileServer, Basic)
71 ASSERT_LE(0, serv.
start());
79 GetInfo::Request get_info_req;
80 get_info_req.path.path =
"test";
82 ASSERT_LE(0, get_info.
call(1, get_info_req));
90 ASSERT_EQ(EntryType::FLAG_FILE | EntryType::FLAG_READABLE,
100 Read::Request read_req;
101 read_req.path.path =
"test";
103 ASSERT_LE(0, read.
call(1, read_req));
131 std::cout <<
"sizeof(uavcan::FileServer): " <<
sizeof(
uavcan::FileServer) << std::endl;
133 ASSERT_LE(0, serv.
start());
std::unique_ptr< Result > result
static const std::string file_name
virtual int16_t getInfo(const Path &path, uint64_t &out_size, EntryType &out_type)
int call(uavcan::NodeID node_id, const typename DataType::Request &request)
protocol::file::EntryType EntryType
TEST(BasicFileServer, Basic)
static const std::string file_data
static GlobalDataTypeRegistry & instance()
static MonotonicDuration fromMSec(int64_t ms)
int spinBoth(uavcan::MonotonicDuration duration)
protocol::file::Path::FieldTypes::path Path
virtual int16_t read(const Path &path, const uint64_t offset, uint8_t *out_buffer, uint16_t &inout_size)