Skip to content

Commit 07036e1

Browse files
authored
Add more unit tests (#212)
* Add tests to cover empty cases of prepare_transform_spectral() Signed-off-by: Aleksandr Motsjonov <[email protected]> * More tests Signed-off-by: Aleksandr Motsjonov <[email protected]> * More tests Signed-off-by: Aleksandr Motsjonov <[email protected]> * formatting Signed-off-by: Aleksandr Motsjonov <[email protected]> * remove duplicate test Signed-off-by: Aleksandr Motsjonov <[email protected]> * Trying fix windows build Signed-off-by: Aleksandr Motsjonov <[email protected]> * remove unused cmake file Signed-off-by: Aleksandr Motsjonov <[email protected]> * PR review comment address Signed-off-by: Aleksandr Motsjonov <[email protected]> * Add main.cpp to coverage. Signed-off-by: Aleksandr Motsjonov <[email protected]> * comment out comment Signed-off-by: Aleksandr Motsjonov <[email protected]> * Removed extra DNG test file; replace test with direct usage one; introduce a test utility wrapper that allow capturing of stderr buffer Signed-off-by: Aleksandr Motsjonov <[email protected]> --------- Signed-off-by: Aleksandr Motsjonov <[email protected]>
1 parent 1b86a2f commit 07036e1

File tree

13 files changed

+872
-154
lines changed

13 files changed

+872
-154
lines changed

build_scripts/vcpkg.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"dependencies": [
44
"ceres",
55
"nlohmann-json",
6-
"openimageio",
6+
{ "name": "openimageio", "features": [ "libraw" ] },
77
"nanobind"
88
],
99
"overrides": [

cmake/CodeCoverage.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function(generate_coverage_report)
7878
COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure || true
7979
COMMAND ${CMAKE_COMMAND} -E echo "Generating coverage report..."
8080
COMMAND ${LCOV_PATH} --ignore-errors inconsistent,unsupported,format,unused,corrupt --directory ${CMAKE_BINARY_DIR} --capture --output-file ${CMAKE_BINARY_DIR}/coverage/coverage.info
81-
COMMAND ${LCOV_PATH} --ignore-errors inconsistent,unsupported,format,unused,corrupt --extract ${CMAKE_BINARY_DIR}/coverage/coverage.info '*/src/rawtoaces_*' '*/include/rawtoaces/*' --output-file ${CMAKE_BINARY_DIR}/coverage/coverage_temp.info
81+
COMMAND ${LCOV_PATH} --ignore-errors inconsistent,unsupported,format,unused,corrupt --extract ${CMAKE_BINARY_DIR}/coverage/coverage.info '*/src/rawtoaces_*' '*/src/rawtoaces/*' '*/include/rawtoaces/*' --output-file ${CMAKE_BINARY_DIR}/coverage/coverage_temp.info
8282
COMMAND ${LCOV_PATH} --ignore-errors inconsistent,unsupported,format,unused,corrupt --remove ${CMAKE_BINARY_DIR}/coverage/coverage_temp.info '*/tests/*' --output-file ${CMAKE_BINARY_DIR}/coverage/coverage_filtered.info
8383
COMMAND ${GENHTML_PATH} --ignore-errors inconsistent,unsupported,corrupt,category ${CMAKE_BINARY_DIR}/coverage/coverage_filtered.info --output-directory ${CMAKE_BINARY_DIR}/coverage/html
8484
COMMAND ${CMAKE_COMMAND} -E echo "Coverage report generated in ${CMAKE_BINARY_DIR}/coverage/html/index.html"

cmake/modules/Findlibraw.cmake

Lines changed: 0 additions & 91 deletions
This file was deleted.

src/bindings/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ if ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" )
2020
target_compile_options ( rawtoaces_bindings PRIVATE -Wno-error=zero-length-bounds )
2121
endif ()
2222
elseif ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang" )
23-
target_compile_options ( nanobind-static PRIVATE -Wno-error=zero-length-array )
24-
target_compile_options ( rawtoaces_bindings PRIVATE -Wno-error=zero-length-array )
23+
target_compile_options ( nanobind-static PRIVATE -Wno-error=zero-length-array -Wno-zero-length-array )
24+
target_compile_options ( rawtoaces_bindings PRIVATE -Wno-error=zero-length-array -Wno-zero-length-array )
2525
endif()
2626

2727
set_target_properties( rawtoaces_bindings PROPERTIES

src/rawtoaces/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
cmake_minimum_required(VERSION 3.12)
22

3+
# Include coverage support if enabled
4+
if( ENABLE_COVERAGE )
5+
include( ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/CodeCoverage.cmake )
6+
endif()
7+
38
add_executable( rawtoaces
49
main.cpp
510
)
@@ -9,4 +14,9 @@ target_link_libraries ( rawtoaces
914
${RAWTOACES_UTIL_LIB}
1015
)
1116

17+
# Enable coverage for this executable if coverage is enabled
18+
if( ENABLE_COVERAGE AND COVERAGE_SUPPORTED )
19+
setup_coverage_flags(rawtoaces)
20+
endif()
21+
1222
install( TARGETS rawtoaces DESTINATION ${INSTALL_BIN_DIR} )

src/rawtoaces_core/rawtoaces_core.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ bool SpectralSolver::calculate_WB()
416416
{
417417
std::cerr << "ERROR: camera needs to be initialised prior to calling "
418418
<< "SpectralSolver::calculate_WB()" << std::endl;
419+
return false;
419420
}
420421

421422
if ( illuminant.data.count( "main" ) == 0 ||

src/rawtoaces_util/image_converter.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,9 @@ bool prepare_transform_spectral(
338338

339339
success = solver.find_illuminant( tmp_wb_multipliers );
340340

341-
if ( !success )
342-
{
343-
std::cerr << "ERROR: Failed to find a suitable illuminant."
344-
<< std::endl;
345-
return false;
346-
}
341+
// Expected to be true due to camera lookup success in the previous step,
342+
// since lack of camera is the only way for find_illuminant to return false;
343+
assert( success );
347344

348345
if ( settings.verbosity > 0 )
349346
{

src/rawtoaces_util/rawtoaces_util_priv.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <string>
88
#include <vector>
99
#include <OpenImageIO/imageio.h>
10+
#include "../include/rawtoaces/image_converter.h"
1011

1112
// Contains the declarations of the private functions,
1213
// exposed here for unit-testing.
@@ -20,5 +21,12 @@ std::vector<std::string>
2021
database_paths( const std::string &override_path = "" );
2122
void fix_metadata( OIIO::ImageSpec &spec );
2223

24+
bool prepare_transform_spectral(
25+
const OIIO::ImageSpec &image_spec,
26+
const ImageConverter::Settings &settings,
27+
std::vector<double> &WB_multipliers,
28+
std::vector<std::vector<double>> &IDT_matrix,
29+
std::vector<std::vector<double>> &CAT_matrix );
30+
2331
} // namespace util
2432
} // namespace rta

tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ add_test ( NAME Test_Misc COMMAND Test_Misc )
171171
add_executable (
172172
Test_UsageTimer
173173
testUsageTimer.cpp
174+
test_utils.cpp
174175
)
175176

176177
target_link_libraries(
@@ -188,6 +189,7 @@ add_test ( NAME Test_UsageTimer COMMAND Test_UsageTimer )
188189
add_executable (
189190
Test_ImageConverter
190191
test_image_converter.cpp
192+
test_utils.cpp
191193
)
192194

193195
target_link_libraries(

tests/testUsageTimer.cpp

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <string>
1212
#include <thread>
1313

14+
#include "test_utils.h"
15+
1416
using namespace rta::util;
1517

1618
// Helper function to extract time value from output
@@ -111,13 +113,8 @@ void testTimingOutput()
111113
std::this_thread::sleep_for( std::chrono::milliseconds( 50 ) );
112114

113115
// Capture output to verify timing
114-
std::stringstream buffer;
115-
std::streambuf *old = std::cerr.rdbuf( buffer.rdbuf() );
116-
117-
timer.print( "test_path", "test_message" );
118-
119-
std::cerr.rdbuf( old );
120-
std::string output = buffer.str();
116+
std::string output =
117+
capture_stderr( [&]() { timer.print( "test_path", "test_message" ); } );
121118

122119
// Should contain timing information
123120
OIIO_CHECK_ASSERT( output.find( "Timing:" ) != std::string::npos );
@@ -172,17 +169,11 @@ void testMultipleIndependentInstances()
172169
std::this_thread::sleep_for( std::chrono::milliseconds( 5 ) );
173170

174171
// Capture outputs to verify different timing
175-
std::stringstream buffer1, buffer2;
176-
std::streambuf *old = std::cerr.rdbuf( buffer1.rdbuf() );
177-
178-
timer1.print( "path1", "message1" );
179-
std::cerr.rdbuf( buffer2.rdbuf() );
180-
timer2.print( "path2", "message2" );
172+
std::string output1 =
173+
capture_stderr( [&]() { timer1.print( "path1", "message1" ); } );
181174

182-
std::cerr.rdbuf( old );
183-
184-
std::string output1 = buffer1.str();
185-
std::string output2 = buffer2.str();
175+
std::string output2 =
176+
capture_stderr( [&]() { timer2.print( "path2", "message2" ); } );
186177

187178
// Both should contain timing information
188179
OIIO_CHECK_ASSERT( output1.find( "Timing:" ) != std::string::npos );
@@ -212,13 +203,8 @@ void testTimingAccuracy()
212203
std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) );
213204

214205
// Capture output to verify timing
215-
std::stringstream buffer;
216-
std::streambuf *old = std::cerr.rdbuf( buffer.rdbuf() );
217-
218-
timer.print( "test_path", "test_message" );
219-
220-
std::cerr.rdbuf( old );
221-
std::string output = buffer.str();
206+
std::string output =
207+
capture_stderr( [&]() { timer.print( "test_path", "test_message" ); } );
222208

223209
// Should contain timing information
224210
OIIO_CHECK_ASSERT( output.find( "Timing:" ) != std::string::npos );

0 commit comments

Comments
 (0)