@@ -106,123 +106,87 @@ 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 ];
109+ FOSSIL_TEST_CASE (cpp_test_stream_get_type) {
110+ const char *filename = " testfile_type.txt" ;
113111
114- // Write data to the file
112+ // Create the file
115113 ASSUME_ITS_EQUAL_I32 (0 , fossil_fstream_open (&cpp_stream, filename, " w" ));
116- fossil_fstream_write (&cpp_stream, content, strlen (content), 1 );
117114 fossil_fstream_close (&cpp_stream);
118115
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);
116+ // Check the file type
117+ ASSUME_ITS_EQUAL_I32 (2 , fossil_fstream_get_type (filename)); // Regular file
122118}
123119
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 ." ;
120+ FOSSIL_TEST_CASE (cpp_test_stream_class_write_and_read_file ) {
121+ const char *filename = " testfile .txt" ;
122+ const char *content = " This is a test ." ;
127123
128- // Write data to the file with buffering
129- ASSUME_ITS_EQUAL_I32 (0 , fossil_fstream_write_buffered (filename, content, strlen (content)));
124+ // Write data to the file
125+ ASSUME_ITS_EQUAL_I32 (0 , fossil::io::Stream::open (&cpp_stream, filename, " w" ));
126+ fossil::io::Stream::write (&cpp_stream, content, strlen (content), 1 );
127+ fossil::io::Stream::close (&cpp_stream);
130128
131- // Read data from the file to verify
129+ // Read data from the file
132130 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);
131+ ASSUME_ITS_EQUAL_I32 (0 , fossil::io::Stream::open (&cpp_stream, filename, " r" ));
132+ fossil::io::Stream::read (&cpp_stream, buffer, sizeof (buffer), 1 );
133+ fossil::io::Stream::close (&cpp_stream);
138134}
139135
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);
136+ FOSSIL_TEST_CASE (cpp_test_stream_class_open_and_close_file) {
137+ const char *filename = " testfile.txt" ;
147138
148- // Unlock the file
149- ASSUME_ITS_EQUAL_I32 (0 , fossil_fstream_unlock (filename));
139+ // Open the file
140+ ASSUME_ITS_EQUAL_I32 (0 , fossil::io::Stream::open (&cpp_stream, filename, " w" ));
141+ fossil::io::Stream::close (&cpp_stream);
150142}
151143
152- FOSSIL_TEST_CASE (cpp_test_stream_get_type) {
153- const char *filename = " testfile_type.txt" ;
144+ FOSSIL_TEST_CASE (cpp_test_stream_class_multiple_files) {
145+ const char *filename1 = " testfile1.txt" ;
146+ const char *filename2 = " testfile2.txt" ;
154147
155- // Create the file
156- ASSUME_ITS_EQUAL_I32 (0 , fossil_fstream_open (&cpp_stream, filename , " w" ));
157- fossil_fstream_close (&cpp_stream);
148+ // Open the first file
149+ ASSUME_ITS_EQUAL_I32 (0 , fossil::io::Stream::open (&cpp_stream, filename1 , " w" ));
150+ fossil::io::Stream::close (&cpp_stream);
158151
159- // Check the file type
160- ASSUME_ITS_EQUAL_I32 (2 , fossil_fstream_get_type (filename)); // Regular file
152+ // Open the second file
153+ ASSUME_ITS_EQUAL_I32 (0 , fossil::io::Stream::open (&cpp_stream, filename2, " w" ));
154+ fossil::io::Stream::close (&cpp_stream);
161155}
162156
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- }
157+ FOSSIL_TEST_CASE (cpp_test_stream_class_seek_and_tell) {
158+ const char *filename = " testfile.txt" ;
159+ const char *content = " This is a test." ;
174160
175- FOSSIL_TEST_CASE (cpp_test_stream_set_and_get_permissions) {
176- const char *filename = " testfile_set_permissions.txt" ;
161+ // Write data to the file
162+ ASSUME_ITS_EQUAL_I32 (0 , fossil::io::Stream::open (&cpp_stream, filename, " w" ));
163+ fossil::io::Stream::write (&cpp_stream, content, strlen (content), 1 );
164+ fossil::io::Stream::close (&cpp_stream);
177165
178- // Create the file
179- ASSUME_ITS_EQUAL_I32 (0 , fossil_fstream_open (&cpp_stream, filename, " w" ));
180- fossil_fstream_close (&cpp_stream);
166+ // Open the file
167+ ASSUME_ITS_EQUAL_I32 (0 , fossil::io::Stream::open (&cpp_stream, filename, " r" ));
181168
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- }
169+ // Seek to the end of the file
170+ fossil::io::Stream::seek (&cpp_stream, 0 , SEEK_END);
186171
187- FOSSIL_TEST_CASE (cpp_test_stream_restrict_permissions) {
188- const char *filename = " testfile_restrict.txt " ;
172+ // Get the current position
173+ long position = fossil::io::Stream::tell (&cpp_stream) ;
189174
190- // Create the file
191- ASSUME_ITS_EQUAL_I32 (0 , fossil_fstream_open (&cpp_stream, filename, " w" ));
192- fossil_fstream_close (&cpp_stream);
175+ ASSUME_ITS_TRUE (position > 0 );
193176
194- // Restrict permissions
195- ASSUME_ITS_EQUAL_I32 (0 , fossil_fstream_restrict (filename));
196- ASSUME_ITS_EQUAL_I32 (0600 , fossil_fstream_get_permissions (filename));
177+ // Close the file
178+ fossil::io::Stream::close (&cpp_stream);
197179}
198180
199- FOSSIL_TEST_CASE (cpp_test_stream_check_ownership ) {
200- const char *filename = " testfile_ownership .txt" ;
181+ FOSSIL_TEST_CASE (cpp_test_stream_class_get_type ) {
182+ const char *filename = " testfile_type .txt" ;
201183
202184 // 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" ;
185+ ASSUME_ITS_EQUAL_I32 (0 , fossil::io::Stream::open (&cpp_stream, filename, " w" ));
186+ fossil::io::Stream::close (&cpp_stream);
213187
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));
188+ // Check the file type
189+ ASSUME_ITS_EQUAL_I32 (2 , fossil::io::Stream::get_type (filename)); // Regular file
226190}
227191
228192// * * * * * * * * * * * * * * * * * * * * * * * *
@@ -234,15 +198,13 @@ FOSSIL_TEST_GROUP(cpp_file_tests) {
234198 FOSSIL_TEST_ADD (cpp_stream_suite, cpp_test_stream_let_open_and_close_file);
235199 FOSSIL_TEST_ADD (cpp_stream_suite, cpp_test_stream_multiple_files);
236200 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);
240201 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);
202+
203+ FOSSIL_TEST_ADD (cpp_stream_suite, cpp_test_stream_class_write_and_read_file);
204+ FOSSIL_TEST_ADD (cpp_stream_suite, cpp_test_stream_class_open_and_close_file);
205+ FOSSIL_TEST_ADD (cpp_stream_suite, cpp_test_stream_class_multiple_files);
206+ FOSSIL_TEST_ADD (cpp_stream_suite, cpp_test_stream_class_seek_and_tell);
207+ FOSSIL_TEST_ADD (cpp_stream_suite, cpp_test_stream_class_get_type);
246208
247209 FOSSIL_TEST_REGISTER (cpp_stream_suite);
248210}
0 commit comments