RTC Toolkit  0.1.0-alpha
mockOldb.hpp
Go to the documentation of this file.
1 #ifndef MockOldb_HPP
2 #define MockOldb_HPP
3 
4 #include <gmock/gmock.h>
5 #include <mal/utility/Uri.hpp>
9 
10 using ::testing::InSequence;
11 using ::testing::SetArgPointee;
12 using ::testing::_;
13 
14 using namespace rtctk::componentFramework;
16 using ::elt::mal::Uri;
17 
18 // TODO: complete for all cases.
19 // add as used
20 class MockOldb : public FileRepository, public OldbApiIf
21 {
22 public:
23  explicit MockOldb(const ::elt::mal::Uri& datauri) : FileRepository(datauri, 0) { }
24  virtual ~MockOldb() { }
25  void CreateDataPoint(const DataPointPath& path, const std::string& type) override { }
26  void DeleteDataPoint(const DataPointPath& path) override { }
27  std::string GetDataPointType(const DataPointPath& path) const override { return ""; }
28  size_t GetDataPointSize(const DataPointPath& path) const override { return 0; }
29  bool DataPointExists(const DataPointPath& path) const override { return false; }
30  std::pair<StringList, StringList> GetChildren(const DataPointPath& path) const override {
31  return std::make_pair(StringList(),StringList());
32  }
33 
34  Response SendReadRequest(const Request& request) const override {
35  auto& req = request.GetParams()[0];
36 
37  if(req.m_type == std::type_index(typeid(bool)))
38  ReadBool(req.m_path, (bool*)req.m_buffer);
39  else if(req.m_type == std::type_index(typeid(int32_t)))
40  ReadInt(req.m_path, (int32_t*)req.m_buffer);
41  else if(req.m_type == std::type_index(typeid(float)))
42  ReadFloat(req.m_path, (float*)req.m_buffer);
43  else if(req.m_type == std::type_index(typeid(double)))
44  ReadDouble(req.m_path, (double*)req.m_buffer);
45  else if(req.m_type == std::type_index(typeid(std::vector<float>)))
46  ReadVectorFloat(req.m_path, (std::vector<float>*)req.m_buffer);
47  else if(req.m_type == std::type_index(typeid(MatrixBuffer<float>)))
48  ReadMatrixFloat(req.m_path, (MatrixBuffer<float>*)req.m_buffer);
49  else
50  ReadVoid(req.m_path, req.m_buffer);
51 
52  std::promise<void>p;
53  p.set_value();
54  return Response(p.get_future());
55  }
56 
57  Response SendWriteRequest(const Request& request) override {
58  auto& req = request.GetParams()[0];
59 
60  if(req.m_type == std::type_index(typeid(bool)))
61  WriteBool(req.m_path, *(bool*)req.m_buffer);
62  else if(req.m_type == std::type_index(typeid(int32_t)))
63  WriteInt(req.m_path, *(int32_t*)req.m_buffer);
64  else if(req.m_type == std::type_index(typeid(float)))
65  WriteFloat(req.m_path, *(float*)req.m_buffer);
66  else if(req.m_type == std::type_index(typeid(double)))
67  WriteDouble(req.m_path, *(double*)req.m_buffer);
68  else if(req.m_type == std::type_index(typeid(std::vector<float>)))
69  WriteVectorFloat(req.m_path, *(std::vector<float>*)req.m_buffer);
70  else if(req.m_type == std::type_index(typeid(MatrixBuffer<float>)))
71  WriteMatrixFloat(req.m_path, *(MatrixBuffer<float>*)req.m_buffer);
72  else
73  WriteVoid(req.m_path, req.m_buffer);
74 
75  std::promise<void>p;
76  p.set_value();
77  return Response(p.get_future());
78  }
79 
80  // void Subscribe(const Subscription& subscription) const override { }
81  // void Unsubscribe(const Subscription& subscription) const override { }
82 
83  MOCK_CONST_METHOD2(ReadVoid, void(const DataPointPath& path, void*));
84  MOCK_CONST_METHOD2(ReadBool, void(const DataPointPath& path, bool*));
85  MOCK_CONST_METHOD2(ReadInt, void(const DataPointPath& path, int32_t*));
86  MOCK_CONST_METHOD2(ReadFloat, void(const DataPointPath& path, float*));
87  MOCK_CONST_METHOD2(ReadDouble, void(const DataPointPath& path, double*));
88  MOCK_CONST_METHOD2(ReadVectorFloat, void(const DataPointPath& path, std::vector<float>*));
89  MOCK_CONST_METHOD2(ReadMatrixFloat, void(const DataPointPath& path, MatrixBuffer<float>*));
90 
91  MOCK_CONST_METHOD2(WriteVoid, void(const DataPointPath& path, void*));
92  MOCK_CONST_METHOD2(WriteBool, void(const DataPointPath& path, bool));
93  MOCK_CONST_METHOD2(WriteInt, void(const DataPointPath& path, int));
94  MOCK_CONST_METHOD2(WriteFloat, void(const DataPointPath& path, float));
95  MOCK_CONST_METHOD2(WriteDouble, void(const DataPointPath& path, double));
96  MOCK_CONST_METHOD2(WriteVectorFloat, void(const DataPointPath& path, std::vector<float>));
97  MOCK_CONST_METHOD2(WriteMatrixFloat, void(const DataPointPath& path, MatrixBuffer<float>&));
98 
99 };
100 
101 #endif
MockOldb::MOCK_CONST_METHOD2
MOCK_CONST_METHOD2(ReadDouble, void(const DataPointPath &path, double *))
MockOldb::MOCK_CONST_METHOD2
MOCK_CONST_METHOD2(WriteFloat, void(const DataPointPath &path, float))
MockOldb::MOCK_CONST_METHOD2
MOCK_CONST_METHOD2(ReadInt, void(const DataPointPath &path, int32_t *))
MockOldb::MOCK_CONST_METHOD2
MOCK_CONST_METHOD2(ReadMatrixFloat, void(const DataPointPath &path, MatrixBuffer< float > *))
MockOldb::CreateDataPoint
void CreateDataPoint(const DataPointPath &path, const std::string &type) override
Creates a new datapoint in the repository with a specified type.
Definition: mockOldb.hpp:25
MockOldb::MOCK_CONST_METHOD2
MOCK_CONST_METHOD2(ReadFloat, void(const DataPointPath &path, float *))
rtctk::componentFramework::RepositoryIf::Request
A request object to pass information about datapoints that should be read (written) from (to) the rep...
Definition: repositoryIf.hpp:37
rtctk::componentFramework::FileRepository
Definition: fileRepository.hpp:44
MockOldb::SendReadRequest
Response SendReadRequest(const Request &request) const override
Sends a request to read data from the repository.
Definition: mockOldb.hpp:34
rtctk::componentFramework
Definition: rtcComponent.hpp:17
oldbApiIf.hpp
Header file for OldbApiIf, which defines the API for OldbAdapters.
matrixBuffer.hpp
Declaration of the MatrixBuffer template class used in APIs.
MockOldb::MOCK_CONST_METHOD2
MOCK_CONST_METHOD2(ReadVoid, void(const DataPointPath &path, void *))
MockOldb::GetChildren
std::pair< StringList, StringList > GetChildren(const DataPointPath &path) const override
Queries the datapoints and child paths for a given path.
Definition: mockOldb.hpp:30
rtctkExampleDataTaskRobotTest.path
string path
Definition: rtctkExampleDataTaskRobotTest.py:228
MockOldb::MOCK_CONST_METHOD2
MOCK_CONST_METHOD2(WriteVoid, void(const DataPointPath &path, void *))
rtctk::componentFramework::RepositoryIf::Request::GetParams
const std::vector< Parameters > & GetParams() const
Definition: repositoryIf.hpp:62
rtctk::componentFramework::RepositoryIf::StringList
std::vector< std::string > StringList
Definition: repositoryIf.hpp:30
rtctk::componentFramework::OldbApiIf
Definition: oldbApiIf.hpp:18
MockOldb::MOCK_CONST_METHOD2
MOCK_CONST_METHOD2(WriteMatrixFloat, void(const DataPointPath &path, MatrixBuffer< float > &))
MockOldb::MOCK_CONST_METHOD2
MOCK_CONST_METHOD2(WriteVectorFloat, void(const DataPointPath &path, std::vector< float >))
MockOldb::DeleteDataPoint
void DeleteDataPoint(const DataPointPath &path) override
Deletes a datapoint.
Definition: mockOldb.hpp:26
Response
rtctk::componentFramework::RepositoryIf::Response Response
Definition: testFileRepository.cpp:15
MockOldb::MOCK_CONST_METHOD2
MOCK_CONST_METHOD2(WriteInt, void(const DataPointPath &path, int))
fileRepository.hpp
Declaration of FileRepository that provides a simple file based repository.
MockOldb
Definition: mockOldb.hpp:21
MockOldb::DataPointExists
bool DataPointExists(const DataPointPath &path) const override
Checks for the existence of a datapoint in the repository.
Definition: mockOldb.hpp:29
mudpi::int32_t
int int32_t
Definition: mudpi.h:17
MockOldb::MOCK_CONST_METHOD2
MOCK_CONST_METHOD2(WriteBool, void(const DataPointPath &path, bool))
MockOldb::MockOldb
MockOldb(const ::elt::mal::Uri &datauri)
Definition: mockOldb.hpp:23
MockOldb::GetDataPointSize
size_t GetDataPointSize(const DataPointPath &path) const override
Fetches the size of the datapoint's data.
Definition: mockOldb.hpp:28
rtctk::componentFramework::DataPointPath
Definition: dataPointPath.hpp:30
MockOldb::SendWriteRequest
Response SendWriteRequest(const Request &request) override
Sends a request to write data to the repository.
Definition: mockOldb.hpp:57
rtctk::componentFramework::RepositoryIf::Response
An object used to wait for a request to complete.
Definition: repositoryIf.hpp:74
MockOldb::MOCK_CONST_METHOD2
MOCK_CONST_METHOD2(WriteDouble, void(const DataPointPath &path, double))
MockOldb::~MockOldb
virtual ~MockOldb()
Definition: mockOldb.hpp:24
MockOldb::GetDataPointType
std::string GetDataPointType(const DataPointPath &path) const override
Fetches the type of the datapoint.
Definition: mockOldb.hpp:27
MockOldb::MOCK_CONST_METHOD2
MOCK_CONST_METHOD2(ReadBool, void(const DataPointPath &path, bool *))
rtctk::componentFramework::MatrixBuffer
Definition: matrixBuffer.hpp:19
MockOldb::MOCK_CONST_METHOD2
MOCK_CONST_METHOD2(ReadVectorFloat, void(const DataPointPath &path, std::vector< float > *))