|
| 1 | +//------------------------------------------------------------------------------------------- |
| 2 | +//- Copyright 2017 Applied Research Associates, Inc. |
| 3 | +//- Licensed under the Apache License, Version 2.0 (the "License"); you may not use |
| 4 | +//- this file except in compliance with the License. You may obtain a copy of the License |
| 5 | +//- at: |
| 6 | +//- http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +//- Unless required by applicable law or agreed to in writing, software distributed under |
| 8 | +//- the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 9 | +//- CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 10 | +//- specific language governing permissions and limitations under the License. |
| 11 | +//------------------------------------------------------------------------------------------- |
| 12 | + |
| 13 | +//! |
| 14 | +//! @author David Lee |
| 15 | +//! @date 2017 Aug 3rd |
| 16 | +//! |
| 17 | +//! Unit Test for NGSS Config |
| 18 | +//! |
| 19 | +#include <thread> |
| 20 | + |
| 21 | +#include <gtest/gtest.h> |
| 22 | + |
| 23 | +#include <biogears/cdm/utils/FileUtils.h> |
| 24 | +#include <biogears/filesystem/path.h> |
| 25 | + |
| 26 | +#ifdef DISABLE_BIOGEARS_FileUtils_TEST |
| 27 | +#define TEST_FIXTURE_NAME DISABLED_FileUtilsFixture |
| 28 | +#else |
| 29 | +#define TEST_FIXTURE_NAME FileUtilsFixture |
| 30 | +#endif |
| 31 | + |
| 32 | +// The fixture for testing class Foo. |
| 33 | +class TEST_FIXTURE_NAME : public ::testing::Test { |
| 34 | +protected: |
| 35 | + // You can do set-up work for each test here. |
| 36 | + TEST_FIXTURE_NAME() = default; |
| 37 | + |
| 38 | + // You can do clean-up work that doesn't throw exceptions here. |
| 39 | + virtual ~TEST_FIXTURE_NAME() = default; |
| 40 | + |
| 41 | + // If the constructor and destructor are not enough for setting up |
| 42 | + // and cleaning up each test, you can define the following methods: |
| 43 | + |
| 44 | + // Code here will be called immediately after the constructor (right |
| 45 | + // before each test). |
| 46 | + virtual void SetUp(); |
| 47 | + |
| 48 | + // Code here will be called immediately after each test (right |
| 49 | + // before the destructor). |
| 50 | + virtual void TearDown(); |
| 51 | +}; |
| 52 | + |
| 53 | +void TEST_FIXTURE_NAME::SetUp() |
| 54 | +{ |
| 55 | +} |
| 56 | + |
| 57 | +void TEST_FIXTURE_NAME::TearDown() |
| 58 | +{ |
| 59 | + biogears::SetCurrentWorkingDirectory(""); |
| 60 | +} |
| 61 | + |
| 62 | +TEST_F(TEST_FIXTURE_NAME, FileUtils_CWD_Change) |
| 63 | +{ |
| 64 | + using namespace biogears; |
| 65 | + EXPECT_EQ("", biogears::GetCurrentWorkingDirectory()); |
| 66 | +#ifdef _WIN32 |
| 67 | + biogears::SetCurrentWorkingDirectory("C:/"); |
| 68 | + EXPECT_EQ("C:/", biogears::GetCurrentWorkingDirectory()); |
| 69 | +#else |
| 70 | + SetCurrentWorkingDirectory("/opt/biogears"); |
| 71 | + EXPECT_EQ("/opt/biogears", biogears::GetCurrentWorkingDirectory()); |
| 72 | +#endif |
| 73 | +} |
| 74 | + |
| 75 | +TEST_F(TEST_FIXTURE_NAME, FileUtils_ResolvePath) |
| 76 | +{ |
| 77 | + using namespace biogears; |
| 78 | + using namespace biogears::filesystem; |
| 79 | + biogears::SetCurrentWorkingDirectory(""); |
| 80 | + EXPECT_EQ(path::getcwd() / "test_file.txt", ResolvePath("test_file.txt")); |
| 81 | + EXPECT_EQ(path::getcwd() / "test_file.txt", ResolvePath("./test_file.txt")); |
| 82 | + EXPECT_EQ(path("C:/biogears/test_file.txt").make_normal(), ResolvePath("C:/biogears/test_file.txt")); |
| 83 | + |
| 84 | +#ifdef _WIN32 |
| 85 | + biogears::SetCurrentWorkingDirectory("C:/"); |
| 86 | + EXPECT_EQ(path("C:/test_file.txt").make_normal(), ResolvePath("test_file.txt")); |
| 87 | + EXPECT_EQ(path("C:/test_file.txt").make_normal(), ResolvePath("./test_file.txt")); |
| 88 | + EXPECT_EQ(path("C:/biogears/test_file.txt").make_normal(), ResolvePath("C:/biogears/test_file.txt")); |
| 89 | +#else |
| 90 | + SetCurrentWorkingDirectory("/opt/biogears"); |
| 91 | + EXPECT_EQ(path("/opt/biogears/test_file.txt").make_normal(), ResolvePath("test_file.txt")); |
| 92 | + EXPECT_EQ(path("/opt/biogears/test_file.txt").make_normal(), ResolvePath("./test_file.txt")); |
| 93 | + EXPECT_EQ(path("/opt/biogears/biogears/test_file.txt").make_normal(), ResolvePath("/opt/biogears/biogears/test_file.txt")); |
| 94 | +#endif |
| 95 | + |
| 96 | + auto cwd = path::getcwd().parent_path(); |
| 97 | + biogears::SetCurrentWorkingDirectory(".."); |
| 98 | + EXPECT_EQ((cwd/"test_file.txt").make_normal(), ResolvePath("test_file.txt")); |
| 99 | + EXPECT_EQ((cwd/"test_file.txt").make_normal(), ResolvePath("./test_file.txt")); |
| 100 | +#ifdef _WIN32 |
| 101 | + EXPECT_EQ(path("C:/biogears/test_file.txt").make_normal(), ResolvePath("C:\\biogears\\test_file.txt")); |
| 102 | +#else |
| 103 | + EXPECT_EQ(path("/opt/biogears/test_file.txt").make_normal(), ResolvePath("/opt/biogears/test_file.txt")); |
| 104 | +#endif |
| 105 | +} |
0 commit comments