Skip to content

Commit

Permalink
Merge pull request diffCheckOrg#36 from diffCheckOrg/test_suite
Browse files Browse the repository at this point in the history
MERGE: Test suite structure + fixes
  • Loading branch information
9and3 authored Jul 11, 2024
2 parents 35cfe5b + 7681361 commit 64007b1
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 120 deletions.
74 changes: 28 additions & 46 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
include(external_tools)
include(options)

# check that the -DCMAKE_BUILD_TYPE is set
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
endif()

# do a submodule init if not done already
execute_process(COMMAND git submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
Expand Down Expand Up @@ -48,7 +54,7 @@ target_include_directories(${SHARED_LIB_NAME}
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src
)

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


Expand Down Expand Up @@ -78,7 +84,7 @@ target_link_libraries(${SHARED_LIB_NAME} PUBLIC Open3D::Open3D)
if(WIN32)
get_target_property(open3d_type Open3D::Open3D TYPE)
if(open3d_type STREQUAL "SHARED_LIBRARY")
message(STATUS "Copying Open3D.dll to ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>")
message(STATUS "Copying Open3D.dll to ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}")
add_custom_command(TARGET ${SHARED_LIB_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
$<TARGET_FILE:Open3D::Open3D>
Expand Down Expand Up @@ -146,54 +152,30 @@ if (BUILD_PYTHON_MODULE)
$<TARGET_FILE:${PYBINDMODULE_NAME}>
${PYPI_DIR}
)

# get all the files -dlls in the bin directory and copy them one by one to the pypi directory
file(GLOB files ${CMAKE_BINARY_DIR}/bin/Release/*.dll)
foreach(file ${files})
message(STATUS "Copying ${file} to ${TARGET_DLL_PYPI_DIR}")
add_custom_command(TARGET ${PYBINDMODULE_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${file}
${TARGET_DLL_PYPI_DIR}
)
endforeach()
copy_dlls(${TARGET_DLL_PYPI_DIR} ${PYBINDMODULE_NAME})

endif()

#--------------------------------------------------------------------------
# Tests
#--------------------------------------------------------------------------
include(CTest)
enable_testing()
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/deps/googletest)
set(TESTS_OUT_DIR ${CMAKE_BINARY_DIR}/df_tests/)
set(TEST_OUT_DIR_BINARY ${TESTS_OUT_DIR}/${CMAKE_BUILD_TYPE})

# add new test suites .cc here
set(UNIT_TESTS df_test_suites)
add_executable(${UNIT_TESTS}
tests/unit_tests/DFPointCloudTest.cc
tests/entryTest.cc
)
set_target_properties(${UNIT_TESTS} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${TESTS_OUT_DIR}
)
target_link_libraries(${UNIT_TESTS} gtest gtest_main)
target_link_libraries(${UNIT_TESTS} ${SHARED_LIB_NAME})

# include(CTest)
# enable_testing()
# add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/deps/googletest)
# set(TESTS_OUT_DIR ${CMAKE_BINARY_DIR}/tests/)


# # Unit testing ------------------------------------------------------------
# set(UNIT_TESTS unit_tests)
# add_executable(${UNIT_TESTS} tests/unit_tests/DFPointCloudTest.cc)
# set_target_properties(${UNIT_TESTS} PROPERTIES
# RUNTIME_OUTPUT_DIRECTORY ${TESTS_OUT_DIR}
# )

# target_link_libraries(${UNIT_TESTS} gtest gtest_main)
# target_link_libraries(${UNIT_TESTS} ${SHARED_LIB_NAME})

# add_test(NAME ${UNIT_TESTS} COMMAND ${UNIT_TESTS})

# Integration testing -----------------------------------------------------
# Component testing -------------------------------------------------------
# etc ---------------------------------------------------------------------

# # TODO: a better way to copy the dlls to the tests directory for the tests
# # get all the files -dlls in the bin directory and copy them one by one to tests dir
# file(GLOB files ${CMAKE_BINARY_DIR}/bin/Release/*.dll)
# foreach(file ${files})
# message(STATUS "Copying ${file} to ${TESTS_OUT_DIR}")
# add_custom_command(TARGET ${UNIT_TESTS} POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E copy
# ${file}
# ${TESTS_OUT_DIR}/Release
# )
# endforeach()
add_test(NAME ${UNIT_TESTS} COMMAND ${UNIT_TESTS})
copy_dlls(${TEST_OUT_DIR_BINARY} ${UNIT_TESTS})
42 changes: 7 additions & 35 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,43 +320,15 @@ dfVisualizerPtr->Run();


### CTesting (TO BE UPDATED)
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.
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:

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

First create a new sub-folder in the folder `./test` as `./test/exampletest`.
Here add a console cpp file called `tester.cpp` which returns 0 or 1 and add a new `CMakeLists.txt` as such:
```cmake
add_executable(example_test tester.cpp)
/* <--
Insert here linking necessary for the executable
Note that if you already found packages in the head CMakeLists file
you can simply use the macros here.
--> */
add_test(NAME "ExampleTest" COMMAND "example_test" <argv-here> WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
```
In the `./test`'s `CMakeLists.txt` add the created sub-directory:
```cmake
if (TEST_EXAMPLE)
add_subdirectory(exampletest)
endif()
To run the tests from terminal
```
Finally add an option in the main `CMakeLists.txt` describing the test:
```cmake
include(CTest)
# ...
option(TEST_EXAMPLE "Test to test something important." ON)
# ...
if(TEST_EXAMPLE)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests/exampletest)
endif()
ctest --test-dir .\build\ -C Release -V
```

Next, `./configure.sh -c` and `./build.sh` and:
```bash
cd ./build
ctest -N # <--- to see how many tests there are
ctest -V # <--- run the tests
or
```
.\build\df_tests\<config>\df_tests.exe
```
2 changes: 1 addition & 1 deletion cmake/__noenv__config.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
REM configure the project
cmake -S . -B build
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
2 changes: 1 addition & 1 deletion cmake/clean_config.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ REM clean the build directory and reconfigure it
rmdir /s /q build

REM configure the project
cmake -S . -B build
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
2 changes: 1 addition & 1 deletion cmake/config.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ REM activate the conda diff_check environment otherwise the python wrap won't wo
call cmake/activate_conda.bat

REM configure the project
cmake -S . -B build
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
19 changes: 19 additions & 0 deletions cmake/external_tools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,23 @@ function(download_submodule_project project_name)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update --init --recursive --remote failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
endfunction()

# ------------------------------------------------------------------------------
function (copy_dlls directory_to_copy_dlls post_build_target)
message (STATUS "Erasing old DLLs and copy new ones to ${directory_to_copy_dlls}")
file(GLOB files ${directory_to_copy_dlls}/*.dll)
foreach(file ${files})
message(STATUS "Removing ${file}")
file(REMOVE ${file})
endforeach()
file(GLOB files ${CMAKE_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE}/*.dll)
foreach(file ${files})
message(STATUS "Copying ${file} to ${directory_to_copy_dlls}")
add_custom_command(TARGET ${post_build_target} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${file}
${directory_to_copy_dlls}
)
endforeach()
endfunction()
42 changes: 21 additions & 21 deletions src/diffCheckApp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,39 @@ int main()
std::shared_ptr<diffCheck::geometry::DFMesh> dfMeshPtr
= std::make_shared<diffCheck::geometry::DFMesh>();

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

// dfPointCloudPtr->LoadFromPLY(pathCloud);
dfMeshPtr->LoadFromPLY(pathMesh);
// // dfPointCloudPtr->LoadFromPLY(pathCloud);
// dfMeshPtr->LoadFromPLY(pathMesh);

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


// convert the sphere to a diffCheck point cloud
// auto o3dPointCloud = meshO3d.SamplePointsUniformly(1000);
// // convert the sphere to a diffCheck point cloud
// // auto o3dPointCloud = meshO3d.SamplePointsUniformly(1000);

std::shared_ptr<open3d::geometry::PointCloud> tightBBOX = std::make_shared<open3d::geometry::PointCloud>();
// std::shared_ptr<open3d::geometry::PointCloud> tightBBOX = std::make_shared<open3d::geometry::PointCloud>();

// compute the bounding box
open3d::geometry::OrientedBoundingBox bbox = meshO3d.GetMinimalOrientedBoundingBox();
std::vector<Eigen::Vector3d> bboxPts = bbox.GetBoxPoints();
for (auto &pt : bboxPts)
{
tightBBOX->points_.push_back(pt);
}
// // compute the bounding box
// open3d::geometry::OrientedBoundingBox bbox = meshO3d.GetMinimalOrientedBoundingBox();
// std::vector<Eigen::Vector3d> bboxPts = bbox.GetBoxPoints();
// for (auto &pt : bboxPts)
// {
// tightBBOX->points_.push_back(pt);
// }


dfPointCloudPtr->Cvt2DFPointCloud(tightBBOX);
// dfPointCloudPtr->Cvt2DFPointCloud(tightBBOX);




std::shared_ptr<diffCheck::visualizer::Visualizer> vis = std::make_shared<diffCheck::visualizer::Visualizer>();
vis->AddPointCloud(dfPointCloudPtr);
// vis->AddMesh(dfMeshPtr);
vis->Run();
// std::shared_ptr<diffCheck::visualizer::Visualizer> vis = std::make_shared<diffCheck::visualizer::Visualizer>();
// vis->AddPointCloud(dfPointCloudPtr);
// // vis->AddMesh(dfMeshPtr);
// vis->Run();


return 0;
Expand Down
3 changes: 0 additions & 3 deletions tests/entry_test.cc → tests/entryTest.cc
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
#include <gtest/gtest.h>

// Function to test
int add(int a, int b) {
return a + b;
}

// Test case
TEST(AddTest, HandlesPositiveInput) {
EXPECT_EQ(6, add(2, 4));
}

// Main function
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
Expand Down
Empty file added tests/test_data/.gitkeep
Empty file.
76 changes: 64 additions & 12 deletions tests/unit_tests/DFPointCloudTest.cc
Original file line number Diff line number Diff line change
@@ -1,21 +1,73 @@
#include <filesystem>

#include <gtest/gtest.h>
#include "diffCheck.hh"

class DFPointCloudTestFixture : public ::testing::Test {
protected:
std::vector<Eigen::Vector3d> points;
std::vector<Eigen::Vector3d> colors;
std::vector<Eigen::Vector3d> normals;
diffCheck::geometry::DFPointCloud dfPointCloud;

DFPointCloudTestFixture() : dfPointCloud(points, colors, normals) {}

void SetUp() override {
std::filesystem::path path = std::filesystem::path(__FILE__).parent_path();
std::filesystem::path pathCloud = path / "test_data" / "cloud.ply";

dfPointCloud = diffCheck::geometry::DFPointCloud();
dfPointCloud.LoadFromPLY(pathCloud.string());
}

void TearDown() override {
// Clean up any resources if needed
}
};

TEST_F(DFPointCloudTestFixture, ConvertionO3dPointCloud) {
std::shared_ptr<open3d::geometry::PointCloud> o3dPointCloud = dfPointCloud.Cvt2O3DPointCloud();
std::shared_ptr<diffCheck::geometry::DFPointCloud> dfPointCloud2 = std::make_shared<diffCheck::geometry::DFPointCloud>();

dfPointCloud2->Cvt2DFPointCloud(o3dPointCloud);

EXPECT_EQ(dfPointCloud.GetNumPoints(), dfPointCloud2->GetNumPoints());
EXPECT_EQ(dfPointCloud.GetNumColors(), dfPointCloud2->GetNumColors());
EXPECT_EQ(dfPointCloud.GetNumNormals(), dfPointCloud2->GetNumNormals());
}

// TODO: cilantro cloud convertion test + new methods

TEST(DFPointCloudTest, TestConstructor) {
std::vector<Eigen::Vector3d> points = {Eigen::Vector3d(1, 2, 3)};
std::vector<Eigen::Vector3d> colors = {Eigen::Vector3d(255, 255, 255)};
std::vector<Eigen::Vector3d> normals = {Eigen::Vector3d(0, 0, 1)};
TEST_F(DFPointCloudTestFixture, ComputeAABB) {
std::vector<Eigen::Vector3d> bbox = dfPointCloud.ComputeBoundingBox();
EXPECT_EQ(bbox.size(), 2);
}

TEST_F(DFPointCloudTestFixture, ComputeOBB) {
std::vector<Eigen::Vector3d> obb = dfPointCloud.GetTightBoundingBox();
EXPECT_EQ(obb.size(), 8);
}

TEST_F(DFPointCloudTestFixture, GetNumPoints){
EXPECT_EQ(dfPointCloud.GetNumPoints(), 1);
}

diffCheck::geometry::DFPointCloud dfPointCloud(points, colors, normals);
TEST_F(DFPointCloudTestFixture, GetNumColors) {
EXPECT_EQ(dfPointCloud.GetNumColors(), 1);
}

TEST_F(DFPointCloudTestFixture, GetNumNormals) {
EXPECT_EQ(dfPointCloud.GetNumNormals(), 1);
}

TEST_F(DFPointCloudTestFixture, HasPoints) {
EXPECT_TRUE(dfPointCloud.HasPoints());
}

// Verify that the points, colors, and normals are set correctly
EXPECT_EQ(dfPointCloud.Points[0], points[0]);
EXPECT_EQ(dfPointCloud.Colors[0], colors[0]);
EXPECT_EQ(dfPointCloud.Normals[0], normals[0]);
TEST_F(DFPointCloudTestFixture, HasColors) {
EXPECT_TRUE(dfPointCloud.HasColors());
}

int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
TEST_F(DFPointCloudTestFixture, HasNormals) {
EXPECT_TRUE(dfPointCloud.HasNormals());
}

0 comments on commit 64007b1

Please sign in to comment.