@@ -131,30 +131,53 @@ FOSSIL_TEST(cpp_test_archive_class_get_type) {
131131 fossil::io::Stream::remove (zip_path);
132132}
133133
134+ // ======================================================
135+ // Test C++ Archive class — Get Stats
136+ // ======================================================
134137FOSSIL_TEST (cpp_test_archive_class_get_stats) {
135138 const std::string archive_path = " test_cpp_stats.zip" ;
136139 const std::string test_file = " temp_cpp_test.txt" ;
137140 const std::string content = " C++ archive test content" ;
138-
139- // Create test file
140- fossil_fstream_t temp_stream;
141- ASSUME_ITS_EQUAL_I32 (0 , fossil::io::Stream::open (&temp_stream, test_file, " w" ));
142- fossil::io::Stream::write (&temp_stream, content.c_str (), content.length (), 1 );
141+
142+ // Always zero-init low-level C structs
143+ fossil_fstream_t temp_stream = {0 };
144+ fossil_io_archive_stats_t stats = {0 };
145+
146+ // Create temporary test file
147+ ASSUME_ITS_EQUAL_I32 (0 , fossil::io::Stream::open (&temp_stream, test_file.c_str (), " w" ));
148+ ASSUME_ITS_EQUAL_SIZE (
149+ content.size (),
150+ fossil::io::Stream::write (&temp_stream, content.c_str (), content.size (), 1 )
151+ );
143152 fossil::io::Stream::close (&temp_stream);
144-
145- // Create archive and add file using C++ class
146- auto archive = fossil::io::Archive::create (archive_path, FOSSIL_IO_ARCHIVE_ZIP, FOSSIL_IO_COMPRESSION_NORMAL);
153+
154+ // Create archive and add file using C++ wrapper
155+ auto archive = fossil::io::Archive::create (
156+ archive_path,
157+ FOSSIL_IO_ARCHIVE_ZIP,
158+ FOSSIL_IO_COMPRESSION_NORMAL
159+ );
160+
147161 ASSUME_ITS_TRUE (archive.is_valid ());
148162 ASSUME_ITS_TRUE (archive.add_file (test_file, " test.txt" ));
149-
150- // Get stats
151- fossil_io_archive_stats_t stats;
163+
164+ // Get stats safely
152165 ASSUME_ITS_TRUE (archive.get_stats (stats));
153166 ASSUME_ITS_EQUAL_SIZE (1 , stats.total_entries );
154- ASSUME_ITS_EQUAL_SIZE (content.length (), stats.total_size );
155-
156- fossil::io::Stream::remove (test_file);
157- fossil::io::Stream::remove (archive_path);
167+ ASSUME_ITS_EQUAL_SIZE (content.size (), stats.total_size );
168+ ASSUME_ITS_TRUE (stats.compression_ratio >= 0.0 && stats.compression_ratio <= 1.0 );
169+
170+ // Explicitly close before cleanup — avoids macOS file locks
171+ archive.close ();
172+
173+ // Allow filesystem to settle (important for macOS/APFS)
174+ #ifdef __APPLE__
175+ usleep (10000 ); // 10 ms delay
176+ #endif
177+
178+ // Remove test artifacts
179+ fossil::io::Stream::remove (test_file.c_str ());
180+ fossil::io::Stream::remove (archive_path.c_str ());
158181}
159182
160183FOSSIL_TEST (cpp_test_archive_class_list) {
0 commit comments