2020-10-01 18:59:18 +08:00
|
|
|
// Copyright 2020 Google LLC
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#include <optional>
|
|
|
|
#include <string>
|
|
|
|
|
2020-10-19 23:08:03 +08:00
|
|
|
#include "gdal_sandbox.h" // NOLINT(build/include)
|
|
|
|
#include "get_raster_data.h" // NOLINT(build/include)
|
|
|
|
#include "gtiff_converter.h" // NOLINT(build/include)
|
2020-10-01 18:59:18 +08:00
|
|
|
#include "gtest/gtest.h"
|
2020-10-17 00:15:11 +08:00
|
|
|
#include "sandboxed_api/sandbox2/testing.h"
|
2020-10-15 23:13:11 +08:00
|
|
|
#include "sandboxed_api/sandbox2/util/fileops.h"
|
2020-10-17 00:15:11 +08:00
|
|
|
#include "sandboxed_api/sandbox2/util/path.h"
|
2020-10-14 04:03:04 +08:00
|
|
|
#include "utils.h" // NOLINT(build/include)
|
2020-10-01 18:59:18 +08:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
inline constexpr absl::string_view kTempFilePrefix = "temp_data";
|
2020-10-19 23:08:03 +08:00
|
|
|
inline constexpr absl::string_view kFirstTestDataPath = "testdata/cea.tif";
|
|
|
|
inline constexpr absl::string_view kSecondTestDataPath =
|
2020-10-17 00:15:11 +08:00
|
|
|
"testdata/SP27GTIF.tif";
|
2020-10-01 18:59:18 +08:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
class TestGTiffProcessor : public testing::TestWithParam<absl::string_view> {
|
|
|
|
public:
|
2020-10-19 23:08:03 +08:00
|
|
|
TestGTiffProcessor() : tempfile_(sandbox2::GetTestTempPath()) {}
|
2020-10-01 18:59:18 +08:00
|
|
|
|
|
|
|
protected:
|
2020-10-15 23:13:11 +08:00
|
|
|
const gdal::sandbox::utils::TempFile tempfile_;
|
2020-10-01 18:59:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST_P(TestGTiffProcessor, TestProcessorOnGTiffData) {
|
2020-10-17 00:15:11 +08:00
|
|
|
std::string file_path = gdal::sandbox::utils::GetTestDataPath(GetParam());
|
|
|
|
|
|
|
|
ASSERT_TRUE(sandbox2::file_util::fileops::Exists(file_path, false))
|
|
|
|
<< "Error finding input dataset";
|
2020-10-01 18:59:18 +08:00
|
|
|
|
2020-10-19 23:08:03 +08:00
|
|
|
ASSERT_TRUE(tempfile_.HasValue()) << "Error creating temporary output file";
|
2020-10-01 18:59:18 +08:00
|
|
|
|
2020-10-19 23:08:03 +08:00
|
|
|
gdal::sandbox::parser::RasterDataset original_bands_data =
|
2020-10-17 00:15:11 +08:00
|
|
|
gdal::sandbox::parser::GetRasterBandsFromFile(file_path);
|
2020-10-01 18:59:18 +08:00
|
|
|
|
2020-10-19 23:08:03 +08:00
|
|
|
std::optional<std::string> proj_db_path =
|
2020-10-15 23:13:11 +08:00
|
|
|
gdal::sandbox::utils::FindProjDbPath();
|
2020-10-06 02:01:15 +08:00
|
|
|
ASSERT_TRUE(proj_db_path != std::nullopt)
|
|
|
|
<< "Specified proj.db does not exist";
|
|
|
|
|
2020-10-19 23:08:03 +08:00
|
|
|
gdal::sandbox::RasterToGTiffProcessor processor(
|
|
|
|
tempfile_.GetPath(), std::move(proj_db_path.value()),
|
|
|
|
original_bands_data);
|
|
|
|
|
2020-10-01 18:59:18 +08:00
|
|
|
ASSERT_EQ(processor.Run(), absl::OkStatus())
|
|
|
|
<< "Error creating new GTiff dataset inside sandbox";
|
2020-10-06 19:06:54 +08:00
|
|
|
|
2020-10-19 23:08:03 +08:00
|
|
|
ASSERT_EQ(original_bands_data,
|
|
|
|
gdal::sandbox::parser::GetRasterBandsFromFile(tempfile_.GetPath()))
|
2020-10-01 18:59:18 +08:00
|
|
|
<< "New dataset doesn't match the original one";
|
|
|
|
}
|
|
|
|
|
2020-10-19 23:08:03 +08:00
|
|
|
INSTANTIATE_TEST_CASE_P(GDALTests, TestGTiffProcessor,
|
|
|
|
::testing::Values(kFirstTestDataPath,
|
|
|
|
kSecondTestDataPath));
|