diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2020-01-14 00:53:07 +0100 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2020-01-14 23:33:16 +0100 |
| commit | 941bb82c7eecbf56821075f95991916c30c31b4e (patch) | |
| tree | fe7a9096f4daae7692d07bbd6ae85f4c6e90870c | |
| parent | 9cb40a8322f4ccbf8305daf368308783969d1c94 (diff) | |
| download | PROJ-941bb82c7eecbf56821075f95991916c30c31b4e.tar.gz PROJ-941bb82c7eecbf56821075f95991916c30c31b4e.zip | |
Add test/unit/test_grids.cpp to improve testing coverage
| -rw-r--r-- | data/Makefile.am | 1 | ||||
| -rw-r--r-- | data/tests/test_hgrid_with_two_level_of_subgrids_no_grid_name.tif | bin | 0 -> 3504 bytes | |||
| -rw-r--r-- | scripts/reference_exported_symbols.txt | 29 | ||||
| -rw-r--r-- | src/grids.cpp | 4 | ||||
| -rw-r--r-- | src/grids.hpp | 135 | ||||
| -rw-r--r-- | test/gie/geotiff_grids.gie | 14 | ||||
| -rw-r--r-- | test/unit/CMakeLists.txt | 12 | ||||
| -rw-r--r-- | test/unit/Makefile.am | 2 | ||||
| -rw-r--r-- | test/unit/test_grids.cpp | 227 | ||||
| -rwxr-xr-x | travis/mingw32/install.sh | 1 |
10 files changed, 356 insertions, 69 deletions
diff --git a/data/Makefile.am b/data/Makefile.am index 4bba2649..d8abfe32 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -85,6 +85,7 @@ EXTRA_DIST = proj.ini GL27 nad.lst nad27 nad83 \ tests/nkgrf03vel_realigned_extract.tif \ tests/nkgrf03vel_realigned_xy_extract.ct2 \ tests/nkgrf03vel_realigned_z_extract.gtx \ + tests/test_hgrid_with_two_level_of_subgrids_no_grid_name.tif \ null \ generate_all_sql_in.cmake sql_filelist.cmake \ $(SQL_ORDERED_LIST) diff --git a/data/tests/test_hgrid_with_two_level_of_subgrids_no_grid_name.tif b/data/tests/test_hgrid_with_two_level_of_subgrids_no_grid_name.tif Binary files differnew file mode 100644 index 00000000..2abb3226 --- /dev/null +++ b/data/tests/test_hgrid_with_two_level_of_subgrids_no_grid_name.tif diff --git a/scripts/reference_exported_symbols.txt b/scripts/reference_exported_symbols.txt index dd66197a..1774b79b 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<std::string> const&, osgeo::proj::util::optional<osgeo::proj::datum::RealizationMethod> 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<std::string, std::allocator<std::string> > 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 b4c3ad24..d5f961f7 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 6b6ee0d2..0fd1b7b0 100644 --- a/src/grids.hpp +++ b/src/grids.hpp @@ -51,7 +51,7 @@ struct ExtentAndRes { // --------------------------------------------------------------------------- -class Grid { +class PROJ_GCC_DLL Grid { protected: std::string m_name; int m_width; @@ -62,40 +62,42 @@ class Grid { const ExtentAndRes &extentIn); public: - virtual ~Grid(); + PROJ_FOR_TEST virtual ~Grid(); - int width() const { return m_width; } - int height() const { return m_height; } - const ExtentAndRes &extentAndRes() const { return m_extent; } - const std::string &name() const { return m_name; } + PROJ_FOR_TEST int width() const { return m_width; } + PROJ_FOR_TEST int height() const { return m_height; } + PROJ_FOR_TEST const ExtentAndRes &extentAndRes() const { return m_extent; } + PROJ_FOR_TEST const std::string &name() const { return m_name; } - virtual bool isNullGrid() const { return false; } - virtual bool hasChanged() const = 0; + PROJ_FOR_TEST virtual bool isNullGrid() const { return false; } + PROJ_FOR_TEST virtual bool hasChanged() const = 0; }; // --------------------------------------------------------------------------- -class VerticalShiftGrid : public Grid { +class PROJ_GCC_DLL VerticalShiftGrid : public Grid { protected: std::vector<std::unique_ptr<VerticalShiftGrid>> m_children{}; public: - VerticalShiftGrid(const std::string &nameIn, int widthIn, int heightIn, - const ExtentAndRes &extentIn); + PROJ_FOR_TEST VerticalShiftGrid(const std::string &nameIn, int widthIn, + int heightIn, const ExtentAndRes &extentIn); + PROJ_FOR_TEST ~VerticalShiftGrid() override; - const VerticalShiftGrid *gridAt(double lon, double lat) const; + PROJ_FOR_TEST const VerticalShiftGrid *gridAt(double lon, double lat) const; - virtual bool isNodata(float /*val*/, double /* multiplier */) const; + PROJ_FOR_TEST 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; + PROJ_FOR_TEST virtual bool valueAt(int x, int y, float &out) const = 0; - virtual void reassign_context(PJ_CONTEXT *ctx) = 0; + PROJ_FOR_TEST virtual void reassign_context(PJ_CONTEXT *ctx) = 0; }; // --------------------------------------------------------------------------- -class VerticalShiftGridSet { +class PROJ_GCC_DLL VerticalShiftGridSet { protected: std::string m_name{}; std::string m_format{}; @@ -104,45 +106,50 @@ class VerticalShiftGridSet { VerticalShiftGridSet(); public: - virtual ~VerticalShiftGridSet(); + PROJ_FOR_TEST virtual ~VerticalShiftGridSet(); - static std::unique_ptr<VerticalShiftGridSet> + PROJ_FOR_TEST static std::unique_ptr<VerticalShiftGridSet> open(PJ_CONTEXT *ctx, const std::string &filename); - const std::string &name() const { return m_name; } - const std::string &format() const { return m_format; } - const std::vector<std::unique_ptr<VerticalShiftGrid>> &grids() const { + PROJ_FOR_TEST const std::string &name() const { return m_name; } + PROJ_FOR_TEST const std::string &format() const { return m_format; } + PROJ_FOR_TEST const std::vector<std::unique_ptr<VerticalShiftGrid>> & + grids() const { return m_grids; } - const VerticalShiftGrid *gridAt(double lon, double lat) const; + PROJ_FOR_TEST const VerticalShiftGrid *gridAt(double lon, double lat) const; - virtual void reassign_context(PJ_CONTEXT *ctx); - virtual bool reopen(PJ_CONTEXT *ctx); + PROJ_FOR_TEST virtual void reassign_context(PJ_CONTEXT *ctx); + PROJ_FOR_TEST virtual bool reopen(PJ_CONTEXT *ctx); }; // --------------------------------------------------------------------------- -class HorizontalShiftGrid : public Grid { +class PROJ_GCC_DLL HorizontalShiftGrid : public Grid { protected: std::vector<std::unique_ptr<HorizontalShiftGrid>> m_children{}; public: - HorizontalShiftGrid(const std::string &nameIn, int widthIn, int heightIn, - const ExtentAndRes &extentIn); - ~HorizontalShiftGrid() override; + PROJ_FOR_TEST HorizontalShiftGrid(const std::string &nameIn, int widthIn, + int heightIn, + const ExtentAndRes &extentIn); + PROJ_FOR_TEST ~HorizontalShiftGrid() override; - const HorizontalShiftGrid *gridAt(double lon, double lat) const; + PROJ_FOR_TEST const HorizontalShiftGrid *gridAt(double lon, + double lat) const; // x = 0 is western-most column, y = 0 is southern-most line - virtual bool valueAt(int x, int y, bool compensateNTConvention, - float &lonShift, float &latShift) const = 0; + PROJ_FOR_TEST virtual bool valueAt(int x, int y, + bool compensateNTConvention, + float &lonShift, + float &latShift) const = 0; - virtual void reassign_context(PJ_CONTEXT *ctx) = 0; + PROJ_FOR_TEST virtual void reassign_context(PJ_CONTEXT *ctx) = 0; }; // --------------------------------------------------------------------------- -class HorizontalShiftGridSet { +class PROJ_GCC_DLL HorizontalShiftGridSet { protected: std::string m_name{}; std::string m_format{}; @@ -151,54 +158,57 @@ class HorizontalShiftGridSet { HorizontalShiftGridSet(); public: - virtual ~HorizontalShiftGridSet(); + PROJ_FOR_TEST virtual ~HorizontalShiftGridSet(); - static std::unique_ptr<HorizontalShiftGridSet> + PROJ_FOR_TEST static std::unique_ptr<HorizontalShiftGridSet> open(PJ_CONTEXT *ctx, const std::string &filename); - const std::string &name() const { return m_name; } - const std::string &format() const { return m_format; } - const std::vector<std::unique_ptr<HorizontalShiftGrid>> &grids() const { + PROJ_FOR_TEST const std::string &name() const { return m_name; } + PROJ_FOR_TEST const std::string &format() const { return m_format; } + PROJ_FOR_TEST const std::vector<std::unique_ptr<HorizontalShiftGrid>> & + grids() const { return m_grids; } - const HorizontalShiftGrid *gridAt(double lon, double lat) const; + PROJ_FOR_TEST const HorizontalShiftGrid *gridAt(double lon, + double lat) const; - virtual void reassign_context(PJ_CONTEXT *ctx); - virtual bool reopen(PJ_CONTEXT *ctx); + PROJ_FOR_TEST virtual void reassign_context(PJ_CONTEXT *ctx); + PROJ_FOR_TEST virtual bool reopen(PJ_CONTEXT *ctx); }; // --------------------------------------------------------------------------- -class GenericShiftGrid : public Grid { +class PROJ_GCC_DLL GenericShiftGrid : public Grid { protected: std::vector<std::unique_ptr<GenericShiftGrid>> m_children{}; public: - GenericShiftGrid(const std::string &nameIn, int widthIn, int heightIn, - const ExtentAndRes &extentIn); + PROJ_FOR_TEST GenericShiftGrid(const std::string &nameIn, int widthIn, + int heightIn, const ExtentAndRes &extentIn); - ~GenericShiftGrid() override; + PROJ_FOR_TEST ~GenericShiftGrid() override; - const GenericShiftGrid *gridAt(double lon, double lat) const; + PROJ_FOR_TEST const GenericShiftGrid *gridAt(double lon, double lat) const; - virtual std::string unit(int sample) const = 0; + PROJ_FOR_TEST virtual std::string unit(int sample) const = 0; - virtual std::string description(int sample) const = 0; + PROJ_FOR_TEST virtual std::string description(int sample) const = 0; - virtual std::string metadataItem(const std::string &key, - int sample = -1) const = 0; + PROJ_FOR_TEST virtual std::string metadataItem(const std::string &key, + int sample = -1) const = 0; - virtual int samplesPerPixel() const = 0; + PROJ_FOR_TEST virtual int samplesPerPixel() const = 0; // x = 0 is western-most column, y = 0 is southern-most line - virtual bool valueAt(int x, int y, int sample, float &out) const = 0; + PROJ_FOR_TEST virtual bool valueAt(int x, int y, int sample, + float &out) const = 0; - virtual void reassign_context(PJ_CONTEXT *ctx) = 0; + PROJ_FOR_TEST virtual void reassign_context(PJ_CONTEXT *ctx) = 0; }; // --------------------------------------------------------------------------- -class GenericShiftGridSet { +class PROJ_GCC_DLL GenericShiftGridSet { protected: std::string m_name{}; std::string m_format{}; @@ -207,20 +217,21 @@ class GenericShiftGridSet { GenericShiftGridSet(); public: - virtual ~GenericShiftGridSet(); + PROJ_FOR_TEST virtual ~GenericShiftGridSet(); - static std::unique_ptr<GenericShiftGridSet> + PROJ_FOR_TEST static std::unique_ptr<GenericShiftGridSet> open(PJ_CONTEXT *ctx, const std::string &filename); - const std::string &name() const { return m_name; } - const std::string &format() const { return m_format; } - const std::vector<std::unique_ptr<GenericShiftGrid>> &grids() const { + PROJ_FOR_TEST const std::string &name() const { return m_name; } + PROJ_FOR_TEST const std::string &format() const { return m_format; } + PROJ_FOR_TEST const std::vector<std::unique_ptr<GenericShiftGrid>> & + grids() const { return m_grids; } - const GenericShiftGrid *gridAt(double lon, double lat) const; + PROJ_FOR_TEST const GenericShiftGrid *gridAt(double lon, double lat) const; - virtual void reassign_context(PJ_CONTEXT *ctx); - virtual bool reopen(PJ_CONTEXT *ctx); + PROJ_FOR_TEST virtual void reassign_context(PJ_CONTEXT *ctx); + PROJ_FOR_TEST virtual bool reopen(PJ_CONTEXT *ctx); }; // --------------------------------------------------------------------------- diff --git a/test/gie/geotiff_grids.gie b/test/gie/geotiff_grids.gie index 85c0cbe9..62a5b16d 100644 --- a/test/gie/geotiff_grids.gie +++ b/test/gie/geotiff_grids.gie @@ -277,6 +277,20 @@ accept -80.5041667 44.5458333 0 expect -80.50401615833 44.5458827236 0 ------------------------------------------------------------------------------- +# Check a nested grid of a nested grid only based on spatial extent analysis +------------------------------------------------------------------------------- +operation +proj=hgridshift +grids=tests/test_hgrid_with_two_level_of_subgrids_no_grid_name.tif +------------------------------------------------------------------------------- +accept -45.0 22.5 +accept -44.9983333334 22.5013888889 + +# Check a nested grid of a nested grid only based on spatial extent analysis +------------------------------------------------------------------------------- +operation +proj=vgridshift +grids=tests/test_hgrid_with_two_level_of_subgrids_no_grid_name.tif +multiplier=1 +------------------------------------------------------------------------------- +accept -45.0 22.5 0 +accept -45.0 22.5 5 + ------------------------------------------------------------------------------- operation +proj=hgridshift +grids=tests/test_vgrid.tif ------------------------------------------------------------------------------- diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index e1eefcf0..e14d4c70 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 7ffb06ae..b7a26d4e 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 00000000..5240949e --- /dev/null +++ b/test/unit/test_grids.cpp @@ -0,0 +1,227 @@ +/****************************************************************************** + * + * Project: PROJ + * Purpose: Test grids.hpp + * Author: Even Rouault <even dot rouault at spatialys dot com> + * + ****************************************************************************** + * Copyright (c) 2020, Even Rouault <even dot rouault at spatialys dot com> + * + * 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_gtx) { + 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); + grid = gridSet->gridAt(4.15 / 180 * M_PI, 52.15 / 180 * M_PI); + EXPECT_NE(grid, nullptr); +} + +// --------------------------------------------------------------------------- + +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, HorizontalShiftGridSet_gtiff) { + auto gridSet = + NS_PROJ::HorizontalShiftGridSet::open(m_ctxt, "tests/test_hgrid.tif"); + ASSERT_NE(gridSet, nullptr); + EXPECT_EQ(gridSet->format(), "gtiff"); + EXPECT_TRUE(gridSet->name().find("tests/test_hgrid.tif") != + std::string::npos) + << gridSet->name(); + EXPECT_EQ(gridSet->grids().size(), 1U); + ASSERT_EQ(gridSet->gridAt(-100, -100), nullptr); + auto grid = gridSet->gridAt(5.5 / 180 * M_PI, 53.5 / 180 * M_PI); + ASSERT_NE(grid, nullptr); + EXPECT_EQ(grid->width(), 4); + EXPECT_EQ(grid->height(), 4); + EXPECT_EQ(grid->extentAndRes().westLon, 4.0 / 180 * M_PI); + EXPECT_FALSE(grid->isNullGrid()); + EXPECT_FALSE(grid->hasChanged()); + float out1 = -1.0f; + float out2 = -1.0f; + EXPECT_TRUE(grid->valueAt(0, 3, false, out1, out2)); + EXPECT_EQ(out1, static_cast<float>(14400.0 / 3600. / 180 * M_PI)); + EXPECT_EQ(out2, static_cast<float>(900.0 / 3600. / 180 * M_PI)); + gridSet->reassign_context(m_ctxt2); + gridSet->reopen(m_ctxt2); + grid = gridSet->gridAt(5.5 / 180 * M_PI, 53.5 / 180 * M_PI); + EXPECT_NE(grid, nullptr); +} + +// --------------------------------------------------------------------------- + +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_gtiff) { + 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)); + EXPECT_EQ(grid->metadataItem("area_of_use"), "Nordic and Baltic countries"); + EXPECT_EQ(grid->metadataItem("non_existing"), std::string()); + EXPECT_EQ(grid->metadataItem("non_existing", 1), std::string()); + EXPECT_EQ(grid->metadataItem("non_existing", 10), std::string()); + gridSet->reassign_context(m_ctxt2); + gridSet->reopen(m_ctxt2); + grid = gridSet->gridAt(21.3333333 / 180 * M_PI, 63.0 / 180 * M_PI); + EXPECT_NE(grid, nullptr); +} + +// --------------------------------------------------------------------------- + +TEST_F(GridTest, GenericShiftGridSet_gtiff_with_subgrid) { + auto gridSet = NS_PROJ::GenericShiftGridSet::open( + m_ctxt, "tests/test_hgrid_with_subgrid.tif"); + ASSERT_NE(gridSet, nullptr); + ASSERT_EQ(gridSet->gridAt(-100, -100), nullptr); + auto grid = + gridSet->gridAt(-115.5416667 / 180 * M_PI, 51.1666667 / 180 * M_PI); + ASSERT_NE(grid, nullptr); + EXPECT_EQ(grid->width(), 11); + EXPECT_EQ(grid->height(), 21); + EXPECT_EQ(grid->metadataItem("grid_name"), "ALbanff"); +} + +// --------------------------------------------------------------------------- + +TEST_F(GridTest, + GenericShiftGridSet_gtiff_with_two_level_of_subgrids_no_grid_name) { + auto gridSet = NS_PROJ::GenericShiftGridSet::open( + m_ctxt, "tests/test_hgrid_with_two_level_of_subgrids_no_grid_name.tif"); + ASSERT_NE(gridSet, nullptr); + ASSERT_EQ(gridSet->gridAt(-100, -100), nullptr); + auto grid = gridSet->gridAt(-45.5 / 180 * M_PI, 22.5 / 180 * M_PI); + ASSERT_NE(grid, nullptr); + EXPECT_EQ(grid->width(), 8); + EXPECT_EQ(grid->height(), 8); +} + +} // namespace diff --git a/travis/mingw32/install.sh b/travis/mingw32/install.sh index abe79c7b..8c756ced 100755 --- a/travis/mingw32/install.sh +++ b/travis/mingw32/install.sh @@ -53,6 +53,7 @@ make install make dist-all find /tmp/proj_autoconf_install (cd test; make -j2) +cp -r ../data/tests /tmp/proj_autoconf_install/share/proj test/unit/test_cpp_api.exe cd .. # Now with grids |
