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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
20 // A test execution class
21 /****************************************************************************/
22 #ifndef TRACITESTCLIENT_H
23 #define TRACITESTCLIENT_H
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <string>
35 #include <sstream>
36 #include <vector>
37 
38 #include <foreign/tcpip/socket.h>
39 #include <utils/traci/TraCIAPI.h>
40 
41 
42 // ===========================================================================
43 // class definitions
44 // ===========================================================================
51 class TraCITestClient : public TraCIAPI {
52 public:
56  TraCITestClient(std::string outputFileName = "testclient_result.out");
57 
58 
61 
62 
68  int run(std::string fileName, int port, std::string host = "localhost");
69 
70 
71 protected:
74 
79 
80 
83  void commandClose();
84 
85 
88  void commandSetOrder(int order);
89 
90 
97  void commandGetVariable(int domID, int varID, const std::string& objID, tcpip::Storage* addData = 0);
98 
99 
106  void commandSetValue(int domID, int varID, const std::string& objID, std::ifstream& defFile);
107 
108 
117  void commandSubscribeObjectVariable(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime, int varNo, std::ifstream& defFile);
118 
119 
130  void commandSubscribeContextVariable(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime, int domain, double range, int varNo, std::ifstream& defFile);
132 
133 
134 
135 private:
138 
141  void writeResult();
142 
143 
147  void errorMsg(std::stringstream& msg);
149 
150 
151 
154 
160 
161 
168 
169 
170 
173 
181  int setValueTypeDependant(tcpip::Storage& into, std::ifstream& defFile, std::stringstream& msg);
182 
183 
188  void readAndReportTypeDependent(tcpip::Storage& inMsg, int valueDataType);
190 
191 
193  void testAPI();
194 
195 private:
197  std::string outputFileName;
198 
200  std::stringstream answerLog;
201 
202 };
203 
204 #endif
int run(std::string fileName, int port, std::string host="localhost")
Runs a test.
A test execution class.
void readAndReportTypeDependent(tcpip::Storage &inMsg, int valueDataType)
Reads a value of the given type from the given storage and reports it.
C++ TraCI client API implementation.
Definition: TraCIAPI.h:58
void commandSetOrder(int order)
Sends and validates a SetOrder command.
std::stringstream answerLog
Stream containing the log.
void commandSubscribeObjectVariable(int domID, const std::string &objID, SUMOTime beginTime, SUMOTime endTime, int varNo, std::ifstream &defFile)
Sends and validates a SubscribeVariable command.
void testAPI()
call all API methods once
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.
bool validateSubscription(tcpip::Storage &inMsg)
Validates whether the given message is a valid subscription return message.
std::string outputFileName
The name of the file to write the results log into.
bool validateSimulationStep2(tcpip::Storage &inMsg)
Validates whether the given message is a valid answer to CMD_SIMSTEP.
void commandSetValue(int domID, int varID, const std::string &objID, std::ifstream &defFile)
Sends and validates a SetVariable command.
void writeResult()
Writes the results file.
TraCITestClient(std::string outputFileName="testclient_result.out")
Constructor.
void errorMsg(std::stringstream &msg)
Writes an error message.
void commandSubscribeContextVariable(int domID, const std::string &objID, SUMOTime beginTime, SUMOTime endTime, int domain, double range, int varNo, std::ifstream &defFile)
Sends and validates a SubscribeContext command.
void commandClose()
Sends and validates a Close command.
long long int SUMOTime
Definition: TraCIDefs.h:51
void commandGetVariable(int domID, int varID, const std::string &objID, tcpip::Storage *addData=0)
Sends and validates a GetVariable command.
void commandSimulationStep(SUMOTime time)
Sends and validates a simulation step command.
~TraCITestClient()
Destructor.