@@ -106,6 +106,125 @@ FOSSIL_TEST_CASE(cpp_test_stream_seek_and_tell) {
106106 fossil_fstream_close (&cpp_stream);
107107}
108108
109+ FOSSIL_TEST_CASE (cpp_test_stream_read_buffered) {
110+ const char *filename = " testfile_buffered.txt" ;
111+ const char *content = " Buffered read test content." ;
112+ char buffer[1024 ];
113+
114+ // Write data to the file
115+ ASSUME_ITS_EQUAL_I32 (0 , fossil_fstream_open (&cpp_stream, filename, " w" ));
116+ fossil_fstream_write (&cpp_stream, content, strlen (content), 1 );
117+ fossil_fstream_close (&cpp_stream);
118+
119+ // Read data from the file with buffering
120+ ASSUME_ITS_EQUAL_I32 (0 , fossil_fstream_read_buffered (filename, buffer, strlen (content)));
121+ ASSUME_ITS_EQUAL_CSTR (content, buffer);
122+ }
123+
124+ FOSSIL_TEST_CASE (cpp_test_stream_write_buffered) {
125+ const char *filename = " testfile_buffered_write.txt" ;
126+ const char *content = " Buffered write test content." ;
127+
128+ // Write data to the file with buffering
129+ ASSUME_ITS_EQUAL_I32 (0 , fossil_fstream_write_buffered (filename, content, strlen (content)));
130+
131+ // Read data from the file to verify
132+ char buffer[1024 ];
133+ ASSUME_ITS_EQUAL_I32 (0 , fossil_fstream_open (&cpp_stream, filename, " r" ));
134+ fossil_fstream_read (&cpp_stream, buffer, sizeof (buffer), 1 );
135+ fossil_fstream_close (&cpp_stream);
136+
137+ ASSUME_ITS_EQUAL_CSTR (content, buffer);
138+ }
139+
140+ FOSSIL_TEST_CASE (cpp_test_stream_lock_and_unlock) {
141+ const char *filename = " testfile_lock.txt" ;
142+
143+ // Create and lock the file
144+ ASSUME_ITS_EQUAL_I32 (0 , fossil_fstream_open (&cpp_stream, filename, " w" ));
145+ ASSUME_ITS_EQUAL_I32 (0 , fossil_fstream_lock (filename));
146+ fossil_fstream_close (&cpp_stream);
147+
148+ // Unlock the file
149+ ASSUME_ITS_EQUAL_I32 (0 , fossil_fstream_unlock (filename));
150+ }
151+
152+ FOSSIL_TEST_CASE (cpp_test_stream_get_type) {
153+ const char *filename = " testfile_type.txt" ;
154+
155+ // Create the file
156+ ASSUME_ITS_EQUAL_I32 (0 , fossil_fstream_open (&cpp_stream, filename, " w" ));
157+ fossil_fstream_close (&cpp_stream);
158+
159+ // Check the file type
160+ ASSUME_ITS_EQUAL_I32 (2 , fossil_fstream_get_type (filename)); // Regular file
161+ }
162+
163+ FOSSIL_TEST_CASE (cpp_test_stream_check_permission) {
164+ const char *filename = " testfile_permission.txt" ;
165+
166+ // Create the file
167+ ASSUME_ITS_EQUAL_I32 (0 , fossil_fstream_open (&cpp_stream, filename, " w" ));
168+ fossil_fstream_close (&cpp_stream);
169+
170+ // Check read and write permissions
171+ ASSUME_ITS_EQUAL_I32 (1 , fossil_fstream_check_permission (filename, " r" ));
172+ ASSUME_ITS_EQUAL_I32 (1 , fossil_fstream_check_permission (filename, " w" ));
173+ }
174+
175+ FOSSIL_TEST_CASE (cpp_test_stream_set_and_get_permissions) {
176+ const char *filename = " testfile_set_permissions.txt" ;
177+
178+ // Create the file
179+ ASSUME_ITS_EQUAL_I32 (0 , fossil_fstream_open (&cpp_stream, filename, " w" ));
180+ fossil_fstream_close (&cpp_stream);
181+
182+ // Set and get permissions
183+ ASSUME_ITS_EQUAL_I32 (0 , fossil_fstream_set_permissions (filename, 0644 ));
184+ ASSUME_ITS_EQUAL_I32 (0644 , fossil_fstream_get_permissions (filename));
185+ }
186+
187+ FOSSIL_TEST_CASE (cpp_test_stream_restrict_permissions) {
188+ const char *filename = " testfile_restrict.txt" ;
189+
190+ // Create the file
191+ ASSUME_ITS_EQUAL_I32 (0 , fossil_fstream_open (&cpp_stream, filename, " w" ));
192+ fossil_fstream_close (&cpp_stream);
193+
194+ // Restrict permissions
195+ ASSUME_ITS_EQUAL_I32 (0 , fossil_fstream_restrict (filename));
196+ ASSUME_ITS_EQUAL_I32 (0600 , fossil_fstream_get_permissions (filename));
197+ }
198+
199+ FOSSIL_TEST_CASE (cpp_test_stream_check_ownership) {
200+ const char *filename = " testfile_ownership.txt" ;
201+
202+ // Create the file
203+ ASSUME_ITS_EQUAL_I32 (0 , fossil_fstream_open (&cpp_stream, filename, " w" ));
204+ fossil_fstream_close (&cpp_stream);
205+
206+ // Check ownership
207+ ASSUME_ITS_EQUAL_I32 (1 , fossil_fstream_check_ownership (filename));
208+ }
209+
210+ FOSSIL_TEST_CASE (cpp_test_stream_compare_permissions) {
211+ const char *filename1 = " testfile_compare1.txt" ;
212+ const char *filename2 = " testfile_compare2.txt" ;
213+
214+ // Create the files
215+ ASSUME_ITS_EQUAL_I32 (0 , fossil_fstream_open (&cpp_stream, filename1, " w" ));
216+ fossil_fstream_close (&cpp_stream);
217+ ASSUME_ITS_EQUAL_I32 (0 , fossil_fstream_open (&cpp_stream, filename2, " w" ));
218+ fossil_fstream_close (&cpp_stream);
219+
220+ // Set permissions
221+ ASSUME_ITS_EQUAL_I32 (0 , fossil_fstream_set_permissions (filename1, 0644 ));
222+ ASSUME_ITS_EQUAL_I32 (0 , fossil_fstream_set_permissions (filename2, 0644 ));
223+
224+ // Compare permissions
225+ ASSUME_ITS_EQUAL_I32 (1 , fossil_fstream_compare_permissions (filename1, filename2));
226+ }
227+
109228// * * * * * * * * * * * * * * * * * * * * * * * *
110229// * Fossil Logic Test Pool
111230// * * * * * * * * * * * * * * * * * * * * * * * *
@@ -114,6 +233,16 @@ FOSSIL_TEST_GROUP(cpp_file_tests) {
114233 FOSSIL_TEST_ADD (cpp_stream_suite, cpp_test_stream_let_write_and_read_file);
115234 FOSSIL_TEST_ADD (cpp_stream_suite, cpp_test_stream_let_open_and_close_file);
116235 FOSSIL_TEST_ADD (cpp_stream_suite, cpp_test_stream_multiple_files);
236+ FOSSIL_TEST_ADD (cpp_stream_suite, cpp_test_stream_seek_and_tell);
237+ FOSSIL_TEST_ADD (cpp_stream_suite, cpp_test_stream_read_buffered);
238+ FOSSIL_TEST_ADD (cpp_stream_suite, cpp_test_stream_write_buffered);
239+ FOSSIL_TEST_ADD (cpp_stream_suite, cpp_test_stream_lock_and_unlock);
240+ FOSSIL_TEST_ADD (cpp_stream_suite, cpp_test_stream_get_type);
241+ FOSSIL_TEST_ADD (cpp_stream_suite, cpp_test_stream_check_permission);
242+ FOSSIL_TEST_ADD (cpp_stream_suite, cpp_test_stream_set_and_get_permissions);
243+ FOSSIL_TEST_ADD (cpp_stream_suite, cpp_test_stream_restrict_permissions);
244+ FOSSIL_TEST_ADD (cpp_stream_suite, cpp_test_stream_check_ownership);
245+ FOSSIL_TEST_ADD (cpp_stream_suite, cpp_test_stream_compare_permissions);
117246
118247 FOSSIL_TEST_REGISTER (cpp_stream_suite);
119248}
0 commit comments