mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
use ctest for testing and set testing environment for using test data
This commit is contained in:
parent
113e6c8229
commit
219da51823
|
@ -22,7 +22,8 @@ You should add `-DTIFF_SAPI_ENABLE_EXAMPLES=ON` to use the example and run:
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Tests:
|
#### Tests:
|
||||||
You should add `-DTIFF_SAPI_ENABLE_TESTS=ON` to use tests and run:
|
You should add `-DTIFF_SAPI_ENABLE_TESTS=ON` to use tests and do:
|
||||||
```
|
```
|
||||||
./test/tests
|
cd test
|
||||||
|
ctest .
|
||||||
```
|
```
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
include(GoogleTest)
|
include(GoogleTest)
|
||||||
|
enable_testing()
|
||||||
|
|
||||||
add_executable(tests
|
add_executable(tests
|
||||||
../test/data.h
|
../test/data.h
|
||||||
|
@ -35,4 +36,4 @@ target_link_libraries(tests PRIVATE
|
||||||
tiff_sapi
|
tiff_sapi
|
||||||
)
|
)
|
||||||
|
|
||||||
gtest_discover_tests(tests)
|
gtest_discover_tests(tests PROPERTIES ENVIRONMENT "TEST_SRCDIR=${PROJECT_SOURCE_DIR}")
|
||||||
|
|
|
@ -15,24 +15,13 @@
|
||||||
#include "helper.h" // NOLINT(build/include)
|
#include "helper.h" // NOLINT(build/include)
|
||||||
|
|
||||||
#include "../sandboxed.h" // NOLINT(build/include)
|
#include "../sandboxed.h" // NOLINT(build/include)
|
||||||
#include "sandboxed_api/sandbox2/util/fileops.h"
|
|
||||||
#include "sandboxed_api/sandbox2/util/path.h"
|
#include "sandboxed_api/sandbox2/util/path.h"
|
||||||
|
|
||||||
|
std::string GetSourcePath() { return getenv("TEST_SRCDIR"); }
|
||||||
|
|
||||||
std::string GetFilePath(absl::string_view filename) {
|
std::string GetFilePath(absl::string_view filename) {
|
||||||
std::string cwd = sandbox2::file_util::fileops::GetCWD();
|
std::string src = GetSourcePath();
|
||||||
auto find = cwd.rfind("/build");
|
return GetFilePath(GetSourcePath(), filename);
|
||||||
if (find == std::string::npos) {
|
|
||||||
LOG(ERROR)
|
|
||||||
<< "Something went wrong: CWD don't contain build dir. Please run "
|
|
||||||
"tests from build dir. To run example send project dir as a "
|
|
||||||
"parameter: ./sandboxed /absolute/path/to/project/dir .\n"
|
|
||||||
"Falling back to using current working directory as root dir.\n";
|
|
||||||
|
|
||||||
return sandbox2::file::JoinPath(cwd, "test", "images");
|
|
||||||
}
|
|
||||||
|
|
||||||
return sandbox2::file::JoinPath(cwd.substr(0, find), "test", "images",
|
|
||||||
filename);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetFilePath(absl::string_view dir, absl::string_view filename) {
|
std::string GetFilePath(absl::string_view dir, absl::string_view filename) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user