mirror of
https://github.com/doukutsu-rs/doukutsu-rs
synced 2024-09-28 21:19:24 +00:00
remove ggez tests to stop them from interfering with our tests
This commit is contained in:
parent
6a84c732b1
commit
f1e1d41931
|
@ -431,20 +431,3 @@ impl Conf {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use crate::conf;
|
|
||||||
|
|
||||||
/// Tries to encode and decode a `Conf` object
|
|
||||||
/// and makes sure it gets the same result it had.
|
|
||||||
#[test]
|
|
||||||
fn headless_encode_round_trip() {
|
|
||||||
let c1 = conf::Conf::new();
|
|
||||||
let mut writer = Vec::new();
|
|
||||||
let _c = c1.to_toml_file(&mut writer).unwrap();
|
|
||||||
let mut reader = writer.as_slice();
|
|
||||||
let c2 = conf::Conf::from_toml_file(&mut reader).unwrap();
|
|
||||||
assert_eq!(c1, c2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,19 +1,10 @@
|
||||||
//! Error types and conversion functions.
|
//! Error types and conversion functions.
|
||||||
|
|
||||||
use std;
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use gfx;
|
|
||||||
use glutin;
|
|
||||||
use winit;
|
|
||||||
|
|
||||||
use gilrs;
|
|
||||||
use image;
|
|
||||||
use lyon;
|
|
||||||
use toml;
|
|
||||||
use std::string::FromUtf8Error;
|
use std::string::FromUtf8Error;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
/// An enum containing all kinds of game framework errors.
|
/// An enum containing all kinds of game framework errors.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -49,6 +40,7 @@ pub enum GameError {
|
||||||
GamepadError(String),
|
GamepadError(String),
|
||||||
/// Something went wrong with the `lyon` shape-tesselation library.
|
/// Something went wrong with the `lyon` shape-tesselation library.
|
||||||
LyonError(String),
|
LyonError(String),
|
||||||
|
ParseError(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for GameError {
|
impl fmt::Display for GameError {
|
||||||
|
@ -233,3 +225,10 @@ impl From<lyon::lyon_tessellation::geometry_builder::GeometryBuilderError> for G
|
||||||
GameError::LyonError(errstr)
|
GameError::LyonError(errstr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<strum::ParseError> for GameError {
|
||||||
|
fn from(s: strum::ParseError) -> GameError {
|
||||||
|
let errstr = format!("Strum parse error: {}", s);
|
||||||
|
GameError::ParseError(errstr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -378,16 +378,3 @@ impl Drawable for Image {
|
||||||
self.blend_mode
|
self.blend_mode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
use crate::ContextBuilder;
|
|
||||||
#[test]
|
|
||||||
fn test_invalid_image_size() {
|
|
||||||
let (ctx, _) = &mut ContextBuilder::new("unittest", "unittest").build().unwrap();
|
|
||||||
let _i = assert!(Image::from_rgba8(ctx, 0, 0, &vec![]).is_err());
|
|
||||||
let _i = assert!(Image::from_rgba8(ctx, 3432, 432, &vec![]).is_err());
|
|
||||||
let _i = Image::from_rgba8(ctx, 2, 2, &vec![99; 16]).unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -102,8 +102,5 @@ pub mod input;
|
||||||
pub mod timer;
|
pub mod timer;
|
||||||
mod vfs;
|
mod vfs;
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
pub mod tests;
|
|
||||||
|
|
||||||
pub use crate::ggez::context::{Context, ContextBuilder};
|
pub use crate::ggez::context::{Context, ContextBuilder};
|
||||||
pub use crate::ggez::error::*;
|
pub use crate::ggez::error::*;
|
||||||
|
|
|
@ -1,128 +0,0 @@
|
||||||
use crate::audio::SoundSource;
|
|
||||||
use crate::tests;
|
|
||||||
use crate::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn audio_load_ogg() {
|
|
||||||
let (c, _e) = &mut tests::make_context();
|
|
||||||
|
|
||||||
// OGG format
|
|
||||||
let filename = "/pew.ogg";
|
|
||||||
let _sound = audio::Source::new(c, filename).unwrap();
|
|
||||||
let _sound = audio::SpatialSource::new(c, filename).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn audio_load_wav() {
|
|
||||||
let (c, _e) = &mut tests::make_context();
|
|
||||||
|
|
||||||
// WAV format
|
|
||||||
let filename = "/pew.wav";
|
|
||||||
let _sound = audio::Source::new(c, filename).unwrap();
|
|
||||||
let _sound = audio::SpatialSource::new(c, filename).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn audio_load_flac() {
|
|
||||||
let (c, _e) = &mut tests::make_context();
|
|
||||||
|
|
||||||
// FLAC format
|
|
||||||
let filename = "/pew.flac";
|
|
||||||
let _sound = audio::Source::new(c, filename).unwrap();
|
|
||||||
let _sound = audio::SpatialSource::new(c, filename).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn fail_when_loading_nonexistent_file() {
|
|
||||||
let (c, _e) = &mut tests::make_context();
|
|
||||||
|
|
||||||
// File does not exist
|
|
||||||
let filename = "/does-not-exist.ogg";
|
|
||||||
assert!(audio::Source::new(c, filename).is_err());
|
|
||||||
assert!(audio::SpatialSource::new(c, filename).is_err());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn fail_when_loading_non_audio_file() {
|
|
||||||
let (c, _e) = &mut tests::make_context();
|
|
||||||
|
|
||||||
let filename = "/player.png";
|
|
||||||
assert!(audio::Source::new(c, filename).is_err());
|
|
||||||
assert!(audio::SpatialSource::new(c, filename).is_err());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn playing_returns_correct_value_based_on_state() {
|
|
||||||
let (c, _e) = &mut tests::make_context();
|
|
||||||
|
|
||||||
let mut sound = audio::Source::new(c, "/pew.ogg").unwrap();
|
|
||||||
assert!(!sound.playing());
|
|
||||||
|
|
||||||
sound.play().unwrap();
|
|
||||||
assert!(sound.playing());
|
|
||||||
|
|
||||||
sound.pause();
|
|
||||||
assert!(!sound.playing());
|
|
||||||
|
|
||||||
sound.resume();
|
|
||||||
assert!(sound.playing());
|
|
||||||
|
|
||||||
sound.stop();
|
|
||||||
assert!(!sound.playing());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn paused_returns_correct_value_based_on_state() {
|
|
||||||
let (c, _e) = &mut tests::make_context();
|
|
||||||
|
|
||||||
let mut sound = audio::Source::new(c, "/pew.ogg").unwrap();
|
|
||||||
assert!(!sound.paused());
|
|
||||||
|
|
||||||
sound.play().unwrap();
|
|
||||||
assert!(!sound.paused());
|
|
||||||
|
|
||||||
sound.pause();
|
|
||||||
assert!(sound.paused());
|
|
||||||
|
|
||||||
sound.resume();
|
|
||||||
assert!(!sound.paused());
|
|
||||||
|
|
||||||
sound.pause();
|
|
||||||
assert!(sound.paused());
|
|
||||||
|
|
||||||
sound.stop();
|
|
||||||
assert!(!sound.paused());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn volume_persists_after_stop() {
|
|
||||||
let (c, _e) = &mut tests::make_context();
|
|
||||||
let filename = "/pew.ogg";
|
|
||||||
test_volume_after_stop(audio::Source::new(c, filename).unwrap());
|
|
||||||
test_volume_after_stop(audio::SpatialSource::new(c, filename).unwrap());
|
|
||||||
|
|
||||||
fn test_volume_after_stop(mut sound: impl SoundSource) {
|
|
||||||
let volume = 0.8;
|
|
||||||
sound.set_volume(volume);
|
|
||||||
assert_eq!(sound.volume(), volume);
|
|
||||||
sound.stop();
|
|
||||||
assert_eq!(sound.volume(), volume);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn volume_persists_after_play() {
|
|
||||||
let (c, _e) = &mut tests::make_context();
|
|
||||||
let filename = "/pew.ogg";
|
|
||||||
test_volume(audio::Source::new(c, filename).unwrap());
|
|
||||||
test_volume(audio::SpatialSource::new(c, filename).unwrap());
|
|
||||||
|
|
||||||
fn test_volume(mut sound: impl SoundSource) {
|
|
||||||
let volume = 0.8;
|
|
||||||
assert_eq!(sound.volume(), 1.0);
|
|
||||||
sound.set_volume(volume);
|
|
||||||
assert_eq!(sound.volume(), volume);
|
|
||||||
sound.play().unwrap();
|
|
||||||
assert_eq!(sound.volume(), volume);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,32 +0,0 @@
|
||||||
use crate::*;
|
|
||||||
use std::env;
|
|
||||||
use std::path;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
#[ignore]
|
|
||||||
pub fn context_build_tests() {
|
|
||||||
let confs = vec![
|
|
||||||
conf::Conf::default().window_mode(conf::WindowMode::default().dimensions(800.0, 600.0)),
|
|
||||||
conf::Conf::default().window_mode(conf::WindowMode::default().dimensions(400.0, 400.0)),
|
|
||||||
conf::Conf::default().window_mode(conf::WindowMode::default().resizable(false)),
|
|
||||||
conf::Conf::default().window_mode(
|
|
||||||
conf::WindowMode::default().fullscreen_type(conf::FullscreenType::Windowed),
|
|
||||||
),
|
|
||||||
conf::Conf::default()
|
|
||||||
.window_mode(conf::WindowMode::default().fullscreen_type(conf::FullscreenType::True)),
|
|
||||||
conf::Conf::default().modules(conf::ModuleConf::default().audio(false)),
|
|
||||||
];
|
|
||||||
for conf in confs.into_iter() {
|
|
||||||
let mut cb = ContextBuilder::new("ggez_unit_tests", "ggez").conf(conf);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
let (c, _e) = cb.clone().build().unwrap();
|
|
||||||
let (w, h) = graphics::drawable_size(&c);
|
|
||||||
assert_eq!(w, cb.conf.window_mode.width.into());
|
|
||||||
assert_eq!(h, cb.conf.window_mode.height.into());
|
|
||||||
// Can't really test whether or not the window is resizable?
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
use crate::tests;
|
|
||||||
use crate::*;
|
|
||||||
|
|
||||||
use std::io::Write;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn filesystem_create_correct_paths() {
|
|
||||||
let (c, _e) = &mut tests::make_context();
|
|
||||||
|
|
||||||
{
|
|
||||||
let mut f = filesystem::create(c, "/filesystem_create_path").unwrap();
|
|
||||||
let _ = f.write(b"foo").unwrap();
|
|
||||||
}
|
|
||||||
let userdata_path = filesystem::user_config_dir(c);
|
|
||||||
let userdata_path = &mut userdata_path.to_owned();
|
|
||||||
userdata_path.push("filesystem_create_path");
|
|
||||||
println!("Userdata path: {:?}", userdata_path);
|
|
||||||
assert!(userdata_path.is_file());
|
|
||||||
}
|
|
|
@ -1,175 +0,0 @@
|
||||||
use crate::graphics::Color;
|
|
||||||
use crate::tests;
|
|
||||||
use crate::*;
|
|
||||||
use cgmath::Point2;
|
|
||||||
|
|
||||||
// use std::path;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn image_encode() {
|
|
||||||
let (c, _e) = &mut tests::make_context();
|
|
||||||
let image = graphics::Image::new(c, "/player.png").unwrap();
|
|
||||||
image
|
|
||||||
.encode(c, graphics::ImageFormat::Png, "/encode_test.png")
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_rgba_sample(rgba_buf: &[u8], width: usize, sample_pos: Point2<f32>) -> (u8, u8, u8, u8) {
|
|
||||||
(
|
|
||||||
rgba_buf[(width * sample_pos.y as usize + sample_pos.x as usize) * 4 + 0],
|
|
||||||
rgba_buf[(width * sample_pos.y as usize + sample_pos.x as usize) * 4 + 1],
|
|
||||||
rgba_buf[(width * sample_pos.y as usize + sample_pos.x as usize) * 4 + 2],
|
|
||||||
rgba_buf[(width * sample_pos.y as usize + sample_pos.x as usize) * 4 + 3],
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn save_screenshot_test(c: &mut Context) {
|
|
||||||
graphics::clear(c, Color::new(0.1, 0.2, 0.3, 1.0));
|
|
||||||
|
|
||||||
let width = graphics::drawable_size(c).0;
|
|
||||||
let height = graphics::drawable_size(c).1;
|
|
||||||
|
|
||||||
let topleft = graphics::DrawParam::new()
|
|
||||||
.color(graphics::WHITE)
|
|
||||||
.dest(Point2::new(0.0, 0.0));
|
|
||||||
let topright = graphics::DrawParam::new()
|
|
||||||
.color(Color::new(1.0, 0.0, 0.0, 1.0))
|
|
||||||
.dest(Point2::new(width / 2.0, 0.0));
|
|
||||||
let bottomleft = graphics::DrawParam::new()
|
|
||||||
.color(Color::new(0.0, 1.0, 0.0, 1.0))
|
|
||||||
.dest(Point2::new(0.0, height / 2.0));
|
|
||||||
let bottomright = graphics::DrawParam::new()
|
|
||||||
.color(Color::new(0.0, 0.0, 1.0, 1.0))
|
|
||||||
.dest(Point2::new(width / 2.0, height / 2.0));
|
|
||||||
|
|
||||||
let rect = graphics::Mesh::new_rectangle(
|
|
||||||
c,
|
|
||||||
graphics::DrawMode::fill(),
|
|
||||||
graphics::types::Rect {
|
|
||||||
x: 0.0,
|
|
||||||
y: 0.0,
|
|
||||||
w: width / 2.0,
|
|
||||||
h: height / 2.0,
|
|
||||||
},
|
|
||||||
graphics::WHITE,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
graphics::draw(c, &rect, topleft).unwrap();
|
|
||||||
graphics::draw(c, &rect, topright).unwrap();
|
|
||||||
graphics::draw(c, &rect, bottomleft).unwrap();
|
|
||||||
graphics::draw(c, &rect, bottomright).unwrap();
|
|
||||||
|
|
||||||
// Don't do graphics::present(c) since calling it once (!) would mean that the result of our draw operation
|
|
||||||
// went to the front buffer and the active screen texture is actually empty.
|
|
||||||
c.gfx_context.encoder.flush(&mut *c.gfx_context.device);
|
|
||||||
|
|
||||||
let screenshot = graphics::screenshot(c).unwrap();
|
|
||||||
|
|
||||||
// Check if screenshot has right general properties
|
|
||||||
assert_eq!(width as u16, screenshot.width);
|
|
||||||
assert_eq!(height as u16, screenshot.height);
|
|
||||||
assert_eq!(None, screenshot.blend_mode);
|
|
||||||
|
|
||||||
// Image comparision or rendered output is hard, but we *know* that top left should be white.
|
|
||||||
// So take a samples in the middle of each rectangle we drew and compare.
|
|
||||||
// Note that we only use fully saturated colors to avoid any issues with color spaces.
|
|
||||||
let rgba_buf = screenshot.to_rgba8(c).unwrap();
|
|
||||||
let half_rect = cgmath::Vector2::new(width / 4.0, height / 4.0);
|
|
||||||
let width = width as usize;
|
|
||||||
assert_eq!(
|
|
||||||
topleft.color.to_rgba(),
|
|
||||||
get_rgba_sample(&rgba_buf, width, Point2::from(topleft.dest) + half_rect)
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
topright.color.to_rgba(),
|
|
||||||
get_rgba_sample(&rgba_buf, width, Point2::from(topright.dest) + half_rect)
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
bottomleft.color.to_rgba(),
|
|
||||||
get_rgba_sample(&rgba_buf, width, Point2::from(bottomleft.dest) + half_rect)
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
bottomright.color.to_rgba(),
|
|
||||||
get_rgba_sample(&rgba_buf, width, Point2::from(bottomright.dest) + half_rect)
|
|
||||||
);
|
|
||||||
|
|
||||||
// save screenshot (no check, just to see if it doesn't crash)
|
|
||||||
screenshot
|
|
||||||
.encode(c, graphics::ImageFormat::Png, "/screenshot_test.png")
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn save_screenshot() {
|
|
||||||
let (c, _e) = &mut tests::make_context();
|
|
||||||
save_screenshot_test(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Not supported, see https://github.com/ggez/ggez/issues/751
|
|
||||||
// #[test]
|
|
||||||
// fn save_screenshot_with_antialiasing() {
|
|
||||||
// let cb = ContextBuilder::new("ggez_unit_tests", "ggez")
|
|
||||||
// .window_setup(conf::WindowSetup::default().samples(conf::NumSamples::Eight));
|
|
||||||
// let (c, _e) = &mut tests::make_context_from_contextbuilder(cb);
|
|
||||||
// save_screenshot_test(c);
|
|
||||||
// }
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn load_images() {
|
|
||||||
let (c, _e) = &mut tests::make_context();
|
|
||||||
let image = graphics::Image::new(c, "/player.png").unwrap();
|
|
||||||
image
|
|
||||||
.encode(c, graphics::ImageFormat::Png, "/player_save_test.png")
|
|
||||||
.unwrap();
|
|
||||||
let _i2 = graphics::Image::new(c, "/player_save_test.png").unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn sanity_check_window_sizes() {
|
|
||||||
let (c, e) = &mut tests::make_context();
|
|
||||||
|
|
||||||
// Make sure that window sizes are what we ask for, and not what hidpi gives us.
|
|
||||||
let w = c.conf.window_mode.width;
|
|
||||||
let h = c.conf.window_mode.height;
|
|
||||||
let size = graphics::drawable_size(c);
|
|
||||||
assert_eq!(w, size.0);
|
|
||||||
assert_eq!(h, size.1);
|
|
||||||
|
|
||||||
let outer_size = graphics::size(c);
|
|
||||||
assert!(size.0 <= outer_size.0);
|
|
||||||
assert!(size.1 <= outer_size.1);
|
|
||||||
|
|
||||||
// Make sure resizing the window works.
|
|
||||||
let w = 100.0;
|
|
||||||
let h = 200.0;
|
|
||||||
graphics::set_drawable_size(c, w, h).unwrap();
|
|
||||||
// ahahaha this apparently REQUIRES a delay between setting
|
|
||||||
// the size and it actually altering, at least on Linux X11
|
|
||||||
std::thread::sleep(std::time::Duration::from_millis(100));
|
|
||||||
// Maybe we need to run the event pump too? It seems VERY flaky.
|
|
||||||
// Sometimes you need one, sometimes you need both...
|
|
||||||
e.poll_events(|event| {
|
|
||||||
c.process_event(&event);
|
|
||||||
});
|
|
||||||
|
|
||||||
let size = graphics::drawable_size(c);
|
|
||||||
assert_eq!(w, size.0);
|
|
||||||
assert_eq!(h, size.1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Ensure that the transform stack applies operations in the correct order.
|
|
||||||
#[test]
|
|
||||||
fn test_transform_stack_order() {
|
|
||||||
let (ctx, _e) = &mut tests::make_context();
|
|
||||||
let p1 = graphics::DrawParam::default();
|
|
||||||
let p2 = graphics::DrawParam::default();
|
|
||||||
let t1 = p1.to_matrix();
|
|
||||||
let t2 = p2.to_matrix();
|
|
||||||
graphics::push_transform(ctx, Some(t1));
|
|
||||||
graphics::mul_transform(ctx, t2);
|
|
||||||
let res = crate::nalgebra::Matrix4::<f32>::from(graphics::transform(ctx));
|
|
||||||
let m1: crate::nalgebra::Matrix4<f32> = t1.into();
|
|
||||||
let m2: crate::nalgebra::Matrix4<f32> = t2.into();
|
|
||||||
assert_eq!(res, m2 * m1);
|
|
||||||
}
|
|
|
@ -1,78 +0,0 @@
|
||||||
use crate::tests;
|
|
||||||
use crate::*;
|
|
||||||
|
|
||||||
const TRIANGLE_VERTS: &[graphics::Vertex] = &[
|
|
||||||
graphics::Vertex {
|
|
||||||
pos: [0.0, 0.0],
|
|
||||||
uv: [0.0, 0.0],
|
|
||||||
color: [1.0, 1.0, 1.0, 1.0],
|
|
||||||
},
|
|
||||||
graphics::Vertex {
|
|
||||||
pos: [0.0, 0.0],
|
|
||||||
uv: [0.0, 0.0],
|
|
||||||
color: [1.0, 1.0, 1.0, 1.0],
|
|
||||||
},
|
|
||||||
graphics::Vertex {
|
|
||||||
pos: [0.0, 0.0],
|
|
||||||
uv: [0.0, 0.0],
|
|
||||||
color: [1.0, 1.0, 1.0, 1.0],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
/// Mesh creation fails if verts or indices are empty.
|
|
||||||
#[test]
|
|
||||||
fn test_mesh_verts_empty() {
|
|
||||||
let (mut ctx, _ev) = tests::make_context();
|
|
||||||
let bad_verts: Vec<graphics::Vertex> = vec![];
|
|
||||||
let bad_indices = vec![];
|
|
||||||
let good_indices = vec![0, 1, 2];
|
|
||||||
let m = graphics::Mesh::from_raw(&mut ctx, &bad_verts, &bad_indices, None);
|
|
||||||
assert!(m.is_err());
|
|
||||||
|
|
||||||
let m = graphics::Mesh::from_raw(&mut ctx, &bad_verts, &good_indices, None);
|
|
||||||
assert!(m.is_err());
|
|
||||||
|
|
||||||
let m = graphics::Mesh::from_raw(&mut ctx, TRIANGLE_VERTS, &bad_indices, None);
|
|
||||||
assert!(m.is_err());
|
|
||||||
|
|
||||||
let m = graphics::Mesh::from_raw(&mut ctx, TRIANGLE_VERTS, &good_indices, None);
|
|
||||||
assert!(m.is_ok());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Mesh creation fails if not enough indices to make a triangle.
|
|
||||||
#[test]
|
|
||||||
fn test_mesh_verts_invalid_count() {
|
|
||||||
let (mut ctx, _ev) = tests::make_context();
|
|
||||||
let indices: Vec<u32> = vec![0, 1];
|
|
||||||
let m = graphics::Mesh::from_raw(&mut ctx, TRIANGLE_VERTS, &indices, None);
|
|
||||||
assert!(m.is_err());
|
|
||||||
|
|
||||||
let indices: Vec<u32> = vec![0, 1, 2, 0];
|
|
||||||
let m = graphics::Mesh::from_raw(&mut ctx, TRIANGLE_VERTS, &indices, None);
|
|
||||||
assert!(m.is_err());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_mesh_points_clockwise() {
|
|
||||||
let (mut ctx, _ev) = tests::make_context();
|
|
||||||
|
|
||||||
// Points in CCW order
|
|
||||||
let points: Vec<graphics::Point2> = vec![
|
|
||||||
graphics::Point2::new(0.0, 0.0),
|
|
||||||
graphics::Point2::new(0.0, 1.0),
|
|
||||||
graphics::Point2::new(1.0, 1.0),
|
|
||||||
];
|
|
||||||
|
|
||||||
let _trapezoid_mesh = graphics::Mesh::new_polygon(
|
|
||||||
&mut ctx,
|
|
||||||
graphics::DrawMode::fill(),
|
|
||||||
&points,
|
|
||||||
[0.0, 0.0, 1.0, 1.0].into(),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// TODO LATER: This is actually tricky to test for well...
|
|
||||||
// We don't actually check for CCW points in
|
|
||||||
// the `Mesh` building functions yet, so this will never fail.
|
|
||||||
//assert!(trapezoid_mesh.is_err());
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
//! Utility functions shared among various unit tests.
|
|
||||||
|
|
||||||
use crate::*;
|
|
||||||
use std::env;
|
|
||||||
use std::path;
|
|
||||||
|
|
||||||
mod audio;
|
|
||||||
mod conf;
|
|
||||||
mod filesystem;
|
|
||||||
mod graphics;
|
|
||||||
mod mesh;
|
|
||||||
mod text;
|
|
||||||
|
|
||||||
pub fn make_context_from_contextbuilder(mut cb: ContextBuilder) -> (Context, event::EventsLoop) {
|
|
||||||
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()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Make a basic `Context` with sane defaults.
|
|
||||||
pub fn make_context() -> (Context, event::EventsLoop) {
|
|
||||||
let cb = ContextBuilder::new("ggez_unit_tests", "ggez");
|
|
||||||
make_context_from_contextbuilder(cb)
|
|
||||||
}
|
|
|
@ -1,56 +0,0 @@
|
||||||
// #[cfg(all(test, has_display))]
|
|
||||||
|
|
||||||
use crate::tests;
|
|
||||||
use crate::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_calculated_text_width() {
|
|
||||||
let (ctx, _ev) = &mut tests::make_context();
|
|
||||||
let font = graphics::Font::default();
|
|
||||||
|
|
||||||
let text = graphics::Text::new(("Hello There", font, 24.0));
|
|
||||||
|
|
||||||
let expected_width = text.width(ctx);
|
|
||||||
// For now we just test against a known value, since rendering it
|
|
||||||
// is odd.
|
|
||||||
assert_eq!(expected_width, 123);
|
|
||||||
// let rendered_width = graphics::Text::new((text, font, 24)).unwrap().width();
|
|
||||||
|
|
||||||
// println!("Text: {:?}, expected: {}, rendered: {}", text, expected_width, rendered_width);
|
|
||||||
// assert_eq!(expected_width as usize, rendered_width as usize);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Make sure that the "height" of text with ascenders/descenders
|
|
||||||
/// is the same as text without
|
|
||||||
#[test]
|
|
||||||
fn test_calculated_text_height() {
|
|
||||||
let (ctx, _ev) = &mut tests::make_context();
|
|
||||||
let font = graphics::Font::default();
|
|
||||||
|
|
||||||
let text1 = graphics::Text::new(("strength", font, 24.0));
|
|
||||||
let text2 = graphics::Text::new(("moves", font, 24.0));
|
|
||||||
|
|
||||||
let h1 = text1.height(ctx);
|
|
||||||
let h2 = text2.height(ctx);
|
|
||||||
assert_eq!(h1, h2);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_monospace_text_is_actually_monospace() {
|
|
||||||
let (ctx, _ev) = &mut tests::make_context();
|
|
||||||
let font = graphics::Font::new(ctx, "/DejaVuSansMono.ttf").unwrap();
|
|
||||||
|
|
||||||
let text1 = graphics::Text::new(("Hello 1", font, 24.0));
|
|
||||||
let text2 = graphics::Text::new(("Hello 2", font, 24.0));
|
|
||||||
let text3 = graphics::Text::new(("Hello 3", font, 24.0));
|
|
||||||
let text4 = graphics::Text::new(("Hello 4", font, 24.0));
|
|
||||||
|
|
||||||
let width1 = text1.width(ctx);
|
|
||||||
let width2 = text3.width(ctx);
|
|
||||||
let width3 = text2.width(ctx);
|
|
||||||
let width4 = text4.width(ctx);
|
|
||||||
|
|
||||||
assert_eq!(width1, width2);
|
|
||||||
assert_eq!(width2, width3);
|
|
||||||
assert_eq!(width3, width4);
|
|
||||||
}
|
|
Loading…
Reference in a new issue