Skip to content

Commit e4ef69a

Browse files
committed
Fix Linux tests
1 parent b34207e commit e4ef69a

File tree

3 files changed

+76
-24
lines changed

3 files changed

+76
-24
lines changed

.gitlab-ci.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ build-x64-windows-debug:
6262
.job_template: &test-windows
6363
tags:
6464
- windows
65+
before_script:
66+
- set GDAL_DATA=%VCPKG_ROOT%\installed\x64-windows\share\gdal
67+
- set PROJ_LIB=%VCPKG_ROOT%\installed\x64-windows\share\proj4
6568
stage: test
6669
cache:
6770
policy: pull
@@ -70,11 +73,8 @@ test-x64-windows-release:
7073
<<: *test-windows
7174
dependencies:
7275
- build-x64-windows-release
73-
before_script:
74-
- cd %VCPKG_ROOT%/installed/x64-windows/bin
7576
script:
76-
- set GDAL_DATA=%VCPKG_ROOT%\installed\x64-windows\share\gdal
77-
- set PROJ_LIB=%VCPKG_ROOT%\installed\x64-windows\share\proj4
77+
- cd %VCPKG_ROOT%/installed/x64-windows/bin
7878
- copy proj_4_9.dll proj.dll
7979
- "%CI_PROJECT_DIR%/build/build-x64-windows-release/bin/test_pdalc"
8080
cache:
@@ -86,11 +86,8 @@ test-x64-windows-debug:
8686
<<: *test-windows
8787
dependencies:
8888
- build-x64-windows-debug
89-
before_script:
90-
- cd %VCPKG_ROOT%/installed/x64-windows/debug/bin
9189
script:
92-
- set GDAL_DATA=%VCPKG_ROOT%\installed\x64-windows\share\gdal
93-
- set PROJ_LIB=%VCPKG_ROOT%\installed\x64-windows\share\proj4
90+
- cd %VCPKG_ROOT%/installed/x64-windows/debug/bin
9491
- copy proj_4_9_d.dll proj.dll
9592
- "%CI_PROJECT_DIR%/build/build-x64-windows-debug/bin/test_pdalcd"
9693
cache:

source/pdal/pdalc_config.cpp

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77
#include <pdal/pdal_config.hpp>
88
#include <pdal/util/Utils.hpp>
99

10+
#include <cstdlib>
1011
#include <cstring>
1112
#include <string>
1213

1314
namespace pdal
1415
{
1516
namespace capi
1617
{
17-
std::ofstream pdalcConfigLog("pdalc_config.log");
18-
1918
size_t PDALGetGdalDataPath(char *path, size_t size)
2019
{
2120
size_t length = 0;
@@ -25,9 +24,22 @@ namespace pdal
2524
path[0] = '\0';
2625
path[size-1] = '\0';
2726

28-
std::string s = std::getenv("GDAL_DATA");
29-
std::strncpy(path, s.c_str(), size - 1);
30-
length = std::min(s.length(), size - 1);
27+
char *env = nullptr;
28+
29+
try
30+
{
31+
env = std::getenv("GDAL_DATA");
32+
}
33+
catch (const std::exception &e)
34+
{
35+
env = nullptr;
36+
}
37+
38+
if (env)
39+
{
40+
std::strncpy(path, env, size - 1);
41+
length = std::min(std::strlen(env), size - 1);
42+
}
3143
}
3244

3345
return length;
@@ -42,9 +54,22 @@ namespace pdal
4254
path[0] = '\0';
4355
path[size-1] = '\0';
4456

45-
std::string s = std::getenv("PROJ_LIB");
46-
std::strncpy(path, s.c_str(), size - 1);
47-
length = std::min(s.length(), size - 1);
57+
char *env = nullptr;
58+
59+
try
60+
{
61+
env = std::getenv("PROJ_LIB");
62+
}
63+
catch (const std::exception &e)
64+
{
65+
env = nullptr;
66+
}
67+
68+
if (env)
69+
{
70+
std::strncpy(path, env, size - 1);
71+
length = std::min(std::strlen(env), size - 1);
72+
}
4873
}
4974

5075
return length;

tests/pdal/test_pdalc_config.c

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,28 @@ SUITE(test_pdalc_config);
1616

1717
TEST testPDALGetSetGdalDataPath(void)
1818
{
19+
size_t size = PDALGetGdalDataPath(NULL, 1024);
20+
ASSERT_EQ(0, size);
21+
1922
char *original = getenv("GDAL_DATA");
2023
char path[1024];
21-
size_t size = PDALGetGdalDataPath(path, 1024);
22-
ASSERT_STR_EQ(original, path);
23-
ASSERT_EQ(strlen(path), size);
2424

25-
char *expected = "An arbitrary string set as the GDAL data path";
25+
size = PDALGetGdalDataPath(path, 0);
26+
ASSERT_EQ(0, size);
27+
28+
size = PDALGetGdalDataPath(path, 1024);
29+
30+
if (original)
31+
{
32+
ASSERT_STR_EQ(original, path);
33+
ASSERT_EQ(strlen(path), size);
34+
}
35+
else
36+
{
37+
ASSERT_EQ(0, path[0]);
38+
}
39+
40+
const char *expected = "An arbitrary string set as the GDAL data path";
2641
PDALSetGdalDataPath(expected);
2742
size = PDALGetGdalDataPath(path, 1024);
2843
ASSERT_STR_EQ(expected, path);
@@ -35,13 +50,28 @@ TEST testPDALGetSetGdalDataPath(void)
3550

3651
TEST testPDALGetSetProj4DataPath(void)
3752
{
53+
size_t size = PDALGetProj4DataPath(NULL, 1024);
54+
ASSERT_EQ(0, size);
55+
3856
char *original = getenv("PROJ_LIB");
3957
char path[1024];
40-
size_t size = PDALGetProj4DataPath(path, 1024);
41-
ASSERT_STR_EQ(original, path);
42-
ASSERT_EQ(size, strlen(path));
4358

44-
char *expected = "An arbitrary string set as the proj4 data path";
59+
size = PDALGetProj4DataPath(path, 0);
60+
ASSERT_EQ(0, size);
61+
62+
size = PDALGetProj4DataPath(path, 1024);
63+
64+
if (original)
65+
{
66+
ASSERT_STR_EQ(original, path);
67+
ASSERT_EQ(size, strlen(path));
68+
}
69+
else
70+
{
71+
ASSERT_EQ(0, path[0]);
72+
}
73+
74+
const char *expected = "An arbitrary string set as the proj4 data path";
4575
PDALSetProj4DataPath(expected);
4676
size = PDALGetProj4DataPath(path, 1024);
4777
ASSERT_STR_EQ(expected, path);

0 commit comments

Comments
 (0)