SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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-2016 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/common/SUMOTime.h>
41 #include <utils/traci/TraCIAPI.h>
42 
43 
44 // ===========================================================================
45 // class definitions
46 // ===========================================================================
53 class TraCITestClient : public TraCIAPI {
54 public:
58  TraCITestClient(std::string outputFileName = "testclient_result.out");
59 
60 
63 
64 
70  bool run(std::string fileName, int port, std::string host = "localhost");
71 
72 
73 protected:
76 
81 
82 
85  void commandClose();
86 
87 
94  void commandGetVariable(int domID, int varID, const std::string& objID, tcpip::Storage* addData = 0);
95 
96 
103  void commandSetValue(int domID, int varID, const std::string& objID, std::ifstream& defFile);
104 
105 
114  void commandSubscribeObjectVariable(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime, int varNo, std::ifstream& defFile);
115 
116 
127  void commandSubscribeContextVariable(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime, int domain, SUMOReal range, int varNo, std::ifstream& defFile);
129 
130 
131 
132 private:
135 
138  void writeResult();
139 
140 
144  void errorMsg(std::stringstream& msg);
146 
147 
148 
151 
157 
158 
165 
166 
167 
170 
178  int setValueTypeDependant(tcpip::Storage& into, std::ifstream& defFile, std::stringstream& msg);
179 
180 
185  void readAndReportTypeDependent(tcpip::Storage& inMsg, int valueDataType);
187 
188 
190  void testAPI();
191 
192 private:
194  std::string outputFileName;
195 
197  std::stringstream answerLog;
198 
199 };
200 
201 #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.
long long int SUMOTime
Definition: SUMOTime.h:43
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_SIMSTEP2.
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 commandClose()
Sends and validates a Close command.
#define SUMOReal
Definition: config.h:214
void commandSubscribeContextVariable(int domID, const std::string &objID, SUMOTime beginTime, SUMOTime endTime, int domain, SUMOReal range, int varNo, std::ifstream &defFile)
Sends and validates a SubscribeContext command.
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.