Gazebo Common
API Reference
7.4.0
insert_drive_file
Tutorials
library_books
Classes
toc
Namespaces
insert_drive_file
Files
launch
Gazebo Website
Index
List
Hierarchy
Members: All
Members: Functions
Members: Variables
Members: Typedefs
Members: Enumerations
Members: Enumerator
List
Members
Functions
Typedefs
Variables
Enumerations
Enumerator
src
gz-common
testing
include
gz
common
testing
TestPaths.hh
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2022 Open Source Robotics Foundation
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*
16
*/
17
#ifndef GZ_COMMON_TESTING_TESTPATHS_HH_
18
#define GZ_COMMON_TESTING_TESTPATHS_HH_
19
20
#include <memory>
21
#include <string>
22
23
#include "
gz/common/Filesystem.hh
"
24
#include "
gz/common/TempDirectory.hh
"
25
#include "
gz/common/Util.hh
"
26
27
#include "gz/common/testing/Export.hh"
28
29
#include <gz/utils/SuppressWarning.hh>
30
31
#ifndef TESTING_PROJECT_SOURCE_DIR
32
#define TESTING_PROJECT_SOURCE_DIR ""
33
#endif
34
35
namespace
gz::common::testing
36
{
37
47
constexpr
char
kTestingProjectSourceDir
[] =
TESTING_PROJECT_SOURCE_DIR
;
48
51
enum class
BuildType
52
{
53
kUnknown
,
54
kCMake
,
55
kBazel
56
};
57
64
class
GZ_COMMON_TESTING_VISIBLE
TestPaths
65
{
68
public
:
explicit
TestPaths
(
69
const
std::string
&_projectSourcePath = kTestingProjectSourceDir);
70
72
public
:
virtual
~TestPaths
();
73
77
public
:
virtual
bool
ProjectSourcePath
(
std::string
&_sourceDir) = 0;
78
82
public
:
virtual
bool
TestTmpPath
(
std::string
&_tmpDir) = 0;
83
84
GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
86
protected
:
std::string
projectSourcePath
;
87
GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
88
};
89
101
std::shared_ptr<gz::common::TempDirectory>
102
GZ_COMMON_TESTING_VISIBLE
103
MakeTestTempDirectoryImpl
(
const
std::string
&_projectSourcePath,
104
const
std::string
&_prefix =
"test"
,
105
const
std::string
&_subDir =
"gz"
,
106
bool
_cleanup =
true
);
107
108
120
inline
std::shared_ptr<gz::common::TempDirectory>
121
MakeTestTempDirectory
(
const
std::string
&_prefix =
"test"
,
122
const
std::string
&_subDir =
"gz"
,
123
bool
_cleanup =
true
)
124
{
125
return
MakeTestTempDirectoryImpl
(
kTestingProjectSourceDir
,
126
_prefix,
127
_subDir,
128
_cleanup);
129
}
130
136
BuildType
137
GZ_COMMON_TESTING_VISIBLE
138
TestBuildType
(
139
const
std::string
&_projectSourcePath = kTestingProjectSourceDir);
140
146
std::unique_ptr<TestPaths>
147
GZ_COMMON_TESTING_VISIBLE
148
TestPathFactory
(
149
const
std::string
&_projectSourcePath = kTestingProjectSourceDir);
150
159
template
<
typename
... Args>
160
std::string
SourceFile
(Args
const
&... args)
161
{
162
auto
testPaths =
TestPathFactory
(
kTestingProjectSourceDir
);
163
assert(
nullptr
!= testPaths);
164
165
std::string
dataDir;
166
testPaths->ProjectSourcePath(dataDir);
167
return
common::joinPaths(dataDir, args...);
168
}
169
178
template
<
typename
... Args>
179
std::string
TestFile
(Args
const
&... args)
180
{
181
return
SourceFile
(
"test"
, args...);
182
}
183
192
template
<
typename
... Args>
193
std::string
TempPath
(Args
const
&... args)
194
{
195
auto
testPaths =
TestPathFactory
(
kTestingProjectSourceDir
);
196
assert(
nullptr
!= testPaths);
197
198
std::string
dataDir;
199
testPaths->TestTmpPath(dataDir);
200
return
common::joinPaths(dataDir, args...);
201
}
202
}
// namespace gz::common::testing
203
#endif
// GZ_COMMON_TESTING_TESTPATHS_HH_