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