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

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

Generated by: LCOV version 1.14