LCOV - code coverage report
Current view: top level - autotest/cpp - testclosedondestroydm.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 115 117 98.3 %
Date: 2024-11-21 22:18:42 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  * $Id$
       3             :  *
       4             :  * Project:  GDAL Core
       5             :  * Purpose:  Test block cache & writing behaviour under multi-threading
       6             :  * Author:   Even Rouault, <even dot rouault at spatialys dot com>
       7             :  *
       8             :  ******************************************************************************
       9             :  * Copyright (c) 2011, Even Rouault <even dot rouault at spatialys dot com>
      10             :  *
      11             :  * SPDX-License-Identifier: MIT
      12             :  ****************************************************************************/
      13             : 
      14             : #include "cpl_conv.h"
      15             : #include "cpl_string.h"
      16             : #include "gdal_alg.h"
      17             : #include "gdal_priv.h"
      18             : #include "gdal.h"
      19             : 
      20             : #include "test_data.h"
      21             : 
      22             : #include "gtest_include.h"
      23             : 
      24             : namespace
      25             : {
      26             : 
      27             : // ---------------------------------------------------------------------------
      28             : 
      29           1 : static void OpenJPEG2000(const char *pszFilename)
      30             : {
      31           1 :     const int N_DRIVERS = 6;
      32           1 :     const char *const apszDrivers[] = {"JP2ECW",   "JP2OpenJPEG", "JPEG2000",
      33             :                                        "JP2MrSID", "JP2KAK",      "JP2Lura"};
      34             :     GDALDriverH aphDrivers[N_DRIVERS];
      35             :     GDALDatasetH hDS;
      36             :     int i, j;
      37             : 
      38           7 :     for (i = 0; i < N_DRIVERS; i++)
      39           6 :         aphDrivers[i] = GDALGetDriverByName(apszDrivers[i]);
      40             : 
      41           7 :     for (i = 0; i < N_DRIVERS; i++)
      42             :     {
      43           6 :         if (aphDrivers[i] == nullptr)
      44           4 :             continue;
      45          14 :         for (j = 0; j < N_DRIVERS; j++)
      46             :         {
      47          12 :             if (i == j || aphDrivers[j] == nullptr)
      48          10 :                 continue;
      49           2 :             GDALDeregisterDriver(aphDrivers[j]);
      50             :         }
      51             : 
      52           2 :         hDS = GDALOpen(pszFilename, GA_ReadOnly);
      53           2 :         if (!EQUAL(apszDrivers[i], "JP2Lura") &&
      54           2 :             !EQUAL(apszDrivers[i], "JPEG2000"))
      55             :         {
      56           2 :             ASSERT_TRUE(hDS != nullptr);
      57             :         }
      58          14 :         for (j = 0; j < N_DRIVERS; j++)
      59             :         {
      60          12 :             if (i == j || aphDrivers[j] == nullptr)
      61          10 :                 continue;
      62           2 :             GDALRegisterDriver(aphDrivers[j]);
      63             :         }
      64             :     }
      65             : }
      66             : 
      67             : // ---------------------------------------------------------------------------
      68             : 
      69           4 : TEST(testclosedondestroydm, test)
      70             : {
      71             :     int nOvrLevel;
      72             :     int nBandNum;
      73             :     GDALDatasetH hDS;
      74             :     GDALDatasetH hSrcDS;
      75             :     FILE *f;
      76             : 
      77           1 :     const char *pszGDAL_SKIP = CPLGetConfigOption("GDAL_SKIP", nullptr);
      78           1 :     if (pszGDAL_SKIP == nullptr)
      79           1 :         CPLSetConfigOption("GDAL_SKIP", "GIF");
      80             :     else
      81           0 :         CPLSetConfigOption("GDAL_SKIP", CPLSPrintf("%s GIF", pszGDAL_SKIP));
      82             : 
      83           1 :     GDALAllRegister();
      84             : 
      85           1 :     hDS = GDALOpen(GCORE_DATA_DIR "byte.tif", GA_ReadOnly);
      86           1 :     if (hDS)
      87           1 :         GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0,
      88             :                           GDALGetRasterXSize(hDS), GDALGetRasterYSize(hDS));
      89             : 
      90           1 :     hDS = GDALOpen(GCORE_DATA_DIR "byte.vrt", GA_ReadOnly);
      91           1 :     if (hDS)
      92           1 :         GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0,
      93             :                           GDALGetRasterXSize(hDS), GDALGetRasterYSize(hDS));
      94             : 
      95           1 :     hDS = GDALOpen(GDRIVERS_DIR "data/vrt/rgb_warp.vrt", GA_ReadOnly);
      96           1 :     if (hDS)
      97           1 :         GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0,
      98             :                           GDALGetRasterXSize(hDS), GDALGetRasterYSize(hDS));
      99             : 
     100           1 :     hDS = GDALOpen(GDRIVERS_DIR "data/nitf/A.TOC", GA_ReadOnly);
     101             : 
     102           1 :     hDS = GDALOpen("NITF_TOC_ENTRY:CADRG_ONC_1,000,000_2_0:" GDRIVERS_DIR
     103             :                    "data/nitf/A.TOC",
     104             :                    GA_ReadOnly);
     105           1 :     if (hDS)
     106           1 :         GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0,
     107             :                           GDALGetRasterXSize(hDS), GDALGetRasterYSize(hDS));
     108             : 
     109           1 :     hDS = GDALOpen(GDRIVERS_DIR "data/til/testtil.til", GA_ReadOnly);
     110           1 :     if (hDS)
     111           1 :         GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0,
     112             :                           GDALGetRasterXSize(hDS), GDALGetRasterYSize(hDS));
     113             : 
     114           1 :     hDS = GDALOpen(GDRIVERS_DIR "data/rs2/product.xml", GA_ReadOnly);
     115           1 :     if (hDS)
     116           1 :         GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0,
     117             :                           GDALGetRasterXSize(hDS), GDALGetRasterYSize(hDS));
     118             : 
     119           1 :     hDS = GDALOpen(GDRIVERS_DIR "data/dimap/METADATA.DIM", GA_ReadOnly);
     120           1 :     if (hDS)
     121           1 :         GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0,
     122             :                           GDALGetRasterXSize(hDS), GDALGetRasterYSize(hDS));
     123             : 
     124           1 :     hDS = GDALOpen(GDRIVERS_DIR "tmp/cache/file9_j2c.ntf", GA_ReadOnly);
     125           1 :     if (hDS)
     126           0 :         GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0,
     127             :                           GDALGetRasterXSize(hDS), GDALGetRasterYSize(hDS));
     128             : 
     129           1 :     hDS = GDALOpen(GDRIVERS_DIR "data/gif/bug407.gif", GA_ReadOnly);
     130           1 :     if (hDS)
     131             :     {
     132           1 :         GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0,
     133             :                           GDALGetRasterXSize(hDS), GDALGetRasterYSize(hDS));
     134           1 :         GDALSetCacheMax(0);
     135           1 :         GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0,
     136             :                           GDALGetRasterXSize(hDS), GDALGetRasterYSize(hDS));
     137             :     }
     138             : 
     139             :     /* Create external overviews */
     140           1 :     hSrcDS = GDALOpen(GCORE_DATA_DIR "byte.tif", GA_ReadOnly);
     141           1 :     hDS = GDALCreateCopy(GDALGetDriverByName("GTiff"), "byte.tif", hSrcDS, 0,
     142             :                          nullptr, nullptr, nullptr);
     143           1 :     GDALClose(hSrcDS);
     144           1 :     hSrcDS = nullptr;
     145           1 :     hDS = GDALOpen("byte.tif", GA_ReadOnly);
     146           1 :     nOvrLevel = 2;
     147           1 :     nBandNum = 1;
     148           1 :     CPL_IGNORE_RET_VAL(GDALBuildOverviews(hDS, "NEAR", 1, &nOvrLevel, 1,
     149             :                                           &nBandNum, nullptr, nullptr));
     150           1 :     GDALClose(hDS);
     151             : 
     152           1 :     hDS = GDALOpen("byte.tif", GA_ReadOnly);
     153           1 :     GDALGetOverviewCount(GDALGetRasterBand(hDS, 1));
     154             : 
     155             :     /* Create internal overviews */
     156           1 :     hSrcDS = GDALOpen(GCORE_DATA_DIR "byte.tif", GA_ReadOnly);
     157           1 :     hDS = GDALCreateCopy(GDALGetDriverByName("GTiff"), "byte2.tif", hSrcDS, 0,
     158             :                          nullptr, nullptr, nullptr);
     159           1 :     GDALClose(hSrcDS);
     160           1 :     hSrcDS = nullptr;
     161           1 :     hDS = GDALOpen("byte2.tif", GA_Update);
     162           1 :     nOvrLevel = 2;
     163           1 :     nBandNum = 1;
     164           1 :     CPL_IGNORE_RET_VAL(GDALBuildOverviews(hDS, "NEAR", 1, &nOvrLevel, 1,
     165             :                                           &nBandNum, nullptr, nullptr));
     166           1 :     GDALClose(hDS);
     167             : 
     168           1 :     hDS = GDALOpen("byte2.tif", GA_ReadOnly);
     169           1 :     GDALGetOverviewCount(GDALGetRasterBand(hDS, 1));
     170             : 
     171             :     /* Create external mask */
     172           1 :     hSrcDS = GDALOpen(GCORE_DATA_DIR "byte.tif", GA_ReadOnly);
     173           1 :     hDS = GDALCreateCopy(GDALGetDriverByName("GTiff"), "byte3.tif", hSrcDS, 0,
     174             :                          nullptr, nullptr, nullptr);
     175           1 :     GDALClose(hSrcDS);
     176           1 :     hSrcDS = nullptr;
     177           1 :     hDS = GDALOpen("byte3.tif", GA_ReadOnly);
     178           1 :     GDALCreateDatasetMaskBand(hDS, GMF_PER_DATASET);
     179           1 :     GDALClose(hDS);
     180             : 
     181           1 :     hDS = GDALOpen("byte3.tif", GA_ReadOnly);
     182           1 :     GDALGetMaskFlags(GDALGetRasterBand(hDS, 1));
     183             : 
     184           1 :     f = fopen("byte.vrt", "wb");
     185           1 :     fprintf(f, "%s",
     186             :             "<VRTDataset rasterXSize=\"20\" rasterYSize=\"20\">"
     187             :             "<VRTRasterBand dataType=\"Byte\" band=\"1\">"
     188             :             "<SimpleSource>"
     189             :             "<SourceFilename relativeToVRT=\"1\">" GCORE_DATA_DIR
     190             :             "byte.tif</SourceFilename>"
     191             :             "<SourceBand>1</SourceBand>"
     192             :             "<SourceProperties RasterXSize=\"20\" RasterYSize=\"20\" "
     193             :             "DataType=\"Byte\" BlockXSize=\"20\" BlockYSize=\"20\" />"
     194             :             "<SrcRect xOff=\"0\" yOff=\"0\" xSize=\"20\" ySize=\"20\"/>"
     195             :             "<DstRect xOff=\"0\" yOff=\"0\" xSize=\"20\" ySize=\"20\"/>"
     196             :             "</SimpleSource>"
     197             :             "</VRTRasterBand>"
     198             :             "</VRTDataset>");
     199           1 :     fclose(f);
     200             : 
     201           1 :     hDS = GDALOpen("byte.vrt", GA_ReadOnly);
     202           1 :     nOvrLevel = 2;
     203           1 :     nBandNum = 1;
     204           1 :     CPL_IGNORE_RET_VAL(GDALBuildOverviews(hDS, "NEAR", 1, &nOvrLevel, 1,
     205             :                                           &nBandNum, nullptr, nullptr));
     206           1 :     GDALClose(hDS);
     207             : 
     208           1 :     hDS = GDALOpen("byte.vrt", GA_ReadOnly);
     209           1 :     GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0, GDALGetRasterXSize(hDS),
     210             :                       GDALGetRasterYSize(hDS));
     211           1 :     GDALGetOverviewCount(GDALGetRasterBand(hDS, 1));
     212             : 
     213             :     hDS =
     214           1 :         GDALOpen("<VRTDataset rasterXSize=\"20\" rasterYSize=\"20\">"
     215             :                  "<VRTRasterBand dataType=\"Byte\" band=\"1\">"
     216             :                  "<SimpleSource>"
     217             :                  "<SourceFilename relativeToVRT=\"1\">byte.vrt</SourceFilename>"
     218             :                  "<SourceBand>1</SourceBand>"
     219             :                  "<SourceProperties RasterXSize=\"20\" RasterYSize=\"20\" "
     220             :                  "DataType=\"Byte\" BlockXSize=\"20\" BlockYSize=\"20\" />"
     221             :                  "<SrcRect xOff=\"0\" yOff=\"0\" xSize=\"20\" ySize=\"20\"/>"
     222             :                  "<DstRect xOff=\"0\" yOff=\"0\" xSize=\"20\" ySize=\"20\"/>"
     223             :                  "</SimpleSource>"
     224             :                  "</VRTRasterBand>"
     225             :                  "</VRTDataset>",
     226             :                  GA_ReadOnly);
     227           1 :     GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0, GDALGetRasterXSize(hDS),
     228             :                       GDALGetRasterYSize(hDS));
     229             : 
     230           1 :     hDS = GDALOpenShared(GCORE_DATA_DIR "byte.tif", GA_ReadOnly);
     231           1 :     hDS = GDALOpenShared(GCORE_DATA_DIR "byte.tif", GA_ReadOnly);
     232             : 
     233           1 :     hDS = GDALOpenShared(GDRIVERS_DIR "data/sid/mercator.sid", GA_ReadOnly);
     234             : 
     235           1 :     hDS = GDALOpen("RASTERLITE:" GDRIVERS_DIR
     236             :                    "data/rasterlite/rasterlite_pyramids.sqlite,table=test",
     237             :                    GA_ReadOnly);
     238           1 :     hDS = GDALOpen(
     239             :         "RASTERLITE:" GDRIVERS_DIR
     240             :         "data/rasterlite/rasterlite_pyramids.sqlite,table=test,level=1",
     241             :         GA_ReadOnly);
     242             : 
     243           1 :     OpenJPEG2000(GDRIVERS_DIR "data/jpeg2000/rgbwcmyk01_YeGeo_kakadu.jp2");
     244             : 
     245           1 :     hDS = GDALOpen(GDRIVERS_DIR "tmp/cache/Europe 2001_OZF.map", GA_ReadOnly);
     246             : 
     247           1 :     CPLDebug("TEST", "Call GDALDestroyDriverManager()");
     248           1 :     GDALDestroyDriverManager();
     249             : 
     250           1 :     unlink("byte.tif");
     251           1 :     unlink("byte.tif.ovr");
     252           1 :     unlink("byte2.tif");
     253           1 :     unlink("byte3.tif");
     254           1 :     unlink("byte3.tif.msk");
     255           1 :     unlink("byte.vrt");
     256           1 :     unlink("byte.vrt.ovr");
     257           1 : }
     258             : 
     259             : }  // namespace

Generated by: LCOV version 1.14