LCOV - code coverage report
Current view: top level - src/traci_testclient - tracitestclient_main.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 79.3 % 29 23
Test Date: 2024-11-21 15:56:26 Functions: 100.0 % 1 1

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
       4              : // This program and the accompanying materials are made available under the
       5              : // terms of the Eclipse Public License 2.0 which is available at
       6              : // https://www.eclipse.org/legal/epl-2.0/
       7              : // This Source Code may also be made available under the following Secondary
       8              : // Licenses when the conditions for such availability set forth in the Eclipse
       9              : // Public License 2.0 are satisfied: GNU General Public License, version 2
      10              : // or later which is available at
      11              : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
      12              : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
      13              : /****************************************************************************/
      14              : /// @file    tracitestclient_main.cpp
      15              : /// @author  Friedemann Wesner
      16              : /// @author  Axel Wegener
      17              : /// @author  Michael Behrisch
      18              : /// @author  Daniel Krajzewicz
      19              : /// @date    2008/04/07
      20              : ///
      21              : // Main method for TraCITestClient
      22              : /****************************************************************************/
      23              : #include <config.h>
      24              : 
      25              : #include <iostream>
      26              : #include <string>
      27              : #include <cstdlib>
      28              : #include "TraCITestClient.h"
      29              : 
      30              : 
      31              : // ===========================================================================
      32              : // method definitions
      33              : // ===========================================================================
      34         1218 : int main(int argc, char* argv[]) {
      35         1218 :     std::string defFile = "";
      36         1218 :     std::string outFileName = "testclient_out.txt";
      37              :     int port = -1;
      38         1218 :     std::string host = "localhost";
      39              : 
      40         1218 :     if ((argc == 1) || (argc % 2 == 0)) {
      41              :         std::cout << "Usage: TraCITestClient -def <definition_file>  -p <remote port>"
      42              :                   << "[-h <remote host>] [-o <outputfile name>]" << std::endl;
      43              :         return 0;
      44              :     }
      45              : 
      46         4872 :     for (int i = 1; i < argc; i++) {
      47         3654 :         std::string arg = argv[i];
      48         3654 :         if (arg.compare("-def") == 0) {
      49         1218 :             defFile = argv[i + 1];
      50         1218 :             i++;
      51         2436 :         } else if (arg.compare("-o") == 0) {
      52         1218 :             outFileName = argv[i + 1];
      53         1218 :             i++;
      54         1218 :         } else if (arg.compare("-p") == 0) {
      55         1218 :             port = atoi(argv[i + 1]);
      56         1218 :             i++;
      57            0 :         } else if (arg.compare("-h") == 0) {
      58            0 :             host = argv[i + 1];
      59            0 :             i++;
      60              :         } else {
      61            0 :             std::cerr << "unknown parameter: " << argv[i] << std::endl;
      62              :             return 1;
      63              :         }
      64              :     }
      65              : 
      66         1218 :     if (port == -1) {
      67              :         std::cerr << "Missing port" << std::endl;
      68              :         return 1;
      69              :     }
      70         1218 :     if (defFile.compare("") == 0) {
      71              :         std::cerr << "Missing definition file" << std::endl;
      72              :         return 1;
      73              :     }
      74              : 
      75              :     try {
      76         2436 :         TraCITestClient client(outFileName);
      77         2436 :         return client.run(defFile, port, host);
      78         1219 :     } catch (tcpip::SocketException& e) {
      79            1 :         std::cerr << "Socket error running the test client: " << e.what();
      80              :         return 1;
      81            1 :     } catch (libsumo::TraCIException& e) {
      82            0 :         std::cerr << "TraCI error running the test client: " << e.what();
      83              :         return 1;
      84            0 :     }
      85              : }
        

Generated by: LCOV version 2.0-1