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-sim.org/
13 // Copyright (C) 2001-2014 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 #include <string>
30 #include <sstream>
31 #include <vector>
32 
33 #include <foreign/tcpip/socket.h>
34 #include <utils/common/SUMOTime.h>
35 #include <utils/traci/TraCIAPI.h>
36 
37 
38 // ===========================================================================
39 // class definitions
40 // ===========================================================================
47 class TraCITestClient : public TraCIAPI {
48 public:
52  TraCITestClient(std::string outputFileName = "testclient_result.out");
53 
54 
57 
58 
64  bool run(std::string fileName, int port, std::string host = "localhost");
65 
66 
67 protected:
70 
75 
76 
79  void commandClose();
80 
81 
88  void commandGetVariable(int domID, int varID, const std::string& objID, tcpip::Storage* addData = 0);
89 
90 
97  void commandSetValue(int domID, int varID, const std::string& objID, std::ifstream& defFile);
98 
99 
108  void commandSubscribeObjectVariable(int domID, const std::string& objID, int beginTime, int endTime, int varNo, std::ifstream& defFile);
109 
110 
121  void commandSubscribeContextVariable(int domID, const std::string& objID, int beginTime, int endTime, int domain, SUMOReal range, int varNo, std::ifstream& defFile);
123 
124 
125 
126 private:
129 
132  void writeResult();
133 
134 
138  void errorMsg(std::stringstream& msg);
140 
141 
142 
145 
151 
152 
159 
160 
161 
164 
172  int setValueTypeDependant(tcpip::Storage& into, std::ifstream& defFile, std::stringstream& msg);
173 
174 
179  void readAndReportTypeDependent(tcpip::Storage& inMsg, int valueDataType);
181 
182 
183 private:
185  std::string outputFileName;
186 
188  std::stringstream answerLog;
189 
190 };
191 
192 #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:54
std::stringstream answerLog
Stream containing the log.
void commandSubscribeContextVariable(int domID, const std::string &objID, int beginTime, int endTime, int domain, SUMOReal range, int varNo, std::ifstream &defFile)
Sends and validates a SubscribeContext command.
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.
void commandSubscribeObjectVariable(int domID, const std::string &objID, int beginTime, int endTime, int varNo, std::ifstream &defFile)
Sends and validates a SubscribeVariable command.
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:215
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.