Skip to content

Commit

Permalink
Merge pull request OSGeo#2934 from toonn/cross-platform-test
Browse files Browse the repository at this point in the history
test: Make CApi test cross-platform
  • Loading branch information
a0x8o committed Nov 10, 2021
1 parent 28d1083 commit b32c284
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
30 changes: 26 additions & 4 deletions src/iso19111/c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,24 @@ const char *proj_context_get_database_path(PJ_CONTEXT *ctx) {
* The returned pointer remains valid while ctx is valid, and until
* proj_context_get_database_metadata() is called.
*
* Available keys:
*
* - DATABASE.LAYOUT.VERSION.MAJOR
* - DATABASE.LAYOUT.VERSION.MINOR
* - EPSG.VERSION
* - EPSG.DATE
* - ESRI.VERSION
* - ESRI.DATE
* - IGNF.SOURCE
* - IGNF.VERSION
* - IGNF.DATE
* - NKG.SOURCE
* - NKG.VERSION
* - NKG.DATE
* - PROJ.VERSION
* - PROJ_DATA.VERSION : PROJ-data version most compatible with this database.
*
*
* @param ctx PROJ context, or NULL for default context
* @param key Metadata key. Must not be NULL
* @return value, or nullptr
Expand Down Expand Up @@ -1572,6 +1590,11 @@ const char *proj_as_wkt(PJ_CONTEXT *ctx, const PJ *obj, PJ_WKT_TYPE type,
* and until a next call to proj_as_proj_string() with the same input
* object.
*
* \warning If a CRS object was not created from a PROJ string,
* exporting to a PROJ string will in most cases
* cause a loss of information. This can potentially lead to
* erroneous transformations.
*
* This function calls
* osgeo::proj::io::IPROJStringExportable::exportToPROJString().
*
Expand Down Expand Up @@ -3707,8 +3730,8 @@ PJ *proj_alter_name(PJ_CONTEXT *ctx, const PJ *obj, const char *name) {
* @return Object that must be unreferenced with
* proj_destroy(), or NULL in case of error.
*/
PJ *proj_alter_id(PJ_CONTEXT *ctx, const PJ *obj,
const char *auth_name, const char *code) {
PJ *proj_alter_id(PJ_CONTEXT *ctx, const PJ *obj, const char *auth_name,
const char *code) {
SANITIZE_CTX(ctx);
if (!obj || !auth_name || !code) {
proj_context_errno_set(ctx, PROJ_ERR_OTHER_API_MISUSE);
Expand Down Expand Up @@ -4143,8 +4166,7 @@ PJ *proj_crs_demote_to_2D(PJ_CONTEXT *ctx, const char *crs_2D_name,
* @return Object that must be unreferenced with
* proj_destroy(), or NULL in case of error.
*/
PJ *proj_create_engineering_crs(PJ_CONTEXT *ctx,
const char *crs_name) {
PJ *proj_create_engineering_crs(PJ_CONTEXT *ctx, const char *crs_name) {
SANITIZE_CTX(ctx);
try {
return pj_obj_create(
Expand Down
2 changes: 1 addition & 1 deletion src/iso19111/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7678,7 +7678,7 @@ const std::string &PROJStringFormatter::toString() const {
iterCur = steps.erase(iterPrev, std::next(iterCur));
if (iterCur != steps.begin())
iterCur = std::prev(iterCur);
if (iterCur == steps.begin())
if (iterCur == steps.begin() && iterCur != steps.end())
++iterCur;
};

Expand Down
3 changes: 2 additions & 1 deletion src/iso19111/operation/transformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2011,7 +2011,8 @@ isGeographic3DToGravityRelatedHeight(const OperationMethodNNPtr &method,
"1100", // Geog3D to Geog2D+GravityRelatedHeight (PL txt)
"1103", // Geog3D to Geog2D+GravityRelatedHeight (EGM)
"1105", // Geog3D to Geog2D+GravityRelatedHeight (ITAL2005)
// "1110", // Geog3D to Geog2D+Depth (Gravsoft) FIXME: to investigate how to map this to PROJ pipeline (depth vs height)
// "1110", // Geog3D to Geog2D+Depth (Gravsoft) FIXME: to investigate
// how to map this to PROJ pipeline (depth vs height)
"9661", // Geographic3D to GravityRelatedHeight (EGM)
"9662", // Geographic3D to GravityRelatedHeight (Ausgeoid98)
"9663", // Geographic3D to GravityRelatedHeight (OSGM-GB)
Expand Down
19 changes: 16 additions & 3 deletions test/unit/test_c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@

#include <sqlite3.h>

#if !defined(_WIN32)
#include <sys/resource.h>
#endif

#ifndef __MINGW32__
#include <thread>
#endif
Expand Down Expand Up @@ -6104,9 +6108,18 @@ TEST_F(CApi, open_plenty_of_contexts) {
// database
std::vector<FILE *> dummyFilePointers;
std::vector<PJ_CONTEXT *> ctxts;
// 1024 is the number of file descriptors that can be opened simultaneously
// by a Linux process (by default)
for (int i = 0; i < 1024 - 50; i++) {
// The number of file descriptors that can be opened simultaneously by a
// process varies across platforms so we make use of getrlimit(2) to
// retrieve it.
struct rlimit open_max;
getrlimit(RLIMIT_NOFILE, &open_max);
// On some platforms fopen returned nullptrs before reaching limit - 50, we
// can avoid this by capping the limit to 1024.
if (open_max.rlim_cur > 1024) {
open_max.rlim_cur = 1024;
setrlimit(RLIMIT_NOFILE, &open_max);
}
for (rlim_t i = 0; i < open_max.rlim_cur - 50; i++) {
FILE *f = fopen("/dev/null", "rb");
ASSERT_TRUE(f != nullptr);
dummyFilePointers.push_back(f);
Expand Down

0 comments on commit b32c284

Please sign in to comment.