@@ -61,6 +61,34 @@ FOSSIL_TEST_CASE(c_test_stream_let_write_and_read_file) {
61
61
fossil_fstream_close (& c_stream );
62
62
}
63
63
64
+ FOSSIL_TEST_CASE (c_test_stream_redirect_to_devnull ) {
65
+ const char * filename = "testfile_redirect.txt" ;
66
+ const char * content = "This is a test." ;
67
+
68
+ // Create the file and write data to it
69
+ ASSUME_ITS_EQUAL_I32 (0 , fossil_fstream_open (& c_stream , filename , "w" ));
70
+ fossil_fstream_write (& c_stream , content , strlen (content ), 1 );
71
+
72
+ // Redirect the stream to /dev/null
73
+ ASSUME_ITS_EQUAL_I32 (0 , fossil_fstream_redirect_to_devnull (& c_stream ));
74
+
75
+ // Attempt to write more data (should not affect the file)
76
+ const char * extra_content = "This should not be written." ;
77
+ fossil_fstream_write (& c_stream , extra_content , strlen (extra_content ), 1 );
78
+
79
+ // Close the stream
80
+ fossil_fstream_close (& c_stream );
81
+
82
+ // Reopen the file and verify its content remains unchanged
83
+ char buffer [1024 ] = {0 };
84
+ ASSUME_ITS_EQUAL_I32 (0 , fossil_fstream_open (& c_stream , filename , "r" ));
85
+ fossil_fstream_read (& c_stream , buffer , sizeof (buffer ), 1 );
86
+ fossil_fstream_close (& c_stream );
87
+
88
+ ASSUME_ITS_EQUAL_CSTR (content , buffer );
89
+ }
90
+
91
+
64
92
FOSSIL_TEST_CASE (c_test_stream_let_open_and_close_file ) {
65
93
const char * filename = "testfile.txt" ;
66
94
@@ -240,6 +268,7 @@ FOSSIL_TEST_CASE(c_test_stream_setpos_and_getpos) {
240
268
FOSSIL_TEST_GROUP (c_file_tests ) {
241
269
FOSSIL_TEST_ADD (c_stream_suite , c_test_stream_let_write_and_read_file );
242
270
FOSSIL_TEST_ADD (c_stream_suite , c_test_stream_let_open_and_close_file );
271
+ FOSSIL_TEST_ADD (c_stream_suite , c_test_stream_redirect_to_devnull );
243
272
FOSSIL_TEST_ADD (c_stream_suite , c_test_stream_multiple_files );
244
273
FOSSIL_TEST_ADD (c_stream_suite , c_test_stream_seek_and_tell );
245
274
FOSSIL_TEST_ADD (c_stream_suite , c_test_stream_get_type );
0 commit comments