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: 2025-01-18 12:42:00 Functions: 5 5 100.0 %

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

Generated by: LCOV version 1.14