Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

projCtx_t: Copy ini file settings, proj4_init_rules, etc.. when initializing context from global #2331

Merged
merged 5 commits into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ install_manifest.txt
/data/stlrnc
/data/stpaul
/data/tv_out
/data/for_tests/

# docs
tmp_breathe
Expand All @@ -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

Expand All @@ -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
36 changes: 22 additions & 14 deletions src/ctx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/************************************************************************/
Expand Down
11 changes: 6 additions & 5 deletions src/proj_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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&);
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(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);
Expand Down