Skip to content

Commit 9ec91f3

Browse files
soswowantond-weta
authored andcommitted
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]>
1 parent 9802e88 commit 9ec91f3

File tree

6 files changed

+100
-39
lines changed

6 files changed

+100
-39
lines changed

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(
-4.76 MB
Binary file not shown.

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 );

tests/test_image_converter.cpp

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717
#include <fstream>
1818
#include <iostream>
1919
#include <nlohmann/json.hpp>
20+
#include <sstream>
2021
#include <vector>
2122
#include <ctime>
2223

24+
#include "test_utils.h"
25+
2326
#ifdef WIN32
2427
# include <io.h>
2528
# include <process.h>
@@ -965,12 +968,22 @@ void test_missing_camera_manufacturer()
965968
std::vector<std::vector<double>> IDT_matrix;
966969
std::vector<std::vector<double>> CAT_matrix;
967970

968-
// This should fail because there's no camera make
969-
bool success = prepare_transform_spectral(
970-
image_spec, settings, WB_multipliers, IDT_matrix, CAT_matrix );
971+
// Capture stderr output to verify error messages
972+
bool success;
973+
std::string output = capture_stderr( [&]() {
974+
// This should fail because there's no camera make
975+
success = prepare_transform_spectral(
976+
image_spec, settings, WB_multipliers, IDT_matrix, CAT_matrix );
977+
} );
971978

972979
// Should fail
973980
OIIO_CHECK_ASSERT( !success );
981+
982+
// Assert on the expected error message
983+
OIIO_CHECK_ASSERT(
984+
output.find(
985+
"Missing the camera manufacturer name in the file metadata. You can provide a camera make using the --custom-camera-make parameter" ) !=
986+
std::string::npos );
974987
}
975988

976989
/// Tests that conversion fails when camera model is missing (should fail)
@@ -990,19 +1003,34 @@ void test_empty_camera_model()
9901003
// Create illuminant data (so illuminant data loading succeeds)
9911004
test_dir.create_test_data_file( "illuminant", { { "illuminant", "D65" } } );
9921005

993-
// Use the DNG file with camera make but no model
994-
std::string test_file =
995-
"../../tests/materials/blackmagic_cinema_camera_cinemadng_no_model.dng";
996-
997-
// Test: Missing camera model via main entrance (no custom camera info provided)
998-
std::vector<std::string> args = {
999-
"--wb-method", "illuminant", "--illuminant", "D65", "--mat-method",
1000-
"spectral", "--verbose", "--overwrite", test_file
1001-
};
1006+
// Create ImageSpec with camera make but no model
1007+
OIIO::ImageSpec image_spec;
1008+
image_spec["cameraMake"] = "Blackmagic";
1009+
// Do not set cameraModel - this is what we're testing
1010+
1011+
// Set up ImageConverter with spectral mode settings
1012+
ImageConverter converter;
1013+
converter.settings.WB_method =
1014+
ImageConverter::Settings::WBMethod::Illuminant;
1015+
converter.settings.matrix_method =
1016+
ImageConverter::Settings::MatrixMethod::Spectral;
1017+
converter.settings.illuminant = "D65";
1018+
converter.settings.verbosity = 1;
1019+
converter.settings.database_directories.push_back(
1020+
test_dir.get_database_path() );
1021+
1022+
// Create empty options list
1023+
OIIO::ParamValueList options;
1024+
1025+
// Capture stderr output to verify error messages
1026+
bool success;
1027+
std::string output = capture_stderr( [&]() {
1028+
// This should fail with error message about missing camera model
1029+
success = converter.configure( image_spec, options );
1030+
} );
10021031

1003-
// This should fail with error message about missing camera model
1004-
std::string output = run_rawtoaces_with_data_dir(
1005-
args, test_dir.get_database_path(), false, true );
1032+
// Should fail
1033+
OIIO_CHECK_ASSERT( !success );
10061034

10071035
// Assert on the expected error message - focus on the main camera identifier error
10081036
OIIO_CHECK_ASSERT(

tests/test_utils.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright Contributors to the rawtoaces Project.
3+
4+
#include "test_utils.h"
5+
6+
#include <functional>
7+
#include <iostream>
8+
#include <sstream>
9+
#include <streambuf>
10+
11+
/// RAII helper class to capture stderr output for testing
12+
class StderrCapture
13+
{
14+
public:
15+
StderrCapture() : buffer(), old( std::cerr.rdbuf( buffer.rdbuf() ) ) {}
16+
17+
~StderrCapture() { std::cerr.rdbuf( old ); }
18+
19+
/// Get the captured output as a string
20+
std::string str() const { return buffer.str(); }
21+
22+
private:
23+
std::stringstream buffer;
24+
std::streambuf *old;
25+
};
26+
27+
/// Wrapper function that captures stderr output from a callable action
28+
std::string capture_stderr( std::function<void()> action )
29+
{
30+
StderrCapture capture;
31+
action();
32+
return capture.str();
33+
}

tests/test_utils.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright Contributors to the rawtoaces Project.
3+
4+
#pragma once
5+
6+
#include <functional>
7+
#include <string>
8+
9+
/// Wrapper function that captures stderr output from a callable action
10+
/// @param action A callable (function, lambda, etc.) that may write to stderr
11+
/// @return The captured stderr output as a string
12+
std::string capture_stderr( std::function<void()> action );

0 commit comments

Comments
 (0)