Skip to content

Commit 40b2ae9

Browse files
author
Daniel Tobon
committed
added test concrete parses cases
1 parent 51efd51 commit 40b2ae9

File tree

5 files changed

+104
-20
lines changed

5 files changed

+104
-20
lines changed

CMakeLists.txt

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
##############################################################################
1+
# #############################################################################
22
# CMAKE CONFIGURATION
3-
##############################################################################
3+
# #############################################################################
44
cmake_minimum_required(VERSION 3.5.1 FATAL_ERROR)
55

66
# set project name
7-
project(pcl-visualizer VERSION 1.0.0
8-
DESCRIPTION "Point cloud visualizser with PCL"
7+
project(pcl-visualizer VERSION 1.0.0
8+
DESCRIPTION "Point cloud visualizser with PCL"
99
)
1010

1111
# set build type = Release mode
@@ -22,56 +22,59 @@ set(CMAKE_CXX_STANDARD 17)
2222
set(CMAKE_CXX_STANDARD_REQUIRED True)
2323
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
2424
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
25-
##############################################################################
25+
26+
# #############################################################################
2627
# PACKAGES DEPENDENCIES
27-
##############################################################################
28+
# #############################################################################
2829
message("${BoldYellow}***********************")
2930
message("${BoldYellow}PCL PACKAGE")
3031
message("${BoldYellow}***********************")
3132

3233
find_package(PCL 1.8 REQUIRED QUIET)
34+
3335
if(PCL_FOUND)
3436
message(STATUS "${BoldGreen}PCL status:")
3537
message(STATUS " version: ${PCL_VERSION}")
3638
message(STATUS " directory: ${PCL_DIR}")
3739
else()
38-
message(FATAL_ERROR "${BoldRed} ERROR: PCL minimum required version 1.8. Not found")
40+
message(FATAL_ERROR "${BoldRed} ERROR: PCL minimum required version 1.8. Not found")
3941
endif()
4042

4143
message("${BoldYellow}***********************")
4244
message("${BoldYellow}VTK PACKAGE")
4345
message("${BoldYellow}***********************")
4446

4547
find_package(VTK 8.1 REQUIRED QUIET)
48+
4649
if(VTK_FOUND)
4750
message(STATUS "${BoldGreen}VTK status:")
4851
message(STATUS " version: ${VTK_VERSION}")
4952
message(STATUS " directory: ${VTK_DIR}")
5053
else()
51-
message(FATAL_ERROR "${BoldRed} ERROR: VTK minimum required version 8.1. Not found")
54+
message(FATAL_ERROR "${BoldRed} ERROR: VTK minimum required version 8.1. Not found")
5255
endif()
5356

5457
# Use the compile definitions defined in PCL
5558
add_definitions(${PCL_DEFINITIONS})
5659

57-
##############################################################################
60+
# #############################################################################
5861
# ADD LIBRARIES FOLDER
59-
##############################################################################
62+
# #############################################################################
6063
add_subdirectory(parser)
6164

62-
##############################################################################
65+
# #############################################################################
6366
# SOURCE CODE
64-
##############################################################################
67+
# #############################################################################
6568
set(MAIN_SOURCE "src/main.cpp")
6669

67-
##############################################################################
70+
# #############################################################################
6871
# EXECUTABLES
69-
##############################################################################
72+
# #############################################################################
7073
add_executable(${PROJECT_NAME} ${MAIN_SOURCE})
7174

72-
##############################################################################
75+
# #############################################################################
7376
# TARGET LIBRARIES
74-
##############################################################################
77+
# #############################################################################
7578
target_include_directories(${PROJECT_NAME} PRIVATE ${PCL_INCLUDE_DIRS} ${VTK_INCLUDE_DIRS})
7679
target_include_directories(cloud_parser PRIVATE ${PCL_INCLUDE_DIRS} ${VTK_INCLUDE_DIRS})
7780
target_link_libraries(${PROJECT_NAME} ${PCL_LIBRARIES} ${VTK_LIBRARIES} cloud_parser)
@@ -81,9 +84,9 @@ message("${BoldCyan}=========================================")
8184
message("${BoldCyan}Project: ${PROJECT_NAME} COMPILED WITH CMAKE " ${CMAKE_VERSION})
8285
message("${BoldCyan}=========================================")
8386

84-
##############################################################################
87+
# #############################################################################
8588
# INSTALL DIRECTORY
86-
##############################################################################
89+
# #############################################################################
8790
install(TARGETS ${PROJECT_NAME}
8891
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
8992
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
@@ -97,10 +100,16 @@ if(BUILD_TESTING)
97100
enable_testing()
98101
add_subdirectory(external)
99102
add_subdirectory(tests)
103+
100104
if(CODE_COVERAGE)
101-
message("${BoldWhite} Coverage enabled ${ColourReset}")
105+
message("${BoldWhite} Coverage enabled ${ColourReset}")
102106
include("${CMAKE_CURRENT_LIST_DIR}/cmake/CodeCoverage.cmake")
103107
append_coverage_compiler_flags()
104-
setup_target_for_coverage_lcov(NAME coverage EXECUTABLE testlib BASE_DIRECTORY ../coverage)
108+
setup_target_for_coverage_lcov(NAME coverage EXECUTABLE ctest -j ${n_cores}
109+
BASE_DIRECTORY ../coverage
110+
DEPENDENCIES
111+
testlib
112+
testconcreteparses
113+
)
105114
endif()
106115
endif()

tests/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
# Tests need to be added as executables first
22
add_executable(testlib test_parser.cpp)
3+
add_executable(testconcreteparses test_concrete_parses.cpp)
34

45
# I'm using C++17 in the test
56
target_compile_features(testlib PRIVATE cxx_std_17)
7+
target_compile_features(testconcreteparses PRIVATE cxx_std_17)
68

79
# Should be linked to the main library, as well as the Catch2 testing library
810
target_link_libraries(testlib PRIVATE Catch2 cloud_parser ${PCL_LIBRARIES} ${VTK_LIBRARIES})
11+
target_link_libraries(testconcreteparses PRIVATE Catch2 cloud_parser ${PCL_LIBRARIES} ${VTK_LIBRARIES})
912

1013
# If you register a test, then ctest and make test will run it.
1114
# You can also run examples and check the output, as well.
1215
add_test(NAME testlibtest COMMAND testlib) # Command can be a target
16+
add_test(NAME testconcreteparses COMMAND testconcreteparses WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}") # Command can be a target
1317

18+
# custom target to get more verbose level in test with: make check
19+
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --verbose)

tests/cloudfiles/cloud.pcd

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# .PCD v.7 - Point Cloud Data file format
2+
VERSION .7
3+
FIELDS x y z rgb
4+
SIZE 4 4 4 4
5+
TYPE F F F F
6+
COUNT 1 1 1 1
7+
WIDTH 5
8+
HEIGHT 1
9+
VIEWPOINT 0 0 0 1 0 0 0
10+
POINTS 5
11+
DATA ascii
12+
0.93773 0.33763 0 4.2108e+06
13+
0.90805 0.35641 0 4.2108e+06
14+
0.81915 0.32 0 4.2108e+06
15+
0.97192 0.278 0 4.2108e+06
16+
0.944 0.29474 0 4.2108e+06

tests/cloudfiles/cloud.ply

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ply
2+
format ascii 1.0
3+
comment created by platoply
4+
element vertex 5
5+
property float32 x
6+
property float32 y
7+
property float32 z
8+
element face 0
9+
property list uint8 int32 vertex_indices
10+
end_header
11+
-1 -1 -1
12+
1 -1 -1
13+
1 1 -1
14+
-1 1 -1
15+
-1 -1 1

tests/test_concrete_parses.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#define CATCH_CONFIG_MAIN
2+
#include <catch2/catch.hpp>
3+
#include <filesystem>
4+
#include <modern/concrete_parses.hpp>
5+
6+
TEST_CASE("Testing ParserPCD") {
7+
CloudParserLibrary::ParserPCD* parser = new CloudParserLibrary::ParserPCD();
8+
9+
std::filesystem::path filespath("cloudfiles");
10+
std::filesystem::path filename("cloud.pcd");
11+
std::filesystem::path TESTDATA_FILENAME = filespath / filename;
12+
13+
SECTION("Loading cloud pcd file with success") {
14+
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>());
15+
parser->load_cloudfile(TESTDATA_FILENAME, cloud);
16+
REQUIRE((int)cloud->points.size() == 5);
17+
}
18+
}
19+
20+
TEST_CASE("Testing ParserPLY") {
21+
CloudParserLibrary::ParserPLY* parser = new CloudParserLibrary::ParserPLY();
22+
23+
std::filesystem::path filespath("cloudfiles");
24+
std::filesystem::path filename("cloud.ply");
25+
std::filesystem::path TESTDATA_FILENAME = filespath / filename;
26+
27+
SECTION("Loading cloud ply file with success") {
28+
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>());
29+
parser->load_cloudfile(TESTDATA_FILENAME, cloud);
30+
REQUIRE((int)cloud->points.size() == 5);
31+
}
32+
33+
SECTION("Testing cloud_is_good function") {
34+
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>());
35+
parser->load_cloudfile(TESTDATA_FILENAME, cloud);
36+
CHECK(parser->cloud_is_good(cloud));
37+
}
38+
}

0 commit comments

Comments
 (0)