Skip to content

File tree

9 files changed

+164
-97
lines changed

9 files changed

+164
-97
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
tests/pdal-stats.las
33
tests/data/*.json
44
tests/pdal/test_pdalc_*.c
5+
!tests/pdal/test_pdalc_utils.c
56

67
# Ignore doxygen docs
78
/doc/doxygen
89
/doc/Doxyfile
910

1011
# Select VS Code configurations
12+
.vscode/ipch/**
1113
.vscode/settings.json
1214
.vscode/c_cpp_properties.json
1315

tests/pdal/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ set(CONFIGS )
77
set(SOURCES
88
main.c
99
test_pdalc_config.c
10+
test_pdalc_utils.c
11+
)
12+
13+
set(HEADERS
14+
test_pdalc_utils.h
1015
)
1116

12-
set(HEADERS )
1317
set(DEPENDENCIES
1418
${PDAL_LIBRARIES}
1519
pdalc

tests/pdal/test_pdalc_pipeline.c.in

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
/******************************************************************************
23
* Copyright (c) 2019, Simverge Software LLC. All rights reserved.
34
*
@@ -27,37 +28,21 @@
2728
* POSSIBILITY OF SUCH DAMAGE.
2829
*****************************************************************************/
2930

30-
#include <stdlib.h>
3131
#include <stdio.h>
3232
#include <assert.h>
3333

3434
#include <pdal/pdalc_pipeline.h>
3535

3636
#include "greatest.h"
37+
#include "test_pdalc_utils.h"
3738

3839
SUITE(test_pdalc_pipeline);
3940

4041
static char *gPipelineJson = NULL;
4142

4243
static void setup_test_pdalc_pipeline(void *arg)
4344
{
44-
FILE *file = fopen("@CMAKE_BINARY_DIR@/data/stats.json", "rb");
45-
46-
if (file)
47-
{
48-
fseek(file, 0, SEEK_END);
49-
long length = ftell(file);
50-
fseek(file, 0, SEEK_SET);
51-
gPipelineJson = malloc(length + 1);
52-
53-
if (gPipelineJson)
54-
{
55-
fread(gPipelineJson, 1, length, file);
56-
gPipelineJson[length] = '\0';
57-
}
58-
59-
fclose(file);
60-
}
45+
gPipelineJson = PDALReadPipelineJson("@CMAKE_BINARY_DIR@/data/stats.json");
6146
}
6247

6348
static void teardown_test_pdalc_pipeline(void *arg)

tests/pdal/test_pdalc_pointlayout.c.in

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@
2727
* POSSIBILITY OF SUCH DAMAGE.
2828
*****************************************************************************/
2929

30-
#include <stdlib.h>
31-
#include <stdio.h>
3230
#include <assert.h>
3331

3432
#include <pdal/pdalc.h>
3533

3634
#include "greatest.h"
35+
#include "test_pdalc_utils.h"
3736

3837
SUITE(test_pdalc_pointlayout);
3938

@@ -43,41 +42,21 @@ static PDALPointLayoutPtr gLayout = NULL;
4342

4443
static void setup_test_pdalc_pointlayout(void *arg)
4544
{
46-
FILE *file = fopen("@CMAKE_BINARY_DIR@/data/simple-reproject.json", "rb");
47-
char *json = NULL;
45+
gPipeline = PDALLoadPipeline("@CMAKE_BINARY_DIR@/data/simple-reproject.json");
4846

49-
if (file)
47+
if (gPipeline)
5048
{
51-
fseek(file, 0, SEEK_END);
52-
long length = ftell(file);
53-
fseek(file, 0, SEEK_SET);
54-
char *json = malloc(length + 1);
49+
PDALPointViewIteratorPtr views = PDALGetPointViews(gPipeline);
5550

56-
if (json)
51+
if (PDALHasNextPointView(views))
5752
{
58-
fread(json, 1, length, file);
59-
json[length] = '\0';
60-
gPipeline = PDALCreatePipeline(json);
53+
gPointView = PDALGetNextPointView(views);
6154

62-
if (gPipeline && PDALExecutePipeline(gPipeline))
55+
if (gPointView)
6356
{
64-
PDALPointViewIteratorPtr views = PDALGetPointViews(gPipeline);
65-
66-
if (PDALHasNextPointView(views))
67-
{
68-
gPointView = PDALGetNextPointView(views);
69-
70-
if (gPointView)
71-
{
72-
gLayout = PDALGetPointViewLayout(gPointView);
73-
}
74-
}
57+
gLayout = PDALGetPointViewLayout(gPointView);
7558
}
76-
77-
free(json);
7859
}
79-
80-
fclose(file);
8160
}
8261
}
8362

tests/pdal/test_pdalc_pointview.c.in

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <pdal/pdalc.h>
3535

3636
#include "greatest.h"
37+
#include "test_pdalc_utils.h"
3738

3839
/// A simple binary tree implementation for int values
3940
struct node
@@ -85,31 +86,11 @@ static PDALPointViewIteratorPtr gPointViewIterator = NULL;
8586

8687
static void setup_test_pdalc_pointview(void *arg)
8788
{
88-
FILE *file = fopen("@CMAKE_BINARY_DIR@/data/simple-reproject.json", "rb");
89-
char *json = NULL;
89+
gPipeline = PDALLoadPipeline("@CMAKE_BINARY_DIR@/data/simple-reproject.json");
9090

91-
if (file)
91+
if (gPipeline)
9292
{
93-
fseek(file, 0, SEEK_END);
94-
long length = ftell(file);
95-
fseek(file, 0, SEEK_SET);
96-
char *json = malloc(length + 1);
97-
98-
if (json)
99-
{
100-
fread(json, 1, length, file);
101-
json[length] = '\0';
102-
gPipeline = PDALCreatePipeline(json);
103-
104-
if (gPipeline && PDALExecutePipeline(gPipeline))
105-
{
106-
gPointViewIterator = PDALGetPointViews(gPipeline);
107-
}
108-
109-
free(json);
110-
}
111-
112-
fclose(file);
93+
gPointViewIterator = PDALGetPointViews(gPipeline);
11394
}
11495
}
11596

tests/pdal/test_pdalc_pointviewiterator.c.in

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,32 +44,11 @@ static PDALPointViewIteratorPtr gPointViewIterator = NULL;
4444

4545
static void setup_test_pdalc_pointviewiterator(void *arg)
4646
{
47-
FILE *file = fopen("@CMAKE_BINARY_DIR@/data/stats.json", "rb");
48-
char *json = NULL;
47+
gPipeline = PDALLoadPipeline("@CMAKE_BINARY_DIR@/data/simple-reproject.json");
4948

50-
if (file)
49+
if (gPipeline)
5150
{
52-
fseek(file, 0, SEEK_END);
53-
long length = ftell(file);
54-
fseek(file, 0, SEEK_SET);
55-
char *json = malloc(length + 1);
56-
57-
if (json)
58-
{
59-
fread(json, 1, length, file);
60-
json[length] = '\0';
61-
62-
gPipeline = PDALCreatePipeline(json);
63-
64-
if (gPipeline && PDALExecutePipeline(gPipeline))
65-
{
66-
gPointViewIterator = PDALGetPointViews(gPipeline);
67-
}
68-
69-
free(json);
70-
}
71-
72-
fclose(file);
51+
gPointViewIterator = PDALGetPointViews(gPipeline);
7352
}
7453
}
7554

tests/pdal/test_pdalc_utils.c

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/******************************************************************************
2+
* Copyright (c) 2019, Simverge Software LLC. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following
6+
* conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice,
9+
* this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation
12+
* and/or other materials provided with the distribution.
13+
* 3. Neither the name of Simverge Software LLC nor the names of its
14+
* contributors may be used to endorse or promote products derived from this
15+
* software without specific prior written permission.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
* POSSIBILITY OF SUCH DAMAGE.
28+
*****************************************************************************/
29+
30+
#include "test_pdalc_utils.h"
31+
32+
#include <stdlib.h>
33+
#include <stdio.h>
34+
35+
const char *PDALReadPipelineJson(const char *path)
36+
{
37+
FILE *file = fopen(path, "rb");
38+
char *json = NULL;
39+
40+
if (file)
41+
{
42+
fseek(file, 0, SEEK_END);
43+
size_t length = (size_t) ftell(file);
44+
fseek(file, 0, SEEK_SET);
45+
json = malloc(length + 1);
46+
47+
if (json && fread(json, 1, length, file) == length)
48+
{
49+
json[length] = '\0';
50+
}
51+
else
52+
{
53+
free(json);
54+
json = NULL;
55+
}
56+
57+
fclose(file);
58+
file = NULL;
59+
}
60+
61+
return json;
62+
}
63+
64+
PDALPipelinePtr *PDALLoadPipeline(const char *path)
65+
{
66+
PDALPipelinePtr *pipeline = NULL;
67+
const char *json = PDALReadPipelineJson(path);
68+
69+
if (json)
70+
{
71+
pipeline = PDALCreatePipeline(json);
72+
73+
if (!PDALExecutePipeline(pipeline))
74+
{
75+
PDALDisposePipeline(pipeline);
76+
pipeline = NULL;
77+
}
78+
79+
free(json);
80+
json = NULL;
81+
}
82+
83+
return pipeline;
84+
}

tests/pdal/test_pdalc_utils.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/******************************************************************************
2+
* Copyright (c) 2019, Simverge Software LLC. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following
6+
* conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice,
9+
* this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation
12+
* and/or other materials provided with the distribution.
13+
* 3. Neither the name of Simverge Software LLC nor the names of its
14+
* contributors may be used to endorse or promote products derived from this
15+
* software without specific prior written permission.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
* POSSIBILITY OF SUCH DAMAGE.
28+
*****************************************************************************/
29+
30+
#include <pdal/pdalc.h>
31+
32+
/**
33+
* Reads the contents of a PDAL pipeline file.
34+
*
35+
* @note Caller obtains ownership of the returned string and is responsible for
36+
* freeing the allocated memory.
37+
*
38+
* @param path The path to the PDAL pipeline JSON file
39+
* @return The contents of the PDAL pipeline JSON file as a string
40+
*/
41+
const char *PDALReadPipelineJson(const char *path);
42+
43+
/**
44+
* Creates a PDAL pipeline from the provided path and attempts to execute it.
45+
*
46+
* @note Caller obtains ownership of the returned pipeline and is responsible for
47+
* freeing the allocated memory with PDALDisposePipeline.
48+
* @note The returned pipeline will be NULL if it could not be executed.
49+
*
50+
* @param path The path to the PDAL pipeline JSON file
51+
* @return The loaded PDAL pipeline
52+
*/
53+
PDALPipelinePtr *PDALLoadPipeline(const char *path);

tests/travis/script.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if [ "$SCAN" = "sonarcloud" ]; then
1111
rm build-wrapper-linux-x86.zip
1212
export SONARCLOUD_DIR=${PWD}/build-wrapper-linux-x86
1313

14-
elif [ "$SCAN" = "coverity" ] && [ "$TRAVIS_BRANCH" = "master" ]; then
14+
elif [ "$SCAN" = "coverity" ] && [ "$TRAVIS_BRANCH" = "github-6_address-coverity-faults" ]; then
1515
curl -LsS -d "token=${COVERITY_TOKEN}&project=Simverge%2Fpdal-c" -X POST https://scan.coverity.com/download/cxx/linux64 > coverity_tool.tgz
1616
tar xaf coverity_tool.tgz
1717
rm coverity_tool.tgz
@@ -37,7 +37,7 @@ cmake -G "Unix Makefiles" \
3737

3838
if [ "$SCAN" = "sonarcloud" ]; then
3939
${SONARCLOUD_DIR}/build-wrapper-linux-x86-64 --out-dir ${CI_PROJECT_DIR}/bw-output make
40-
elif [ "$SCAN" = "coverity" ] && [ "$TRAVIS_BRANCH" = "master" ]; then
40+
elif [ "$SCAN" = "coverity" ] && [ "$TRAVIS_BRANCH" = "github-6_address-coverity-faults" ]; then
4141
${COVERITY_DIR}/cov-configure --gcc
4242
${COVERITY_DIR}/cov-build --dir ${CI_PROJECT_DIR}/cov-int make
4343
cd ${CI_PROJECT_DIR}

0 commit comments

Comments
 (0)