Skip to content

Commit

Permalink
Adding unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
icefoxen committed Nov 20, 2018
1 parent e4376a0 commit 43119e9
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 20 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ authors = [
"Sven-Hendrik Haase <[email protected]>",
"Simon Heath <[email protected]>",
]
# TODO: Uncomment this before release?
edition = "2018"
license = "MIT"
readme = "README.md"
Expand Down
9 changes: 5 additions & 4 deletions examples/canvas_subframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ impl MainState {
.scale(Vector2::new(
((time % cycle * 2) as f32 / cycle as f32 * 6.28)
.cos()
.abs() * 0.0625,
.abs()
* 0.0625,
((time % cycle * 2) as f32 / cycle as f32 * 6.28)
.cos()
.abs() * 0.0625,
))
.rotation(-2.0 * ((time % cycle) as f32 / cycle as f32 * 6.28));
.abs()
* 0.0625,
)).rotation(-2.0 * ((time % cycle) as f32 / cycle as f32 * 6.28));
self.spritebatch.add(p);
}
}
Expand Down
4 changes: 1 addition & 3 deletions examples/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ impl App {
// More fragments can be appended at any time.
text.add(" default fragment, should be long enough to showcase everything")
// `add()` can be chained, along with most `Text` methods.
.add(
TextFragment::new(" magenta fragment")
.color(Color::new(1.0, 0.0, 1.0, 1.0)))
.add(TextFragment::new(" magenta fragment").color(Color::new(1.0, 0.0, 1.0, 1.0)))
.add(" another default fragment, to really drive the point home");

// This loads a new TrueType font into the context and returns a
Expand Down
3 changes: 1 addition & 2 deletions src/graphics/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ impl Image {
u32::from(self.width),
u32::from(self.height),
color_format,
)
.map_err(|e| e.into()),
).map_err(|e| e.into()),
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/graphics/spritebatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ impl SpriteBatch {
new_param.color = new_param.color;
let primitive_param = graphics::DrawTransform::from(new_param);
primitive_param.to_instance_properties(ctx.gfx_context.is_srgb())
})
.collect::<Vec<_>>();
}).collect::<Vec<_>>();

let gfx = &mut ctx.gfx_context;
if gfx.data.rect_instance_properties.len() < self.sprites.len() {
Expand Down
3 changes: 1 addition & 2 deletions src/graphics/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,7 @@ where
encoder,
&(render_tgt, color_format),
&(depth_view, depth_format),
)
.map_err(|e| GameError::RenderError(e.to_string()))
).map_err(|e| GameError::RenderError(e.to_string()))
}

#[cfg(test)]
Expand Down
11 changes: 11 additions & 0 deletions src/input/gamepad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,14 @@ pub fn axis() {
pub fn button_pressed() {
unimplemented!()
}


#[cfg(test)]
mod tests {
use super::*;

#[test]
fn gilrs_init() {
assert!(GilrsGamepadContext::new().is_ok());
}
}
3 changes: 1 addition & 2 deletions src/input/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,7 @@ impl KeyboardContext {
} else {
None
}
})
.collect()
}).collect()
}

pub(crate) fn active_mods(&self) -> KeyMods {
Expand Down
3 changes: 1 addition & 2 deletions src/input/mouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ pub fn set_position(ctx: &mut Context, point: Point2) -> GameResult<()> {
.set_cursor_position(dpi::LogicalPosition {
x: f64::from(point.x),
y: f64::from(point.y),
})
.map_err(|_| GameError::WindowError("Couldn't set mouse cursor position!".to_owned()))
}).map_err(|_| GameError::WindowError("Couldn't set mouse cursor position!".to_owned()))
}

/// Get the distance the cursor was moved during last frame, in pixels.
Expand Down
3 changes: 1 addition & 2 deletions src/vfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,7 @@ impl ZipFS {
.expect("Should never happen!")
.name()
.to_string()
})
.collect();
}).collect();
Ok(Self {
source: filename.into(),
archive: RefCell::new(archive),
Expand Down
32 changes: 32 additions & 0 deletions tests/screenshot.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

extern crate ggez;
use ggez::*;

use std::env;
use std::path;

// TODO: Is there a good way to dedupe this?
fn make_context() -> (Context, event::EventsLoop) {
let mut cb = ContextBuilder::new("ggez_unit_tests", "ggez");
if let Ok(manifest_dir) = env::var("CARGO_MANIFEST_DIR") {
let mut path = path::PathBuf::from(manifest_dir);
path.push("resources");
cb = cb.add_resource_path(path);
}
cb.build().unwrap()
}

#[test]
fn image_encode() {
let (c, _e) = &mut make_context();
let image = graphics::Image::new(c, "/player.png").unwrap();
image.encode(c, graphics::ImageFormat::Png, "/encode_test.png").unwrap();
}


#[test]
fn save_screenshot() {
let (c, _e) = &mut make_context();
let screenshot = graphics::screenshot(c).unwrap();
// screenshot.encode(c, graphics::ImageFormat::Png, "/screenshot_test.png").unwrap();
}
1 change: 0 additions & 1 deletion tests/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fn make_context() -> (Context, event::EventsLoop) {
path.push("resources");
cb = cb.add_resource_path(path);
}

cb.build().unwrap()
}
/* TODO; the font API has changed and I don't want to deal with it now
Expand Down

0 comments on commit 43119e9

Please sign in to comment.