From 7bc88d541fa840cfde588309f101d3e61a0f7756 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 2 Jun 2015 16:38:46 +0530 Subject: [PATCH] Add unit test for plugin --- components/servo/Cargo.lock | 1 + tests/unit/util/Cargo.toml | 4 ++++ tests/unit/util/lib.rs | 3 +++ tests/unit/util/mem.rs | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+) create mode 100644 tests/unit/util/mem.rs diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index e698c8811a7..439a17d6ecc 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -1280,6 +1280,7 @@ name = "util_tests" version = "0.0.1" dependencies = [ "geom 0.1.0 (git+https://github.com/servo/rust-geom)", + "plugins 0.0.1", "util 0.0.1", ] diff --git a/tests/unit/util/Cargo.toml b/tests/unit/util/Cargo.toml index 48df1b5aedb..f6adbaca25d 100644 --- a/tests/unit/util/Cargo.toml +++ b/tests/unit/util/Cargo.toml @@ -11,5 +11,9 @@ doctest = false [dependencies.util] path = "../../../components/util" + +[dependencies.plugins] +path = "../../../components/plugins" + [dependencies.geom] git = "https://github.com/servo/rust-geom" diff --git a/tests/unit/util/lib.rs b/tests/unit/util/lib.rs index 07ce741d972..2048c2a0b57 100644 --- a/tests/unit/util/lib.rs +++ b/tests/unit/util/lib.rs @@ -2,6 +2,8 @@ * 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/. */ +#![feature(plugin, custom_derive, custom_attributes)] +#![plugin(plugins)] extern crate util; extern crate geom; @@ -9,3 +11,4 @@ extern crate geom; #[cfg(test)] mod logical_geometry; #[cfg(test)] mod task; #[cfg(test)] mod vec; +#[cfg(test)] mod mem; diff --git a/tests/unit/util/mem.rs b/tests/unit/util/mem.rs new file mode 100644 index 00000000000..8ad01063809 --- /dev/null +++ b/tests/unit/util/mem.rs @@ -0,0 +1,33 @@ +/* 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 util::mem::HeapSizeOf; + + +struct Four; +impl HeapSizeOf for Four { + fn heap_size_of_children(&self) -> usize { + 4 + } +} + +#[derive(HeapSizeOf)] +struct Eight(Four, Four, bool, bool, bool); + +#[derive(HeapSizeOf)] +enum EightOrFour { + Eight(Eight), + Four(Four), + Zero(u8) +} + +#[test] +fn test_heap_size() { + assert_eq!(Four.heap_size_of_children(), 4); + let eight = Eight(Four, Four, true, true, true); + assert_eq!(eight.heap_size_of_children(), 8); + assert_eq!(EightOrFour::Eight(eight).heap_size_of_children(), 8); + assert_eq!(EightOrFour::Four(Four).heap_size_of_children(), 4); + assert_eq!(EightOrFour::Zero(1).heap_size_of_children(), 0); +}