sandboxed-api/oss-internship-2020/gdal/raster_to_gtiff/tests.cc
Bohdan Tyshchenko b1a1aef39e Project architecture redesign, coding style update
Put duplicated code inside the transaction, which is used by both tests and raster_to_gtiff
Removed <filesystem> header, reimplemented one of its utilities for file checking
Code style changes
Replaced .data() with .c_str() for std::string
Updated README to show how to build both GDAL and PROJ inside the build folder and how to link them to the sandbox
2020-10-13 13:03:04 -07:00

82 lines
2.5 KiB
C++

// 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>
#include "gtest/gtest.h"
#include "gdal_sandbox.h" // NOLINT(build/include)
#include "get_raster_data.h" // NOLINT(build/include)
#include "gtiff_converter.h" // NOLINT(build/include)
#include "utils.h" // NOLINT(build/include)
namespace gdal::sandbox::tests {
namespace {
inline constexpr absl::string_view kTempFilePrefix = "temp_data";
inline constexpr absl::string_view kFirstTestDataPath =
"../testdata/cea.tif";
inline constexpr absl::string_view kSecondTestDataPath =
"../testdata/SP27GTIF.tif";
} // namespace
class TestGTiffProcessor : public testing::TestWithParam<absl::string_view> {
public:
TestGTiffProcessor()
: tempfile_(kTempFilePrefix)
{}
protected:
const utils::TempFile tempfile_;
};
TEST_P(TestGTiffProcessor, TestProcessorOnGTiffData) {
std::string filename = std::string(GetParam());
ASSERT_TRUE(tempfile_.HasValue())
<< "Error creating temporary output file";
parser::RasterDataset original_bands_data =
parser::GetRasterBandsFromFile(filename);
std::optional<std::string> proj_db_path = utils::FindProjDbPath();
ASSERT_TRUE(proj_db_path != std::nullopt)
<< "Specified proj.db does not exist";
RasterToGTiffProcessor processor(absl::StrCat(
sandbox2::file_util::fileops::GetCWD(), "/", tempfile_.GetPath()),
sandbox2::file_util::fileops::GetCWD(), std::move(proj_db_path.value()),
original_bands_data);
ASSERT_EQ(processor.Run(), absl::OkStatus())
<< "Error creating new GTiff dataset inside sandbox";
ASSERT_EQ(original_bands_data,
parser::GetRasterBandsFromFile(tempfile_.GetPath()))
<< "New dataset doesn't match the original one";
}
INSTANTIATE_TEST_CASE_P(
GDALTests,
TestGTiffProcessor,
::testing::Values(kFirstTestDataPath,
kSecondTestDataPath
)
);
} // namespace gdal::sandbox::tests