diff --git a/scripts/reference_exported_symbols.txt b/scripts/reference_exported_symbols.txt index dd66197a69..1774b79bb3 100644 --- a/scripts/reference_exported_symbols.txt +++ b/scripts/reference_exported_symbols.txt @@ -279,6 +279,26 @@ osgeo::proj::datum::TemporalDatum::temporalOrigin() const osgeo::proj::datum::VerticalReferenceFrame::create(osgeo::proj::util::PropertyMap const&, osgeo::proj::util::optional const&, osgeo::proj::util::optional const&) osgeo::proj::datum::VerticalReferenceFrame::realizationMethod() const osgeo::proj::datum::VerticalReferenceFrame::~VerticalReferenceFrame() +osgeo::proj::GenericShiftGrid::~GenericShiftGrid() +osgeo::proj::GenericShiftGrid::GenericShiftGrid(std::string const&, int, int, osgeo::proj::ExtentAndRes const&) +osgeo::proj::GenericShiftGrid::gridAt(double, double) const +osgeo::proj::GenericShiftGridSet::~GenericShiftGridSet() +osgeo::proj::GenericShiftGridSet::GenericShiftGridSet() +osgeo::proj::GenericShiftGridSet::gridAt(double, double) const +osgeo::proj::GenericShiftGridSet::open(projCtx_t*, std::string const&) +osgeo::proj::GenericShiftGridSet::reassign_context(projCtx_t*) +osgeo::proj::GenericShiftGridSet::reopen(projCtx_t*) +osgeo::proj::Grid::~Grid() +osgeo::proj::Grid::Grid(std::string const&, int, int, osgeo::proj::ExtentAndRes const&) +osgeo::proj::HorizontalShiftGrid::gridAt(double, double) const +osgeo::proj::HorizontalShiftGrid::~HorizontalShiftGrid() +osgeo::proj::HorizontalShiftGrid::HorizontalShiftGrid(std::string const&, int, int, osgeo::proj::ExtentAndRes const&) +osgeo::proj::HorizontalShiftGridSet::gridAt(double, double) const +osgeo::proj::HorizontalShiftGridSet::~HorizontalShiftGridSet() +osgeo::proj::HorizontalShiftGridSet::HorizontalShiftGridSet() +osgeo::proj::HorizontalShiftGridSet::open(projCtx_t*, std::string const&) +osgeo::proj::HorizontalShiftGridSet::reassign_context(projCtx_t*) +osgeo::proj::HorizontalShiftGridSet::reopen(projCtx_t*) osgeo::proj::internal::ci_equal(std::string const&, char const*) osgeo::proj::internal::ci_equal(std::string const&, std::string const&) osgeo::proj::internal::ci_find(std::string const&, char const*) @@ -696,6 +716,15 @@ osgeo::proj::util::PropertyMap::set(std::string const&, std::string const&) osgeo::proj::util::PropertyMap::set(std::string const&, std::vector > const&) osgeo::proj::util::UnsupportedOperationException::~UnsupportedOperationException() osgeo::proj::util::UnsupportedOperationException::UnsupportedOperationException(osgeo::proj::util::UnsupportedOperationException const&) +osgeo::proj::VerticalShiftGrid::gridAt(double, double) const +osgeo::proj::VerticalShiftGridSet::gridAt(double, double) const +osgeo::proj::VerticalShiftGridSet::open(projCtx_t*, std::string const&) +osgeo::proj::VerticalShiftGridSet::reassign_context(projCtx_t*) +osgeo::proj::VerticalShiftGridSet::reopen(projCtx_t*) +osgeo::proj::VerticalShiftGridSet::~VerticalShiftGridSet() +osgeo::proj::VerticalShiftGridSet::VerticalShiftGridSet() +osgeo::proj::VerticalShiftGrid::~VerticalShiftGrid() +osgeo::proj::VerticalShiftGrid::VerticalShiftGrid(std::string const&, int, int, osgeo::proj::ExtentAndRes const&) pj_acquire_lock pj_add_type_crs_if_needed(std::string const&) pj_apply_gridshift diff --git a/src/grids.cpp b/src/grids.cpp index b4c3ad24ce..d5f961f715 100644 --- a/src/grids.cpp +++ b/src/grids.cpp @@ -112,9 +112,7 @@ VerticalShiftGrid::VerticalShiftGrid(const std::string &nameIn, int widthIn, // --------------------------------------------------------------------------- -bool VerticalShiftGrid::isNodata(float /*val*/, double /* multiplier */) const { - return false; -} +VerticalShiftGrid::~VerticalShiftGrid() = default; // --------------------------------------------------------------------------- diff --git a/src/grids.hpp b/src/grids.hpp index 6b6ee0d2f1..7fa6bd2823 100644 --- a/src/grids.hpp +++ b/src/grids.hpp @@ -51,7 +51,7 @@ struct ExtentAndRes { // --------------------------------------------------------------------------- -class Grid { +class PROJ_FOR_TEST Grid { protected: std::string m_name; int m_width; @@ -75,17 +75,18 @@ class Grid { // --------------------------------------------------------------------------- -class VerticalShiftGrid : public Grid { +class PROJ_FOR_TEST VerticalShiftGrid : public Grid { protected: std::vector> m_children{}; public: VerticalShiftGrid(const std::string &nameIn, int widthIn, int heightIn, const ExtentAndRes &extentIn); + ~VerticalShiftGrid() override; const VerticalShiftGrid *gridAt(double lon, double lat) const; - virtual bool isNodata(float /*val*/, double /* multiplier */) const; + virtual bool isNodata(float /*val*/, double /* multiplier */) const = 0; // x = 0 is western-most column, y = 0 is southern-most line virtual bool valueAt(int x, int y, float &out) const = 0; @@ -95,7 +96,7 @@ class VerticalShiftGrid : public Grid { // --------------------------------------------------------------------------- -class VerticalShiftGridSet { +class PROJ_FOR_TEST VerticalShiftGridSet { protected: std::string m_name{}; std::string m_format{}; @@ -122,7 +123,7 @@ class VerticalShiftGridSet { // --------------------------------------------------------------------------- -class HorizontalShiftGrid : public Grid { +class PROJ_FOR_TEST HorizontalShiftGrid : public Grid { protected: std::vector> m_children{}; @@ -142,7 +143,7 @@ class HorizontalShiftGrid : public Grid { // --------------------------------------------------------------------------- -class HorizontalShiftGridSet { +class PROJ_FOR_TEST HorizontalShiftGridSet { protected: std::string m_name{}; std::string m_format{}; @@ -169,7 +170,7 @@ class HorizontalShiftGridSet { // --------------------------------------------------------------------------- -class GenericShiftGrid : public Grid { +class PROJ_FOR_TEST GenericShiftGrid : public Grid { protected: std::vector> m_children{}; @@ -198,7 +199,7 @@ class GenericShiftGrid : public Grid { // --------------------------------------------------------------------------- -class GenericShiftGridSet { +class PROJ_FOR_TEST GenericShiftGridSet { protected: std::string m_name{}; std::string m_format{}; diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index e1eefcf057..e14d4c70e6 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -128,14 +128,20 @@ add_executable(proj_test_cpp_api test_operation.cpp test_datum.cpp test_factory.cpp - test_c_api.cpp) + test_c_api.cpp + test_grids.cpp) target_link_libraries(proj_test_cpp_api GTest::gtest ${PROJ_LIBRARIES} ${SQLITE3_LIBRARY}) add_test(NAME proj_test_cpp_api COMMAND proj_test_cpp_api) -set_property(TEST proj_test_cpp_api - PROPERTY ENVIRONMENT "PROJ_IGNORE_USER_WRITABLE_DIRECTORY=YES;PROJ_LIB=${PROJECT_BINARY_DIR}/data") +if(MSVC) + set_property(TEST proj_test_cpp_api + PROPERTY ENVIRONMENT "PROJ_IGNORE_USER_WRITABLE_DIRECTORY=YES;PROJ_LIB=${PROJECT_BINARY_DIR}/data\\;${PROJECT_SOURCE_DIR}/data") +else() + set_property(TEST proj_test_cpp_api + PROPERTY ENVIRONMENT "PROJ_IGNORE_USER_WRITABLE_DIRECTORY=YES;PROJ_LIB=${PROJECT_BINARY_DIR}/data:${PROJECT_SOURCE_DIR}/data") +endif() add_executable(gie_self_tests diff --git a/test/unit/Makefile.am b/test/unit/Makefile.am index 7ffb06aecc..b7a26d4e3f 100644 --- a/test/unit/Makefile.am +++ b/test/unit/Makefile.am @@ -49,7 +49,7 @@ proj_context_test_LDADD = ../../src/libproj.la @GTEST_LIBS@ proj_context_test-check: proj_context_test PROJ_IGNORE_USER_WRITABLE_DIRECTORY=YES ./proj_context_test -test_cpp_api_SOURCES = test_util.cpp test_common.cpp test_crs.cpp test_metadata.cpp test_io.cpp test_operation.cpp test_datum.cpp test_factory.cpp test_c_api.cpp main.cpp +test_cpp_api_SOURCES = test_util.cpp test_common.cpp test_crs.cpp test_metadata.cpp test_io.cpp test_operation.cpp test_datum.cpp test_factory.cpp test_c_api.cpp test_grids.cpp main.cpp test_cpp_api_LDADD = ../../src/libproj.la @GTEST_LIBS@ @SQLITE3_LIBS@ test_cpp_api-check: test_cpp_api diff --git a/test/unit/test_grids.cpp b/test/unit/test_grids.cpp new file mode 100644 index 0000000000..99cec85188 --- /dev/null +++ b/test/unit/test_grids.cpp @@ -0,0 +1,160 @@ +/****************************************************************************** + * + * Project: PROJ + * Purpose: Test grids.hpp + * Author: Even Rouault + * + ****************************************************************************** + * Copyright (c) 2020, Even Rouault + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + ****************************************************************************/ + +#include "gtest_include.h" + +#include "grids.hpp" + +#include "proj_internal.h" // M_PI + +namespace { + +// --------------------------------------------------------------------------- + +class GridTest : public ::testing::Test { + + static void DummyLogFunction(void *, int, const char *) {} + + protected: + void SetUp() override { + m_ctxt = proj_context_create(); + proj_log_func(m_ctxt, nullptr, DummyLogFunction); + m_ctxt2 = proj_context_create(); + proj_log_func(m_ctxt2, nullptr, DummyLogFunction); + } + + void TearDown() override { + proj_context_destroy(m_ctxt); + proj_context_destroy(m_ctxt2); + } + + PJ_CONTEXT *m_ctxt = nullptr; + PJ_CONTEXT *m_ctxt2 = nullptr; +}; + +// --------------------------------------------------------------------------- + +TEST_F(GridTest, VerticalShiftGridSet_null) { + auto gridSet = NS_PROJ::VerticalShiftGridSet::open(m_ctxt, "null"); + ASSERT_NE(gridSet, nullptr); + auto grid = gridSet->gridAt(0.0, 0.0); + ASSERT_NE(grid, nullptr); + EXPECT_EQ(grid->width(), 3); + EXPECT_EQ(grid->height(), 3); + EXPECT_EQ(grid->extentAndRes().westLon, -M_PI); + EXPECT_TRUE(grid->isNullGrid()); + EXPECT_FALSE(grid->hasChanged()); + float out = -1.0f; + EXPECT_TRUE(grid->valueAt(0, 0, out)); + EXPECT_EQ(out, 0.0f); + EXPECT_FALSE(grid->isNodata(0.0f, 0.0)); + gridSet->reassign_context(m_ctxt2); + gridSet->reopen(m_ctxt2); +} + +// --------------------------------------------------------------------------- + +TEST_F(GridTest, VerticalShiftGridSet_regular) { + ASSERT_EQ(NS_PROJ::VerticalShiftGridSet::open(m_ctxt, "foobar"), nullptr); + auto gridSet = + NS_PROJ::VerticalShiftGridSet::open(m_ctxt, "tests/test_nodata.gtx"); + ASSERT_NE(gridSet, nullptr); + ASSERT_EQ(gridSet->gridAt(-100, -100), nullptr); + auto grid = gridSet->gridAt(4.15 / 180 * M_PI, 52.15 / 180 * M_PI); + ASSERT_NE(grid, nullptr); + EXPECT_TRUE(grid->isNodata(-88.8888f, 1.0)); + gridSet->reassign_context(m_ctxt2); + gridSet->reopen(m_ctxt2); +} + +// --------------------------------------------------------------------------- + +TEST_F(GridTest, HorizontalShiftGridSet_null) { + auto gridSet = NS_PROJ::HorizontalShiftGridSet::open(m_ctxt, "null"); + ASSERT_NE(gridSet, nullptr); + auto grid = gridSet->gridAt(0.0, 0.0); + ASSERT_NE(grid, nullptr); + EXPECT_EQ(grid->width(), 3); + EXPECT_EQ(grid->height(), 3); + EXPECT_EQ(grid->extentAndRes().westLon, -M_PI); + EXPECT_TRUE(grid->isNullGrid()); + EXPECT_FALSE(grid->hasChanged()); + float out1 = -1.0f; + float out2 = -1.0f; + EXPECT_TRUE(grid->valueAt(0, 0, false, out1, out2)); + EXPECT_EQ(out1, 0.0f); + EXPECT_EQ(out2, 0.0f); + gridSet->reassign_context(m_ctxt2); + gridSet->reopen(m_ctxt2); +} + +// --------------------------------------------------------------------------- + +TEST_F(GridTest, GenericShiftGridSet_null) { + auto gridSet = NS_PROJ::GenericShiftGridSet::open(m_ctxt, "null"); + ASSERT_NE(gridSet, nullptr); + auto grid = gridSet->gridAt(0.0, 0.0); + ASSERT_NE(grid, nullptr); + EXPECT_EQ(grid->width(), 3); + EXPECT_EQ(grid->height(), 3); + EXPECT_EQ(grid->extentAndRes().westLon, -M_PI); + EXPECT_TRUE(grid->isNullGrid()); + EXPECT_FALSE(grid->hasChanged()); + float out = -1.0f; + EXPECT_TRUE(grid->valueAt(0, 0, 0, out)); + EXPECT_EQ(out, 0.0f); + EXPECT_EQ(grid->unit(0), ""); + EXPECT_EQ(grid->description(0), ""); + EXPECT_EQ(grid->metadataItem("foo"), ""); + EXPECT_EQ(grid->samplesPerPixel(), 0); + gridSet->reassign_context(m_ctxt2); + gridSet->reopen(m_ctxt2); +} + +// --------------------------------------------------------------------------- + +TEST_F(GridTest, GenericShiftGridSet_regular) { + ASSERT_EQ(NS_PROJ::GenericShiftGridSet::open(m_ctxt, "foobar"), nullptr); + auto gridSet = NS_PROJ::GenericShiftGridSet::open( + m_ctxt, "tests/nkgrf03vel_realigned_extract.tif"); + ASSERT_NE(gridSet, nullptr); + ASSERT_EQ(gridSet->gridAt(-100, -100), nullptr); + auto grid = gridSet->gridAt(21.3333333 / 180 * M_PI, 63.0 / 180 * M_PI); + ASSERT_NE(grid, nullptr); + EXPECT_EQ(grid->width(), 5); + EXPECT_EQ(grid->height(), 5); + EXPECT_EQ(grid->extentAndRes().westLon, 21.0 / 180 * M_PI); + EXPECT_FALSE(grid->isNullGrid()); + EXPECT_FALSE(grid->hasChanged()); + float out = -1.0f; + EXPECT_FALSE(grid->valueAt(0, 0, grid->samplesPerPixel(), out)); + gridSet->reassign_context(m_ctxt2); + gridSet->reopen(m_ctxt2); +} + +} // namespace