aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcus Klaas <mail@marcusklaas.nl>2015-04-17 16:27:51 +0200
committerMarcus Klaas <mail@marcusklaas.nl>2015-04-17 16:44:51 +0200
commit0d482e36e68ec471e85a4688f71631190030e3be (patch)
tree2fdae5989e74c9c34c7e3676ee27b86bd80d4733
parent4fd4370a9680f4845f05efd43ce9cb26c7433f05 (diff)
downloadservo-0d482e36e68ec471e85a4688f71631190030e3be.tar.gz
servo-0d482e36e68ec471e85a4688f71631190030e3be.zip
Fix compiler warnings in net unit tests
-rw-r--r--tests/unit/lib.rs2
-rw-r--r--tests/unit/net/image_cache_task.rs46
-rw-r--r--tests/unit/net/mime_classifier.rs61
3 files changed, 60 insertions, 49 deletions
diff --git a/tests/unit/lib.rs b/tests/unit/lib.rs
index f040b2e9513..05542a17840 100644
--- a/tests/unit/lib.rs
+++ b/tests/unit/lib.rs
@@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#![feature(plugin)]
-#![cfg_attr(test, feature(net, alloc))]
+#![cfg_attr(test, feature(net, alloc, path, io))]
#![plugin(string_cache_plugin)]
diff --git a/tests/unit/net/image_cache_task.rs b/tests/unit/net/image_cache_task.rs
index a12e9b2b2e0..b19258a7dd8 100644
--- a/tests/unit/net/image_cache_task.rs
+++ b/tests/unit/net/image_cache_task.rs
@@ -7,7 +7,7 @@ use net_traits::image_cache_task::ImageResponseMsg::*;
use net_traits::image_cache_task::Msg::*;
use net::resource_task::{start_sending, ProgressSender};
-use net_traits::{ControlMsg, Metadata, ProgressMsg, ResourceTask, ResponseSenders};
+use net_traits::{ControlMsg, Metadata, ResourceTask, ResponseSenders};
use net_traits::image_cache_task::{ImageCacheTask, ImageCacheTaskClient, ImageResponseMsg, Msg};
use net_traits::ProgressMsg::{Payload, Done};
use profile::time;
@@ -110,7 +110,7 @@ fn mock_resource_task<T: Closure + Send + 'static>(on_load: Box<T>) -> ResourceT
spawn_listener(move |port: Receiver<ControlMsg>| {
loop {
match port.recv().unwrap() {
- ControlMsg::Load(response, consumer) => {
+ ControlMsg::Load(_, consumer) => {
let chan = start_sending(ResponseSenders::from_consumer(consumer), Metadata::default(
Url::parse("file:///fake").unwrap()));
on_load.invoke(chan);
@@ -280,15 +280,15 @@ fn should_not_request_image_from_resource_task_if_image_is_already_available() {
let mock_resource_task = spawn_listener(move |port: Receiver<ControlMsg>| {
loop {
match port.recv().unwrap() {
- ControlMsg::Load(response, consumer) => {
+ ControlMsg::Load(_, consumer) => {
let chan = start_sending(ResponseSenders::from_consumer(consumer), Metadata::default(
Url::parse("file:///fake").unwrap()));
- chan.send(Payload(test_image_bin()));
- chan.send(Done(Ok(())));
- image_bin_sent_chan.send(());
+ chan.send(Payload(test_image_bin())).unwrap();
+ chan.send(Done(Ok(()))).unwrap();
+ image_bin_sent_chan.send(()).unwrap();
}
ControlMsg::Exit => {
- resource_task_exited_chan.send(());
+ resource_task_exited_chan.send(()).unwrap();
break
}
_ => {}
@@ -309,7 +309,7 @@ fn should_not_request_image_from_resource_task_if_image_is_already_available() {
image_cache_task.send(Prefetch(url.clone()));
image_cache_task.exit();
- mock_resource_task.send(ControlMsg::Exit);
+ mock_resource_task.send(ControlMsg::Exit).unwrap();
resource_task_exited.recv().unwrap();
@@ -329,15 +329,15 @@ fn should_not_request_image_from_resource_task_if_image_fetch_already_failed() {
let mock_resource_task = spawn_listener(move |port: Receiver<ControlMsg>| {
loop {
match port.recv().unwrap() {
- ControlMsg::Load(response, consumer) => {
+ ControlMsg::Load(_, consumer) => {
let chan = start_sending(ResponseSenders::from_consumer(consumer), Metadata::default(
Url::parse("file:///fake").unwrap()));
- chan.send(Payload(test_image_bin()));
- chan.send(Done(Err("".to_string())));
- image_bin_sent_chan.send(());
+ chan.send(Payload(test_image_bin())).unwrap();
+ chan.send(Done(Err("".to_string()))).unwrap();
+ image_bin_sent_chan.send(()).unwrap();
}
ControlMsg::Exit => {
- resource_task_exited_chan.send(());
+ resource_task_exited_chan.send(()).unwrap();
break
}
_ => {}
@@ -360,7 +360,7 @@ fn should_not_request_image_from_resource_task_if_image_fetch_already_failed() {
image_cache_task.send(Decode(url.clone()));
image_cache_task.exit();
- mock_resource_task.send(ControlMsg::Exit);
+ mock_resource_task.send(ControlMsg::Exit).unwrap();
resource_task_exited.recv().unwrap();
@@ -397,7 +397,7 @@ fn should_return_failed_if_image_bin_cannot_be_fetched() {
}
image_cache_task.exit();
- mock_resource_task.send(ControlMsg::Exit);
+ mock_resource_task.send(ControlMsg::Exit).unwrap();
}
#[test]
@@ -433,7 +433,7 @@ fn should_return_failed_for_multiple_get_image_requests_if_image_bin_cannot_be_f
}
image_cache_task.exit();
- mock_resource_task.send(ControlMsg::Exit);
+ mock_resource_task.send(ControlMsg::Exit).unwrap();
}
#[test]
@@ -463,7 +463,7 @@ fn should_return_failed_if_image_decode_fails() {
}
image_cache_task.exit();
- mock_resource_task.send(ControlMsg::Exit);
+ mock_resource_task.send(ControlMsg::Exit).unwrap();
}
#[test]
@@ -491,7 +491,7 @@ fn should_return_image_on_wait_if_image_is_already_loaded() {
}
image_cache_task.exit();
- mock_resource_task.send(ControlMsg::Exit);
+ mock_resource_task.send(ControlMsg::Exit).unwrap();
}
#[test]
@@ -511,7 +511,7 @@ fn should_return_image_on_wait_if_image_is_not_yet_loaded() {
let (response_chan, response_port) = channel();
image_cache_task.send(Msg::WaitForImage(url, response_chan));
- wait_chan.send(());
+ wait_chan.send(()).unwrap();
match response_port.recv().unwrap() {
ImageResponseMsg::ImageReady(..) => (),
@@ -519,7 +519,7 @@ fn should_return_image_on_wait_if_image_is_not_yet_loaded() {
}
image_cache_task.exit();
- mock_resource_task.send(ControlMsg::Exit);
+ mock_resource_task.send(ControlMsg::Exit).unwrap();
}
#[test]
@@ -539,7 +539,7 @@ fn should_return_image_failed_on_wait_if_image_fails_to_load() {
let (response_chan, response_port) = channel();
image_cache_task.send(Msg::WaitForImage(url, response_chan));
- wait_chan.send(());
+ wait_chan.send(()).unwrap();
match response_port.recv().unwrap() {
ImageResponseMsg::ImageFailed => (),
@@ -547,7 +547,7 @@ fn should_return_image_failed_on_wait_if_image_fails_to_load() {
}
image_cache_task.exit();
- mock_resource_task.send(ControlMsg::Exit);
+ mock_resource_task.send(ControlMsg::Exit).unwrap();
}
#[test]
@@ -570,5 +570,5 @@ fn sync_cache_should_wait_for_images() {
}
image_cache_task.exit();
- mock_resource_task.send(ControlMsg::Exit);
+ mock_resource_task.send(ControlMsg::Exit).unwrap();
}
diff --git a/tests/unit/net/mime_classifier.rs b/tests/unit/net/mime_classifier.rs
index dcad85000ee..e56e76d1cb3 100644
--- a/tests/unit/net/mime_classifier.rs
+++ b/tests/unit/net/mime_classifier.rs
@@ -2,19 +2,30 @@
* 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 std::old_io::File;
-use std::os;
+use std::fs::File;
+use std::io::{self, Read};
+use std::env;
+use std::path::{self, PathBuf};
use net::mime_classifier::Mp4Matcher;
use net::mime_classifier::MIMEClassifier;
use net::mime_classifier::as_string_option;
+fn read_file(path: &path::Path) -> io::Result<Vec<u8>> {
+ let mut file = try!(File::open(path));
+ let mut buffer = Vec::new();
+
+ try!(file.read_to_end(&mut buffer));
+
+ Ok(buffer)
+}
+
#[test]
fn test_sniff_mp4_matcher() {
let matcher = Mp4Matcher;
- let p = Path::new("../../tests/unit/net/parsable_mime/video/mp4/test.mp4");
- let mut file = File::open(&p);
- let read_result = file.read_to_end();
+ let p = PathBuf::new("../../tests/unit/net/parsable_mime/video/mp4/test.mp4");
+ let read_result = read_file(&p);
+
match read_result {
Ok(data) => {
println!("Data Length {:?}",data.len());
@@ -27,42 +38,42 @@ fn test_sniff_mp4_matcher() {
}
#[cfg(test)]
-fn test_sniff_full(filename_orig: &Path,type_string: &str,subtype_string: &str,
+fn test_sniff_full(filename_orig: &path::Path,type_string: &str,subtype_string: &str,
supplied_type: Option<(&'static str,&'static str)>){
- let current_working_directory = os::getcwd().unwrap();
+ let current_working_directory = env::current_dir().unwrap();
println!("The current directory is {}", current_working_directory.display());
- let mut filename = Path::new("../../tests/unit/net/parsable_mime/");
-
+ let mut filename = PathBuf::new("../../tests/unit/net/parsable_mime/");
filename.push(filename_orig);
+
let classifier = MIMEClassifier::new();
- let mut file = File::open(&filename);
- let read_result = file.read_to_end();
+ let read_result = read_file(&filename);
+
match read_result {
Ok(data) => {
match classifier.classify(false, false, &as_string_option(supplied_type), &data) {
Some((parsed_type, parsed_subtp)) => {
- if (parsed_type.as_slice() != type_string) ||
- (parsed_subtp.as_slice() != subtype_string) {
- panic!("File {} parsed incorrectly should be {}/{}, parsed as {}/{}",
- filename.as_str().unwrap(), type_string, subtype_string,
+ if (&parsed_type[..] != type_string) ||
+ (&parsed_subtp[..] != subtype_string) {
+ panic!("File {:?} parsed incorrectly should be {}/{}, parsed as {}/{}",
+ filename, type_string, subtype_string,
parsed_type, parsed_subtp);
}
}
- None => panic!("No classification found for {} with supplied type {:?}",
- filename.as_str().unwrap(), supplied_type),
+ None => panic!("No classification found for {:?} with supplied type {:?}",
+ filename, supplied_type),
}
}
- Err(e) => panic!("Couldn't read from file {} with error {}",
- filename.as_str().unwrap(), e),
+ Err(e) => panic!("Couldn't read from file {:?} with error {}",
+ filename, e),
}
}
#[cfg(test)]
fn test_sniff_classification(file: &str,type_string: &str,subtype_string: &str,
supplied_type: Option<(&'static str,&'static str)>){
- let mut x = Path::new("./");
+ let mut x = PathBuf::new("./");
x.push(type_string);
x.push(subtype_string);
x.push(file);
@@ -170,19 +181,19 @@ fn test_sniff_vsn_ms_fontobject() {
#[test]
#[should_panic]
fn test_sniff_true_type() {
- test_sniff_full(&Path::new("unknown/true_type.ttf"), "(TrueType)", "", None);
+ test_sniff_full(&PathBuf::new("unknown/true_type.ttf"), "(TrueType)", "", None);
}
#[test]
#[should_panic]
fn test_sniff_open_type() {
- test_sniff_full(&Path::new("unknown/open_type"), "(OpenType)", "", None);
+ test_sniff_full(&PathBuf::new("unknown/open_type"), "(OpenType)", "", None);
}
#[test]
#[should_panic]
fn test_sniff_true_type_collection() {
- test_sniff_full(&Path::new("unknown/true_type_collection.ttc"), "(TrueType Collection)", "", None);
+ test_sniff_full(&PathBuf::new("unknown/true_type_collection.ttc"), "(TrueType Collection)", "", None);
}
#[test]
@@ -424,10 +435,10 @@ fn test_sniff_utf_8_bom() {
#[test]
fn test_sniff_rss_feed() {
- test_sniff_full(&Path::new("text/xml/feed.rss"), "application", "rss+xml", Some(("text", "html")));
+ test_sniff_full(&PathBuf::new("text/xml/feed.rss"), "application", "rss+xml", Some(("text", "html")));
}
#[test]
fn test_sniff_atom_feed() {
- test_sniff_full(&Path::new("text/xml/feed.atom"), "application", "atom+xml", Some(("text", "html")));
+ test_sniff_full(&PathBuf::new("text/xml/feed.atom"), "application", "atom+xml", Some(("text", "html")));
}