From 987ec455b4e7fc03fdc1cfd248169cac4fdf7597 Mon Sep 17 00:00:00 2001 From: Kornel Date: Thu, 14 Sep 2017 23:54:48 +0100 Subject: [PATCH] Test --- src/context.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/context.rs b/src/context.rs index d6c44d3..20d84bf 100644 --- a/src/context.rs +++ b/src/context.rs @@ -105,6 +105,7 @@ impl CGContext { bytes_per_row, space.as_concrete_TypeRef(), bitmap_info); + assert!(!result.is_null()); TCFType::wrap_under_create_rule(result) } } @@ -223,6 +224,30 @@ impl CGContext { } } +#[test] +fn create_bitmap_context_test() { + use geometry::*; + + let cs = CGColorSpace::create_device_rgb(); + let ctx = CGContext::create_bitmap_context(None, + 16, 8, + 8, 0, + &cs, + ::base::kCGImageAlphaPremultipliedLast); + ctx.set_rgb_fill_color(1.,0.,1.,1.); + ctx.fill_rect(CGRect::new(&CGPoint::new(0.,0.), &CGSize::new(8.,8.))); + let img = ctx.create_image().unwrap(); + assert_eq!(16, img.width()); + assert_eq!(8, img.height()); + assert_eq!(8, img.bits_per_component()); + assert_eq!(32, img.bits_per_pixel()); + let data = img.data(); + assert_eq!(255, data.bytes()[0]); + assert_eq!(0, data.bytes()[1]); + assert_eq!(255, data.bytes()[2]); + assert_eq!(255, data.bytes()[3]); +} + #[link(name = "ApplicationServices", kind = "framework")] extern { fn CGBitmapContextCreate(data: *mut c_void,