Eclipse SUMO - Simulation of Urban MObility
TraCITestClient.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // A test execution class
18 /****************************************************************************/
19 #ifndef TRACITESTCLIENT_H
20 #define TRACITESTCLIENT_H
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <string>
28 #include <sstream>
29 #include <vector>
30 
31 #include <foreign/tcpip/socket.h>
32 #include <utils/traci/TraCIAPI.h>
33 
34 
35 // ===========================================================================
36 // class definitions
37 // ===========================================================================
44 class TraCITestClient : public TraCIAPI {
45 public:
49  TraCITestClient(std::string outputFileName = "testclient_result.out");
50 
51 
54 
55 
61  int run(std::string fileName, int port, std::string host = "localhost");
62 
63 
64 protected:
67 
71  void commandSimulationStep(double time);
72 
73 
76  void commandClose();
77 
78 
81  void commandSetOrder(int order);
82 
83 
90  void commandGetVariable(int domID, int varID, const std::string& objID, tcpip::Storage* addData = 0);
91 
92 
99  void commandSetValue(int domID, int varID, const std::string& objID, std::ifstream& defFile);
100 
101 
110  void commandSubscribeObjectVariable(int domID, const std::string& objID, double beginTime, double endTime, int varNo, std::ifstream& defFile);
111 
112 
123  void commandSubscribeContextVariable(int domID, const std::string& objID, double beginTime, double endTime, int domain, double range, int varNo, std::ifstream& defFile);
125 
126 
127 
128 private:
131 
134  void writeResult();
135 
136 
140  void errorMsg(std::stringstream& msg);
142 
143 
144 
147 
153 
154 
161 
162 
163 
166 
174  int setValueTypeDependant(tcpip::Storage& into, std::ifstream& defFile, std::stringstream& msg);
175 
176 
181  void readAndReportTypeDependent(tcpip::Storage& inMsg, int valueDataType);
183 
184 
186  void testAPI();
187 
188 private:
190  std::string outputFileName;
191 
193  std::stringstream answerLog;
194 
195 };
196 
197 #endif
TraCITestClient::commandSimulationStep
void commandSimulationStep(double time)
Sends and validates a simulation step command.
Definition: TraCITestClient.cpp:177
TraCITestClient::outputFileName
std::string outputFileName
The name of the file to write the results log into.
Definition: TraCITestClient.h:190
TraCITestClient::~TraCITestClient
~TraCITestClient()
Destructor.
Definition: TraCITestClient.cpp:56
TraCITestClient::commandSubscribeObjectVariable
void commandSubscribeObjectVariable(int domID, const std::string &objID, double beginTime, double endTime, int varNo, std::ifstream &defFile)
Sends and validates a SubscribeVariable command.
Definition: TraCITestClient.cpp:281
TraCITestClient::run
int run(std::string fileName, int port, std::string host="localhost")
Runs a test.
Definition: TraCITestClient.cpp:62
TraCITestClient::writeResult
void writeResult()
Writes the results file.
Definition: TraCITestClient.cpp:332
TraCITestClient::commandSetValue
void commandSetValue(int domID, int varID, const std::string &objID, std::ifstream &defFile)
Sends and validates a SetVariable command.
Definition: TraCITestClient.cpp:257
TraCITestClient::commandSubscribeContextVariable
void commandSubscribeContextVariable(int domID, const std::string &objID, double beginTime, double endTime, int domain, double range, int varNo, std::ifstream &defFile)
Sends and validates a SubscribeContext command.
Definition: TraCITestClient.cpp:305
TraCIAPI
C++ TraCI client API implementation.
Definition: TraCIAPI.h:49
TraCIAPI.h
TraCITestClient::validateSimulationStep2
bool validateSimulationStep2(tcpip::Storage &inMsg)
Validates whether the given message is a valid answer to CMD_SIMSTEP.
Definition: TraCITestClient.cpp:359
TraCITestClient
A test execution class.
Definition: TraCITestClient.h:44
TraCITestClient::setValueTypeDependant
int setValueTypeDependant(tcpip::Storage &into, std::ifstream &defFile, std::stringstream &msg)
Parses the next value type / value pair from the stream and inserts it into the storage.
Definition: TraCITestClient.cpp:434
TraCITestClient::readAndReportTypeDependent
void readAndReportTypeDependent(tcpip::Storage &inMsg, int valueDataType)
Reads a value of the given type from the given storage and reports it.
Definition: TraCITestClient.cpp:565
TraCITestClient::commandSetOrder
void commandSetOrder(int order)
Sends and validates a SetOrder command.
Definition: TraCITestClient.cpp:208
TraCITestClient::commandClose
void commandClose()
Sends and validates a Close command.
Definition: TraCITestClient.cpp:193
socket.h
TraCITestClient::validateSubscription
bool validateSubscription(tcpip::Storage &inMsg)
Validates whether the given message is a valid subscription return message.
Definition: TraCITestClient.cpp:376
config.h
TraCITestClient::answerLog
std::stringstream answerLog
Stream containing the log.
Definition: TraCITestClient.h:193
TraCITestClient::testAPI
void testAPI()
call all API methods once
Definition: TraCITestClient.cpp:643
TraCITestClient::commandGetVariable
void commandGetVariable(int domID, int varID, const std::string &objID, tcpip::Storage *addData=0)
Sends and validates a GetVariable command.
Definition: TraCITestClient.cpp:223
tcpip::Storage
Definition: storage.h:38
TraCITestClient::TraCITestClient
TraCITestClient(std::string outputFileName="testclient_result.out")
Constructor.
Definition: TraCITestClient.cpp:48
TraCITestClient::errorMsg
void errorMsg(std::stringstream &msg)
Writes an error message.
Definition: TraCITestClient.cpp:348