#13262 Add a unit test verifying that SpecificFragmentInfo size

This commit is contained in:
Florent FAYOLLE 2016-09-24 14:16:28 +02:00
parent 89804bb251
commit 9df00199c6
2 changed files with 26 additions and 14 deletions

View file

@ -98,3 +98,4 @@ pub mod wrapper;
// For unit tests: // For unit tests:
pub use fragment::Fragment; pub use fragment::Fragment;
pub use fragment::SpecificFragmentInfo;

View file

@ -3,24 +3,35 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use layout::Fragment; use layout::Fragment;
use layout::SpecificFragmentInfo;
use std::mem::size_of; use std::mem::size_of;
fn check_size_for(name: &'static str, expected: usize, actual: usize) {
if actual < expected {
panic!("Your changes have decreased the stack size of {} \
from {} to {}. Good work! Please update the size in tests/unit/layout/size_of.rs",
name, expected, actual);
}
if actual > expected {
panic!("Your changes have increased the stack size of {} \
from {} to {}. Please consider choosing a design which avoids this increase. \
If you feel that the increase is necessary, update the size in \
tests/unit/layout/size_of.rs.",
name, expected, actual);
}
}
#[test] #[test]
fn test_size_of_fragment() { fn test_size_of_fragment() {
let expected = 160; let expected = 160;
let actual = size_of::<Fragment>(); let actual = size_of::<Fragment>();
check_size_for("layout::fragment::Fragment", expected, actual);
if actual < expected { }
panic!("Your changes have decreased the stack size of layout::fragment::Fragment \
from {} to {}. Good work! Please update the size in tests/unit/layout/size_of.rs", #[test]
expected, actual); fn test_size_of_specific_fragment_info() {
} let expected = 24;
let actual = size_of::<SpecificFragmentInfo>();
if actual > expected { check_size_for("layout::fragment::SpecificFragmentInfo", expected, actual);
panic!("Your changes have increased the stack size of layout::fragment::Fragment \
from {} to {}. Please consider choosing a design which avoids this increase. \
If you feel that the increase is necessary, update the size in \
tests/unit/layout/size_of.rs.",
expected, actual);
}
} }