// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of // the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/ //! Tests for basic `Frame` functionality like appending, prepending, joining, popping and removing. #![cfg_attr(rustfmt, rustfmt_skip)] // ------------------------------------------------------------------------------------------------- extern crate cognitive_qualia as qualia; extern crate cognitive_frames as frames; mod common; use qualia::Position; use frames::Parameters; use frames::Geometry::{Horizontal, Stacked, Vertical}; use frames::representation::FrameRepresentation; use common::{assertions, layouts}; // ------------------------------------------------------------------------------------------------- /// Checks if simple frame layout is constructed correctly by appending all frames. #[test] fn test_append() { let r = layouts::make_simple_frames_appending().0; assertions::assert_simple_frames_timed(&r); assertions::assert_simple_frames_spaced(&r); r.destroy(); } // ------------------------------------------------------------------------------------------------- /// Checks if simple frame layout is constructed correctly by prepending all frames. #[test] fn test_prepend() { let r = layouts::make_simple_frames_prepending().0; assertions::assert_simple_frames_timed_reversed(&r); assertions::assert_simple_frames_spaced(&r); r.destroy(); } // ------------------------------------------------------------------------------------------------- /// Checks remove from begin, center and end works correctly. #[test] fn test_remove() { let (r, _, _, _, mut v1, _, _, _, mut h2, _, _, _, mut s3) = layouts::make_simple_frames_appending(); // Remove chosen frames and destroy them. v1.remove(); h2.remove(); s3.remove(); v1.destroy(); h2.destroy(); s3.destroy(); // Prepare representation. let repr = FrameRepresentation::new( Parameters::new_workspace(String::new(), Vertical, true), vec![ FrameRepresentation::new( Parameters::new_container(Vertical), vec![ FrameRepresentation::new_leaf(12, Stacked), FrameRepresentation::new_leaf(13, Stacked), ] ), FrameRepresentation::new( Parameters::new_container(Horizontal), vec![ FrameRepresentation::new_leaf(21, Stacked), FrameRepresentation::new_leaf(23, Stacked), ] ), FrameRepresentation::new( Parameters::new_container(Stacked), vec![ FrameRepresentation::new_leaf(31, Stacked), FrameRepresentation::new_leaf(32, Stacked), ] ), ] ); repr.assert_frames_timed(&r); repr.assert_frames_spaced(&r); r.destroy(); } // ------------------------------------------------------------------------------------------------- /// Checks if popping surfaces works correctly. Test popping from the end and from inside. Spaced /// order should not change. #[test] fn test_pop() { let (r, _, _, mut s, _, mut v2, _, _, _, _, _, _, mut s3) = layouts::make_simple_frames_appending(); // Perform pop s.pop(); s3.pop(); v2.pop(); // Check spaced layout. assertions::assert_simple_frames_spaced(&r); // Check timed layout. let time_repr = FrameRepresentation::new( Parameters::new_workspace(String::new(), Vertical, true), vec![ FrameRepresentation::new( Parameters::new_container(Stacked), vec![ FrameRepresentation::new_leaf(33, Stacked), FrameRepresentation::new_leaf(31, Stacked), FrameRepresentation::new_leaf(32, Stacked), ] ), FrameRepresentation::new( Parameters::new_container(Vertical), vec![ FrameRepresentation::new_leaf(12, Stacked), FrameRepresentation::new_leaf(11, Stacked), FrameRepresentation::new_leaf(13, Stacked), ] ), FrameRepresentation::new( Parameters::new_container(Horizontal), vec![ FrameRepresentation::new_leaf(21, Stacked), FrameRepresentation::new_leaf(22, Stacked), FrameRepresentation::new_leaf(23, Stacked), ] ), ] ); time_repr.assert_frames_timed(&r); r.destroy(); } // ------------------------------------------------------------------------------------------------- /// Checks if spaced order is correct when inserting frames at the begin, center and end. #[test] fn test_prejoin_adjoin() { let (r, _, _, _, mut v1, mut v2, _, mut h1, mut h2, _, mut s1, mut s2, _) = layouts::make_simple_frames_joining(); // Pop some surfaces just to be able to use predefined timed representation v2.pop(); v1.pop(); h2.pop(); h1.pop(); s2.pop(); s1.pop(); // Assert layouts assertions::assert_simple_frames_spaced(&r); assertions::assert_simple_frames_timed(&r); r.destroy(); } // ------------------------------------------------------------------------------------------------- /// Tests forward iteration in time. #[test] fn test_iteration_forward_in_time() { let (r, v, _, _, v1, v2, v3, _, _, _, _, _, _) = layouts::make_simple_frames_appending(); let mut iter = v.time_iter(); assertions::assert_frame_equal_exact(&iter.next().unwrap(), &v1); assertions::assert_frame_equal_exact(&iter.next().unwrap(), &v2); assertions::assert_frame_equal_exact(&iter.next().unwrap(), &v3); assert!(iter.next().is_none()); r.destroy(); } // ------------------------------------------------------------------------------------------------- /// Tests backward iteration in time. #[test] fn test_iteration_backward_in_time() { let (r, v, _, _, v1, v2, v3, _, _, _, _, _, _) = layouts::make_simple_frames_appending(); let mut iter = v.time_rev_iter(); assertions::assert_frame_equal_exact(&iter.next().unwrap(), &v3); assertions::assert_frame_equal_exact(&iter.next().unwrap(), &v2); assertions::assert_frame_equal_exact(&iter.next().unwrap(), &v1); assert!(iter.next().is_none()); r.destroy(); } // ------------------------------------------------------------------------------------------------- /// Tests calculating global position. #[test] fn test_calculating_global_position() { let (r, _, _, _, _, _, _, _, _, _, _, f, _, _, _, z) = layouts::make_sized_for_homogenizing(); assert_eq!(f.get_position(), Position::new(60, 0)); assert_eq!(f.calculate_global_position(), Position::new(60, 300)); assert_eq!(z.get_position(), Position::new(13, 23)); assert_eq!(z.calculate_global_position(), Position::new(13, 23)); r.destroy(); } // -------------------------------------------------------------------------------------------------