From 21f0af0f8b56ab76b93aaf6ce962580ec7978fcb Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sat, 10 Apr 2021 16:59:08 +0200 Subject: createFromUserInput(): add support for OGC URLs e.g: http://www.opengis.net/def/crs/EPSG/0/4326 http://www.opengis.net/def/crs-compound?1=http://www.opengis.net/def/crs/EPSG/0/4326&2=http://www.opengis.net/def/crs/EPSG/0/3855 --- test/unit/test_io.cpp | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) (limited to 'test/unit/test_io.cpp') diff --git a/test/unit/test_io.cpp b/test/unit/test_io.cpp index 9d627ce9..708b3874 100644 --- a/test/unit/test_io.cpp +++ b/test/unit/test_io.cpp @@ -10637,6 +10637,84 @@ TEST(io, createFromUserInput) { // --------------------------------------------------------------------------- +TEST(io, createFromUserInput_ogc_crs_url) { + auto dbContext = DatabaseContext::create(); + + { + auto obj = createFromUserInput( + "http://www.opengis.net/def/crs/EPSG/0/4326", dbContext); + auto crs = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(crs != nullptr); + } + + EXPECT_THROW( + createFromUserInput("http://www.opengis.net/def/crs", dbContext), + ParsingException); + + EXPECT_THROW( + createFromUserInput("http://www.opengis.net/def/crs/EPSG/0", dbContext), + ParsingException); + + EXPECT_THROW(createFromUserInput( + "http://www.opengis.net/def/crs/EPSG/0/XXXX", dbContext), + NoSuchAuthorityCodeException); + + { + auto obj = createFromUserInput( + "http://www.opengis.net/def/crs-compound?1=http://www.opengis.net/" + "def/crs/EPSG/0/4326&2=http://www.opengis.net/def/crs/EPSG/0/3855", + dbContext); + auto crs = nn_dynamic_pointer_cast(obj); + ASSERT_TRUE(crs != nullptr); + EXPECT_EQ(crs->nameStr(), "WGS 84 + EGM2008 height"); + } + + // No part + EXPECT_THROW(createFromUserInput("http://www.opengis.net/def/crs-compound?", + dbContext), + ParsingException); + + // Just one part + EXPECT_THROW( + createFromUserInput("http://www.opengis.net/def/crs-compound?1=http://" + "www.opengis.net/def/crs/EPSG/0/4326", + dbContext), + InvalidCompoundCRSException); + + // Invalid compound CRS + EXPECT_THROW( + createFromUserInput( + "http://www.opengis.net/def/crs-compound?1=http://www.opengis.net/" + "def/crs/EPSG/0/4326&2=http://www.opengis.net/def/crs/EPSG/0/4326", + dbContext), + InvalidCompoundCRSException); + + // Missing 2= + EXPECT_THROW( + createFromUserInput( + "http://www.opengis.net/def/crs-compound?1=http://www.opengis.net/" + "def/crs/EPSG/0/4326&3=http://www.opengis.net/def/crs/EPSG/0/3855", + dbContext), + ParsingException); + + // Invalid query parameter + EXPECT_THROW( + createFromUserInput("http://www.opengis.net/def/crs-compound?1=http://" + "www.opengis.net/def/crs/EPSG/0/4326&bla", + dbContext), + ParsingException); + + // Invalid query parameter + EXPECT_THROW( + createFromUserInput("http://www.opengis.net/def/crs-compound?1=http://" + "www.opengis.net/def/crs/EPSG/0/4326&two=http://" + "www.opengis.net/def/crs/EPSG/0/3855", + dbContext), + ParsingException); +} + +// --------------------------------------------------------------------------- + TEST(io, createFromUserInput_hack_EPSG_102100) { auto dbContext = DatabaseContext::create(); auto obj = createFromUserInput("EPSG:102100", dbContext); -- cgit v1.2.3