LCOV - code coverage report
Current view: top level - autotest/cpp - test_utilities.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 20 20 100.0 %
Date: 2024-05-14 23:54:21 Functions: 4 4 100.0 %

          Line data    Source code
       1             : ///////////////////////////////////////////////////////////////////////////////
       2             : //
       3             : // Project:  C++ Test Suite for GDAL/OGR
       4             : // Purpose:  Test the C API of utilities as library functions
       5             : // Author:   Even Rouault <even.rouault at spatialys.com>
       6             : //
       7             : ///////////////////////////////////////////////////////////////////////////////
       8             : // Copyright (c) 2023, Even Rouault <even.rouault at spatialys.com>
       9             : /*
      10             :  * Permission is hereby granted, free of charge, to any person obtaining a
      11             :  * copy of this software and associated documentation files (the "Software"),
      12             :  * to deal in the Software without restriction, including without limitation
      13             :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      14             :  * and/or sell copies of the Software, and to permit persons to whom the
      15             :  * Software is furnished to do so, subject to the following conditions:
      16             :  *
      17             :  * The above copyright notice and this permission notice shall be included
      18             :  * in all copies or substantial portions of the Software.
      19             :  *
      20             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      21             :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      22             :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      23             :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      24             :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      25             :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      26             :  * DEALINGS IN THE SOFTWARE.
      27             :  ****************************************************************************/
      28             : 
      29             : #include "gdal_unit_test.h"
      30             : 
      31             : #include "cpl_error.h"
      32             : #include "cpl_string.h"
      33             : #include "gdal_priv.h"
      34             : #include "gdal_utils.h"
      35             : 
      36             : #include "gtest_include.h"
      37             : 
      38             : namespace
      39             : {
      40             : 
      41             : struct test_utilities : public ::testing::Test
      42             : {
      43             : };
      44             : 
      45           4 : TEST_F(test_utilities, GDALFootprint)
      46             : {
      47           2 :     CPLErrorHandlerPusher oQuietErrors(CPLQuietErrorHandler);
      48             :     // Test if (pszDest == nullptr && hDstDS == nullptr)
      49           1 :     EXPECT_EQ(GDALFootprint(/* pszDest = */ nullptr,
      50             :                             /* hDstDS = */ nullptr,
      51             :                             /* hSrcDataset = */ nullptr,
      52             :                             /* psOptionsIn = */ nullptr,
      53             :                             /* pbUsageError = */ nullptr),
      54             :               nullptr);
      55             : 
      56             :     // Test if (hSrcDataset == nullptr)
      57           1 :     EXPECT_EQ(GDALFootprint(/* pszDest = */ "/vsimem/out",
      58             :                             /* hDstDS = */ nullptr,
      59             :                             /* hSrcDataset = */ nullptr,
      60             :                             /* psOptionsIn = */ nullptr,
      61             :                             /* pbUsageError = */ nullptr),
      62             :               nullptr);
      63             : 
      64             :     // Test if (hDstDS != nullptr && psOptionsIn && psOptionsIn->bCreateOutput)
      65             :     {
      66           2 :         CPLStringList aosArgv;
      67           1 :         aosArgv.AddString("-of");
      68           1 :         aosArgv.AddString("Memory");
      69           1 :         auto poMemDrv = GetGDALDriverManager()->GetDriverByName("Memory");
      70           1 :         if (poMemDrv)
      71             :         {
      72           1 :             auto psOptions = GDALFootprintOptionsNew(aosArgv.List(), nullptr);
      73             :             auto poInDS = std::unique_ptr<GDALDataset>(
      74           2 :                 poMemDrv->Create("", 0, 0, 0, GDT_Unknown, nullptr));
      75             :             auto poOutDS = std::unique_ptr<GDALDataset>(
      76           2 :                 poMemDrv->Create("", 0, 0, 0, GDT_Unknown, nullptr));
      77           1 :             EXPECT_EQ(
      78             :                 GDALFootprint(
      79             :                     /* pszDest = */ nullptr,
      80             :                     /* hDstDS = */ GDALDataset::ToHandle(poOutDS.get()),
      81             :                     /* hSrcDataset = */ GDALDataset::ToHandle(poInDS.get()),
      82             :                     /* psOptionsIn = */ psOptions,
      83             :                     /* pbUsageError = */ nullptr),
      84             :                 nullptr);
      85           1 :             GDALFootprintOptionsFree(psOptions);
      86             :         }
      87             :     }
      88             : 
      89             :     // Test if (psOptions == nullptr)
      90             :     // and if (poSrcDS->GetRasterCount() == 0)
      91             :     {
      92           1 :         auto poMemDrv = GetGDALDriverManager()->GetDriverByName("Memory");
      93           1 :         if (poMemDrv)
      94             :         {
      95             :             auto poInDS = std::unique_ptr<GDALDataset>(
      96           2 :                 poMemDrv->Create("", 0, 0, 0, GDT_Unknown, nullptr));
      97             :             auto poOutDS = std::unique_ptr<GDALDataset>(
      98           2 :                 poMemDrv->Create("", 0, 0, 0, GDT_Unknown, nullptr));
      99           1 :             EXPECT_EQ(
     100             :                 GDALFootprint(
     101             :                     /* pszDest = */ nullptr,
     102             :                     /* hDstDS = */ GDALDataset::ToHandle(poOutDS.get()),
     103             :                     /* hSrcDataset = */ GDALDataset::ToHandle(poInDS.get()),
     104             :                     /* psOptionsIn = */ nullptr,
     105             :                     /* pbUsageError = */ nullptr),
     106             :                 nullptr);
     107             :         }
     108             :     }
     109           1 : }
     110             : 
     111             : }  // namespace

Generated by: LCOV version 1.14