Use new verify_png_snapshot! macro in insta-image for cleaner tests.

This commit is contained in:
trurl committed 2026-10-08 14:50:14 -04:00
1 parent e74328cc8e
commit 404e8736e4
4 files changed
+362 -414

No files matched your search

+1 -1
View File
@@ -6,7 +6,7 @@ edition = "2024"
[dependencies]
libc = "0.2"
insta = "1.47"
insta-image = { version = "1.0.1", features = ["png"] }
insta-image = { version = "1.1.0", features = ["png"] }
png = "0.18"
tempdir = "0.3.7"
wings-rs = { path = "../wings-rs" }
+11 -12
View File
@@ -381,13 +381,10 @@ impl SubprocessMonitor {
#[cfg(test)]
mod tests {
use crate::headless::DisplayNumberRegistry;
use super::XvfbProcess;
use insta_image::assert_png_snapshot;
use std::{
thread,
time::Duration,
};
use crate::headless::DisplayNumberRegistry;
use insta_image::verify_png_snapshot;
use std::{error::Error, thread, time::Duration};
/// Starts Xvfb and returns a managing object, or panics.
fn start_xvfb() -> XvfbProcess {
@@ -423,7 +420,7 @@ mod tests {
}
#[test]
fn png_blank_screenshot() {
fn png_blank_screenshot() -> Result<(), Box<dyn Error>> {
let xvfb = start_xvfb();
let xwd = xvfb.xwd_screenshot().unwrap();
@@ -437,11 +434,12 @@ mod tests {
assert_eq!(xwd.header.width, args.width);
assert_eq!(xwd.header.height, args.height);
assert_png_snapshot!("blank_screen", xwd.into_png().unwrap());
verify_png_snapshot!("blank_screen", xwd.into_png().unwrap())?;
Ok(())
}
#[test]
fn png_xeyes_screenshot() {
fn png_xeyes_screenshot() -> Result<(), Box<dyn Error>> {
let mut xvfb = start_xvfb();
xeyes_color(&mut xvfb);
thread::sleep(Duration::from_millis(250));
@@ -453,11 +451,11 @@ mod tests {
assert_eq!(image_data.width, args.width);
assert_eq!(image_data.height, args.height);
assert_png_snapshot!("xeyes", compressed);
verify_png_snapshot!("xeyes", compressed)?;
Ok(())
}
#[test]
fn png_lamp_image() {
let mut xvfb = start_xvfb();
xvfb.run_args("xwud", "xwud", |c| {
c.arg("-in").arg("src/headless/snowlamp.xwd");
@@ -467,6 +465,7 @@ mod tests {
let compressed = xvfb.png_screenshot();
assert_png_snapshot!("snowlamp_in_window", compressed);
verify_png_snapshot!("snowlamp_in_window", compressed)?;
Ok(())
}
}
+10 -12
View File
@@ -1,17 +1,15 @@
use insta_image::assert_png_snapshot;
use std::time::Instant;
use insta_image::verify_png_snapshot;
use std::{error::Error, time::Instant};
use wings_rs::font_panel::FontPanel;
use wings_rs_tests::HeadlessApplication;
#[test]
fn show_font_panel() {
let screenshot = {
let mut app = HeadlessApplication::new();
let mut font_panel =
FontPanel::new(app.screen.as_ptr()).expect("could not construct font panel");
font_panel.show();
while app.pump_event_queue(Instant::now()) {}
app.xvfb.png_screenshot()
};
assert_png_snapshot!("font_panel", screenshot);
fn show_font_panel() -> Result<(), Box<dyn Error>> {
let mut app = HeadlessApplication::new();
let mut font_panel =
FontPanel::new(app.screen.as_ptr()).expect("could not construct font panel");
font_panel.show();
while app.pump_event_queue(Instant::now()) {}
let screenshot = app.xvfb.png_screenshot();
verify_png_snapshot!("font_panel", screenshot)
}
+340 -389
View File
@@ -1,5 +1,6 @@
use insta_image::assert_png_snapshot;
use insta_image::verify_png_snapshot;
use std::{
error::Error,
ptr::{self, NonNull},
time::Instant,
};
@@ -12,43 +13,41 @@ use wings_rs_tests::HeadlessApplication;
use wrlib_rs::ffi::{RColor, RLoadImage, RReleaseImage};
#[test]
fn draw_blank_pixmap() -> Result<(), ()> {
let empty_window_snapshot;
let empty_pixmap_on_window_snapshot;
{
let mut app = HeadlessApplication::new();
unsafe {
let display = (*app.screen.as_ptr()).display;
let win = x11::xlib::XCreateSimpleWindow(
display,
(*app.screen.as_ptr()).rootWin,
0,
0,
512,
512,
1,
1,
x11::xlib::XWhitePixel(display, 0),
);
x11::xlib::XMapWindow(display, win);
fn draw_blank_pixmap() -> Result<(), Box<dyn Error>> {
let mut app = HeadlessApplication::new();
unsafe {
let display = (*app.screen.as_ptr()).display;
let win = x11::xlib::XCreateSimpleWindow(
display,
(*app.screen.as_ptr()).rootWin,
0,
0,
512,
512,
1,
1,
x11::xlib::XWhitePixel(display, 0),
);
x11::xlib::XMapWindow(display, win);
let pixmap = NonNull::new(WMCreatePixmap(app.screen.as_ptr(), 128, 196, 24, 1)).ok_or(())?;
WMDrawPixmap(pixmap.as_ptr(), win, 64, 96);
while app.pump_event_queue(Instant::now()) {}
empty_window_snapshot = app.xvfb.png_screenshot();
let pixmap =
NonNull::new(WMCreatePixmap(app.screen.as_ptr(), 128, 196, 24, 1))
.ok_or_else(|| Box::<dyn Error>::from("could not allocate pixmap resource"))?;
WMDrawPixmap(pixmap.as_ptr(), win, 64, 96);
while app.pump_event_queue(Instant::now()) {}
verify_png_snapshot!("empty_window", app.xvfb.png_screenshot())?;
let gc = x11::xlib::XCreateGC(display, (*pixmap.as_ptr()).pixmap, 0, ptr::null_mut());
x11::xlib::XSetForeground(display, gc, 0);
x11::xlib::XFillRectangle(display, (*pixmap.as_ptr()).pixmap, gc, 0, 0, 128, 196);
WMDrawPixmap(pixmap.as_ptr(), win, 64, 96);
while app.pump_event_queue(Instant::now()) {}
empty_pixmap_on_window_snapshot = app.xvfb.png_screenshot();
x11::xlib::XFreeGC(display, gc);
WMReleasePixmap(pixmap.as_ptr());
}
let gc = x11::xlib::XCreateGC(display, (*pixmap.as_ptr()).pixmap, 0, ptr::null_mut());
x11::xlib::XSetForeground(display, gc, 0);
x11::xlib::XFillRectangle(display, (*pixmap.as_ptr()).pixmap, gc, 0, 0, 128, 196);
WMDrawPixmap(pixmap.as_ptr(), win, 64, 96);
while app.pump_event_queue(Instant::now()) {}
verify_png_snapshot!("empty_pixmap_on_window", app.xvfb.png_screenshot())?;
x11::xlib::XFreeGC(display, gc);
WMReleasePixmap(pixmap.as_ptr());
}
assert_png_snapshot!("empty_window", empty_window_snapshot);
assert_png_snapshot!("empty_pixmap_on_window", empty_pixmap_on_window_snapshot);
Ok(())
}
@@ -56,233 +55,214 @@ fn draw_blank_pixmap() -> Result<(), ()> {
// fields. Coverage from other tests in this file should be adequate.
#[test]
fn draw_pixmap_from_file() -> Result<(), ()> {
let snapshot;
{
let mut app = HeadlessApplication::new();
unsafe {
let display = (*app.screen.as_ptr()).display;
let win = x11::xlib::XCreateSimpleWindow(
display,
(*app.screen.as_ptr()).rootWin,
0,
0,
512,
512,
1,
1,
x11::xlib::XWhitePixel(display, 0),
);
x11::xlib::XMapWindow(display, win);
fn draw_pixmap_from_file() -> Result<(), Box<dyn Error>> {
let mut app = HeadlessApplication::new();
unsafe {
let display = (*app.screen.as_ptr()).display;
let win = x11::xlib::XCreateSimpleWindow(
display,
(*app.screen.as_ptr()).rootWin,
0,
0,
512,
512,
1,
1,
x11::xlib::XWhitePixel(display, 0),
);
x11::xlib::XMapWindow(display, win);
let pixmap = NonNull::new(WMCreatePixmapFromFile(
app.screen.as_ptr(),
c"tests/image_128x120.png".as_ptr(),
)).ok_or(())?;
WMDrawPixmap(pixmap.as_ptr(), win, 64, 96);
let pixmap = NonNull::new(WMCreatePixmapFromFile(
app.screen.as_ptr(),
c"tests/image_128x120.png".as_ptr(),
))
.ok_or_else(|| Box::<dyn Error>::from("could not allocate pixmap resource"))?;
WMDrawPixmap(pixmap.as_ptr(), win, 64, 96);
while app.pump_event_queue(Instant::now()) {}
snapshot = app.xvfb.png_screenshot();
while app.pump_event_queue(Instant::now()) {}
verify_png_snapshot!("from_file_pixmap", app.xvfb.png_screenshot())?;
WMReleasePixmap(pixmap.as_ptr());
}
Ok(())
}
#[test]
fn draw_pixmap_from_r_image_no_mask() -> Result<(), Box<dyn Error>> {
let mut app = HeadlessApplication::new();
unsafe {
let display = (*app.screen.as_ptr()).display;
let win = x11::xlib::XCreateSimpleWindow(
display,
(*app.screen.as_ptr()).rootWin,
0,
0,
512,
512,
1,
1,
x11::xlib::XWhitePixel(display, 0),
);
x11::xlib::XMapWindow(display, win);
let rimage = RLoadImage(
(*app.screen.as_ptr()).rcontext,
c"tests/image_128x120.png".as_ptr(),
0,
);
let pixmap = NonNull::new(WMCreatePixmapFromRImage(app.screen.as_ptr(), rimage, 255))
.ok_or_else(|| Box::<dyn Error>::from("could not allocate pixmap resource"))?;
WMDrawPixmap(pixmap.as_ptr(), win, 70, 74);
while app.pump_event_queue(Instant::now()) {}
verify_png_snapshot!("from_r_image_no_mask", app.xvfb.png_screenshot())?;
WMReleasePixmap(pixmap.as_ptr());
}
}
assert_png_snapshot!("from_file_pixmap", snapshot);
Ok(())
}
#[test]
fn draw_pixmap_from_r_image_no_mask() -> Result<(), ()> {
let snapshot;
{
let mut app = HeadlessApplication::new();
unsafe {
let display = (*app.screen.as_ptr()).display;
let win = x11::xlib::XCreateSimpleWindow(
display,
(*app.screen.as_ptr()).rootWin,
0,
0,
512,
512,
1,
1,
x11::xlib::XWhitePixel(display, 0),
);
x11::xlib::XMapWindow(display, win);
fn draw_pixmap_from_r_image_with_mask() -> Result<(), Box<dyn Error>> {
let mut app = HeadlessApplication::new();
unsafe {
let display = (*app.screen.as_ptr()).display;
let win = x11::xlib::XCreateSimpleWindow(
display,
(*app.screen.as_ptr()).rootWin,
0,
0,
512,
512,
1,
1,
x11::xlib::XBlackPixel(display, 0),
);
x11::xlib::XMapWindow(display, win);
let rimage = RLoadImage(
(*app.screen.as_ptr()).rcontext,
c"tests/image_128x120.png".as_ptr(),
0,
);
let pixmap =
NonNull::new(WMCreatePixmapFromRImage(app.screen.as_ptr(), rimage, 255)).ok_or(())?;
WMDrawPixmap(pixmap.as_ptr(), win, 70, 74);
let rimage = NonNull::new(RLoadImage(
(*app.screen.as_ptr()).rcontext,
c"tests/image_128x120_varying_alpha.png".as_ptr(),
255,
))
.ok_or_else(|| Box::<dyn Error>::from("could not allocate pixmap resource"))?;
while app.pump_event_queue(Instant::now()) {}
snapshot = app.xvfb.png_screenshot();
WMReleasePixmap(pixmap.as_ptr());
}
// The threshold given to WMCreatePixmapFromRImage is compared against
// the image's alpha channel. Pixels whose transparency are below the
// threshold are masked out. This should draw a quartet of images with
// varying masks.
// Totally masked.
let pixmap_255 = NonNull::new(WMCreatePixmapFromRImage(
app.screen.as_ptr(),
rimage.as_ptr(),
255,
))
.ok_or_else(|| Box::<dyn Error>::from("could not allocate pixmap resource"))?;
WMDrawPixmap(pixmap_255.as_ptr(), win, 70, 74);
// Three bubbles masked.
let pixmap_200 = NonNull::new(WMCreatePixmapFromRImage(
app.screen.as_ptr(),
rimage.as_ptr(),
200,
))
.ok_or_else(|| Box::<dyn Error>::from("could not allocate pixmap resource"))?;
WMDrawPixmap(pixmap_200.as_ptr(), win, 200, 74);
// Two bubbles masked.
let pixmap_128 = NonNull::new(WMCreatePixmapFromRImage(
app.screen.as_ptr(),
rimage.as_ptr(),
128,
))
.ok_or_else(|| Box::<dyn Error>::from("could not allocate pixmap resource"))?;
WMDrawPixmap(pixmap_128.as_ptr(), win, 70, 200);
// Nothing masked.
let pixmap_0 = NonNull::new(WMCreatePixmapFromRImage(
app.screen.as_ptr(),
rimage.as_ptr(),
0,
))
.ok_or_else(|| Box::<dyn Error>::from("could not allocate pixmap resource"))?;
WMDrawPixmap(pixmap_0.as_ptr(), win, 200, 200);
while app.pump_event_queue(Instant::now()) {}
verify_png_snapshot!("from_r_image_with_mask", app.xvfb.png_screenshot())?;
WMReleasePixmap(pixmap_255.as_ptr());
WMReleasePixmap(pixmap_200.as_ptr());
WMReleasePixmap(pixmap_128.as_ptr());
WMReleasePixmap(pixmap_0.as_ptr());
RReleaseImage(rimage.as_ptr());
}
assert_png_snapshot!("from_r_image_no_mask", snapshot);
Ok(())
}
#[test]
fn draw_pixmap_from_r_image_with_mask() -> Result<(), ()> {
let snapshot;
{
let mut app = HeadlessApplication::new();
unsafe {
let display = (*app.screen.as_ptr()).display;
let win = x11::xlib::XCreateSimpleWindow(
display,
(*app.screen.as_ptr()).rootWin,
0,
0,
512,
512,
1,
1,
x11::xlib::XBlackPixel(display, 0),
);
x11::xlib::XMapWindow(display, win);
fn draw_blended_pixmap_from_r_image() -> Result<(), Box<dyn Error>> {
let mut app = HeadlessApplication::new();
unsafe {
let display = (*app.screen.as_ptr()).display;
let win = x11::xlib::XCreateSimpleWindow(
display,
(*app.screen.as_ptr()).rootWin,
0,
0,
512,
512,
1,
1,
x11::xlib::XWhitePixel(display, 0),
);
x11::xlib::XMapWindow(display, win);
let rimage = NonNull::new(RLoadImage(
(*app.screen.as_ptr()).rcontext,
c"tests/image_128x120_varying_alpha.png".as_ptr(),
255,
))
.ok_or(())?;
let rimage = RLoadImage(
(*app.screen.as_ptr()).rcontext,
c"tests/image_128x120.png".as_ptr(),
0,
);
let pixmap = NonNull::new(WMCreateBlendedPixmapFromRImage(
app.screen.as_ptr(),
rimage,
&RColor {
red: 255,
green: 0,
blue: 0,
alpha: 255,
} as *const _,
))
.ok_or_else(|| Box::<dyn Error>::from("could not allocate pixmap resource"))?;
WMDrawPixmap(pixmap.as_ptr(), win, 70, 74);
// The threshold given to WMCreatePixmapFromRImage is compared against
// the image's alpha channel. Pixels whose transparency are below the
// threshold are masked out. This should draw a quartet of images with
// varying masks.
// Totally masked.
let pixmap_255 = NonNull::new(WMCreatePixmapFromRImage(
app.screen.as_ptr(),
rimage.as_ptr(),
255,
))
.ok_or(())?;
WMDrawPixmap(pixmap_255.as_ptr(), win, 70, 74);
// Three bubbles masked.
let pixmap_200 = NonNull::new(WMCreatePixmapFromRImage(
app.screen.as_ptr(),
rimage.as_ptr(),
200,
))
.ok_or(())?;
WMDrawPixmap(pixmap_200.as_ptr(), win, 200, 74);
// Two bubbles masked.
let pixmap_128 = NonNull::new(WMCreatePixmapFromRImage(
app.screen.as_ptr(),
rimage.as_ptr(),
128,
))
.ok_or(())?;
WMDrawPixmap(pixmap_128.as_ptr(), win, 70, 200);
// Nothing masked.
let pixmap_0 = NonNull::new(WMCreatePixmapFromRImage(
app.screen.as_ptr(),
rimage.as_ptr(),
0,
))
.ok_or(())?;
WMDrawPixmap(pixmap_0.as_ptr(), win, 200, 200);
while app.pump_event_queue(Instant::now()) {}
snapshot = app.xvfb.png_screenshot();
WMReleasePixmap(pixmap_255.as_ptr());
WMReleasePixmap(pixmap_200.as_ptr());
WMReleasePixmap(pixmap_128.as_ptr());
WMReleasePixmap(pixmap_0.as_ptr());
RReleaseImage(rimage.as_ptr());
}
while app.pump_event_queue(Instant::now()) {}
verify_png_snapshot!("from_r_image_no_mask", app.xvfb.png_screenshot())?;
WMReleasePixmap(pixmap.as_ptr());
}
assert_png_snapshot!("from_r_image_with_mask", snapshot);
Ok(())
}
#[test]
fn draw_blended_pixmap_from_r_image() -> Result<(), ()> {
let snapshot;
{
let mut app = HeadlessApplication::new();
unsafe {
let display = (*app.screen.as_ptr()).display;
let win = x11::xlib::XCreateSimpleWindow(
display,
(*app.screen.as_ptr()).rootWin,
0,
0,
512,
512,
1,
1,
x11::xlib::XWhitePixel(display, 0),
);
x11::xlib::XMapWindow(display, win);
fn draw_blended_pixmap_from_file() -> Result<(), Box<dyn Error>> {
let mut app = HeadlessApplication::new();
unsafe {
let display = (*app.screen.as_ptr()).display;
let win = x11::xlib::XCreateSimpleWindow(
display,
(*app.screen.as_ptr()).rootWin,
0,
0,
512,
512,
1,
1,
x11::xlib::XWhitePixel(display, 0),
);
x11::xlib::XMapWindow(display, win);
let rimage = RLoadImage(
(*app.screen.as_ptr()).rcontext,
c"tests/image_128x120.png".as_ptr(),
0,
);
let pixmap = NonNull::new(WMCreateBlendedPixmapFromRImage(
app.screen.as_ptr(),
rimage,
&RColor {
red: 255,
green: 0,
blue: 0,
alpha: 255,
} as *const _,
))
.ok_or(())?;
WMDrawPixmap(pixmap.as_ptr(), win, 70, 74);
while app.pump_event_queue(Instant::now()) {}
snapshot = app.xvfb.png_screenshot();
WMReleasePixmap(pixmap.as_ptr());
}
}
assert_png_snapshot!("from_r_image_no_mask", snapshot);
Ok(())
}
#[test]
fn draw_blended_pixmap_from_file() -> Result<(), ()> {
let from_file_blended_base_pixmap_snapshot;
let from_file_blended_cleared_window_snapshot;
let from_file_blended_with_red_snapshot;
{
let mut app = HeadlessApplication::new();
unsafe {
let display = (*app.screen.as_ptr()).display;
let win = x11::xlib::XCreateSimpleWindow(
display,
(*app.screen.as_ptr()).rootWin,
0,
0,
512,
512,
1,
1,
x11::xlib::XWhitePixel(display, 0),
);
x11::xlib::XMapWindow(display, win);
let pixmap = NonNull::new(WMCreatePixmapFromFile(
app.screen.as_ptr(),
c"tests/image_with_transparent_dot_128x120.png".as_ptr(),
))
.ok_or(())?;
WMDrawPixmap(pixmap.as_ptr(), win, 64, 96);
while app.pump_event_queue(Instant::now()) {}
from_file_blended_base_pixmap_snapshot = app.xvfb.png_screenshot();
let pixmap = NonNull::new(WMCreatePixmapFromFile(
app.screen.as_ptr(),
c"tests/image_with_transparent_dot_128x120.png".as_ptr(),
))
.ok_or_else(|| Box::<dyn Error>::from("could not allocate pixmap resource"))?;
WMDrawPixmap(pixmap.as_ptr(), win, 64, 96);
while app.pump_event_queue(Instant::now()) {}
verify_png_snapshot!("from_file_blended_base_pixmap", app.xvfb.png_screenshot())?;
x11::xlib::XUnmapWindow(display, win);
WMReleasePixmap(pixmap.as_ptr());
@@ -300,7 +280,7 @@ fn draw_blended_pixmap_from_file() -> Result<(), ()> {
);
x11::xlib::XMapWindow(display, win);
while app.pump_event_queue(Instant::now()) {}
from_file_blended_cleared_window_snapshot = app.xvfb.png_screenshot();
verify_png_snapshot!("from_file_blended_cleared_window", app.xvfb.png_screenshot())?;
let pixmap = NonNull::new(WMCreateBlendedPixmapFromFile(
app.screen.as_ptr(),
@@ -312,180 +292,151 @@ fn draw_blended_pixmap_from_file() -> Result<(), ()> {
alpha: 255,
} as *const _,
))
.ok_or(())?;
.ok_or_else(|| Box::<dyn Error>::from("could not allocate pixmap resource"))?;
WMDrawPixmap(pixmap.as_ptr(), win, 64, 96);
while app.pump_event_queue(Instant::now()) {}
from_file_blended_with_red_snapshot = app.xvfb.png_screenshot();
verify_png_snapshot!("from_file_blended_with_red", app.xvfb.png_screenshot())?;
WMReleasePixmap(pixmap.as_ptr());
}
}
assert_png_snapshot!("from_file_blended_base_pixmap", from_file_blended_base_pixmap_snapshot);
assert_png_snapshot!("from_file_blended_cleared_window", from_file_blended_cleared_window_snapshot);
assert_png_snapshot!("from_file_blended_with_red", from_file_blended_with_red_snapshot);
Ok(())
}
#[test]
fn draw_scaled_blended_pixmap_from_file() -> Result<(), ()> {
let from_file_scaled_blended_base_pixmap_snapshot;
let from_file_scaled_blended_cleared_window_snapshot;
let from_file_scaled_blended_with_red_snapshot;
{
let mut app = HeadlessApplication::new();
unsafe {
let display = (*app.screen.as_ptr()).display;
let win = x11::xlib::XCreateSimpleWindow(
display,
(*app.screen.as_ptr()).rootWin,
0,
0,
512,
512,
1,
1,
x11::xlib::XWhitePixel(display, 0),
);
x11::xlib::XMapWindow(display, win);
fn draw_scaled_blended_pixmap_from_file() -> Result<(), Box<dyn Error>> {
let mut app = HeadlessApplication::new();
unsafe {
let display = (*app.screen.as_ptr()).display;
let win = x11::xlib::XCreateSimpleWindow(
display,
(*app.screen.as_ptr()).rootWin,
0,
0,
512,
512,
1,
1,
x11::xlib::XWhitePixel(display, 0),
);
x11::xlib::XMapWindow(display, win);
let pixmap = NonNull::new(WMCreatePixmapFromFile(
app.screen.as_ptr(),
c"tests/image_with_transparent_dot_128x120.png".as_ptr(),
))
.ok_or(())?;
WMDrawPixmap(pixmap.as_ptr(), win, 64, 96);
while app.pump_event_queue(Instant::now()) {}
from_file_scaled_blended_base_pixmap_snapshot = app.xvfb.png_screenshot();
let pixmap = NonNull::new(WMCreatePixmapFromFile(
app.screen.as_ptr(),
c"tests/image_with_transparent_dot_128x120.png".as_ptr(),
))
.ok_or_else(|| Box::<dyn Error>::from("could not allocate pixmap resource"))?;
WMDrawPixmap(pixmap.as_ptr(), win, 64, 96);
while app.pump_event_queue(Instant::now()) {}
verify_png_snapshot!("from_file_scaled_blended_base_pixmap", app.xvfb.png_screenshot())?;
x11::xlib::XUnmapWindow(display, win);
WMReleasePixmap(pixmap.as_ptr());
x11::xlib::XUnmapWindow(display, win);
WMReleasePixmap(pixmap.as_ptr());
let win = x11::xlib::XCreateSimpleWindow(
display,
(*app.screen.as_ptr()).rootWin,
0,
0,
512,
512,
1,
1,
x11::xlib::XWhitePixel(display, 0),
);
x11::xlib::XMapWindow(display, win);
while app.pump_event_queue(Instant::now()) {}
from_file_scaled_blended_cleared_window_snapshot = app.xvfb.png_screenshot();
let win = x11::xlib::XCreateSimpleWindow(
display,
(*app.screen.as_ptr()).rootWin,
0,
0,
512,
512,
1,
1,
x11::xlib::XWhitePixel(display, 0),
);
x11::xlib::XMapWindow(display, win);
while app.pump_event_queue(Instant::now()) {}
verify_png_snapshot!("from_file_scaled_blended_cleared_window", app.xvfb.png_screenshot())?;
let pixmap = NonNull::new(WMCreateScaledBlendedPixmapFromFile(
app.screen.as_ptr(),
c"tests/image_with_transparent_dot_128x120.png".as_ptr(),
&RColor {
red: 255,
green: 0,
blue: 0,
alpha: 255,
} as *const _,
60,
64,
))
.ok_or(())?;
WMDrawPixmap(pixmap.as_ptr(), win, 64, 96);
let pixmap = NonNull::new(WMCreateScaledBlendedPixmapFromFile(
app.screen.as_ptr(),
c"tests/image_with_transparent_dot_128x120.png".as_ptr(),
&RColor {
red: 255,
green: 0,
blue: 0,
alpha: 255,
} as *const _,
60,
64,
))
.ok_or_else(|| Box::<dyn Error>::from("could not allocate pixmap resource"))?;
WMDrawPixmap(pixmap.as_ptr(), win, 64, 96);
while app.pump_event_queue(Instant::now()) {}
from_file_scaled_blended_with_red_snapshot = app.xvfb.png_screenshot();
WMReleasePixmap(pixmap.as_ptr());
}
while app.pump_event_queue(Instant::now()) {}
verify_png_snapshot!("from_file_scaled_blended_with_red", app.xvfb.png_screenshot())?;
WMReleasePixmap(pixmap.as_ptr());
}
assert_png_snapshot!("from_file_scaled_blended_base_pixmap", from_file_scaled_blended_base_pixmap_snapshot);
assert_png_snapshot!("from_file_scaled_blended_cleared_window", from_file_scaled_blended_cleared_window_snapshot);
assert_png_snapshot!("from_file_scaled_blended_with_red", from_file_scaled_blended_with_red_snapshot);
Ok(())
}
#[test]
fn draw_scaled_blended_pixmap_from_file_non_integral_scaling() -> Result<(), ()> {
let from_file_scaled_blended_non_integral_base_pixmap_snapshot;
let from_file_scaled_blended_non_integral_cleared_window_snapshot;
let from_file_scaled_blended_non_integral_scaled_snapshot;
{
let mut app = HeadlessApplication::new();
unsafe {
let display = (*app.screen.as_ptr()).display;
let win = x11::xlib::XCreateSimpleWindow(
display,
(*app.screen.as_ptr()).rootWin,
0,
0,
512,
512,
1,
1,
x11::xlib::XWhitePixel(display, 0),
);
x11::xlib::XMapWindow(display, win);
fn draw_scaled_blended_pixmap_from_file_non_integral_scaling() -> Result<(), Box<dyn Error>> {
let mut app = HeadlessApplication::new();
unsafe {
let display = (*app.screen.as_ptr()).display;
let win = x11::xlib::XCreateSimpleWindow(
display,
(*app.screen.as_ptr()).rootWin,
0,
0,
512,
512,
1,
1,
x11::xlib::XWhitePixel(display, 0),
);
x11::xlib::XMapWindow(display, win);
let pixmap = NonNull::new(WMCreatePixmapFromFile(
app.screen.as_ptr(),
c"tests/image_128x120.png".as_ptr(),
))
.ok_or(())?;
WMDrawPixmap(pixmap.as_ptr(), win, 64, 96);
while app.pump_event_queue(Instant::now()) {}
from_file_scaled_blended_non_integral_base_pixmap_snapshot = app.xvfb.png_screenshot();
let pixmap = NonNull::new(WMCreatePixmapFromFile(
app.screen.as_ptr(),
c"tests/image_128x120.png".as_ptr(),
))
.ok_or_else(|| Box::<dyn Error>::from("could not allocate pixmap resource"))?;
WMDrawPixmap(pixmap.as_ptr(), win, 64, 96);
while app.pump_event_queue(Instant::now()) {}
verify_png_snapshot!("from_file_scaled_blended_non_integral_base_pixmap", app.xvfb.png_screenshot())?;
x11::xlib::XUnmapWindow(display, win);
WMReleasePixmap(pixmap.as_ptr());
x11::xlib::XUnmapWindow(display, win);
WMReleasePixmap(pixmap.as_ptr());
let win = x11::xlib::XCreateSimpleWindow(
display,
(*app.screen.as_ptr()).rootWin,
0,
0,
512,
512,
1,
1,
x11::xlib::XWhitePixel(display, 0),
);
x11::xlib::XMapWindow(display, win);
while app.pump_event_queue(Instant::now()) {}
from_file_scaled_blended_non_integral_cleared_window_snapshot = app.xvfb.png_screenshot();
let win = x11::xlib::XCreateSimpleWindow(
display,
(*app.screen.as_ptr()).rootWin,
0,
0,
512,
512,
1,
1,
x11::xlib::XWhitePixel(display, 0),
);
x11::xlib::XMapWindow(display, win);
while app.pump_event_queue(Instant::now()) {}
verify_png_snapshot!("from_file_scaled_blended_non_integral_cleared_window", app.xvfb.png_screenshot())?;
let pixmap = NonNull::new(WMCreateScaledBlendedPixmapFromFile(
app.screen.as_ptr(),
// No alpha channel on this image, so no color blending happens.
c"tests/image_128x120.png".as_ptr(),
&RColor {
red: 255,
green: 0,
blue: 0,
alpha: 255,
} as *const _,
// Shrink by only a little bit, such that simple integer division
// might be thrown off. This test ensures that rescaling will
// actually happen.
110,
114,
))
.ok_or(())?;
WMDrawPixmap(pixmap.as_ptr(), win, 64, 96);
let pixmap = NonNull::new(WMCreateScaledBlendedPixmapFromFile(
app.screen.as_ptr(),
// No alpha channel on this image, so no color blending happens.
c"tests/image_128x120.png".as_ptr(),
&RColor {
red: 255,
green: 0,
blue: 0,
alpha: 255,
} as *const _,
// Shrink by only a little bit, such that simple integer division
// might be thrown off. This test ensures that rescaling will
// actually happen.
110,
114,
))
.ok_or_else(|| Box::<dyn Error>::from("could not allocate pixmap resource"))?;
WMDrawPixmap(pixmap.as_ptr(), win, 64, 96);
while app.pump_event_queue(Instant::now()) {}
from_file_scaled_blended_non_integral_scaled_snapshot = app.xvfb.png_screenshot();
WMReleasePixmap(pixmap.as_ptr());
}
while app.pump_event_queue(Instant::now()) {}
verify_png_snapshot!("from_file_scaled_blended_non_integral_scaled", app.xvfb.png_screenshot())?;
WMReleasePixmap(pixmap.as_ptr());
}
assert_png_snapshot!(
"from_file_scaled_blended_non_integral_base_pixmap",
from_file_scaled_blended_non_integral_base_pixmap_snapshot
);
assert_png_snapshot!(
"from_file_scaled_blended_non_integral_cleared_window",
from_file_scaled_blended_non_integral_cleared_window_snapshot
);
assert_png_snapshot!(
"from_file_scaled_blended_non_integral_scaled",
from_file_scaled_blended_non_integral_scaled_snapshot
);
Ok(())
}