-
-
Notifications
You must be signed in to change notification settings - Fork 9
one gtk_test::click leads to two clicked events #21
Description
I took the basic example https://github.com/gtk-rs/gtk-test/blob/master/tests/basic.rs and expanded it with an atomic counter and a loop with 10 executions. As we see later in the output, we get two closure evaluations, invoked by connect_clicked().
src/main.rs:
extern crate gtk;
extern crate gtk_test;
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering;
use std::sync::Arc;
use gtk::Button;
use gtk::ButtonExt;
use gtk::ContainerExt;
use gtk::GtkWindowExt;
use gtk::Label;
use gtk::Orientation;
use gtk::Window;
use gtk::WindowType;
use gtk::WidgetExt;
fn main() {
for _a in 0..12 {
println!("===== TEST RUN {} ", _a);
button_with_counter();
}
}
// without gedit on screen: works.
// with gedit on screen: doesnt work.
fn button_with_counter() {
let click_counter = Arc::new(AtomicUsize::new(0));
let ccc = click_counter.clone();
gtk::init().unwrap();
let window = Window::new(WindowType::Toplevel);
let gbox = gtk::Box::new(Orientation::Vertical, 0);
let label: gtk::Label = Label::new("button+counter");
gbox.add(&label);
let button1 = Button::new();
button1.set_label(&"button-1");
button1.connect_clicked(move |_| {
println!(" button1 click received ");
(*ccc).fetch_add(1, Ordering::SeqCst);
});
gbox.add(&button1);
window.add(&gbox);
window.show_all();
window.activate_focus();
gtk_test::click(&button1);
gtk_test::wait(300);
let caw = (*click_counter).load(Ordering::SeqCst);
println!(" counter after wait: {} ", caw);
assert_eq!(1, caw);
window.close();
window.destroy();
gtk::Inhibit(false);
}
Cargo.toml :
[package]
name = "gtktest-doppelclick"
version = "0.0.1"
[[bin]]
name = "doppelclick"
path = "src/main.rs"
[dependencies]
gtk-test = "0.2.0"
[dependencies.gtk]
version = "0.5.0"
features = ["v3_22"]
As result I get on my LinuxMint-19 VM:
===== TEST RUN 0
button1 click received
button1 click received
counter after wait: 2
thread 'main' panicked at 'assertion failed: (left == right)
left: 1,
right: 2', src/main.rs:54:5
On my gentoo host I get this result:
===== TEST RUN 0
button1 click received
counter after wait: 1
===== TEST RUN 1
button1 click received
counter after wait: 1
===== TEST RUN 2
button1 click received
button1 click received
counter after wait: 2
thread 'main' panicked at 'assertion failed: (left == right)
left: 1,
right: 2', src/main.rs:54:5
note: Run with RUST_BACKTRACE=1 for a backtrace.
Additional Hint:
On my gentoo host, i see a behaviour in 90% of the trials: {
- when another gtk program is on the screen, the test fails
- when no other gtk program is on the screen, the test works }
For the remaining 10% of the trials I saw it either working continually, or not working.
Host System information:
Portage 2.3.51 (python 2.7.15-final-0, default/linux/amd64/17.0/desktop, gcc-6.4.0, glibc-2.27-r6, 4.17.8-gentoo x86_64)
System uname: Linux-4.17.8-gentoo-x86_64-AMD_A10-7870K
# rustup show
Default host: x86_64-unknown-linux-gnu
installed toolchains
stable-x86_64-unknown-linux-gnu
nightly-x86_64-unknown-linux-gnu
installed targets for active toolchain
i686-pc-windows-gnu
x86_64-pc-windows-gnu
x86_64-unknown-linux-gnu
active toolchain
stable-x86_64-unknown-linux-gnu (default)
rustc 1.32.0 (9fda7c223 2019-01-16)
VM System information:
Linux Mint 19 Cinnamon, Kernel 4.15
Installed package via console: libgtk-3-dev
# rustup show
Default host: x86_64-unknown-linux-gnu
rustc 1.32.0 (9fda7c223 2019-01-16)