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