Skip to content

Commit

Permalink
projCtx_t: Copy ini file settings, proj4_init_rules, etc.. when initi…
Browse files Browse the repository at this point in the history
…alizing context from global
  • Loading branch information
snowman2 committed Aug 20, 2020
1 parent 2b3475c commit eb040aa
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/ctx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
45 changes: 45 additions & 0 deletions test/unit/test_c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit eb040aa

Please sign in to comment.