Skip to content

Commit 3cf11d9

Browse files
committed
Added some Basic UnitTest for biogears-common::path
1 parent fb9f230 commit 3cf11d9

File tree

1 file changed

+153
-0
lines changed

1 file changed

+153
-0
lines changed
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
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/filesystem/path.h>
24+
25+
#ifdef DISABLE_BIOGEARS_Path_TEST
26+
#define TEST_FIXTURE_NAME DISABLED_PathFixture
27+
#else
28+
#define TEST_FIXTURE_NAME PathFixture
29+
#endif
30+
31+
// The fixture for testing class Foo.
32+
class TEST_FIXTURE_NAME : public ::testing::Test {
33+
protected:
34+
// You can do set-up work for each test here.
35+
TEST_FIXTURE_NAME() = default;
36+
37+
// You can do clean-up work that doesn't throw exceptions here.
38+
virtual ~TEST_FIXTURE_NAME() = default;
39+
40+
// If the constructor and destructor are not enough for setting up
41+
// and cleaning up each test, you can define the following methods:
42+
43+
// Code here will be called immediately after the constructor (right
44+
// before each test).
45+
virtual void SetUp();
46+
47+
// Code here will be called immediately after each test (right
48+
// before the destructor).
49+
virtual void TearDown();
50+
51+
biogears::filesystem::path path_empty;
52+
biogears::filesystem::path path_relative;
53+
biogears::filesystem::path path_absolute_root;
54+
};
55+
56+
void TEST_FIXTURE_NAME::SetUp()
57+
{
58+
using namespace biogears::filesystem;
59+
path_empty = path{ "" };
60+
path_relative = path{ "./" };
61+
#ifdef _WIN32
62+
path_absolute_root = path{ "c:/" };
63+
#else
64+
path_absolute_root = path{ "/" };
65+
#endif
66+
}
67+
68+
void TEST_FIXTURE_NAME::TearDown()
69+
{
70+
}
71+
72+
TEST_F(TEST_FIXTURE_NAME, Path_Constructor)
73+
{
74+
using namespace biogears::filesystem;
75+
76+
path path_1{ "" };
77+
path path_2{ "./" };
78+
path path_3{ "/" };
79+
path path_4{ "c:/" };
80+
}
81+
82+
TEST_F(TEST_FIXTURE_NAME, Path_Empty)
83+
{
84+
using namespace biogears::filesystem;
85+
86+
EXPECT_TRUE(path_empty.empty());
87+
EXPECT_FALSE(path_relative.empty());
88+
EXPECT_FALSE(path_absolute_root.empty());
89+
}
90+
91+
TEST_F(TEST_FIXTURE_NAME, Path_Concatination)
92+
{
93+
using namespace biogears::filesystem;
94+
95+
#ifdef _WIN32
96+
auto empty_absolute = path_empty / path("c:\\biogears");
97+
#else
98+
auto empty_absolute = path_empty / path("biogears");
99+
#endif
100+
auto empty_relative = path_empty / path("biogears");
101+
102+
path_relative /= path("biogears");
103+
path_absolute_root /= path("biogears");
104+
105+
EXPECT_NE(empty_relative, path_relative);
106+
EXPECT_EQ(empty_relative.make_normal(), path_relative.make_normal());
107+
108+
EXPECT_EQ(empty_absolute, path_absolute_root);
109+
}
110+
111+
TEST_F(TEST_FIXTURE_NAME, Path_Normalize)
112+
{
113+
using namespace biogears::filesystem;
114+
115+
auto cwd = path::getcwd();
116+
path_relative /= path("biogears") / "runtime" / path("..") / path("..");
117+
cwd /= path("biogears") / "runtime" / path("..") / path("..");
118+
auto absolute_root = path_absolute_root / path("biogears") / "runtime" / path("..") / path("..");
119+
120+
cwd = cwd.make_normal();
121+
path_relative = path_relative.make_normal();
122+
123+
EXPECT_EQ(cwd, path::getcwd());
124+
EXPECT_EQ(path_relative, path());
125+
EXPECT_EQ(absolute_root.make_normal(),path_absolute_root);
126+
EXPECT_EQ(path("./././../../biogears/././../first/second/../third/../../").make_normal(),
127+
path("").make_normal());
128+
}
129+
130+
TEST_F(TEST_FIXTURE_NAME, Path_Absolute)
131+
{
132+
using namespace biogears::filesystem;
133+
134+
135+
EXPECT_TRUE(path_absolute_root.is_absolute());
136+
EXPECT_FALSE(path_relative.is_absolute());
137+
EXPECT_FALSE(path_empty.is_absolute());
138+
}
139+
140+
141+
TEST_F(TEST_FIXTURE_NAME, Path_IsDirectory)
142+
{
143+
using namespace biogears::filesystem;
144+
145+
146+
EXPECT_TRUE(path_absolute_root.is_directory());
147+
EXPECT_TRUE(path_relative.is_directory());
148+
EXPECT_FALSE(path_empty.is_directory());
149+
150+
path_absolute_root /= "test.txt";
151+
152+
EXPECT_FALSE(path_absolute_root.is_directory());
153+
}

0 commit comments

Comments
 (0)