Fawkes API  Fawkes Development Version
robot_memory_test.h
1 /***************************************************************************
2  * robot_memory_test.h - Test for the RobotMemory and their test class
3  *
4  *
5  * Created: 3:11:53 PM 2016
6  * Copyright 2016 Frederik Zwilling
7  ****************************************************************************/
8 
9 /* This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Library General Public License for more details.
18  *
19  * Read the full text in the LICENSE.GPL file in the doc directory.
20  */
21 
22 #ifndef _PLUGINS_ROBOT_MEMORY_TEST_H_
23 #define _PLUGINS_ROBOT_MEMORY_TEST_H_
24 
25 #include "plugins/robot-memory/robot_memory.h"
26 
27 #include <blackboard/blackboard.h>
28 #include <gtest/gtest.h>
29 
30 #include <stdio.h>
31 
32 /** Environment for running Tests of the RobotMemory
33  * Necessary for making object such as the robot memory available in tests.
34  */
35 class RobotMemoryTestEnvironment : public ::testing::Environment
36 {
37 public:
38  /**
39  * Constructor with objects of the thread
40  * @param robot_memory Robot Memory
41  * @param blackboard Blackboard
42  */
44  {
45  this->robot_memory = robot_memory;
46  this->blackboard = blackboard;
47  }
49  {
50  }
51  /// Setup the environment
52  void
54  {
55  }
56  /// TearDown the environment
57  virtual void
59  {
60  }
61 
62 public:
63  /// Access to Robot Memory
65  /// Access to blackboard
67 };
68 
69 /** Class for Tests of the RobotMemory
70  */
71 class RobotMemoryTest : public ::testing::Test
72 {
73 protected:
74  virtual void SetUp();
75  /// Access to Robot Memory
77  /// Access to blackboard
79 
80 protected:
81  ::testing::AssertionResult contains_pairs(mongo::BSONObj obj, mongo::BSONObj exp);
82 };
83 
84 /**
85  * Class to register callbacks independent of how many tests are using them at the moment
86  */
88 {
89 public:
91  {
92  callback_counter = 0;
93  };
95  /// Counter for how often the callback was called
96  int callback_counter;
97  /**
98  * Test callback function
99  * @param update Trigger update
100  */
101  void
102  callback_test(mongo::BSONObj update)
103  {
105  }
106 };
107 
108 /**
109  * Class providing a computable function
110  */
112 {
113 public:
114  TestComputable(){};
115  ~TestComputable(){};
116  //Different functions for computables:
117  /**
118  * Computable function for static document
119  * @param query Input query
120  * @param collection Corresponding collection
121  * @return Computed docs
122  */
123  std::list<mongo::BSONObj>
124  compute(const mongo::BSONObj &query, const std::string &collection)
125  {
126  std::list<mongo::BSONObj> res;
127  res.push_back(mongo::fromjson("{computed:true, result:'this is computed'}"));
128  return res;
129  }
130  /**
131  * Computable function for addition
132  * @param query Input query
133  * @param collection Corresponding collection
134  * @return Computed docs
135  */
136  std::list<mongo::BSONObj>
137  compute_sum(const mongo::BSONObj &query, const std::string &collection)
138  {
139  std::list<mongo::BSONObj> res;
140  int x = query.getField("x").Int();
141  int y = query.getField("y").Int();
142  int sum = x + y;
143  mongo::BSONObjBuilder b;
144  b << "compute"
145  << "sum"
146  << "x" << x << "y" << y << "sum" << sum;
147  res.push_back(b.obj());
148  return res;
149  }
150  /**
151  * Computable function for multiple static document
152  * @param query Input query
153  * @param collection Corresponding collection
154  * @return Computed docs
155  */
156  std::list<mongo::BSONObj>
157  compute_multiple(const mongo::BSONObj &query, const std::string &collection)
158  {
159  std::list<mongo::BSONObj> res;
160  res.push_back(mongo::fromjson("{compute:'multiple', count:1}"));
161  res.push_back(mongo::fromjson("{compute:'multiple', count:2}"));
162  res.push_back(mongo::fromjson("{compute:'multiple', count:3}"));
163  return res;
164  }
165 };
166 
167 #endif
virtual void SetUp()
Setup for each test.
Environment for running Tests of the RobotMemory Necessary for making object such as the robot memory...
Class to register callbacks independent of how many tests are using them at the moment.
RobotMemoryTestEnvironment(RobotMemory *robot_memory, fawkes::BlackBoard *blackboard)
Constructor with objects of the thread.
std::list< mongo::BSONObj > compute(const mongo::BSONObj &query, const std::string &collection)
Computable function for static document.
virtual void TearDown()
TearDown the environment.
Class providing a computable function.
fawkes::BlackBoard * blackboard
Access to blackboard.
static RobotMemory * robot_memory
Access to Robot Memory.
Access to the robot memory based on mongodb.
Definition: robot_memory.h:48
void SetUp()
Setup the environment.
RobotMemory * robot_memory
Access to Robot Memory.
The BlackBoard abstract class.
Definition: blackboard.h:45
static fawkes::BlackBoard * blackboard
Access to blackboard.
std::list< mongo::BSONObj > compute_sum(const mongo::BSONObj &query, const std::string &collection)
Computable function for addition.
::testing::AssertionResult contains_pairs(mongo::BSONObj obj, mongo::BSONObj exp)
Function for testing if a document contains all key-value pairs of another document.
int callback_counter
Counter for how often the callback was called.
void callback_test(mongo::BSONObj update)
Test callback function.
std::list< mongo::BSONObj > compute_multiple(const mongo::BSONObj &query, const std::string &collection)
Computable function for multiple static document.
Class for Tests of the RobotMemory.