use ctest for testing and set testing environment for using test data

pull/56/head
Alexandra Latysheva 2020-10-30 14:34:33 +00:00
parent 113e6c8229
commit 219da51823
3 changed files with 9 additions and 18 deletions

View File

@ -22,7 +22,8 @@ You should add `-DTIFF_SAPI_ENABLE_EXAMPLES=ON` to use the example and run:
```
#### 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 .
```

View File

@ -13,6 +13,7 @@
# limitations under the License.
include(GoogleTest)
enable_testing()
add_executable(tests
../test/data.h
@ -35,4 +36,4 @@ target_link_libraries(tests PRIVATE
tiff_sapi
)
gtest_discover_tests(tests)
gtest_discover_tests(tests PROPERTIES ENVIRONMENT "TEST_SRCDIR=${PROJECT_SOURCE_DIR}")

View File

@ -15,24 +15,13 @@
#include "helper.h" // NOLINT(build/include)
#include "../sandboxed.h" // NOLINT(build/include)
#include "sandboxed_api/sandbox2/util/fileops.h"
#include "sandboxed_api/sandbox2/util/path.h"
std::string GetSourcePath() { return getenv("TEST_SRCDIR"); }
std::string GetFilePath(absl::string_view filename) {
std::string cwd = sandbox2::file_util::fileops::GetCWD();
auto find = cwd.rfind("/build");
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 src = GetSourcePath();
return GetFilePath(GetSourcePath(), filename);
}
std::string GetFilePath(absl::string_view dir, absl::string_view filename) {