Line data Source code
1 : /****************************************************************************** 2 : * $Id$ 3 : * 4 : * Project: GDAL 5 : * Purpose: Test deferred plugin loading 6 : * Author: Even Rouault, even.rouault at spatialys.com 7 : * 8 : ****************************************************************************** 9 : * Copyright (c) 2023, Even Rouault <even.rouault at spatialys.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 "gdal_priv.h" 31 : 32 : #include "gtest_include.h" 33 : 34 : #include "test_data.h" 35 : 36 : namespace 37 : { 38 : 39 : // --------------------------------------------------------------------------- 40 : 41 4 : TEST(test_deferredplugin, test_missing) 42 : { 43 : #ifdef JPEG_PLUGIN 44 : CPLSetConfigOption("GDAL_DRIVER_PATH", "/i/do_not_exist"); 45 : GDALAllRegister(); 46 : CPLSetConfigOption("GDAL_DRIVER_PATH", nullptr); 47 : GDALDriverH hDrv = GDALGetDriverByName("JPEG"); 48 : EXPECT_EQ(hDrv, nullptr); 49 : CPLPushErrorHandler(CPLQuietErrorHandler); 50 : GDALClose( 51 : GDALOpen(GDRIVERS_DIR "data/jpeg/byte_with_xmp.jpg", GA_ReadOnly)); 52 : CPLPopErrorHandler(); 53 : EXPECT_TRUE( 54 : strstr(CPLGetLastErrorMsg(), 55 : "It could have been recognized by driver JPEG, but plugin") != 56 : nullptr); 57 : #else 58 1 : GTEST_SKIP() << "JPEG driver not built or not built as a plugin"; 59 : #endif 60 : } 61 : 62 4 : TEST(test_deferredplugin, test_nominal) 63 : { 64 : #ifdef JPEG_PLUGIN 65 : GDALAllRegister(); 66 : GDALDriverH hDrv = GDALGetDriverByName("JPEG"); 67 : ASSERT_NE(hDrv, nullptr); 68 : EXPECT_NE(GDALDriver::FromHandle(hDrv)->pfnIdentify, nullptr); 69 : EXPECT_STREQ(GDALGetMetadataItem(hDrv, GDAL_DCAP_OPEN, nullptr), "YES"); 70 : EXPECT_EQ(GDALDriver::FromHandle(hDrv)->pfnOpen, nullptr); 71 : GDALDatasetH hDS = 72 : GDALOpen(GDRIVERS_DIR "data/jpeg/byte_with_xmp.jpg", GA_ReadOnly); 73 : EXPECT_NE(hDS, nullptr); 74 : EXPECT_NE(GDALDriver::FromHandle(hDrv)->pfnOpen, nullptr); 75 : GDALClose(hDS); 76 : #else 77 1 : GTEST_SKIP() << "JPEG driver not built or not built as a plugin"; 78 : #endif 79 : } 80 : 81 : } // namespace