Skip to content

Commit 64007b1

Browse files
authored
Merge pull request #36 from diffCheckOrg/test_suite
MERGE: Test suite structure + fixes
2 parents 35cfe5b + 7681361 commit 64007b1

File tree

10 files changed

+142
-120
lines changed

10 files changed

+142
-120
lines changed

CMakeLists.txt

Lines changed: 28 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
77
include(external_tools)
88
include(options)
99

10+
# check that the -DCMAKE_BUILD_TYPE is set
11+
if(NOT CMAKE_BUILD_TYPE)
12+
message(STATUS "Setting build type to 'Release' as none was specified.")
13+
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
14+
endif()
15+
1016
# do a submodule init if not done already
1117
execute_process(COMMAND git submodule update --init --recursive
1218
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
@@ -48,7 +54,7 @@ target_include_directories(${SHARED_LIB_NAME}
4854
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src
4955
)
5056

51-
#set the MD_DynamicRelease flag for MSVC since we are compiling with /MD for py wrap
57+
#set the MD_DynamicRelease flag for MSVC since we are compiling with /MD for py wrap
5258
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
5359

5460

@@ -78,7 +84,7 @@ target_link_libraries(${SHARED_LIB_NAME} PUBLIC Open3D::Open3D)
7884
if(WIN32)
7985
get_target_property(open3d_type Open3D::Open3D TYPE)
8086
if(open3d_type STREQUAL "SHARED_LIBRARY")
81-
message(STATUS "Copying Open3D.dll to ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>")
87+
message(STATUS "Copying Open3D.dll to ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}")
8288
add_custom_command(TARGET ${SHARED_LIB_NAME} POST_BUILD
8389
COMMAND ${CMAKE_COMMAND} -E copy
8490
$<TARGET_FILE:Open3D::Open3D>
@@ -146,54 +152,30 @@ if (BUILD_PYTHON_MODULE)
146152
$<TARGET_FILE:${PYBINDMODULE_NAME}>
147153
${PYPI_DIR}
148154
)
149-
150-
# get all the files -dlls in the bin directory and copy them one by one to the pypi directory
151-
file(GLOB files ${CMAKE_BINARY_DIR}/bin/Release/*.dll)
152-
foreach(file ${files})
153-
message(STATUS "Copying ${file} to ${TARGET_DLL_PYPI_DIR}")
154-
add_custom_command(TARGET ${PYBINDMODULE_NAME} POST_BUILD
155-
COMMAND ${CMAKE_COMMAND} -E copy
156-
${file}
157-
${TARGET_DLL_PYPI_DIR}
158-
)
159-
endforeach()
155+
copy_dlls(${TARGET_DLL_PYPI_DIR} ${PYBINDMODULE_NAME})
160156

161157
endif()
162158

163159
#--------------------------------------------------------------------------
164160
# Tests
165161
#--------------------------------------------------------------------------
162+
include(CTest)
163+
enable_testing()
164+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/deps/googletest)
165+
set(TESTS_OUT_DIR ${CMAKE_BINARY_DIR}/df_tests/)
166+
set(TEST_OUT_DIR_BINARY ${TESTS_OUT_DIR}/${CMAKE_BUILD_TYPE})
167+
168+
# add new test suites .cc here
169+
set(UNIT_TESTS df_test_suites)
170+
add_executable(${UNIT_TESTS}
171+
tests/unit_tests/DFPointCloudTest.cc
172+
tests/entryTest.cc
173+
)
174+
set_target_properties(${UNIT_TESTS} PROPERTIES
175+
RUNTIME_OUTPUT_DIRECTORY ${TESTS_OUT_DIR}
176+
)
177+
target_link_libraries(${UNIT_TESTS} gtest gtest_main)
178+
target_link_libraries(${UNIT_TESTS} ${SHARED_LIB_NAME})
166179

167-
# include(CTest)
168-
# enable_testing()
169-
# add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/deps/googletest)
170-
# set(TESTS_OUT_DIR ${CMAKE_BINARY_DIR}/tests/)
171-
172-
173-
# # Unit testing ------------------------------------------------------------
174-
# set(UNIT_TESTS unit_tests)
175-
# add_executable(${UNIT_TESTS} tests/unit_tests/DFPointCloudTest.cc)
176-
# set_target_properties(${UNIT_TESTS} PROPERTIES
177-
# RUNTIME_OUTPUT_DIRECTORY ${TESTS_OUT_DIR}
178-
# )
179-
180-
# target_link_libraries(${UNIT_TESTS} gtest gtest_main)
181-
# target_link_libraries(${UNIT_TESTS} ${SHARED_LIB_NAME})
182-
183-
# add_test(NAME ${UNIT_TESTS} COMMAND ${UNIT_TESTS})
184-
185-
# Integration testing -----------------------------------------------------
186-
# Component testing -------------------------------------------------------
187-
# etc ---------------------------------------------------------------------
188-
189-
# # TODO: a better way to copy the dlls to the tests directory for the tests
190-
# # get all the files -dlls in the bin directory and copy them one by one to tests dir
191-
# file(GLOB files ${CMAKE_BINARY_DIR}/bin/Release/*.dll)
192-
# foreach(file ${files})
193-
# message(STATUS "Copying ${file} to ${TESTS_OUT_DIR}")
194-
# add_custom_command(TARGET ${UNIT_TESTS} POST_BUILD
195-
# COMMAND ${CMAKE_COMMAND} -E copy
196-
# ${file}
197-
# ${TESTS_OUT_DIR}/Release
198-
# )
199-
# endforeach()
180+
add_test(NAME ${UNIT_TESTS} COMMAND ${UNIT_TESTS})
181+
copy_dlls(${TEST_OUT_DIR_BINARY} ${UNIT_TESTS})

CONTRIBUTING.md

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -320,43 +320,15 @@ dfVisualizerPtr->Run();
320320

321321

322322
### CTesting (TO BE UPDATED)
323-
When necessary, c++ testing is done by using CTest. Important/critical features (e.g., correcting functioning of graphics with OpenGL and Glfw) needs testing to be written (this is usefull for e.g., GitHub Actions). Such tests can be extracted from the main source code and integrated in a seperate section: cmake testing.
323+
Tests in df are all `.cc` files added to the `tests` source files, all the data needs to be contained in `tests/test_data`. Finally add your `.cc` files in the cmake:
324324

325-
To add a new test do as follow.
325+
https://github.com/diffCheckOrg/diffCheck/blob/efb10e0b5685a1ef1537d0309388f642075d3244/CMakeLists.txt#L170-L173
326326

327-
First create a new sub-folder in the folder `./test` as `./test/exampletest`.
328-
Here add a console cpp file called `tester.cpp` which returns 0 or 1 and add a new `CMakeLists.txt` as such:
329-
```cmake
330-
add_executable(example_test tester.cpp)
331-
332-
/* <--
333-
Insert here linking necessary for the executable
334-
Note that if you already found packages in the head CMakeLists file
335-
you can simply use the macros here.
336-
--> */
337-
338-
add_test(NAME "ExampleTest" COMMAND "example_test" <argv-here> WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
339-
```
340-
In the `./test`'s `CMakeLists.txt` add the created sub-directory:
341-
```cmake
342-
if (TEST_EXAMPLE)
343-
add_subdirectory(exampletest)
344-
endif()
327+
To run the tests from terminal
345328
```
346-
Finally add an option in the main `CMakeLists.txt` describing the test:
347-
```cmake
348-
include(CTest)
349-
# ...
350-
option(TEST_EXAMPLE "Test to test something important." ON)
351-
# ...
352-
if(TEST_EXAMPLE)
353-
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests/exampletest)
354-
endif()
329+
ctest --test-dir .\build\ -C Release -V
355330
```
356-
357-
Next, `./configure.sh -c` and `./build.sh` and:
358-
```bash
359-
cd ./build
360-
ctest -N # <--- to see how many tests there are
361-
ctest -V # <--- run the tests
331+
or
362332
```
333+
.\build\df_tests\<config>\df_tests.exe
334+
```

cmake/__noenv__config.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
REM configure the project
2-
cmake -S . -B build
2+
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release

cmake/clean_config.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ REM clean the build directory and reconfigure it
55
rmdir /s /q build
66

77
REM configure the project
8-
cmake -S . -B build
8+
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release

cmake/config.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ REM activate the conda diff_check environment otherwise the python wrap won't wo
22
call cmake/activate_conda.bat
33

44
REM configure the project
5-
cmake -S . -B build
5+
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release

cmake/external_tools.cmake

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,4 +228,23 @@ function(download_submodule_project project_name)
228228
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
229229
message(FATAL_ERROR "git submodule update --init --recursive --remote failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
230230
endif()
231+
endfunction()
232+
233+
# ------------------------------------------------------------------------------
234+
function (copy_dlls directory_to_copy_dlls post_build_target)
235+
message (STATUS "Erasing old DLLs and copy new ones to ${directory_to_copy_dlls}")
236+
file(GLOB files ${directory_to_copy_dlls}/*.dll)
237+
foreach(file ${files})
238+
message(STATUS "Removing ${file}")
239+
file(REMOVE ${file})
240+
endforeach()
241+
file(GLOB files ${CMAKE_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE}/*.dll)
242+
foreach(file ${files})
243+
message(STATUS "Copying ${file} to ${directory_to_copy_dlls}")
244+
add_custom_command(TARGET ${post_build_target} POST_BUILD
245+
COMMAND ${CMAKE_COMMAND} -E copy
246+
${file}
247+
${directory_to_copy_dlls}
248+
)
249+
endforeach()
231250
endfunction()

src/diffCheckApp.cc

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,39 @@ int main()
1212
std::shared_ptr<diffCheck::geometry::DFMesh> dfMeshPtr
1313
= std::make_shared<diffCheck::geometry::DFMesh>();
1414

15-
// create a sphere from o3d
16-
std::string pathCloud = R"(C:\andre\Downloads\moved_04.ply)";
17-
std::string pathMesh = R"(C:\Users\andre\Downloads\meshtest.ply)";
15+
// // create a sphere from o3d
16+
// std::string pathCloud = R"(C:\andre\Downloads\moved_04.ply)";
17+
// std::string pathMesh = R"(C:\Users\andre\Downloads\meshtest.ply)";
1818

19-
// dfPointCloudPtr->LoadFromPLY(pathCloud);
20-
dfMeshPtr->LoadFromPLY(pathMesh);
19+
// // dfPointCloudPtr->LoadFromPLY(pathCloud);
20+
// dfMeshPtr->LoadFromPLY(pathMesh);
2121

22-
open3d::geometry::TriangleMesh meshO3d = *dfMeshPtr->Cvt2O3DTriangleMesh();
22+
// open3d::geometry::TriangleMesh meshO3d = *dfMeshPtr->Cvt2O3DTriangleMesh();
2323

2424

25-
// convert the sphere to a diffCheck point cloud
26-
// auto o3dPointCloud = meshO3d.SamplePointsUniformly(1000);
25+
// // convert the sphere to a diffCheck point cloud
26+
// // auto o3dPointCloud = meshO3d.SamplePointsUniformly(1000);
2727

28-
std::shared_ptr<open3d::geometry::PointCloud> tightBBOX = std::make_shared<open3d::geometry::PointCloud>();
28+
// std::shared_ptr<open3d::geometry::PointCloud> tightBBOX = std::make_shared<open3d::geometry::PointCloud>();
2929

30-
// compute the bounding box
31-
open3d::geometry::OrientedBoundingBox bbox = meshO3d.GetMinimalOrientedBoundingBox();
32-
std::vector<Eigen::Vector3d> bboxPts = bbox.GetBoxPoints();
33-
for (auto &pt : bboxPts)
34-
{
35-
tightBBOX->points_.push_back(pt);
36-
}
30+
// // compute the bounding box
31+
// open3d::geometry::OrientedBoundingBox bbox = meshO3d.GetMinimalOrientedBoundingBox();
32+
// std::vector<Eigen::Vector3d> bboxPts = bbox.GetBoxPoints();
33+
// for (auto &pt : bboxPts)
34+
// {
35+
// tightBBOX->points_.push_back(pt);
36+
// }
3737

3838

39-
dfPointCloudPtr->Cvt2DFPointCloud(tightBBOX);
39+
// dfPointCloudPtr->Cvt2DFPointCloud(tightBBOX);
4040

4141

4242

4343

44-
std::shared_ptr<diffCheck::visualizer::Visualizer> vis = std::make_shared<diffCheck::visualizer::Visualizer>();
45-
vis->AddPointCloud(dfPointCloudPtr);
46-
// vis->AddMesh(dfMeshPtr);
47-
vis->Run();
44+
// std::shared_ptr<diffCheck::visualizer::Visualizer> vis = std::make_shared<diffCheck::visualizer::Visualizer>();
45+
// vis->AddPointCloud(dfPointCloudPtr);
46+
// // vis->AddMesh(dfMeshPtr);
47+
// vis->Run();
4848

4949

5050
return 0;
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
#include <gtest/gtest.h>
22

3-
// Function to test
43
int add(int a, int b) {
54
return a + b;
65
}
76

8-
// Test case
97
TEST(AddTest, HandlesPositiveInput) {
108
EXPECT_EQ(6, add(2, 4));
119
}
1210

13-
// Main function
1411
int main(int argc, char **argv) {
1512
::testing::InitGoogleTest(&argc, argv);
1613
return RUN_ALL_TESTS();

tests/test_data/.gitkeep

Whitespace-only changes.
Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,73 @@
1+
#include <filesystem>
2+
13
#include <gtest/gtest.h>
24
#include "diffCheck.hh"
35

6+
class DFPointCloudTestFixture : public ::testing::Test {
7+
protected:
8+
std::vector<Eigen::Vector3d> points;
9+
std::vector<Eigen::Vector3d> colors;
10+
std::vector<Eigen::Vector3d> normals;
11+
diffCheck::geometry::DFPointCloud dfPointCloud;
12+
13+
DFPointCloudTestFixture() : dfPointCloud(points, colors, normals) {}
14+
15+
void SetUp() override {
16+
std::filesystem::path path = std::filesystem::path(__FILE__).parent_path();
17+
std::filesystem::path pathCloud = path / "test_data" / "cloud.ply";
18+
19+
dfPointCloud = diffCheck::geometry::DFPointCloud();
20+
dfPointCloud.LoadFromPLY(pathCloud.string());
21+
}
22+
23+
void TearDown() override {
24+
// Clean up any resources if needed
25+
}
26+
};
27+
28+
TEST_F(DFPointCloudTestFixture, ConvertionO3dPointCloud) {
29+
std::shared_ptr<open3d::geometry::PointCloud> o3dPointCloud = dfPointCloud.Cvt2O3DPointCloud();
30+
std::shared_ptr<diffCheck::geometry::DFPointCloud> dfPointCloud2 = std::make_shared<diffCheck::geometry::DFPointCloud>();
31+
32+
dfPointCloud2->Cvt2DFPointCloud(o3dPointCloud);
33+
34+
EXPECT_EQ(dfPointCloud.GetNumPoints(), dfPointCloud2->GetNumPoints());
35+
EXPECT_EQ(dfPointCloud.GetNumColors(), dfPointCloud2->GetNumColors());
36+
EXPECT_EQ(dfPointCloud.GetNumNormals(), dfPointCloud2->GetNumNormals());
37+
}
38+
39+
// TODO: cilantro cloud convertion test + new methods
440

5-
TEST(DFPointCloudTest, TestConstructor) {
6-
std::vector<Eigen::Vector3d> points = {Eigen::Vector3d(1, 2, 3)};
7-
std::vector<Eigen::Vector3d> colors = {Eigen::Vector3d(255, 255, 255)};
8-
std::vector<Eigen::Vector3d> normals = {Eigen::Vector3d(0, 0, 1)};
41+
TEST_F(DFPointCloudTestFixture, ComputeAABB) {
42+
std::vector<Eigen::Vector3d> bbox = dfPointCloud.ComputeBoundingBox();
43+
EXPECT_EQ(bbox.size(), 2);
44+
}
45+
46+
TEST_F(DFPointCloudTestFixture, ComputeOBB) {
47+
std::vector<Eigen::Vector3d> obb = dfPointCloud.GetTightBoundingBox();
48+
EXPECT_EQ(obb.size(), 8);
49+
}
50+
51+
TEST_F(DFPointCloudTestFixture, GetNumPoints){
52+
EXPECT_EQ(dfPointCloud.GetNumPoints(), 1);
53+
}
954

10-
diffCheck::geometry::DFPointCloud dfPointCloud(points, colors, normals);
55+
TEST_F(DFPointCloudTestFixture, GetNumColors) {
56+
EXPECT_EQ(dfPointCloud.GetNumColors(), 1);
57+
}
58+
59+
TEST_F(DFPointCloudTestFixture, GetNumNormals) {
60+
EXPECT_EQ(dfPointCloud.GetNumNormals(), 1);
61+
}
62+
63+
TEST_F(DFPointCloudTestFixture, HasPoints) {
64+
EXPECT_TRUE(dfPointCloud.HasPoints());
65+
}
1166

12-
// Verify that the points, colors, and normals are set correctly
13-
EXPECT_EQ(dfPointCloud.Points[0], points[0]);
14-
EXPECT_EQ(dfPointCloud.Colors[0], colors[0]);
15-
EXPECT_EQ(dfPointCloud.Normals[0], normals[0]);
67+
TEST_F(DFPointCloudTestFixture, HasColors) {
68+
EXPECT_TRUE(dfPointCloud.HasColors());
1669
}
1770

18-
int main(int argc, char **argv) {
19-
::testing::InitGoogleTest(&argc, argv);
20-
return RUN_ALL_TESTS();
71+
TEST_F(DFPointCloudTestFixture, HasNormals) {
72+
EXPECT_TRUE(dfPointCloud.HasNormals());
2173
}

0 commit comments

Comments
 (0)