* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
+use std::io::{Read, Write};
+use std::os::unix::io::FromRawFd;
use common::buffer::{Buffer, BufferUserData};
use common::gps;
use common::storage::{Storage, Error};
assert!(logger.get_recording(1, &mut yenc_buffer).is_ok());
}
+
+// Verifies that Logger::list_recordings() shows a listing
+// of a single recording in the very first sector.
+#[test]
+fn list_recordings1() {
+ let pipe = Pipe::new();
+
+ let mut file = unsafe { std::fs::File::from_raw_fd(pipe.write_fd()) };
+
+ let mut ls_buffer_space = [0u8; 4096];
+ let mut ls_buffer = Buffer::alloc();
+
+ let user_data = (&mut file as *mut std::fs::File) as *mut BufferUserData;
+
+ ls_buffer.init(ls_buffer_space.as_mut_ptr(),
+ ls_buffer_space.len(),
+ flush_write_buffer,
+ user_data);
+
+ let mut fake_storage = FakeStorage::new();
+
+ // Mark first sector as in use.
+ let recording0 = [
+ // Header:
+ 0x01, 0x00, 0x01, 0x00,
+ 0xa2, 0xdb, 0x14, 0x5e,
+ ];
+
+ fake_storage.expected[0..recording0.len()].copy_from_slice(&recording0);
+ fake_storage.actual[0..recording0.len()].copy_from_slice(&recording0);
+
+ let mut logger = Logger::new(&mut fake_storage);
+ logger.init();
+
+ logger.list_recordings(&mut ls_buffer);
+
+ let mut file = unsafe { std::fs::File::from_raw_fd(pipe.read_fd()) };
+
+ let mut listing_raw = [0u8; 256];
+ let num_bytes_read = file.read(&mut listing_raw).unwrap();
+
+ let expected_bytes = b"\
+2020-01-07 19:27:30 1\n";
+
+ assert_eq!(String::from_utf8(expected_bytes.to_vec()).unwrap(),
+ String::from_utf8(listing_raw[0..num_bytes_read].to_vec()).unwrap());
+}