Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve test framework and tests #181

Merged
merged 36 commits into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b261077
Move CuTest.
Jul 20, 2021
500142b
Move utils.h.
Jul 20, 2021
4b54a4d
Rename utils.h to testutils.h.
Jul 20, 2021
dd82bce
Link tests with testutils.
Jul 20, 2021
df5133a
Add testutils.c.
Jul 20, 2021
4a7b65e
Remove return from assert_equal_shape.
Jul 20, 2021
293d339
Add simple C++ integration test.
Jul 20, 2021
9be566d
Add memcheck.
Jul 21, 2021
179e94c
Remove unneeded --config parameter.
Jul 21, 2021
e7bee2e
Install valgrind.
Jul 21, 2021
da64987
Install valgrind in separate step.
Jul 21, 2021
ff67703
Install valgrind on macOS using brew.
Jul 21, 2021
e9329a4
MemCheck only on Linux.
Jul 21, 2021
153e785
Build CuTest and testutils as static library.
Jul 21, 2021
231c256
Remove /D from target_compile_definitions.
Jul 21, 2021
478c631
Remove implicit conversion of size_t to int.
Jul 21, 2021
e12cfa1
WIP: Use macros for BDD style testing.
Jul 21, 2021
83f5cef
Fix some MSVC warnings in tests.
Jul 22, 2021
dd26d44
WIP: Use macros for BDD style testing.
Jul 22, 2021
18fc59e
Fix return value of tests.c.
Jul 22, 2021
1032be6
WIP: Macros for BDD style tests.
Jul 22, 2021
0a75e86
Remove some MSVC warnings in tests.
Jul 22, 2021
8caf06f
Fix more MSVC warnings.
Jul 22, 2021
0341c3e
Macros for BDD style tests.
Jul 22, 2021
1cfbf9f
Remove set_degree, set_order, and set_dimension.
Jul 22, 2021
3e7a9d8
Fix precision of tests for double.
Jul 22, 2021
ec9d340
Fix more MSVC warnings.
Jul 22, 2021
b105d49
Fix more MSVC warnings.
Jul 22, 2021
9db034e
Disable the warnings about unreferenced labels in the test (MSVC).
Jul 22, 2021
b9a873b
Fix typo.
Jul 22, 2021
cf7bb5f
Disable MSVC warnings in source code.
Jul 23, 2021
61594a6
Fix MSVC warnings.
Jul 23, 2021
a6f9000
Fix MSVC warnings.
Jul 23, 2021
c316005
Run memcheck and install with config parameter.
Jul 23, 2021
b974768
Run CMake installation test with build config.
Jul 23, 2021
302007b
Remove unnecessary CMAKE_BUILD_TYPE from installation test.
Jul 23, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Install System Tools
if: runner.os == 'Linux'
shell: bash
run: sudo apt install -y valgrind

- name: Create Build Environment
run: cmake -E make_directory ${{runner.workspace}}/build

Expand Down Expand Up @@ -47,10 +52,16 @@ jobs:
shell: bash
run: ctest -C $BUILD_TYPE

- name: Memory Check
if: runner.os == 'Linux'
working-directory: ${{runner.workspace}}/build
shell: bash
run: cmake --build . --target memcheck --config $BUILD_TYPE

- name: Install
working-directory: ${{runner.workspace}}/build
shell: bash
run: cmake --build . --target install
run: cmake --build . --target install --config $BUILD_TYPE

- name: Test CMake Installation
shell: bash
Expand All @@ -62,8 +73,8 @@ jobs:
else
cmake -DCMAKE_PREFIX_PATH=~/tinyspline ..
fi
cmake --build .
ctest
cmake --build . --config $BUILD_TYPE
ctest -C $BUILD_TYPE

- name: Test Pkg-config Installation
shell: bash
Expand Down
32 changes: 16 additions & 16 deletions examples/cxx/quickstart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,31 @@ int main(int argc, char **argv)

// Setup control points.
std::vector<tinyspline::real> ctrlp = spline.controlPoints();
ctrlp[0] = -1.75; // x0
ctrlp[1] = -1.0; // y0
ctrlp[2] = -1.5; // x1
ctrlp[3] = -0.5; // y1
ctrlp[4] = -1.5; // x2
ctrlp[5] = 0.0; // y2
ctrlp[6] = -1.25; // x3
ctrlp[7] = 0.5; // y3
ctrlp[8] = -0.75; // x4
ctrlp[9] = 0.75; // y4
ctrlp[10] = 0.0; // x5
ctrlp[11] = 0.5; // y5
ctrlp[12] = 0.5; // x6
ctrlp[13] = 0.0; // y6
ctrlp[0] = (tsReal) -1.75; // x0
ctrlp[1] = (tsReal) -1.0; // y0
ctrlp[2] = (tsReal) -1.5; // x1
ctrlp[3] = (tsReal) -0.5; // y1
ctrlp[4] = (tsReal) -1.5; // x2
ctrlp[5] = (tsReal) 0.0; // y2
ctrlp[6] = (tsReal) -1.25; // x3
ctrlp[7] = (tsReal) 0.5; // y3
ctrlp[8] = (tsReal) -0.75; // x4
ctrlp[9] = (tsReal) 0.75; // y4
ctrlp[10] = (tsReal) 0.0; // x5
ctrlp[11] = (tsReal) 0.5; // y5
ctrlp[12] = (tsReal) 0.5; // x6
ctrlp[13] = (tsReal) 0.0; // y6
spline.setControlPoints(ctrlp);

// Evaluate `spline` at u = 0.4 using 'eval'.
std::vector<tinyspline::real> result = spline.eval(0.4).result();
std::vector<tinyspline::real> result = spline.eval(0.4f).result();
std::cout << "x = " << result[0] << ", y = " << result[1] << std::endl;

// Derive `spline` and subdivide it into a sequence of Bezier curves.
tinyspline::BSpline beziers = spline.derive().toBeziers();

// Evaluate `beziers` at u = 0.3 using '()' instead of 'eval'.
result = beziers(0.3).result();
result = beziers((tsReal) 0.3).result();
std::cout << "x = " << result[0] << ", y = " << result[1] << std::endl;

return 0;
Expand Down
38 changes: 0 additions & 38 deletions src/tinyspline.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,54 +155,16 @@ size_t ts_bspline_degree(const tsBSpline *spline)
return spline->pImpl->deg;
}

tsError ts_bspline_set_degree(tsBSpline *spline, size_t deg, tsStatus *status)
{
if (deg >= ts_bspline_num_control_points(spline)) {
TS_RETURN_2(status, TS_DEG_GE_NCTRLP,
"degree (%lu) >= num(control_points) (%lu)",
(unsigned long) deg,
(unsigned long) ts_bspline_num_control_points(spline))
}
spline->pImpl->deg = deg;
TS_RETURN_SUCCESS(status)
}

size_t ts_bspline_order(const tsBSpline *spline)
{
return ts_bspline_degree(spline) + 1;
}

tsError ts_bspline_set_order(tsBSpline *spline, size_t order, tsStatus *status)
{
if (order == 0 || order > ts_bspline_num_control_points(spline)) {
TS_RETURN_2(status, TS_DEG_GE_NCTRLP,
"order (%lu) > num(control_points) (%lu)",
(unsigned long) order,
(unsigned long) ts_bspline_num_control_points(spline))
}
return ts_bspline_set_degree(spline, order - 1, status);
}

size_t ts_bspline_dimension(const tsBSpline *spline)
{
return spline->pImpl->dim;
}

tsError ts_bspline_set_dimension(tsBSpline *spline, size_t dim,
tsStatus *status)
{
if (dim == 0)
TS_RETURN_0(status, TS_DIM_ZERO, "unsupported dimension: 0")
if (ts_bspline_len_control_points(spline) % dim != 0) {
TS_RETURN_2(status, TS_LCTRLP_DIM_MISMATCH,
"len(control_points) (%lu) %% dimension (%lu) != 0",
(unsigned long) ts_bspline_len_control_points(spline),
(unsigned long) dim)
}
spline->pImpl->dim = dim;
TS_RETURN_SUCCESS(status)
}

size_t ts_bspline_len_control_points(const tsBSpline *spline)
{
return ts_bspline_num_control_points(spline) *
Expand Down
63 changes: 0 additions & 63 deletions src/tinyspline.h
Original file line number Diff line number Diff line change
Expand Up @@ -514,23 +514,6 @@ typedef struct
*/
size_t TINYSPLINE_API ts_bspline_degree(const tsBSpline *spline);

/**
* Sets the degree of \p spline.
*
* @param[out] spline
* The spline whose degree is set.
* @param[in] deg
* The degree to be set.
* @param[out] status
* The status of this function. May be NULL.
* @return TS_SUCCESS
* On success.
* @return TS_DEG_GE_NCTRLP
* If \p degree >= ts_bspline_get_control_points(spline).
*/
tsError TINYSPLINE_API ts_bspline_set_degree(tsBSpline *spline, size_t deg,
tsStatus *status);

/**
* Returns the order (degree + 1) of \p spline.
*
Expand All @@ -541,25 +524,6 @@ tsError TINYSPLINE_API ts_bspline_set_degree(tsBSpline *spline, size_t deg,
*/
size_t TINYSPLINE_API ts_bspline_order(const tsBSpline *spline);

/**
* Sets the order (degree + 1) of \p spline.
*
* @param[out] spline
* The spline whose order is set.
* @param[in] order
* The order to be set.
* @param[out] status
* The status of this function. May be NULL.
* @return TS_SUCCESS
* On success.
* @return TS_DEG_GE_NCTRLP
* If \p order > ts_bspline_get_control_points(spline) or if \p order == 0
* ( due to the underflow resulting from: order - 1 => 0 - 1 => INT_MAX
* which always is >= ts_bspline_get_control_points(spline) ).
*/
tsError TINYSPLINE_API ts_bspline_set_order(tsBSpline *spline, size_t order,
tsStatus *status);

/**
* Returns the dimension of \p spline. The dimension of a spline describes the
* number of components for each point in ts_bspline_get_control_points(spline).
Expand All @@ -573,33 +537,6 @@ tsError TINYSPLINE_API ts_bspline_set_order(tsBSpline *spline, size_t order,
*/
size_t TINYSPLINE_API ts_bspline_dimension(const tsBSpline *spline);

/**
* Sets the dimension of \p spline. The following conditions must be satisfied:
*
* (1) dim >= 1
* (2) len_control_points(spline) % dim == 0
*
* with _len_control_points_ being the length of the control point array of \p
* spline. The dimension of a spline describes the number of components for
* each point in ts_bspline_get_control_points(spline). One-dimensional splines
* are possible, albeit their benefit might be questionable.
*
* @param[out] spline
* The spline whose dimension is set.
* @param[in] dim
* The dimension to be set.
* @param[out] status
* The status of this function. May be NULL.
* @return TS_SUCCESS
* On success.
* @return TS_DIM_ZERO
* If \p dimension == 0.
* @return TS_LCTRLP_DIM_MISMATCH
* If len_control_points(spline) % \p dim != 0
*/
tsError TINYSPLINE_API ts_bspline_set_dimension(tsBSpline *spline, size_t dim,
tsStatus *status);

/**
* Returns the length of the control point array of \p spline.
*
Expand Down
49 changes: 45 additions & 4 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
###############################################################################
### Build CuTest.
###############################################################################
add_library(cutest STATIC "cutest/CuTest.c")
target_include_directories(cutest PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/cutest")
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
# Disable the warnings about sprintf.
target_compile_definitions(cutest PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()



###############################################################################
### Build testutils.
###############################################################################
add_library(testutils STATIC "testutils.c")
target_include_directories(cutest PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(testutils PUBLIC cutest tinyspline)



###############################################################################
### Check if code coverage is available. Coverage is measured and visualized
### with gcov, lcov, and genthml.
### using gcov, lcov, and genthml. If one of these tools is missing, code
### coverage cannot be generated.
#
# TINYSPLINE_COVERAGE_AVAILABLE
# TRUE if the tools that are required to generate code coverage are
Expand Down Expand Up @@ -61,19 +83,38 @@ set(TINYSPLINE_COVERAGE_C_LIBRARIES


###############################################################################
### Add subdirectories containing the actual unit tests.
### Add subdirectories containing the unit tests.
###############################################################################
add_subdirectory(c)
add_subdirectory(cxx)



###############################################################################
### Subsume unit tests and code coverage with custom targets.
###############################################################################
add_custom_target(tests
COMMAND tinyspline_tests
DEPENDS tinyspline_tests
DEPENDS tinyspline_tests tinysplinecxx_tests
COMMAND tinyspline_tests tinysplinecxx_tests
)
add_custom_target(coverage
DEPENDS tinyspline_coverage
)



###############################################################################
### Add a custom target for checking memory issues with CTest.
###############################################################################
add_custom_target(memcheck
DEPENDS tests
COMMAND
${CMAKE_CTEST_COMMAND} -T memcheck
COMMAND
${CMAKE_COMMAND} -E cat
"${CMAKE_BINARY_DIR}/Testing/Temporary/MemoryChecker.1.log"
COMMAND
${CMAKE_COMMAND} -E cat
"${CMAKE_BINARY_DIR}/Testing/Temporary/MemoryChecker.2.log"
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
)
24 changes: 7 additions & 17 deletions test/c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
###############################################################################
### Setup compiler suite.
###############################################################################
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
# Disable the warnings about sprintf in CuTest.
add_definitions("/D_CRT_SECURE_NO_WARNINGS")
endif()



###############################################################################
### Create unit tests.
###############################################################################
file(GLOB_RECURSE TINYSPLINE_TESTS_SOURCE_FILES "*.c")
include_directories(cutest)
add_executable(tinyspline_tests "utils.h" ${TINYSPLINE_TESTS_SOURCE_FILES})
target_link_libraries(tinyspline_tests
PRIVATE tinyspline)
add_executable(tinyspline_tests ${TINYSPLINE_TESTS_SOURCE_FILES})
target_link_libraries(tinyspline_tests PRIVATE testutils)

if(EMSCRIPTEN)
add_test(NAME tinyspline_tests
Expand All @@ -34,15 +22,17 @@ endif()
### Create code coverage.
###############################################################################
if(TINYSPLINE_COVERAGE_AVAILABLE)
include_directories(${TINYSPLINE_C_INCLUDE_DIR})
add_executable(tinyspline_tests_coverage
EXCLUDE_FROM_ALL
${TINYSPLINE_TESTS_SOURCE_FILES}
${TINYSPLINE_C_SOURCE_FILES})
target_include_directories(tinyspline_tests_coverage
PRIVATE ${TINYSPLINE_C_INCLUDE_DIR})
set_target_properties(tinyspline_tests_coverage PROPERTIES
COMPILE_FLAGS ${TINYSPLINE_COVERAGE_C_FLAGS})
target_link_libraries(tinyspline_tests_coverage
PRIVATE ${TINYSPLINE_COVERAGE_C_LIBRARIES}
target_link_libraries(tinyspline_tests_coverage PRIVATE
testutils
${TINYSPLINE_COVERAGE_C_LIBRARIES}
${TINYSPLINE_C_LINK_LIBRARIES})
set(TINYSPLINE_COVERAGE_INFO_FILE coverage.info)
add_custom_target(tinyspline_coverage
Expand Down
Loading