Skip to content

Commit c0e0016

Browse files
added test for devnull
1 parent 67ac7a1 commit c0e0016

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

code/tests/cases/test_stream.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,34 @@ FOSSIL_TEST_CASE(c_test_stream_let_write_and_read_file) {
6161
fossil_fstream_close(&c_stream);
6262
}
6363

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+
6492
FOSSIL_TEST_CASE(c_test_stream_let_open_and_close_file) {
6593
const char *filename = "testfile.txt";
6694

@@ -240,6 +268,7 @@ FOSSIL_TEST_CASE(c_test_stream_setpos_and_getpos) {
240268
FOSSIL_TEST_GROUP(c_file_tests) {
241269
FOSSIL_TEST_ADD(c_stream_suite, c_test_stream_let_write_and_read_file);
242270
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);
243272
FOSSIL_TEST_ADD(c_stream_suite, c_test_stream_multiple_files);
244273
FOSSIL_TEST_ADD(c_stream_suite, c_test_stream_seek_and_tell);
245274
FOSSIL_TEST_ADD(c_stream_suite, c_test_stream_get_type);

0 commit comments

Comments
 (0)