gio/
memory_output_stream.rs

1// Copyright 2013-2017, The Gtk-rs Project Developers.
2// See the COPYRIGHT file at the top-level directory of this distribution.
3// Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT>
4
5#[cfg(test)]
6mod tests {
7    use *;
8
9    #[test]
10    fn steal_empty() {
11        let strm = MemoryOutputStream::new_resizable();
12        assert_eq!(strm.get_data_size(), 0);
13
14        assert!(strm.close(::NONE_CANCELLABLE).is_ok());
15        assert_eq!(strm.steal_as_bytes().unwrap(), [].as_ref());
16    }
17
18    #[test]
19    fn steal() {
20        let strm = MemoryOutputStream::new_resizable();
21
22        assert!(strm.write(&[1, 2, 3], ::NONE_CANCELLABLE).is_ok());
23        assert_eq!(strm.get_data_size(), 3);
24
25        assert!(strm.write(&[4, 5], ::NONE_CANCELLABLE).is_ok());
26        assert_eq!(strm.get_data_size(), 5);
27
28        assert!(strm.close(::NONE_CANCELLABLE).is_ok());
29        assert_eq!(strm.steal_as_bytes().unwrap(), [1, 2, 3, 4, 5].as_ref());
30    }
31}