Skip to content

Commit b4b4e67

Browse files
committed
Add functions to retrieve PDAL version information.
1 parent b2d07a2 commit b4b4e67

File tree

7 files changed

+304
-3
lines changed

7 files changed

+304
-3
lines changed

source/pdal/capi/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ find_package(PDAL REQUIRED CONFIG)
44
message(STATUS "Found PDAL ${PDAL_VERSION}")
55

66
set(SOURCES
7+
Config.cpp
78
DimType.cpp
89
Pipeline.cpp
910
PointLayout.cpp
@@ -12,6 +13,7 @@ set(SOURCES
1213
)
1314

1415
set(HEADERS
16+
Config.h
1517
Defines.h
1618
DimType.h
1719
Forward.h

source/pdal/capi/Config.cpp

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
* Copyright (c) Simverge Software LLC - All Rights Reserved
3+
*/
4+
5+
#include "Config.h"
6+
7+
#include <pdal/pdal_config.hpp>
8+
9+
#include <cstring>
10+
#include <string>
11+
12+
namespace pdal
13+
{
14+
namespace capi
15+
{
16+
size_t PDALFullVersionString(char *version, size_t size)
17+
{
18+
size_t length = 0;
19+
20+
if (version && size > 0)
21+
{
22+
version[0] = '\0';
23+
version[size-1] = '\0';
24+
25+
std::string s = pdal::Config::fullVersionString();
26+
std::strncpy(version, s.c_str(), size - 1);
27+
length = std::min(s.length(), size - 1);
28+
}
29+
30+
return length;
31+
}
32+
33+
size_t PDALVersionString(char *version, size_t size)
34+
{
35+
size_t length = 0;
36+
37+
if (version && size > 0)
38+
{
39+
version[0] = '\0';
40+
version[size-1] = '\0';
41+
42+
std::string s = pdal::Config::versionString();
43+
std::strncpy(version, s.c_str(), size - 1);
44+
length = std::min(s.length(), size - 1);
45+
}
46+
47+
return length;
48+
}
49+
50+
int PDALVersionInteger()
51+
{
52+
return pdal::Config::versionInteger();
53+
}
54+
55+
size_t PDALSha1(char *sha1, size_t size)
56+
{
57+
size_t length = 0;
58+
59+
if (sha1 && size > 0)
60+
{
61+
sha1[0] = '\0';
62+
sha1[size-1] = '\0';
63+
64+
std::string s = pdal::Config::sha1();
65+
std::strncpy(sha1, s.c_str(), size - 1);
66+
length = std::min(s.length(), size - 1);
67+
}
68+
69+
return length;
70+
}
71+
72+
int PDALVersionMajor()
73+
{
74+
return pdal::Config::versionMajor();
75+
}
76+
77+
int PDALVersionMinor()
78+
{
79+
return pdal::Config::versionMinor();
80+
}
81+
82+
int PDALVersionPatch()
83+
{
84+
return pdal::Config::versionPatch();
85+
}
86+
87+
size_t PDALDebugInformation(char *info, size_t size)
88+
{
89+
size_t length = 0;
90+
91+
if (info && size > 0)
92+
{
93+
info[0] = '\0';
94+
info[size-1] = '\0';
95+
96+
std::string s = pdal::Config::debugInformation();
97+
std::strncpy(info, s.c_str(), size - 1);
98+
length = std::min(s.length(), size - 1);
99+
}
100+
101+
return length;
102+
}
103+
104+
size_t PDALPluginInstallPath(char *path, size_t size)
105+
{
106+
size_t length = 0;
107+
108+
if (path && size > 0)
109+
{
110+
path[0] = '\0';
111+
path[size-1] = '\0';
112+
113+
std::string s = pdal::Config::pluginInstallPath();
114+
std::strncpy(path, s.c_str(), size - 1);
115+
length = std::min(s.length(), size - 1);
116+
}
117+
118+
return length;
119+
}
120+
}
121+
}
122+

source/pdal/capi/Config.h

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright (c) Simverge Software LLC - All Rights Reserved
3+
*/
4+
5+
#ifndef PDAL_CAPI_CONFIG_H
6+
#define PDAL_CAPI_CONFIG_H
7+
8+
#include "Forward.h"
9+
10+
/**
11+
* @file Config.h
12+
* Functions to PDAL version and configuration information.
13+
*/
14+
15+
#ifdef __cplusplus
16+
17+
namespace pdal
18+
{
19+
namespace capi
20+
{
21+
extern "C"
22+
{
23+
#else
24+
#include <stdbool.h>
25+
#endif
26+
/**
27+
* @see pdal::config::fullVersionString
28+
*/
29+
PDAL_C_API size_t PDALFullVersionString(char *version, size_t size);
30+
31+
/**
32+
* @see pdal::config::versionString
33+
*/
34+
PDAL_C_API size_t PDALVersionString(char *version, size_t size);
35+
36+
/**
37+
* @see pdal::config::versionInteger
38+
*/
39+
PDAL_C_API int PDALVersionInteger();
40+
41+
/**
42+
* @see pdal::config::sha1
43+
*/
44+
PDAL_C_API size_t PDALSha1(char *sha1, size_t size);
45+
46+
/**
47+
* @see pdal::config::versionMajor
48+
*/
49+
PDAL_C_API int PDALVersionMajor();
50+
51+
/**
52+
* @see pdal::config::versionMinor
53+
*/
54+
PDAL_C_API int PDALVersionMinor();
55+
56+
/**
57+
* @see pdal::config::versionPatch
58+
*/
59+
PDAL_C_API int PDALVersionPatch();
60+
61+
/**
62+
* @see pdal::config::debugInformation
63+
*/
64+
PDAL_C_API size_t PDALDebugInformation(char *info, size_t size);
65+
66+
/**
67+
* @see pdal::config::pluginInstallPath
68+
*/
69+
PDAL_C_API size_t PDALPluginInstallPath(char *path, size_t size);
70+
71+
#ifdef __cplusplus
72+
}
73+
}
74+
}
75+
#endif
76+
77+
#endif

tests/pdal/capi/CMakeLists.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
set(TARGET test_pdal_c)
22

3+
find_package(PDAL REQUIRED CONFIG)
4+
35
set(CONFIGS )
46
set(SOURCES main.c)
57
set(HEADERS )
6-
set(DEPENDENCIES pdal_c)
8+
set(DEPENDENCIES
9+
${PDAL_LIBRARIES}
10+
pdal_c
11+
)
712

813
set(TESTS
14+
ConfigTest
915
PipelineTest
1016
PointLayoutTest
1117
PointViewIteratorTest
@@ -20,7 +26,11 @@ foreach(TEST ${TESTS})
2026
endforeach()
2127

2228
source_group("Config Files" FILES ${CONFIGS})
23-
include_directories(${CMAKE_SOURCE_DIR}/source)
29+
30+
include_directories(
31+
${CMAKE_SOURCE_DIR}/source
32+
${PDAL_INCLUDE_DIRS}
33+
)
2434

2535
add_executable(${TARGET} ${SOURCES} ${HEADERS} ${CONFIG})
2636
set_target_properties(${TARGET} PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})

tests/pdal/capi/ConfigTest.c.in

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright (c) Simverge Software LLC - All Rights Reserved
3+
*/
4+
5+
#include <stdlib.h>
6+
#include <stdio.h>
7+
#include <assert.h>
8+
9+
#include <pdal/capi/Config.h>
10+
#include <pdal/gitsha.h>
11+
#include <pdal/pdal_features.hpp>
12+
13+
#include "greatest.h"
14+
15+
SUITE(ConfigTest);
16+
17+
TEST testPDALVersionInfo(void)
18+
{
19+
int versionInteger = PDALVersionInteger();
20+
ASSERT_EQ(PDAL_VERSION_INTEGER, versionInteger);
21+
22+
int major = PDALVersionMajor();
23+
ASSERT_EQ(PDAL_VERSION_MAJOR, major);
24+
25+
int minor = PDALVersionMinor();
26+
ASSERT_EQ(PDAL_VERSION_MINOR, minor);
27+
28+
int patch = PDALVersionPatch();
29+
ASSERT_EQ(PDAL_VERSION_PATCH, patch);
30+
31+
ASSERT_EQ(major*10000 + minor*100 + patch, versionInteger);
32+
33+
char expected[64];
34+
sprintf(expected, "%d.%d.%d", major, minor, patch);
35+
36+
char version[64];
37+
size_t size = PDALVersionString(version, 64);
38+
ASSERT(size > 0 && size <= 64);
39+
ASSERT(version[0]);
40+
ASSERT_STR_EQ(expected, version);
41+
ASSERT_STR_EQ(PDAL_VERSION_STRING, version);
42+
43+
char sha1[64];
44+
size = PDALSha1(sha1, 64);
45+
ASSERT(size > 0 && size <= 64);
46+
ASSERT(sha1[0]);
47+
48+
// Shorten SHA1 to six characters
49+
ASSERT(size > 6);
50+
sha1[6] = '\0';
51+
52+
sprintf(expected + strlen(version), " (git-version: %s)", sha1);
53+
54+
char fullVersion[64];
55+
size = PDALFullVersionString(fullVersion, 64);
56+
ASSERT(size > 0 && size <= 64);
57+
ASSERT(fullVersion[0]);
58+
ASSERT_STR_EQ(expected, fullVersion);
59+
60+
PASS();
61+
}
62+
63+
TEST testPDALDebugInformation(void)
64+
{
65+
char info[1024];
66+
size_t size = PDALDebugInformation(info, 1024);
67+
ASSERT(size > 0 && size <= 1024);
68+
ASSERT(info[0]);
69+
PASS();
70+
}
71+
72+
TEST testPDALPluginInstallPath(void)
73+
{
74+
char path[1024];
75+
size_t size = PDALPluginInstallPath(path, 1024);
76+
ASSERT(size > 0 && size <= 1024);
77+
ASSERT(path[0]);
78+
ASSERT_STR_EQ(PDAL_PLUGIN_INSTALL_PATH, path);
79+
PASS();
80+
}
81+
82+
83+
GREATEST_SUITE(ConfigTest)
84+
{
85+
RUN_TEST(testPDALVersionInfo);
86+
RUN_TEST(testPDALDebugInformation);
87+
RUN_TEST(testPDALPluginInstallPath);
88+
}

tests/pdal/capi/PipelineTest.c.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#include "greatest.h"
1212

13-
SUITE(Pipeline);
13+
SUITE(PipelineTest);
1414

1515
static char *gPipelineJson = NULL;
1616

tests/pdal/capi/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "greatest.h"
1010

11+
SUITE_EXTERN(ConfigTest);
1112
SUITE_EXTERN(PipelineTest);
1213
SUITE_EXTERN(PointLayoutTest);
1314
SUITE_EXTERN(PointViewIteratorTest);
@@ -18,6 +19,7 @@ GREATEST_MAIN_DEFS();
1819
int main(int argc, char **argv)
1920
{
2021
GREATEST_MAIN_BEGIN();
22+
RUN_SUITE(ConfigTest);
2123
RUN_SUITE(PipelineTest);
2224
RUN_SUITE(PointLayoutTest);
2325
RUN_SUITE(PointViewIteratorTest);

0 commit comments

Comments
 (0)