From eb040aaac5b47d6fbb182c16a911b4db0de02b4c Mon Sep 17 00:00:00 2001 From: snowman2 Date: Wed, 19 Aug 2020 20:12:01 -0500 Subject: [PATCH] projCtx_t: Copy ini file settings, proj4_init_rules, etc.. when initializing context from global --- src/ctx.cpp | 10 +++++++++ test/unit/test_c_api.cpp | 45 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/src/ctx.cpp b/src/ctx.cpp index c2b3064452..29758ac0a6 100644 --- a/src/ctx.cpp +++ b/src/ctx.cpp @@ -173,12 +173,22 @@ projCtx_t::projCtx_t(const projCtx_t& other) logger = other.logger; logger_app_data = other.logger_app_data; fileapi_legacy = other.fileapi_legacy; + use_proj4_init_rules = other.use_proj4_init_rules; epsg_file_exists = other.epsg_file_exists; + env_var_proj_lib = other.env_var_proj_lib; set_search_paths(other.search_paths); + user_writable_directory = other.user_writable_directory; file_finder = other.file_finder; file_finder_legacy = other.file_finder_legacy; file_finder_user_data = other.file_finder_user_data; + custom_sqlite3_vfs_name = other.custom_sqlite3_vfs_name; + // BEGIN ini file settings + iniFileLoaded = other.iniFileLoaded; + gridChunkCache = other.gridChunkCache; + endpoint = other.endpoint; networking = other.networking; + defaultTmercAlgo = other.defaultTmercAlgo; + // END ini file settings ca_bundle_path = other.ca_bundle_path; if (other.cpp_context != nullptr) { cpp_context = other.cpp_context->clone(this); diff --git a/test/unit/test_c_api.cpp b/test/unit/test_c_api.cpp index 9fe486b7b5..ad87520932 100644 --- a/test/unit/test_c_api.cpp +++ b/test/unit/test_c_api.cpp @@ -4797,6 +4797,51 @@ TEST_F(CApi, proj_context_set_sqlite3_vfs_name) { // --------------------------------------------------------------------------- +TEST_F(CApi, proj_context_set_sqlite3_vfs_name__from_global_context) { + + // Set a dummy VFS and check it is taken into account + // (failure to open proj.db) + proj_context_set_sqlite3_vfs_name(nullptr, "dummy_vfs_name"); + + PJ_CONTEXT *ctx = proj_context_create(); + proj_log_func(ctx, nullptr, [](void *, int, const char *) -> void {}); + + ASSERT_EQ(proj_create(ctx, "EPSG:4326"), nullptr); + + // Restore default VFS + proj_context_set_sqlite3_vfs_name(nullptr, nullptr); + proj_context_destroy(ctx); +} + +// --------------------------------------------------------------------------- + +TEST_F(CApi, use_proj4_init_rules) { + PJ_CONTEXT *ctx = proj_context_create(); + proj_context_use_proj4_init_rules(nullptr, true); + ASSERT_TRUE(proj_context_get_use_proj4_init_rules(ctx, true)); + proj_context_use_proj4_init_rules(nullptr, false); + ASSERT_TRUE(!proj_context_get_use_proj4_init_rules(ctx, true)); + proj_context_destroy(ctx); +} + +// --------------------------------------------------------------------------- + +TEST_F(CApi, use_proj4_init_rules__from_global_context) { + + bool initial_rules = proj_context_get_use_proj4_init_rules(nullptr, true); + proj_context_use_proj4_init_rules(nullptr, true); + PJ_CONTEXT *ctx = proj_context_create(); + ASSERT_TRUE(proj_context_get_use_proj4_init_rules(ctx, true)); + proj_context_destroy(ctx); + proj_context_use_proj4_init_rules(nullptr, false); + ctx = proj_context_create(); + ASSERT_TRUE(!proj_context_get_use_proj4_init_rules(ctx, true)); + proj_context_destroy(ctx); + proj_context_use_proj4_init_rules(nullptr, initial_rules); +} + +// --------------------------------------------------------------------------- + TEST_F(CApi, proj_is_equivalent_to_with_ctx) { auto from_epsg = proj_create_from_database(m_ctxt, "EPSG", "7844", PJ_CATEGORY_CRS, false, nullptr);