Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: GDAL 4 : * Purpose: Test deferred plugin loading 5 : * Author: Even Rouault, even.rouault at spatialys.com 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2023, Even Rouault <even.rouault at spatialys.com> 9 : * 10 : * SPDX-License-Identifier: MIT 11 : ****************************************************************************/ 12 : 13 : #include "gdal_priv.h" 14 : 15 : #include "gtest_include.h" 16 : 17 : #include "test_data.h" 18 : 19 : namespace 20 : { 21 : 22 : // --------------------------------------------------------------------------- 23 : 24 4 : TEST(test_deferredplugin, test_missing) 25 : { 26 : #ifdef JPEG_PLUGIN 27 : CPLSetConfigOption("GDAL_DRIVER_PATH", "/i/do_not_exist"); 28 : GDALAllRegister(); 29 : CPLSetConfigOption("GDAL_DRIVER_PATH", nullptr); 30 : GDALDriverH hDrv = GDALGetDriverByName("JPEG"); 31 : EXPECT_EQ(hDrv, nullptr); 32 : CPLPushErrorHandler(CPLQuietErrorHandler); 33 : GDALClose( 34 : GDALOpen(GDRIVERS_DIR "data/jpeg/byte_with_xmp.jpg", GA_ReadOnly)); 35 : CPLPopErrorHandler(); 36 : EXPECT_TRUE( 37 : strstr(CPLGetLastErrorMsg(), 38 : "It could have been recognized by driver JPEG, but plugin") != 39 : nullptr); 40 : #else 41 1 : GTEST_SKIP() << "JPEG driver not built or not built as a plugin"; 42 : #endif 43 : } 44 : 45 4 : TEST(test_deferredplugin, test_nominal) 46 : { 47 : #ifdef JPEG_PLUGIN 48 : GDALAllRegister(); 49 : GDALDriverH hDrv = GDALGetDriverByName("JPEG"); 50 : ASSERT_NE(hDrv, nullptr); 51 : EXPECT_NE(GDALDriver::FromHandle(hDrv)->pfnIdentify, nullptr); 52 : EXPECT_STREQ(GDALGetMetadataItem(hDrv, GDAL_DCAP_OPEN, nullptr), "YES"); 53 : EXPECT_EQ(GDALDriver::FromHandle(hDrv)->pfnOpen, nullptr); 54 : GDALDatasetH hDS = 55 : GDALOpen(GDRIVERS_DIR "data/jpeg/byte_with_xmp.jpg", GA_ReadOnly); 56 : EXPECT_NE(hDS, nullptr); 57 : EXPECT_NE(GDALDriver::FromHandle(hDrv)->pfnOpen, nullptr); 58 : GDALClose(hDS); 59 : #else 60 1 : GTEST_SKIP() << "JPEG driver not built or not built as a plugin"; 61 : #endif 62 : } 63 : 64 : } // namespace