Skip to content

Commit d2905ff

Browse files
committed
mERGE-FIX: Merge branch 'test_suite' into segmentation for fixing cmake dll copying
2 parents 701f47d + 7681361 commit d2905ff

File tree

9 files changed

+121
-99
lines changed

9 files changed

+121
-99
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>
@@ -150,54 +156,30 @@ if (BUILD_PYTHON_MODULE)
150156
$<TARGET_FILE:${PYBINDMODULE_NAME}>
151157
${PYPI_DIR}
152158
)
153-
154-
# get all the files -dlls in the bin directory and copy them one by one to the pypi directory
155-
file(GLOB files ${CMAKE_BINARY_DIR}/bin/Release/*.dll)
156-
foreach(file ${files})
157-
message(STATUS "Copying ${file} to ${TARGET_DLL_PYPI_DIR}")
158-
add_custom_command(TARGET ${PYBINDMODULE_NAME} POST_BUILD
159-
COMMAND ${CMAKE_COMMAND} -E copy
160-
${file}
161-
${TARGET_DLL_PYPI_DIR}
162-
)
163-
endforeach()
159+
copy_dlls(${TARGET_DLL_PYPI_DIR} ${PYBINDMODULE_NAME})
164160

165161
endif()
166162

167163
#--------------------------------------------------------------------------
168164
# Tests
169165
#--------------------------------------------------------------------------
166+
include(CTest)
167+
enable_testing()
168+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/deps/googletest)
169+
set(TESTS_OUT_DIR ${CMAKE_BINARY_DIR}/df_tests/)
170+
set(TEST_OUT_DIR_BINARY ${TESTS_OUT_DIR}/${CMAKE_BUILD_TYPE})
171+
172+
# add new test suites .cc here
173+
set(UNIT_TESTS df_test_suites)
174+
add_executable(${UNIT_TESTS}
175+
tests/unit_tests/DFPointCloudTest.cc
176+
tests/entryTest.cc
177+
)
178+
set_target_properties(${UNIT_TESTS} PROPERTIES
179+
RUNTIME_OUTPUT_DIRECTORY ${TESTS_OUT_DIR}
180+
)
181+
target_link_libraries(${UNIT_TESTS} gtest gtest_main)
182+
target_link_libraries(${UNIT_TESTS} ${SHARED_LIB_NAME})
170183

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