Crate gtk_test

source ·
Expand description

Crate to test UI interactions with gtk-rs crates.

Small example:

extern crate gtk;
#[macro_use]
extern crate gtk_test;

use gtk::{prelude::ButtonExt, prelude::ContainerExt, prelude::GtkWindowExt, prelude::LabelExt, prelude::WidgetExt};

gtk::init().expect("GTK init failed");

let win = gtk::Window::new(gtk::WindowType::Toplevel);
let but = gtk::Button::new();

but.set_label(""); // Otherwise, assert_label! call will fail.
but.connect_clicked(|b| {
    b.set_label("clicked!");
});

win.add(&but);
win.show_all();
win.activate_focus(); // Very important, otherwise tests will fail on OSX!

assert_label!(but, "");
gtk_test::click(&but);
gtk_test::wait(1000); // To be sure that GTK has updated the label's text.
assert_label!(but, "clicked!");

Re-exports

  • pub use gtk;
  • pub use gtk::gdk;

Macros

  • To check if the widget’s label matches the given string.
  • To check if the widget’s name matches the given string.
  • To check if the widget’s text matches the given string.
  • To check if the widget’s title matches the given string.
  • Create a new observer for signals.

Structs

  • Used to wait for a widget’s signal.

Functions