Skip to content

Commit 832647b

Browse files
test cases for tempfile function
1 parent b20ad74 commit 832647b

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

code/tests/cases/test_stream.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,31 @@ FOSSIL_TEARDOWN(c_stream_suite) {
4545
// as samples for library usage.
4646
// * * * * * * * * * * * * * * * * * * * * * * * *
4747

48+
FOSSIL_TEST_CASE(c_test_stream_tempfile_creation) {
49+
// Create a temporary file
50+
fossil_fstream_t temp_stream = fossil_fstream_tempfile();
51+
52+
// Check if the temporary file is open
53+
ASSUME_ITS_TRUE(fossil_fstream_is_open(&temp_stream));
54+
55+
// Close the temporary file
56+
fossil_fstream_close(&temp_stream);
57+
}
58+
59+
FOSSIL_TEST_CASE(c_test_stream_tempfile_cleanup) {
60+
// Create a temporary file
61+
fossil_fstream_t temp_stream = fossil_fstream_tempfile();
62+
63+
// Get the temporary file name
64+
const char *temp_filename = temp_stream.filename;
65+
66+
// Close the temporary file
67+
fossil_fstream_close(&temp_stream);
68+
69+
// Verify the temporary file is deleted
70+
ASSUME_NOT_EQUAL_I32(0, fossil_fstream_file_exists(temp_filename));
71+
}
72+
4873
FOSSIL_TEST_CASE(c_test_stream_let_write_and_read_file) {
4974
const char *filename = "testfile.txt";
5075
const char *content = "This is a test.";
@@ -238,6 +263,8 @@ FOSSIL_TEST_CASE(c_test_stream_setpos_and_getpos) {
238263
// * * * * * * * * * * * * * * * * * * * * * * * *
239264

240265
FOSSIL_TEST_GROUP(c_file_tests) {
266+
FOSSIL_TEST_ADD(c_stream_suite, c_test_stream_tempfile_creation);
267+
FOSSIL_TEST_ADD(c_stream_suite, c_test_stream_tempfile_cleanup);
241268
FOSSIL_TEST_ADD(c_stream_suite, c_test_stream_let_write_and_read_file);
242269
FOSSIL_TEST_ADD(c_stream_suite, c_test_stream_let_open_and_close_file);
243270
FOSSIL_TEST_ADD(c_stream_suite, c_test_stream_multiple_files);

code/tests/cases/test_stream.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,31 @@ FOSSIL_TEARDOWN(cpp_stream_suite) {
4545
// as samples for library usage.
4646
// * * * * * * * * * * * * * * * * * * * * * * * *
4747

48+
FOSSIL_TEST_CASE(cpp_test_stream_tempfile_creation) {
49+
// Create a temporary file
50+
fossil_fstream_t temp_stream = fossil_fstream_tempfile();
51+
52+
// Check if the temporary file is open
53+
ASSUME_ITS_TRUE(fossil_fstream_is_open(&temp_stream));
54+
55+
// Close the temporary file
56+
fossil_fstream_close(&temp_stream);
57+
}
58+
59+
FOSSIL_TEST_CASE(cpp_test_stream_tempfile_cleanup) {
60+
// Create a temporary file
61+
fossil_fstream_t temp_stream = fossil_fstream_tempfile();
62+
63+
// Get the temporary file name
64+
const char *temp_filename = temp_stream.filename;
65+
66+
// Close the temporary file
67+
fossil_fstream_close(&temp_stream);
68+
69+
// Verify the temporary file is deleted
70+
ASSUME_NOT_EQUAL_I32(0, fossil_fstream_file_exists(temp_filename));
71+
}
72+
4873
FOSSIL_TEST_CASE(cpp_test_stream_let_write_and_read_file) {
4974
const char *filename = "testfile.txt";
5075
const char *content = "This is a test.";
@@ -233,6 +258,31 @@ FOSSIL_TEST_CASE(cpp_test_stream_setpos_and_getpos) {
233258
fossil_fstream_close(&cpp_stream);
234259
}
235260

261+
FOSSIL_TEST_CASE(cpp_test_stream_class_tempfile_creation) {
262+
// Create a temporary file using the class method
263+
fossil_fstream_t temp_stream = fossil::io::Stream::tempfile();
264+
265+
// Check if the temporary file is open
266+
ASSUME_ITS_TRUE(fossil::io::Stream::is_open(&temp_stream));
267+
268+
// Close the temporary file
269+
fossil::io::Stream::close(&temp_stream);
270+
}
271+
272+
FOSSIL_TEST_CASE(cpp_test_stream_class_tempfile_cleanup) {
273+
// Create a temporary file using the class method
274+
fossil_fstream_t temp_stream = fossil::io::Stream::tempfile();
275+
276+
// Get the temporary file name
277+
const char *temp_filename = temp_stream.filename;
278+
279+
// Close the temporary file
280+
fossil::io::Stream::close(&temp_stream);
281+
282+
// Verify the temporary file is deleted
283+
ASSUME_NOT_EQUAL_I32(0, fossil::io::Stream::file_exists(temp_filename));
284+
}
285+
236286
FOSSIL_TEST_CASE(cpp_test_stream_class_write_and_read_file) {
237287
const char *filename = "testfile.txt";
238288
const char *content = "This is a test.";
@@ -373,6 +423,8 @@ FOSSIL_TEST_CASE(cpp_test_stream_class_get_permissions) {
373423
// * * * * * * * * * * * * * * * * * * * * * * * *
374424

375425
FOSSIL_TEST_GROUP(cpp_file_tests) {
426+
FOSSIL_TEST_ADD(cpp_stream_suite, cpp_test_stream_tempfile_creation);
427+
FOSSIL_TEST_ADD(cpp_stream_suite, cpp_test_stream_tempfile_cleanup);
376428
FOSSIL_TEST_ADD(cpp_stream_suite, cpp_test_stream_let_write_and_read_file);
377429
FOSSIL_TEST_ADD(cpp_stream_suite, cpp_test_stream_let_open_and_close_file);
378430
FOSSIL_TEST_ADD(cpp_stream_suite, cpp_test_stream_multiple_files);
@@ -387,6 +439,8 @@ FOSSIL_TEST_GROUP(cpp_file_tests) {
387439
FOSSIL_TEST_ADD(cpp_stream_suite, cpp_test_stream_flush_file);
388440
FOSSIL_TEST_ADD(cpp_stream_suite, cpp_test_stream_setpos_and_getpos);
389441

442+
FOSSIL_TEST_ADD(cpp_stream_suite, cpp_test_stream_class_tempfile_creation);
443+
FOSSIL_TEST_ADD(cpp_stream_suite, cpp_test_stream_class_tempfile_cleanup);
390444
FOSSIL_TEST_ADD(cpp_stream_suite, cpp_test_stream_class_write_and_read_file);
391445
FOSSIL_TEST_ADD(cpp_stream_suite, cpp_test_stream_class_open_and_close_file);
392446
FOSSIL_TEST_ADD(cpp_stream_suite, cpp_test_stream_class_multiple_files);

0 commit comments

Comments
 (0)