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-2018 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 /****************************************************************************/
18 // A test execution class
19 /****************************************************************************/
20 #ifndef TRACITESTCLIENT_H
21 #define TRACITESTCLIENT_H
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <string>
29 #include <sstream>
30 #include <vector>
31 
32 #include <foreign/tcpip/socket.h>
33 #include <utils/traci/TraCIAPI.h>
34 
35 
36 // ===========================================================================
37 // class definitions
38 // ===========================================================================
45 class TraCITestClient : public TraCIAPI {
46 public:
50  TraCITestClient(std::string outputFileName = "testclient_result.out");
51 
52 
55 
56 
62  int run(std::string fileName, int port, std::string host = "localhost");
63 
64 
65 protected:
68 
72  void commandSimulationStep(double time);
73 
74 
77  void commandClose();
78 
79 
82  void commandSetOrder(int order);
83 
84 
91  void commandGetVariable(int domID, int varID, const std::string& objID, tcpip::Storage* addData = 0);
92 
93 
100  void commandSetValue(int domID, int varID, const std::string& objID, std::ifstream& defFile);
101 
102 
111  void commandSubscribeObjectVariable(int domID, const std::string& objID, double beginTime, double endTime, int varNo, std::ifstream& defFile);
112 
113 
124  void commandSubscribeContextVariable(int domID, const std::string& objID, double beginTime, double endTime, int domain, double range, int varNo, std::ifstream& defFile);
126 
127 
128 
129 private:
132 
135  void writeResult();
136 
137 
141  void errorMsg(std::stringstream& msg);
143 
144 
145 
148 
154 
155 
162 
163 
164 
167 
175  int setValueTypeDependant(tcpip::Storage& into, std::ifstream& defFile, std::stringstream& msg);
176 
177 
182  void readAndReportTypeDependent(tcpip::Storage& inMsg, int valueDataType);
184 
185 
187  void testAPI();
188 
189 private:
191  std::string outputFileName;
192 
194  std::stringstream answerLog;
195 
196 };
197 
198 #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:52
void commandSubscribeObjectVariable(int domID, const std::string &objID, double beginTime, double endTime, int varNo, std::ifstream &defFile)
Sends and validates a SubscribeVariable command.
void commandSetOrder(int order)
Sends and validates a SetOrder command.
std::stringstream answerLog
Stream containing the log.
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 commandSimulationStep(double time)
Sends and validates a simulation step 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, double beginTime, double endTime, int domain, double range, int varNo, std::ifstream &defFile)
Sends and validates a SubscribeContext command.
void commandClose()
Sends and validates a Close command.
void commandGetVariable(int domID, int varID, const std::string &objID, tcpip::Storage *addData=0)
Sends and validates a GetVariable command.
~TraCITestClient()
Destructor.