LCOV - code coverage report
Current view: top level - unittest/src/utils/common - FileHelpersTest.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 34 34
Test Date: 2024-10-24 15:46:30 Functions: 100.0 % 4 4

            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    FileHelpersTest.cpp
      15              : /// @author  Matthias Heppner
      16              : /// @author  Michael Behrisch
      17              : /// @date    2009
      18              : ///
      19              : // Tests FileHelpers class from <SUMO>/src/utils/common
      20              : /****************************************************************************/
      21              : 
      22              : // ===========================================================================
      23              : // included modules
      24              : // ===========================================================================
      25              : #include <config.h>
      26              : 
      27              : #include <gtest/gtest.h>
      28              : #include <utils/common/FileHelpers.h>
      29              : 
      30              : 
      31              : // ===========================================================================
      32              : // test definitions
      33              : // ===========================================================================
      34              : /* Tests the method checkForRelativity. Unify special filenames and make standard file paths relative to the config. */
      35            1 : TEST(FileHelpers, test_method_checkForRelativity) {
      36            2 :     EXPECT_EQ("stdout", FileHelpers::checkForRelativity("-", "")) << "Special filename '-' should be treated as stdout";
      37            2 :     EXPECT_EQ("/home/user/test.net.xml", FileHelpers::checkForRelativity("test.net.xml", "/home/user/test.sumocfg")) << "configuration path should be used.";
      38            2 :     EXPECT_EQ("/test.net.xml", FileHelpers::checkForRelativity("test.net.xml", "/test.sumocfg")) << "configuration path should be used.";
      39            1 : }
      40              : 
      41              : 
      42            1 : TEST(FileHelpers, test_method_getConfigurationRelative) {
      43            2 :     EXPECT_EQ("/home/user/test.net.xml", FileHelpers::getConfigurationRelative("/home/user/test.sumocfg", "test.net.xml")) << "configuration path should be used.";
      44            2 :     EXPECT_EQ("/test.net.xml", FileHelpers::getConfigurationRelative("/test.sumocfg", "test.net.xml")) << "configuration path should be used.";
      45            1 : }
      46              : 
      47              : 
      48            1 : TEST(FileHelpers, test_method_getFilePath) {
      49            2 :     EXPECT_EQ("/home/user/", FileHelpers::getFilePath("/home/user/test.sumocfg")) << "configuration path should be used.";
      50            2 :     EXPECT_EQ("/", FileHelpers::getFilePath("/test.sumocfg")) << "configuration path should be used.";
      51            1 : }
      52              : 
      53              : 
      54            1 : TEST(FileHelpers, test_method_fixRelative) {
      55            2 :     EXPECT_EQ("test.net.xml", FileHelpers::fixRelative("test.net.xml", "test.sumocfg", false, "/home/user")) << "no change for two filenames without paths.";
      56            2 :     EXPECT_EQ("test.net.xml", FileHelpers::fixRelative("test.net.xml", "test.sumocfg", true, "/home/user")) << "no change for two filenames without paths.";
      57            2 :     EXPECT_EQ("/home/user/test.net.xml", FileHelpers::fixRelative("/home/user/test.net.xml", "/home/user/test.sumocfg", false, "/home/user")) << "absolute path is kept without force.";
      58            2 :     EXPECT_EQ("test.net.xml", FileHelpers::fixRelative("/home/user/test.net.xml", "/home/user/test.sumocfg", true, "/home/user")) << "absolute path is removed with force.";
      59            2 :     EXPECT_EQ("test.net.xml", FileHelpers::fixRelative("user/test.net.xml", "user/test.sumocfg", false, "/home/user")) << "relative path is removed without force.";
      60            2 :     EXPECT_EQ("test.net.xml", FileHelpers::fixRelative("user/test.net.xml", "user/test.sumocfg", true, "/home/user")) << "relative path is removed with force.";
      61            2 :     EXPECT_EQ("subdir/test.net.xml", FileHelpers::fixRelative("subdir/test.net.xml", "test.sumocfg", false, "/home/user")) << "config without path means no change.";
      62            2 :     EXPECT_EQ("subdir/test.net.xml", FileHelpers::fixRelative("subdir/test.net.xml", "test.sumocfg", true, "/home/user")) << "config without path means no change.";
      63            2 :     EXPECT_EQ("user/subdir/test.net.xml", FileHelpers::fixRelative("subdir/test.net.xml", "../test.sumocfg", false, "/home/user")) << "config in parent dir makes path different.";
      64            2 :     EXPECT_EQ("user/subdir/test.net.xml", FileHelpers::fixRelative("subdir/test.net.xml", "../test.sumocfg", true, "/home/user")) << "config in parent dir makes path different.";
      65            2 :     EXPECT_EQ("/home/user/subdir/test.net.xml", FileHelpers::fixRelative("/home/user/subdir/test.net.xml", "../test.sumocfg", false, "/home/user")) << "config in parent dir does not change abs path without force.";
      66            2 :     EXPECT_EQ("user/subdir/test.net.xml", FileHelpers::fixRelative("/home/user/subdir/test.net.xml", "../test.sumocfg", true, "/home/user")) << "config in parent dir makes path different.";
      67            2 :     EXPECT_EQ("../../test.net.xml", FileHelpers::fixRelative("../test.net.xml", "subdir/test.sumocfg", false, "/home/user")) << "file in parent dir makes path different.";
      68            2 :     EXPECT_EQ("../../test.net.xml", FileHelpers::fixRelative("../test.net.xml", "subdir/test.sumocfg", true, "/home/user")) << "file in parent dir makes path different.";
      69            2 :     EXPECT_EQ("../../test.net.xml", FileHelpers::fixRelative("../test.net.xml", "/home/user/subdir/test.sumocfg", false, "/home/user")) << "file in parent dir makes path different.";
      70            2 :     EXPECT_EQ("../../test.net.xml", FileHelpers::fixRelative("../test.net.xml", "/home/user/subdir/test.sumocfg", true, "/home/user")) << "file in parent dir makes path different.";
      71            2 :     EXPECT_EQ("../../test.net.xml", FileHelpers::fixRelative("../../test.net.xml", "test.sumocfg", false, "/home/user")) << "file in parent dir with straight cfg should stay unchanged.";
      72            2 :     EXPECT_EQ("../../test.net.xml", FileHelpers::fixRelative("../../test.net.xml", "test.sumocfg", true, "/home/user")) << "file in parent dir with straight cfg should stay unchanged.";
      73            2 :     EXPECT_EQ("stdout", FileHelpers::fixRelative("stdout", "/home/sampledir", true, "/home")) << "check for reserved filenames.";
      74            1 : }
        

Generated by: LCOV version 2.0-1