Skip to content

Commit 4ac443d

Browse files
committed
Add PointView tests
1 parent dfb23a3 commit 4ac443d

File tree

3 files changed

+180
-2
lines changed

3 files changed

+180
-2
lines changed

tests/pdal/capi/CMakeLists.txt

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

33
configure_file(PipelineTest.c.in ${CMAKE_CURRENT_SOURCE_DIR}/PipelineTest.c)
4+
configure_file(PointViewTest.c.in ${CMAKE_CURRENT_SOURCE_DIR}/PointViewTest.c)
45
configure_file(PointViewCollectionTest.c.in ${CMAKE_CURRENT_SOURCE_DIR}/PointViewCollectionTest.c)
56

7+
set(CONFIG
8+
PipelineTest.c.in
9+
PointViewCollectionTest.c.in
10+
PointViewTest.c.in
11+
)
12+
13+
source_group("Config Files" FILES ${CONFIG})
14+
615
set(SOURCES
716
main.c
817
PipelineTest.c
918
PointViewCollectionTest.c
10-
)
19+
PointViewTest.c
20+
)
1121

1222
set(HEADERS )
1323

1424
set(DEPENDENCIES pdal_c)
1525

1626
include_directories(${CMAKE_SOURCE_DIR}/source)
1727

18-
add_executable(${TARGET} ${SOURCES} ${HEADERS})
28+
add_executable(${TARGET} ${SOURCES} ${HEADERS} ${CONFIG})
1929
set_target_properties(${TARGET} PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
2030

2131
target_link_libraries(${TARGET} ${DEPENDENCIES})

tests/pdal/capi/PointViewTest.c.in

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
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 "greatest.h"
10+
11+
#include <pdal/capi/Pipeline.h>
12+
#include <pdal/capi/PointView.h>
13+
#include <pdal/capi/PointViewCollection.h>
14+
15+
/// A simple binary tree implementation for int values
16+
struct node
17+
{
18+
int key;
19+
struct node *left;
20+
struct node *right;
21+
};
22+
23+
void dispose(struct node *n)
24+
{
25+
if (n == NULL)
26+
{
27+
dispose(n->left);
28+
dispose(n->right);
29+
free(n);
30+
}
31+
}
32+
33+
bool insert(int key, struct node **n)
34+
{
35+
bool inserted = false;
36+
37+
if (*n == NULL)
38+
{
39+
*n = (struct node *) malloc(sizeof(struct node));
40+
(*n)->key = key;
41+
(*n)->left = NULL;
42+
(*n)->right = NULL;
43+
inserted = true;
44+
}
45+
else if (key < (*n)->key)
46+
{
47+
inserted = insert(key, &(*n)->left);
48+
}
49+
else if (key > (*n)->key)
50+
{
51+
inserted = insert(key, &(*n)->right);
52+
}
53+
54+
return inserted;
55+
}
56+
57+
SUITE(PointViewTest);
58+
59+
static const int INVALID_POINT_VIEW_ID = 0;
60+
static PDALPipelinePtr gPipeline = NULL;
61+
static PDALPointViewCollectionPtr gPointViewCollection = NULL;
62+
63+
static void setupPointViewTest(void *arg)
64+
{
65+
FILE *file = fopen("@CMAKE_BINARY_DIR@//data/stats.json", "rb");
66+
char *json = NULL;
67+
68+
if (file)
69+
{
70+
fseek(file, 0, SEEK_END);
71+
long length = ftell(file);
72+
fseek(file, 0, SEEK_SET);
73+
char *json = malloc(length + 1);
74+
75+
if (json)
76+
{
77+
fread(json, 1, length, file);
78+
json[length] = '\0';
79+
80+
gPipeline = PDALCreatePipeline(json);
81+
82+
if (gPipeline && PDALExecutePipeline(gPipeline))
83+
{
84+
gPointViewCollection = PDALGetPointViews(gPipeline);
85+
}
86+
87+
free(json);
88+
}
89+
90+
fclose(file);
91+
}
92+
}
93+
94+
static void teardownPointViewTest(void *arg)
95+
{
96+
PDALDisposePointViewCollection(gPointViewCollection);
97+
PDALDisposePipeline(gPipeline);
98+
}
99+
100+
TEST testPDALGetPointViewId(void)
101+
{
102+
ASSERT_EQ(INVALID_POINT_VIEW_ID, PDALGetPointViewId(NULL));
103+
104+
PDALResetPointViewCollection(gPointViewCollection);
105+
bool hasNext = PDALHasNextPointView(gPointViewCollection);
106+
ASSERT_FALSE(!hasNext);
107+
108+
struct node *tree = NULL;
109+
110+
while (hasNext)
111+
{
112+
PDALPointViewPtr view = PDALGetNextPointView(gPointViewCollection);
113+
ASSERT_FALSE(view == NULL);
114+
115+
// Make sure all IDs are valid
116+
int id = PDALGetPointViewId(view);
117+
ASSERT_FALSE(id == INVALID_POINT_VIEW_ID);
118+
119+
// Make sure that there are no duplicate IDs
120+
bool inserted = insert(id, &tree);
121+
ASSERT_FALSE(!inserted);
122+
123+
hasNext = PDALHasNextPointView(gPointViewCollection);
124+
}
125+
126+
dispose(tree);
127+
128+
PASS();
129+
}
130+
131+
TEST testPDALGetPointViewSize(void)
132+
{
133+
ASSERT_EQ(0, PDALGetPointViewSize(NULL));
134+
135+
PASS();
136+
}
137+
138+
TEST testPDALIsPointViewEmpty(void)
139+
{
140+
ASSERT_FALSE(!PDALIsPointViewEmpty(NULL));
141+
142+
PASS();
143+
}
144+
145+
TEST testPDALClonePointView(void)
146+
{
147+
PDALResetPointViewCollection(gPointViewCollection);
148+
149+
150+
PASS();
151+
}
152+
153+
154+
GREATEST_SUITE(PointViewTest)
155+
{
156+
SET_SETUP(setupPointViewTest, NULL);
157+
SET_TEARDOWN(teardownPointViewTest, NULL);
158+
159+
RUN_TEST(testPDALGetPointViewId);
160+
RUN_TEST(testPDALGetPointViewSize);
161+
RUN_TEST(testPDALIsPointViewEmpty);
162+
RUN_TEST(testPDALClonePointView);
163+
164+
SET_SETUP(NULL, NULL);
165+
SET_TEARDOWN(NULL, NULL);
166+
}

tests/pdal/capi/main.c

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

1111
SUITE_EXTERN(PipelineTest);
1212
SUITE_EXTERN(PointViewCollectionTest);
13+
SUITE_EXTERN(PointViewTest);
1314

1415
GREATEST_MAIN_DEFS();
1516

@@ -18,5 +19,6 @@ int main(int argc, char **argv)
1819
GREATEST_MAIN_BEGIN();
1920
RUN_SUITE(PipelineTest);
2021
RUN_SUITE(PointViewCollectionTest);
22+
RUN_SUITE(PointViewTest);
2123
GREATEST_MAIN_END();
2224
}

0 commit comments

Comments
 (0)