Gazebo Common

API Reference

6.0.0
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
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
35namespace gz::common::testing
36{
37
48
51enum class GZ_COMMON_TESTING_VISIBLE BuildType
52{
55 kBazel
56};
57
64class 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
84GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
87GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
88};
89
102GZ_COMMON_TESTING_VISIBLE
103MakeTestTempDirectoryImpl(const std::string &_projectSourcePath,
104 const std::string &_prefix = "test",
105 const std::string &_subDir = "gz",
106 bool _cleanup = true);
107
108
121MakeTestTempDirectory(const std::string &_prefix = "test",
122 const std::string &_subDir = "gz",
123 bool _cleanup = true)
124{
126 _prefix,
127 _subDir,
128 _cleanup);
129}
130
136BuildType
137GZ_COMMON_TESTING_VISIBLE
139 const std::string &_projectSourcePath = kTestingProjectSourceDir);
140
147GZ_COMMON_TESTING_VISIBLE
149 const std::string &_projectSourcePath = kTestingProjectSourceDir);
150
159template <typename... Args>
160std::string SourceFile(Args const &... args)
161{
163 assert(nullptr != testPaths);
164
165 std::string dataDir;
166 testPaths->ProjectSourcePath(dataDir);
167 return common::joinPaths(dataDir, args...);
168}
169
178template <typename... Args>
179std::string TestFile(Args const &... args)
180{
181 return SourceFile("test", args...);
182}
183
192template <typename... Args>
193std::string TempPath(Args const &... args)
194{
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_