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 : * Permission is hereby granted, free of charge, to any person obtaining a
12 : * copy of this software and associated documentation files (the "Software"),
13 : * to deal in the Software without restriction, including without limitation
14 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 : * and/or sell copies of the Software, and to permit persons to whom the
16 : * Software is furnished to do so, subject to the following conditions:
17 : *
18 : * The above copyright notice and this permission notice shall be included
19 : * in all copies or substantial portions of the Software.
20 : *
21 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 : * DEALINGS IN THE SOFTWARE.
28 : ****************************************************************************/
29 :
30 : #include "cpl_conv.h"
31 : #include "cpl_string.h"
32 : #include "gdal_alg.h"
33 : #include "gdal_priv.h"
34 : #include "gdal.h"
35 :
36 : #include "test_data.h"
37 :
38 : #include "gtest_include.h"
39 :
40 : namespace
41 : {
42 :
43 : // ---------------------------------------------------------------------------
44 :
45 1 : static void OpenJPEG2000(const char *pszFilename)
46 : {
47 1 : const int N_DRIVERS = 6;
48 1 : const char *const apszDrivers[] = {"JP2ECW", "JP2OpenJPEG", "JPEG2000",
49 : "JP2MrSID", "JP2KAK", "JP2Lura"};
50 : GDALDriverH aphDrivers[N_DRIVERS];
51 : GDALDatasetH hDS;
52 : int i, j;
53 :
54 7 : for (i = 0; i < N_DRIVERS; i++)
55 6 : aphDrivers[i] = GDALGetDriverByName(apszDrivers[i]);
56 :
57 7 : for (i = 0; i < N_DRIVERS; i++)
58 : {
59 6 : if (aphDrivers[i] == nullptr)
60 4 : continue;
61 14 : for (j = 0; j < N_DRIVERS; j++)
62 : {
63 12 : if (i == j || aphDrivers[j] == nullptr)
64 10 : continue;
65 2 : GDALDeregisterDriver(aphDrivers[j]);
66 : }
67 :
68 2 : hDS = GDALOpen(pszFilename, GA_ReadOnly);
69 2 : if (!EQUAL(apszDrivers[i], "JP2Lura") &&
70 2 : !EQUAL(apszDrivers[i], "JPEG2000"))
71 : {
72 2 : ASSERT_TRUE(hDS != nullptr);
73 : }
74 14 : for (j = 0; j < N_DRIVERS; j++)
75 : {
76 12 : if (i == j || aphDrivers[j] == nullptr)
77 10 : continue;
78 2 : GDALRegisterDriver(aphDrivers[j]);
79 : }
80 : }
81 : }
82 :
83 : // ---------------------------------------------------------------------------
84 :
85 4 : TEST(testclosedondestroydm, test)
86 : {
87 : int nOvrLevel;
88 : int nBandNum;
89 : GDALDatasetH hDS;
90 : GDALDatasetH hSrcDS;
91 : FILE *f;
92 :
93 1 : const char *pszGDAL_SKIP = CPLGetConfigOption("GDAL_SKIP", nullptr);
94 1 : if (pszGDAL_SKIP == nullptr)
95 1 : CPLSetConfigOption("GDAL_SKIP", "GIF");
96 : else
97 0 : CPLSetConfigOption("GDAL_SKIP", CPLSPrintf("%s GIF", pszGDAL_SKIP));
98 :
99 1 : GDALAllRegister();
100 :
101 1 : hDS = GDALOpen(GCORE_DATA_DIR "byte.tif", GA_ReadOnly);
102 1 : if (hDS)
103 1 : GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0,
104 : GDALGetRasterXSize(hDS), GDALGetRasterYSize(hDS));
105 :
106 1 : hDS = GDALOpen(GCORE_DATA_DIR "byte.vrt", GA_ReadOnly);
107 1 : if (hDS)
108 1 : GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0,
109 : GDALGetRasterXSize(hDS), GDALGetRasterYSize(hDS));
110 :
111 1 : hDS = GDALOpen(GDRIVERS_DIR "data/vrt/rgb_warp.vrt", GA_ReadOnly);
112 1 : if (hDS)
113 1 : GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0,
114 : GDALGetRasterXSize(hDS), GDALGetRasterYSize(hDS));
115 :
116 1 : hDS = GDALOpen(GDRIVERS_DIR "data/nitf/A.TOC", GA_ReadOnly);
117 :
118 1 : hDS = GDALOpen("NITF_TOC_ENTRY:CADRG_ONC_1,000,000_2_0:" GDRIVERS_DIR
119 : "data/nitf/A.TOC",
120 : GA_ReadOnly);
121 1 : if (hDS)
122 1 : GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0,
123 : GDALGetRasterXSize(hDS), GDALGetRasterYSize(hDS));
124 :
125 1 : hDS = GDALOpen(GDRIVERS_DIR "data/til/testtil.til", GA_ReadOnly);
126 1 : if (hDS)
127 1 : GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0,
128 : GDALGetRasterXSize(hDS), GDALGetRasterYSize(hDS));
129 :
130 1 : hDS = GDALOpen(GDRIVERS_DIR "data/rs2/product.xml", GA_ReadOnly);
131 1 : if (hDS)
132 1 : GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0,
133 : GDALGetRasterXSize(hDS), GDALGetRasterYSize(hDS));
134 :
135 1 : hDS = GDALOpen(GDRIVERS_DIR "data/dimap/METADATA.DIM", GA_ReadOnly);
136 1 : if (hDS)
137 1 : GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0,
138 : GDALGetRasterXSize(hDS), GDALGetRasterYSize(hDS));
139 :
140 1 : hDS = GDALOpen(GDRIVERS_DIR "tmp/cache/file9_j2c.ntf", GA_ReadOnly);
141 1 : if (hDS)
142 0 : GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0,
143 : GDALGetRasterXSize(hDS), GDALGetRasterYSize(hDS));
144 :
145 1 : hDS = GDALOpen(GDRIVERS_DIR "data/gif/bug407.gif", GA_ReadOnly);
146 1 : if (hDS)
147 : {
148 1 : GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0,
149 : GDALGetRasterXSize(hDS), GDALGetRasterYSize(hDS));
150 1 : GDALSetCacheMax(0);
151 1 : GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0,
152 : GDALGetRasterXSize(hDS), GDALGetRasterYSize(hDS));
153 : }
154 :
155 : /* Create external overviews */
156 1 : hSrcDS = GDALOpen(GCORE_DATA_DIR "byte.tif", GA_ReadOnly);
157 1 : hDS = GDALCreateCopy(GDALGetDriverByName("GTiff"), "byte.tif", hSrcDS, 0,
158 : nullptr, nullptr, nullptr);
159 1 : GDALClose(hSrcDS);
160 1 : hSrcDS = nullptr;
161 1 : hDS = GDALOpen("byte.tif", GA_ReadOnly);
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("byte.tif", GA_ReadOnly);
169 1 : GDALGetOverviewCount(GDALGetRasterBand(hDS, 1));
170 :
171 : /* Create internal overviews */
172 1 : hSrcDS = GDALOpen(GCORE_DATA_DIR "byte.tif", GA_ReadOnly);
173 1 : hDS = GDALCreateCopy(GDALGetDriverByName("GTiff"), "byte2.tif", hSrcDS, 0,
174 : nullptr, nullptr, nullptr);
175 1 : GDALClose(hSrcDS);
176 1 : hSrcDS = nullptr;
177 1 : hDS = GDALOpen("byte2.tif", GA_Update);
178 1 : nOvrLevel = 2;
179 1 : nBandNum = 1;
180 1 : CPL_IGNORE_RET_VAL(GDALBuildOverviews(hDS, "NEAR", 1, &nOvrLevel, 1,
181 : &nBandNum, nullptr, nullptr));
182 1 : GDALClose(hDS);
183 :
184 1 : hDS = GDALOpen("byte2.tif", GA_ReadOnly);
185 1 : GDALGetOverviewCount(GDALGetRasterBand(hDS, 1));
186 :
187 : /* Create external mask */
188 1 : hSrcDS = GDALOpen(GCORE_DATA_DIR "byte.tif", GA_ReadOnly);
189 1 : hDS = GDALCreateCopy(GDALGetDriverByName("GTiff"), "byte3.tif", hSrcDS, 0,
190 : nullptr, nullptr, nullptr);
191 1 : GDALClose(hSrcDS);
192 1 : hSrcDS = nullptr;
193 1 : hDS = GDALOpen("byte3.tif", GA_ReadOnly);
194 1 : GDALCreateDatasetMaskBand(hDS, GMF_PER_DATASET);
195 1 : GDALClose(hDS);
196 :
197 1 : hDS = GDALOpen("byte3.tif", GA_ReadOnly);
198 1 : GDALGetMaskFlags(GDALGetRasterBand(hDS, 1));
199 :
200 1 : f = fopen("byte.vrt", "wb");
201 1 : fprintf(f, "%s",
202 : "<VRTDataset rasterXSize=\"20\" rasterYSize=\"20\">"
203 : "<VRTRasterBand dataType=\"Byte\" band=\"1\">"
204 : "<SimpleSource>"
205 : "<SourceFilename relativeToVRT=\"1\">" GCORE_DATA_DIR
206 : "byte.tif</SourceFilename>"
207 : "<SourceBand>1</SourceBand>"
208 : "<SourceProperties RasterXSize=\"20\" RasterYSize=\"20\" "
209 : "DataType=\"Byte\" BlockXSize=\"20\" BlockYSize=\"20\" />"
210 : "<SrcRect xOff=\"0\" yOff=\"0\" xSize=\"20\" ySize=\"20\"/>"
211 : "<DstRect xOff=\"0\" yOff=\"0\" xSize=\"20\" ySize=\"20\"/>"
212 : "</SimpleSource>"
213 : "</VRTRasterBand>"
214 : "</VRTDataset>");
215 1 : fclose(f);
216 :
217 1 : hDS = GDALOpen("byte.vrt", GA_ReadOnly);
218 1 : nOvrLevel = 2;
219 1 : nBandNum = 1;
220 1 : CPL_IGNORE_RET_VAL(GDALBuildOverviews(hDS, "NEAR", 1, &nOvrLevel, 1,
221 : &nBandNum, nullptr, nullptr));
222 1 : GDALClose(hDS);
223 :
224 1 : hDS = GDALOpen("byte.vrt", GA_ReadOnly);
225 1 : GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0, GDALGetRasterXSize(hDS),
226 : GDALGetRasterYSize(hDS));
227 1 : GDALGetOverviewCount(GDALGetRasterBand(hDS, 1));
228 :
229 : hDS =
230 1 : GDALOpen("<VRTDataset rasterXSize=\"20\" rasterYSize=\"20\">"
231 : "<VRTRasterBand dataType=\"Byte\" band=\"1\">"
232 : "<SimpleSource>"
233 : "<SourceFilename relativeToVRT=\"1\">byte.vrt</SourceFilename>"
234 : "<SourceBand>1</SourceBand>"
235 : "<SourceProperties RasterXSize=\"20\" RasterYSize=\"20\" "
236 : "DataType=\"Byte\" BlockXSize=\"20\" BlockYSize=\"20\" />"
237 : "<SrcRect xOff=\"0\" yOff=\"0\" xSize=\"20\" ySize=\"20\"/>"
238 : "<DstRect xOff=\"0\" yOff=\"0\" xSize=\"20\" ySize=\"20\"/>"
239 : "</SimpleSource>"
240 : "</VRTRasterBand>"
241 : "</VRTDataset>",
242 : GA_ReadOnly);
243 1 : GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0, GDALGetRasterXSize(hDS),
244 : GDALGetRasterYSize(hDS));
245 :
246 1 : hDS = GDALOpenShared(GCORE_DATA_DIR "byte.tif", GA_ReadOnly);
247 1 : hDS = GDALOpenShared(GCORE_DATA_DIR "byte.tif", GA_ReadOnly);
248 :
249 1 : hDS = GDALOpenShared(GDRIVERS_DIR "data/sid/mercator.sid", GA_ReadOnly);
250 :
251 1 : hDS = GDALOpen("RASTERLITE:" GDRIVERS_DIR
252 : "data/rasterlite/rasterlite_pyramids.sqlite,table=test",
253 : GA_ReadOnly);
254 1 : hDS = GDALOpen(
255 : "RASTERLITE:" GDRIVERS_DIR
256 : "data/rasterlite/rasterlite_pyramids.sqlite,table=test,level=1",
257 : GA_ReadOnly);
258 :
259 1 : OpenJPEG2000(GDRIVERS_DIR "data/jpeg2000/rgbwcmyk01_YeGeo_kakadu.jp2");
260 :
261 1 : hDS = GDALOpen(GDRIVERS_DIR "tmp/cache/Europe 2001_OZF.map", GA_ReadOnly);
262 :
263 1 : CPLDebug("TEST", "Call GDALDestroyDriverManager()");
264 1 : GDALDestroyDriverManager();
265 :
266 1 : unlink("byte.tif");
267 1 : unlink("byte.tif.ovr");
268 1 : unlink("byte2.tif");
269 1 : unlink("byte3.tif");
270 1 : unlink("byte3.tif.msk");
271 1 : unlink("byte.vrt");
272 1 : unlink("byte.vrt.ovr");
273 1 : }
274 :
275 : } // namespace
|