diff --git a/.gitignore b/.gitignore index 16a1f87259..5f9508c30e 100644 --- a/.gitignore +++ b/.gitignore @@ -93,6 +93,7 @@ install_manifest.txt /data/stlrnc /data/stpaul /data/tv_out +/data/for_tests/ # docs tmp_breathe @@ -117,6 +118,7 @@ m4/lt~obsolete.m4 /src/proj_config.h /src/proj_config.h.in /src/projinfo +/src/projsync /src/stamp-h1 /src/test-suite.log @@ -130,6 +132,9 @@ m4/lt~obsolete.m4 /test/unit/proj_context_test /test/unit/test_cpp_api /test/unit/proj_errno_string_test +/test/unit/test_defmodel +/test/unit/test_network +/tmp_alias/ # jniwrap jniwrap/out diff --git a/src/ctx.cpp b/src/ctx.cpp index c2b3064452..5575d3aa93 100644 --- a/src/ctx.cpp +++ b/src/ctx.cpp @@ -167,22 +167,30 @@ void projCtx_t::set_ca_bundle_path(const std::string& ca_bundle_path_in) /* projCtx_t(const projCtx_t& other) */ /************************************************************************/ -projCtx_t::projCtx_t(const projCtx_t& other) +projCtx_t::projCtx_t(const projCtx_t& other) : + debug_level(other.debug_level), + logger(other.logger), + logger_app_data(other.logger_app_data), + fileapi_legacy(other.fileapi_legacy), + cpp_context(other.cpp_context ? other.cpp_context->clone(this) : nullptr), + use_proj4_init_rules(other.use_proj4_init_rules), + epsg_file_exists(other.epsg_file_exists), + ca_bundle_path(other.ca_bundle_path), + env_var_proj_lib(other.env_var_proj_lib), + file_finder_legacy(other.file_finder_legacy), + file_finder(other.file_finder), + file_finder_user_data(other.file_finder_user_data), + custom_sqlite3_vfs_name(other.custom_sqlite3_vfs_name), + user_writable_directory(other.user_writable_directory), + // BEGIN ini file settings + iniFileLoaded(other.iniFileLoaded), + endpoint(other.endpoint), + networking(other.networking), + gridChunkCache(other.gridChunkCache), + defaultTmercAlgo(other.defaultTmercAlgo) + // END ini file settings { - debug_level = other.debug_level; - logger = other.logger; - logger_app_data = other.logger_app_data; - fileapi_legacy = other.fileapi_legacy; - epsg_file_exists = other.epsg_file_exists; set_search_paths(other.search_paths); - file_finder = other.file_finder; - file_finder_legacy = other.file_finder_legacy; - file_finder_user_data = other.file_finder_user_data; - networking = other.networking; - ca_bundle_path = other.ca_bundle_path; - if (other.cpp_context != nullptr) { - cpp_context = other.cpp_context->clone(this); - } } /************************************************************************/ diff --git a/src/proj_internal.h b/src/proj_internal.h index 01da337b5f..79b1da1045 100644 --- a/src/proj_internal.h +++ b/src/proj_internal.h @@ -735,22 +735,23 @@ struct projCtx_t { const char* (*file_finder) (PJ_CONTEXT *, const char*, void* user_data) = nullptr; void* file_finder_user_data = nullptr; - projNetworkCallbacksAndData networking{}; - bool defer_grid_opening = false; // set by pj_obj_create() + bool defer_grid_opening = false; // set transiently by pj_obj_create() projFileApiCallbackAndData fileApi{}; std::string custom_sqlite3_vfs_name{}; + std::string user_writable_directory{}; + // BEGIN ini file settings bool iniFileLoaded = false; std::string endpoint{}; - - std::string user_writable_directory{}; + projNetworkCallbacksAndData networking{}; projGridChunkCache gridChunkCache{}; + TMercAlgo defaultTmercAlgo = TMercAlgo::PODER_ENGSAGER; // can be overridden by content of proj.ini + // END ini file settings int projStringParserCreateFromPROJStringRecursionCounter = 0; // to avoid potential infinite recursion in PROJStringParser::createFromPROJString() int pipelineInitRecursiongCounter = 0; // to avoid potential infinite recursion in pipeline.cpp - TMercAlgo defaultTmercAlgo = TMercAlgo::PODER_ENGSAGER; // can be overridden by content of proj.ini projCtx_t() = default; projCtx_t(const projCtx_t&); diff --git a/test/unit/test_c_api.cpp b/test/unit/test_c_api.cpp index 9fe486b7b5..947b993c13 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(ctx, true); + ASSERT_TRUE(proj_context_get_use_proj4_init_rules(ctx, true)); + proj_context_use_proj4_init_rules(ctx, 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) { + + int 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);