mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
Moved test data to paths to environment variables
Added environment variables to remove relative paths from the code
This commit is contained in:
parent
5711a66d77
commit
5159b67d7d
|
@ -12,7 +12,7 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 3.10)
|
cmake_minimum_required(VERSION 3.12)
|
||||||
|
|
||||||
project(GDALSandbox CXX C)
|
project(GDALSandbox CXX C)
|
||||||
|
|
||||||
|
@ -95,6 +95,7 @@ target_link_libraries(utils PUBLIC
|
||||||
sandbox2::temp_file
|
sandbox2::temp_file
|
||||||
sandbox2::fileops
|
sandbox2::fileops
|
||||||
sandbox2::util
|
sandbox2::util
|
||||||
|
sandbox2::file_base
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(gtiff_converter STATIC
|
add_library(gtiff_converter STATIC
|
||||||
|
@ -118,15 +119,23 @@ target_link_libraries(raster_to_gtiff
|
||||||
)
|
)
|
||||||
|
|
||||||
if (ENABLE_TESTS)
|
if (ENABLE_TESTS)
|
||||||
find_package(GTest REQUIRED)
|
include(GoogleTest)
|
||||||
include_directories(${GTEST_INCLUDE_DIRS})
|
enable_testing()
|
||||||
|
|
||||||
add_executable(tests tests.cc)
|
add_executable(tests tests.cc)
|
||||||
target_link_libraries(tests PRIVATE
|
target_link_libraries(tests PRIVATE
|
||||||
data_retriever
|
data_retriever
|
||||||
gtiff_converter
|
gtiff_converter
|
||||||
utils
|
utils
|
||||||
${GTEST_LIBRARIES}
|
gtest
|
||||||
${GTEST_MAIN_LIBRARIES}
|
gtest_main
|
||||||
|
sandbox2::testing
|
||||||
|
sandbox2::file_base
|
||||||
)
|
)
|
||||||
|
|
||||||
|
gtest_discover_tests(tests PROPERTIES
|
||||||
|
ENVIRONMENT "TEST_TMPDIR=/tmp/"
|
||||||
|
ENVIRONMENT "TEST_SRCDIR=${PROJECT_SOURCE_DIR}"
|
||||||
|
)
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -91,6 +91,11 @@ You can run it in the following way:
|
||||||
```
|
```
|
||||||
After that, you can compare both files using the `gdalinfo` utility.
|
After that, you can compare both files using the `gdalinfo` utility.
|
||||||
Also, there are unit tests that automatically convert a few files and then compare input and output raster data to make sure that they are equal.
|
Also, there are unit tests that automatically convert a few files and then compare input and output raster data to make sure that they are equal.
|
||||||
To run tests your CMake build must use `-DENABLE_TESTS=ON`, then you can run tests using `./tests`.
|
To run tests your CMake build must use `-DENABLE_TESTS=ON`, then you can run tests using `ctest`.
|
||||||
|
Note that it will also run Sandboxed API related tests. To run tests manually you will need to specify a few environmental variables and then run `tests` executable.
|
||||||
|
```
|
||||||
|
export TEST_TMPDIR=/tmp/
|
||||||
|
export TEST_SRCDIR=/path/to/project/source
|
||||||
|
```
|
||||||
|
|
||||||
All test data is from [osgeo samples](http://download.osgeo.org/geotiff/samples/).
|
All test data is from [osgeo samples](http://download.osgeo.org/geotiff/samples/).
|
||||||
|
|
|
@ -16,7 +16,9 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
#include "sandboxed_api/sandbox2/testing.h"
|
||||||
#include "sandboxed_api/sandbox2/util/fileops.h"
|
#include "sandboxed_api/sandbox2/util/fileops.h"
|
||||||
|
#include "sandboxed_api/sandbox2/util/path.h"
|
||||||
|
|
||||||
#include "gdal_sandbox.h" // NOLINT(build/include)
|
#include "gdal_sandbox.h" // NOLINT(build/include)
|
||||||
#include "get_raster_data.h" // NOLINT(build/include)
|
#include "get_raster_data.h" // NOLINT(build/include)
|
||||||
|
@ -27,16 +29,16 @@ namespace {
|
||||||
|
|
||||||
inline constexpr absl::string_view kTempFilePrefix = "temp_data";
|
inline constexpr absl::string_view kTempFilePrefix = "temp_data";
|
||||||
inline constexpr absl::string_view kFirstTestDataPath =
|
inline constexpr absl::string_view kFirstTestDataPath =
|
||||||
"../testdata/cea.tif";
|
"testdata/cea.tif";
|
||||||
inline constexpr absl::string_view kSecondTestDataPath =
|
inline constexpr absl::string_view kSecondTestDataPath =
|
||||||
"../testdata/SP27GTIF.tif";
|
"testdata/SP27GTIF.tif";
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
class TestGTiffProcessor : public testing::TestWithParam<absl::string_view> {
|
class TestGTiffProcessor : public testing::TestWithParam<absl::string_view> {
|
||||||
public:
|
public:
|
||||||
TestGTiffProcessor()
|
TestGTiffProcessor()
|
||||||
: tempfile_(kTempFilePrefix)
|
: tempfile_(sandbox2::GetTestTempPath())
|
||||||
{}
|
{}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -44,21 +46,24 @@ class TestGTiffProcessor : public testing::TestWithParam<absl::string_view> {
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_P(TestGTiffProcessor, TestProcessorOnGTiffData) {
|
TEST_P(TestGTiffProcessor, TestProcessorOnGTiffData) {
|
||||||
std::string filename = std::string(GetParam());
|
|
||||||
|
std::string file_path = gdal::sandbox::utils::GetTestDataPath(GetParam());
|
||||||
|
|
||||||
|
ASSERT_TRUE(sandbox2::file_util::fileops::Exists(file_path, false))
|
||||||
|
<< "Error finding input dataset";
|
||||||
|
|
||||||
ASSERT_TRUE(tempfile_.HasValue())
|
ASSERT_TRUE(tempfile_.HasValue())
|
||||||
<< "Error creating temporary output file";
|
<< "Error creating temporary output file";
|
||||||
|
|
||||||
gdal::sandbox::parser::RasterDataset original_bands_data =
|
gdal::sandbox::parser::RasterDataset original_bands_data =
|
||||||
gdal::sandbox::parser::GetRasterBandsFromFile(filename);
|
gdal::sandbox::parser::GetRasterBandsFromFile(file_path);
|
||||||
|
|
||||||
std::optional<std::string> proj_db_path =
|
std::optional<std::string> proj_db_path =
|
||||||
gdal::sandbox::utils::FindProjDbPath();
|
gdal::sandbox::utils::FindProjDbPath();
|
||||||
ASSERT_TRUE(proj_db_path != std::nullopt)
|
ASSERT_TRUE(proj_db_path != std::nullopt)
|
||||||
<< "Specified proj.db does not exist";
|
<< "Specified proj.db does not exist";
|
||||||
|
|
||||||
gdal::sandbox::RasterToGTiffProcessor processor(absl::StrCat(
|
gdal::sandbox::RasterToGTiffProcessor processor(tempfile_.GetPath(),
|
||||||
sandbox2::file_util::fileops::GetCWD(), "/", tempfile_.GetPath()),
|
|
||||||
std::move(proj_db_path.value()), original_bands_data);
|
std::move(proj_db_path.value()), original_bands_data);
|
||||||
|
|
||||||
ASSERT_EQ(processor.Run(), absl::OkStatus())
|
ASSERT_EQ(processor.Run(), absl::OkStatus())
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "sandboxed_api/sandbox2/util/fileops.h"
|
#include "sandboxed_api/sandbox2/util/fileops.h"
|
||||||
|
#include "sandboxed_api/sandbox2/util/path.h"
|
||||||
#include "sandboxed_api/sandbox2/util/temp_file.h"
|
#include "sandboxed_api/sandbox2/util/temp_file.h"
|
||||||
|
|
||||||
namespace gdal::sandbox::utils {
|
namespace gdal::sandbox::utils {
|
||||||
|
@ -70,4 +71,11 @@ std::optional<std::string> FindProjDbPath() {
|
||||||
return proj_db_path;
|
return proj_db_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string GetTestDataPath(absl::string_view testdata_path) {
|
||||||
|
const char* test_srcdir = std::getenv("TEST_SRCDIR");
|
||||||
|
|
||||||
|
return sandbox2::file::JoinPath(test_srcdir == nullptr ?
|
||||||
|
sandbox2::file_util::fileops::GetCWD() : test_srcdir, testdata_path);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace gdal::sandbox::utils
|
} // namespace gdal::sandbox::utils
|
||||||
|
|
|
@ -43,6 +43,10 @@ class TempFile {
|
||||||
// Helper function to retrieve potential proj.db path from environment variable
|
// Helper function to retrieve potential proj.db path from environment variable
|
||||||
std::optional<std::string> FindProjDbPath();
|
std::optional<std::string> FindProjDbPath();
|
||||||
|
|
||||||
|
// Tries to get test folder path from the TEST_SRCDIR environment variable and
|
||||||
|
// uses CWD path otherwise to join it with the testdata_path
|
||||||
|
std::string GetTestDataPath(absl::string_view testdata_path);
|
||||||
|
|
||||||
} // namespace gdal::sandbox::utils
|
} // namespace gdal::sandbox::utils
|
||||||
|
|
||||||
#endif // RASTER_TO_GTIFF_UTILS_H_
|
#endif // RASTER_TO_GTIFF_UTILS_H_
|
||||||
|
|
Loading…
Reference in New Issue
Block a user