2222#include " cpl_compressor.h"
2323#include " cpl_enumerate.h"
2424#include " cpl_error.h"
25+ #include " cpl_error_internal.h"
2526#include " cpl_float.h"
2627#include " cpl_hash_set.h"
2728#include " cpl_levenshtein.h"
@@ -1253,6 +1254,7 @@ TEST_F(test_cpl, CPLSetErrorHandler)
12531254 ASSERT_EQ (gbGotError, false );
12541255 gbGotError = false ;
12551256 CPLSetErrorHandler (oldHandler);
1257+ CPLSetCurrentErrorHandlerCatchDebug (true );
12561258
12571259 CPLPushErrorHandler (myErrorHandler);
12581260 CPLSetCurrentErrorHandlerCatchDebug (FALSE );
@@ -1274,6 +1276,45 @@ TEST_F(test_cpl, CPLSetErrorHandler)
12741276 CPLSetErrorHandler (oldHandler);
12751277}
12761278
1279+ TEST_F (test_cpl, global_error_handler_and_CPLSetCurrentErrorHandlerCatchDebug)
1280+ {
1281+ static bool gbGotDebugMessage = false ;
1282+ static bool gbGotExpectedUserData = false ;
1283+
1284+ struct MyStruct
1285+ {
1286+ static void CPL_STDCALL myErrorHandler (CPLErr eErr, CPLErrorNum,
1287+ const char *msg)
1288+ {
1289+ if (CPLGetErrorHandlerUserData () == &gbGotExpectedUserData)
1290+ {
1291+ gbGotExpectedUserData = true ;
1292+ }
1293+ if (eErr == CE_Debug && strcmp (msg, " TEST: my debug message" ) == 0 )
1294+ {
1295+ gbGotDebugMessage = true ;
1296+ }
1297+ }
1298+ };
1299+
1300+ CPLErrorHandler oldHandler =
1301+ CPLSetErrorHandlerEx (MyStruct::myErrorHandler, &gbGotExpectedUserData);
1302+
1303+ CPLErrorAccumulator oAccumulator;
1304+ {
1305+ auto scopedAccumulator = oAccumulator.InstallForCurrentScope ();
1306+ CPL_IGNORE_RET_VAL (scopedAccumulator);
1307+
1308+ CPLConfigOptionSetter oSetter (" CPL_DEBUG" , " ON" , false );
1309+ CPLDebug (" TEST" , " my debug message" );
1310+ }
1311+
1312+ EXPECT_TRUE (gbGotExpectedUserData);
1313+ EXPECT_TRUE (gbGotDebugMessage);
1314+
1315+ CPLSetErrorHandler (oldHandler);
1316+ }
1317+
12771318/* ***********************************************************************/
12781319/* CPLString::replaceAll() */
12791320/* ***********************************************************************/
0 commit comments