|
11 | 11 | #include <string> |
12 | 12 | #include <thread> |
13 | 13 |
|
| 14 | +#include "test_utils.h" |
| 15 | + |
14 | 16 | using namespace rta::util; |
15 | 17 |
|
16 | 18 | // Helper function to extract time value from output |
@@ -111,13 +113,8 @@ void testTimingOutput() |
111 | 113 | std::this_thread::sleep_for( std::chrono::milliseconds( 50 ) ); |
112 | 114 |
|
113 | 115 | // 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" ); } ); |
121 | 118 |
|
122 | 119 | // Should contain timing information |
123 | 120 | OIIO_CHECK_ASSERT( output.find( "Timing:" ) != std::string::npos ); |
@@ -172,17 +169,11 @@ void testMultipleIndependentInstances() |
172 | 169 | std::this_thread::sleep_for( std::chrono::milliseconds( 5 ) ); |
173 | 170 |
|
174 | 171 | // 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" ); } ); |
181 | 174 |
|
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" ); } ); |
186 | 177 |
|
187 | 178 | // Both should contain timing information |
188 | 179 | OIIO_CHECK_ASSERT( output1.find( "Timing:" ) != std::string::npos ); |
@@ -212,13 +203,8 @@ void testTimingAccuracy() |
212 | 203 | std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) ); |
213 | 204 |
|
214 | 205 | // 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" ); } ); |
222 | 208 |
|
223 | 209 | // Should contain timing information |
224 | 210 | OIIO_CHECK_ASSERT( output.find( "Timing:" ) != std::string::npos ); |
|
0 commit comments