SUMO - Simulation of Urban MObility
TraCITestClient.h
Go to the documentation of this file.
1 /****************************************************************************/
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 #ifndef TRACITESTCLIENT_H
24 #define TRACITESTCLIENT_H
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <string>
36 #include <sstream>
37 #include <vector>
38 
39 #include <foreign/tcpip/socket.h>
40 #include <utils/traci/TraCIAPI.h>
41 
42 
43 // ===========================================================================
44 // class definitions
45 // ===========================================================================
52 class TraCITestClient : public TraCIAPI {
53 public:
57  TraCITestClient(std::string outputFileName = "testclient_result.out");
58 
59 
62 
63 
69  bool run(std::string fileName, int port, std::string host = "localhost");
70 
71 
72 protected:
75 
80 
81 
84  void commandClose();
85 
86 
93  void commandGetVariable(int domID, int varID, const std::string& objID, tcpip::Storage* addData = 0);
94 
95 
102  void commandSetValue(int domID, int varID, const std::string& objID, std::ifstream& defFile);
103 
104 
113  void commandSubscribeObjectVariable(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime, int varNo, std::ifstream& defFile);
114 
115 
126  void commandSubscribeContextVariable(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime, int domain, double range, int varNo, std::ifstream& defFile);
128 
129 
130 
131 private:
134 
137  void writeResult();
138 
139 
143  void errorMsg(std::stringstream& msg);
145 
146 
147 
150 
156 
157 
164 
165 
166 
169 
177  int setValueTypeDependant(tcpip::Storage& into, std::ifstream& defFile, std::stringstream& msg);
178 
179 
184  void readAndReportTypeDependent(tcpip::Storage& inMsg, int valueDataType);
186 
187 
189  void testAPI();
190 
191 private:
193  std::string outputFileName;
194 
196  std::stringstream answerLog;
197 
198 };
199 
200 #endif
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:63
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.
bool run(std::string fileName, int port, std::string host="localhost")
Runs a test.
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:52
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.