aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Brubeck <mbrubeck@limpet.net>2016-03-29 08:11:59 -0700
committerMatt Brubeck <mbrubeck@limpet.net>2016-03-29 08:37:58 -0700
commit14e945f09aaee4d73c79363a158654c43c481447 (patch)
treeadfe2993caf6ad76278e4aade8fe19d9f088b903
parent37799a40251ae4df695d2257f57063c37d739329 (diff)
downloadservo-14e945f09aaee4d73c79363a158654c43c481447.tar.gz
servo-14e945f09aaee4d73c79363a158654c43c481447.zip
Add a unit test for Fragment size
-rw-r--r--components/layout/lib.rs3
-rw-r--r--components/servo/Cargo.lock8
-rw-r--r--components/servo/Cargo.toml3
-rw-r--r--tests/unit/layout/Cargo.toml12
-rw-r--r--tests/unit/layout/lib.rs7
-rw-r--r--tests/unit/layout/size_of.rs26
6 files changed, 59 insertions, 0 deletions
diff --git a/components/layout/lib.rs b/components/layout/lib.rs
index fa8a2231265..4f1d9abdac1 100644
--- a/components/layout/lib.rs
+++ b/components/layout/lib.rs
@@ -100,3 +100,6 @@ mod text;
mod traversal;
mod webrender_helpers;
mod wrapper;
+
+// For unit tests:
+pub use fragment::Fragment;
diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock
index df4759a0ca3..b2b61d0ee09 100644
--- a/components/servo/Cargo.lock
+++ b/components/servo/Cargo.lock
@@ -22,6 +22,7 @@ dependencies = [
"ipc-channel 0.2.1 (git+https://github.com/servo/ipc-channel)",
"layers 0.2.4 (git+https://github.com/servo/rust-layers)",
"layout 0.0.1",
+ "layout_tests 0.0.1",
"libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1",
@@ -1084,6 +1085,13 @@ dependencies = [
]
[[package]]
+name = "layout_tests"
+version = "0.0.1"
+dependencies = [
+ "layout 0.0.1",
+]
+
+[[package]]
name = "layout_traits"
version = "0.0.1"
dependencies = [
diff --git a/components/servo/Cargo.toml b/components/servo/Cargo.toml
index c547e09a071..b7cafca6af9 100644
--- a/components/servo/Cargo.toml
+++ b/components/servo/Cargo.toml
@@ -24,6 +24,9 @@ image = "0.7"
[dev-dependencies.gfx_tests]
path = "../../tests/unit/gfx"
+[dev-dependencies.layout_tests]
+path = "../../tests/unit/layout"
+
[dev-dependencies.net_tests]
path = "../../tests/unit/net"
diff --git a/tests/unit/layout/Cargo.toml b/tests/unit/layout/Cargo.toml
new file mode 100644
index 00000000000..a080eace5a7
--- /dev/null
+++ b/tests/unit/layout/Cargo.toml
@@ -0,0 +1,12 @@
+[package]
+name = "layout_tests"
+version = "0.0.1"
+authors = ["The Servo Project Developers"]
+
+[lib]
+name = "layout_tests"
+path = "lib.rs"
+doctest = false
+
+[dependencies.layout]
+path = "../../../components/layout"
diff --git a/tests/unit/layout/lib.rs b/tests/unit/layout/lib.rs
new file mode 100644
index 00000000000..59092bf4d9a
--- /dev/null
+++ b/tests/unit/layout/lib.rs
@@ -0,0 +1,7 @@
+/* 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/. */
+
+extern crate layout;
+
+#[cfg(all(test, target_pointer_width = "64"))] mod size_of;
diff --git a/tests/unit/layout/size_of.rs b/tests/unit/layout/size_of.rs
new file mode 100644
index 00000000000..a404a3f7d81
--- /dev/null
+++ b/tests/unit/layout/size_of.rs
@@ -0,0 +1,26 @@
+/* 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/. */
+
+use layout::Fragment;
+use std::mem::size_of;
+
+#[test]
+fn test_size_of_fragment() {
+ let expected = 184;
+ let actual = size_of::<Fragment>();
+
+ 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/layout/size_of.rs",
+ expected, actual);
+ }
+
+ if actual > expected {
+ 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/layout/size_of.rs.",
+ expected, actual);
+ }
+}