Add size_of_test crate

This commit is contained in:
Simon Sapin 2017-05-15 15:28:56 +02:00
parent 1afc89e944
commit cf2ae86373
6 changed files with 46 additions and 30 deletions

View file

@ -13,3 +13,4 @@ doctest = false
atomic_refcell = "0.1"
layout = {path = "../../../components/layout"}
script_layout_interface = {path = "../../../components/script_layout_interface"}
size_of_test = {path = "../../../components/size_of_test"}

View file

@ -5,6 +5,7 @@
extern crate atomic_refcell;
extern crate layout;
extern crate script_layout_interface;
#[macro_use] extern crate size_of_test;
#[cfg(test)] mod align_of;
#[cfg(all(test, target_pointer_width = "64"))] mod size_of;

View file

@ -4,34 +4,6 @@
use layout::Fragment;
use layout::SpecificFragmentInfo;
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]
fn test_size_of_fragment() {
let expected = 160;
let actual = size_of::<Fragment>();
check_size_for("layout::fragment::Fragment", expected, actual);
}
#[test]
fn test_size_of_specific_fragment_info() {
let expected = 24;
let actual = size_of::<SpecificFragmentInfo>();
check_size_for("layout::fragment::SpecificFragmentInfo", expected, actual);
}
size_of_test!(test_size_of_fragment, Fragment, 160);
size_of_test!(test_size_of_specific_fragment_info, SpecificFragmentInfo, 24);