Skip to content

Commit d1ab954

Browse files
committed
WIP: working on tests, structure in
1 parent 803fee2 commit d1ab954

File tree

3 files changed

+81
-29
lines changed

3 files changed

+81
-29
lines changed

CMakeLists.txt

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -164,23 +164,42 @@ endif()
164164
# Tests
165165
#--------------------------------------------------------------------------
166166

167-
# include(CTest)
168-
# enable_testing()
169-
# add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/deps/googletest)
170-
# set(TESTS_OUT_DIR ${CMAKE_BINARY_DIR}/tests/)
167+
include(CTest)
168+
enable_testing()
169+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/deps/googletest)
170+
set(TESTS_OUT_DIR ${CMAKE_BINARY_DIR}/df_tests/)
171+
172+
173+
# Unit testing ------------------------------------------------------------
174+
set(UNIT_TESTS df_test_suites)
175+
add_executable(${UNIT_TESTS}
176+
tests/unit_tests/DFPointCloudTest.cc
177+
tests/entryTest.cc
178+
)
179+
set_target_properties(${UNIT_TESTS} PROPERTIES
180+
RUNTIME_OUTPUT_DIRECTORY ${TESTS_OUT_DIR}
181+
)
182+
183+
target_link_libraries(${UNIT_TESTS} gtest gtest_main)
184+
target_link_libraries(${UNIT_TESTS} ${SHARED_LIB_NAME})
185+
186+
add_test(NAME ${UNIT_TESTS} COMMAND ${UNIT_TESTS})
187+
188+
189+
171190

172191

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-
# )
179192

180-
# target_link_libraries(${UNIT_TESTS} gtest gtest_main)
181-
# target_link_libraries(${UNIT_TESTS} ${SHARED_LIB_NAME})
182193

183-
# add_test(NAME ${UNIT_TESTS} COMMAND ${UNIT_TESTS})
194+
# # post build recipe
195+
# add_test(NAME ${UNIT_TEST} COMMAND ${UNIT_TEST})
196+
# add_custom_command(
197+
# TARGET ${UNIT_TEST}
198+
# COMMENT "Run tests"
199+
# POST_BUILD
200+
# WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
201+
# COMMAND ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> -R "^${UNIT_TEST}$" --output-on-failures
202+
# )
184203

185204
# Integration testing -----------------------------------------------------
186205
# Component testing -------------------------------------------------------
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
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
11+
12+
1413
int main(int argc, char **argv) {
1514
::testing::InitGoogleTest(&argc, argv);
1615
return RUN_ALL_TESTS();
Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,55 @@
11
#include <gtest/gtest.h>
22
#include "diffCheck.hh"
33

4+
class DFPointCloudTestFixture : public ::testing::Test {
5+
protected:
6+
std::vector<Eigen::Vector3d> points;
7+
std::vector<Eigen::Vector3d> colors;
8+
std::vector<Eigen::Vector3d> normals;
9+
diffCheck::geometry::DFPointCloud dfPointCloud;
410

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)};
11+
DFPointCloudTestFixture() : dfPointCloud(points, colors, normals) {}
912

10-
diffCheck::geometry::DFPointCloud dfPointCloud(points, colors, normals);
13+
void SetUp() override {
14+
// Initialize your objects and variables here
15+
points = {Eigen::Vector3d(1, 2, 3)};
16+
colors = {Eigen::Vector3d(255, 255, 255)};
17+
normals = {Eigen::Vector3d(0, 0, 1)};
1118

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]);
19+
// Reinitialize dfPointCloud in case you need to reset its state
20+
dfPointCloud = diffCheck::geometry::DFPointCloud(points, colors, normals);
21+
}
22+
23+
void TearDown() override {
24+
// Clean up any resources if needed
25+
}
26+
};
27+
28+
TEST_F(DFPointCloudTestFixture, GetNumPoints) {
29+
EXPECT_EQ(dfPointCloud.GetNumPoints(), 1);
30+
}
31+
32+
TEST_F(DFPointCloudTestFixture, GetNumColors) {
33+
EXPECT_EQ(dfPointCloud.GetNumColors(), 1);
34+
}
35+
36+
TEST_F(DFPointCloudTestFixture, GetNumNormals) {
37+
EXPECT_EQ(dfPointCloud.GetNumNormals(), 1);
38+
}
39+
40+
TEST_F(DFPointCloudTestFixture, HasPoints) {
41+
EXPECT_TRUE(dfPointCloud.HasPoints());
42+
}
43+
44+
TEST_F(DFPointCloudTestFixture, HasColors) {
45+
EXPECT_TRUE(dfPointCloud.HasColors());
46+
}
47+
48+
TEST_F(DFPointCloudTestFixture, HasNormals) {
49+
EXPECT_TRUE(dfPointCloud.HasNormals());
1650
}
1751

18-
int main(int argc, char **argv) {
19-
::testing::InitGoogleTest(&argc, argv);
20-
return RUN_ALL_TESTS();
21-
}
52+
// int main(int argc, char **argv) {
53+
// ::testing::InitGoogleTest(&argc, argv);
54+
// return RUN_ALL_TESTS();
55+
// }

0 commit comments

Comments
 (0)