This repository has been archived by the owner on Jul 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsimulator.cpp
145 lines (117 loc) · 4.01 KB
/
simulator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* Copyright (c) 2006-2016, Juan Hernando <[email protected]>
*
* This file is part of Monsteer <https://github.com/BlueBrain/Monsteer>
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 3.0 as published
* by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <lunchbox/pluginRegisterer.h>
#include <monsteer/steering/simulator.h>
#include <monsteer/steering/simulatorPlugin.h>
#include <monsteer/types.h>
#define BOOST_TEST_MODULE Simulator
#include <boost/test/unit_test.hpp>
struct SimulatorData
{
enum PlaybackState
{
PAUSE = 0u,
PLAY = 1u
};
monsteer::URI subscriber;
brion::uint32_ts cells;
std::string stimulusString;
PlaybackState playbackState;
};
SimulatorData globalData;
class DummySimulator : public monsteer::SimulatorPlugin
{
public:
explicit DummySimulator(const monsteer::SimulatorPluginInitData& pluginData)
{
globalData.subscriber = pluginData.subscriber;
}
static bool handles(const monsteer::SimulatorPluginInitData& pluginData)
{
return pluginData.subscriber.getScheme() == "dummy";
}
static std::string getDescription() { return "dummy://"; }
void injectStimulus(const std::string& jsonParameters,
const brion::uint32_ts& cells) final
{
globalData.stimulusString = jsonParameters;
globalData.cells = cells;
}
void injectMultipleStimuli(const std::string& jsonParameters,
const brion::uint32_ts& cells) final
{
globalData.stimulusString = jsonParameters;
globalData.cells = cells;
}
void play() { globalData.playbackState = SimulatorData::PLAY; }
void pause() { globalData.playbackState = SimulatorData::PAUSE; }
};
lunchbox::PluginRegisterer<DummySimulator> registerer;
BOOST_AUTO_TEST_CASE(test_create_handled_simulator)
{
monsteer::URI uri("dummy://");
monsteer::Simulator simulator(uri);
BOOST_CHECK_EQUAL(globalData.subscriber, uri);
}
BOOST_AUTO_TEST_CASE(test_create_unhandled)
{
BOOST_CHECK_THROW(monsteer::Simulator(monsteer::URI("invalid://")),
std::runtime_error);
}
monsteer::URI uri("dummy://");
uint32_t cellIds[] = {3, 7, 12, 20, 24, 30, 28, 1};
const std::string jsonParameters("blahblah");
namespace std
{
ostream& operator<<(ostream& os, const brion::uint32_ts& cellIds)
{
for (const uint32_t& cellId : cellIds)
os << cellId << " ";
return os << std::endl;
}
}
BOOST_AUTO_TEST_CASE(test_inject_stimulus)
{
monsteer::Simulator simulator(uri);
brion::uint32_ts cells;
for (uint32_t i = 0; i != 8; ++i)
cells.push_back(cellIds[i]);
simulator.injectStimulus(jsonParameters, cells);
BOOST_CHECK_EQUAL(globalData.stimulusString, jsonParameters);
BOOST_CHECK_EQUAL(globalData.cells, cells);
globalData.cells.clear();
}
BOOST_AUTO_TEST_CASE(test_inject_multiple_stimuli)
{
monsteer::Simulator simulator(uri);
brion::uint32_ts cells;
for (uint32_t i = 0; i != 8; ++i)
cells.push_back(cellIds[i]);
simulator.injectMultipleStimuli(jsonParameters, cells);
BOOST_CHECK_EQUAL(globalData.stimulusString, jsonParameters);
BOOST_CHECK_EQUAL(globalData.cells, cells);
globalData.cells.clear();
}
BOOST_AUTO_TEST_CASE(test_play_pause)
{
monsteer::Simulator simulator(uri);
simulator.play();
BOOST_CHECK(globalData.playbackState == SimulatorData::PLAY);
simulator.pause();
BOOST_CHECK(globalData.playbackState == SimulatorData::PAUSE);
}