From: Tilman Sauerbeck Date: Sat, 11 Jan 2020 13:18:53 +0000 (+0100) Subject: test: Verify Logger::list_recordings()'s behavior with empty storage. X-Git-Url: http://git.code-monkey.de/?a=commitdiff_plain;h=4b82362597c3908db091615b403663b8f39b67fa;p=gps-watch.git test: Verify Logger::list_recordings()'s behavior with empty storage. We expect no output in that case. --- diff --git a/test/logger_test.rs b/test/logger_test.rs index 2bb507f..bbf8dd5 100644 --- a/test/logger_test.rs +++ b/test/logger_test.rs @@ -351,6 +351,39 @@ fn get_recording_valid() { assert!(logger.get_recording(1, &mut yenc_buffer).is_ok()); } +// Verifies that Logger::list_recordings() shows an empty listing +// if there are no recordings. +#[test] +fn list_recordings0() { + 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(); + + 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]; + + // There are no recordings, so there's no data in the pipe either. + assert!(file.read(&mut listing_raw).is_err()); +} + // Verifies that Logger::list_recordings() shows a listing // of a single recording in the very first sector. #[test]