GithubHelp home page GithubHelp logo

gtk-test's Introduction

gtk3-rs CI

This project is UNMAINTAINED. Please take a look at gtk4-rs instead!

The gtk-rs organization aims to provide safe Rust binding over GObject-based libraries. You can find more about it on https://gtk-rs.org.

This repository contains all the "core" crates of the gtk-rs organization. For more information about each crate, please refer to their README.md file in their directory.

Minimum supported Rust version

Currently, the minimum supported Rust version is 1.70.0.

Documentation

Ecosystem

The gtk3-rs repository contains Rust crates for GTK 3. However there is a large ecosystem of GObject libraries and many of these libraries have Rust bindings based on the tooling included in gtk-rs. Of particular note:

  • gtk-rs-core - bindings for some of the core libraries such as glib, gio, pango, graphene
  • gstreamer-rs - bindings for the GStreamer media framework

Additionally, Rust bindings for various libraries are hosted on GNOME's GitLab instance and can be found at https://gitlab.gnome.org/World/Rust.

When using crates that are not part of the gtk-rs repository, you will need to be careful and ensure that they do not pull in incompatible versions of core crates like glib-rs.

Regenerating

To regenerate crates using gir, please use the generator.py file as follows:

$ python3 generator.py

If you didn't do so yet, please check out all the submodules before via

$ git submodule update --checkout

Development

This repository is mostly split into two branches: master and crate. master contains the not yet released code and is where new developments are happening. crate contains the last release source code and isn't supposed to be updated.

This repository is structured as follows:

- crate/
   |
   |-- README.md
   |-- Gir.toml
   |-- Cargo.toml
   |-- src/
   |-- sys/

The crate is a "top" directory (so "atk" or "gdk" in here for example). Each crate contains:

  • README.md: explanations about the crate itself and eventually some details.
  • Cargo.toml: descriptor of the crate, used by cargo and Rust.
  • Gir.toml: configuration used by gir to generate most of the crates' code.
  • src: the source code of the crate.
  • sys: the 1:1 bindings of the C API.

The gir and gir-files top folders are not crates, but are git submodules which respectively contain the gir tool and the gir files used by the generator.

When running generator.py the tool will automatically update these git submodules and run the gir tool on the gir files to regenerate the code.

During development, it is useful to execute the generator with a different version of the gir tool or of the gir files, for instance to test if the code generation is successful before submitting a pull request to update one of the submodules. This can be done by specifying arguments to the generator script, for instance, to run the generator on a local copy of the gir files:

$ python3 generator.py --gir-files-directory ../gir-files/

See python3 generator.py --help for more details.

gtk-test's People

Contributors

antoyo avatar arekpiekarz avatar divark avatar dns2utf8 avatar guillaumegomez avatar sanpii avatar sdroege avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

gtk-test's Issues

Fails to compile with gtk 0.14.0

When the newest gtk-test 0.6.1 and gtk 0.14.0 are used in the same project, they fail to compile with a following message:

$ cargo run
    Updating crates.io index
error: failed to select a version for `cairo-sys-rs`.
    ... required by package `gdk v0.13.0`
    ... which is depended on by `gtk-test v0.6.1`
    ... which is depended on by `gtk-with-gtk-test v0.1.0 (/home/user/dev/project/test/rust/gtk-with-gtk-test)`
versions that meet the requirements `^0.10.0` are: 0.10.0

the package `cairo-sys-rs` links to the native library `cairo`, but it conflicts with a previous package which links to `cairo` as well:
package `cairo-sys-rs v0.14.0`
    ... which is depended on by `cairo-rs v0.14.0`
    ... which is depended on by `gdk v0.14.0`
    ... which is depended on by `gtk v0.14.0`
    ... which is depended on by `gtk-with-gtk-test v0.1.0 (/home/user/dev/project/test/rust/gtk-with-gtk-test)`

failed to select a version for `cairo-sys-rs` which could resolve this conflict

The probable cause is gtk-test depends on git = "https://github.com/gtk-rs/gtk", but the up-to-date link should be https://github.com/gtk-rs/gtk3-rs or https://github.com/gtk-rs/gtk3-rs/tree/master/gtk

Cargo.toml to reproduce the issue:

[package]
name = "gtk-with-gtk-test"
version = "0.1.0"
edition = "2018"

[dependencies]
gtk = "0.14.0"

[dev-dependencies]
gtk-test = "0.6.1

Use a server-client system instead

We could send actions to be executed to a client when one connects and then execute them through gtk_main_do_event (that @sdroege suggested) or even gtk_propagate_event (but normally, the first one should be enough).

Lack of support for gtk 0.18

This crate does not support gtk 0.18. This is the error I get when trying to run cargo outdated on my project:

$ cargo outdated
error: failed to select a version for `gtk-sys`.
    ... required by package `gtk v0.17.0`
    ... which satisfies dependency `gtk = "^0.17"` of package `gtk-test v0.17.0`
    ... which satisfies dependency `gtk-test = "^0.17.0"` of package `rusty-git-gui v0.1.0 (/tmp/cargo-outdatedPLtmyc)`
versions that meet the requirements `^0.17` are: 0.17.0

the package `gtk-sys` links to the native library `gtk-3`, but it conflicts with a previous package which links to `gtk-3` as well:
package `gtk-sys v0.18.0`
    ... which satisfies dependency `ffi = "^0.18"` of package `gtk v0.18.0`
    ... which satisfies dependency `gtk = "^0.18.0"` of package `rusty-git-gui v0.1.0 (/tmp/cargo-outdatedPLtmyc)`
Only one package in the dependency graph may specify the same links value. This helps ensure that only one copy of a native library is linked in the final binary. Try to adjust your dependencies so that only one package uses the links ='gtk-sys' value. For more information, see https://doc.rust-lang.org/cargo/reference/resolver.html#links.

failed to select a version for `gtk-sys` which could resolve this conflict

[Support] Unable to init GTK with unit tests

Description

I am trying to add unit tests to my project and my tests keep failing.

Code

#[cfg(test)]
mod tests {
    use gtk::Builder;
    use libmystudio::notebook::cache::NotebookTabCache;
    use tempfile::tempdir;

    use crate::ui::notebook::{
        editor::{get_editor_by_path, get_editor_instance},
        nbmain::{create_notebook_tab, get_notebook},
    };

    use super::set_text_on_editor;

    fn before_each() -> (Builder, tempfile::TempDir, std::path::PathBuf) {
        gtk_test::gtk::init().unwrap();

        // Load UI from glade file
        let glade_src = include_str!("../../../res/ui/main_window.glade");
        let builder: Builder = Builder::from_string(glade_src);

        // Init Notebook UI for testing
        crate::ui::notebook::init(&builder);

        // Create mock file 
        let root_dir = tempdir();
        assert!(root_dir.is_ok());
        let root_dir = root_dir.unwrap();

        let temp_file = root_dir.path().join("index.js");

        (builder, root_dir, temp_file)

    }

    #[test]
    fn get_editor_by_path_test() {
        // init Gtk
        let (builder, root_dir, temp_file) = before_each();
        
        // mock Notebook page
        let notebook = get_notebook().unwrap();
        let mock_editor = get_editor_instance();
        let tab_position = create_notebook_tab(notebook, mock_editor, "title", "icon_name");

        // mock Notebook cache entry
        let mock_cache = NotebookTabCache {
            file_path: temp_file.to_str().unwrap().into(),
            icon_name: "file".into(),
            position: tab_position,
        };
        NotebookTabCache::insert(mock_cache.clone());

        // Verify if editor is available
        let editor = get_editor_by_path(mock_cache.file_path);
        assert!(editor.is_some());
    }

    #[test]
    fn set_text_on_editor_test() {

        // Init
        let (_builder, _root_dir, temp_file_pathbuf) = before_each();
        let temp_file_str = temp_file_pathbuf.to_str().map(|f| f.to_string());

        let mock_editor = get_editor_instance();

        // all params are provided
        set_text_on_editor(Some(mock_editor), temp_file_str.clone(), Some("console.log(1);".into()));
        
        // editor is None
        // set_text_on_editor(None, temp_file_str, Some("console.log(1);".into()));

    }
}

Actual Output

➜  mystudio-ide git:(unit-tests) ✗ cargo test -p mystudio-ide --bin mystudio-ide
   Compiling mystudio-ide v0.1.3 (/home/suryateja/Projects/mystudio-ide/mystudio-ide)
warning: unused variable: `builder`
   --> mystudio-ide/src/ui/notebook/editor.rs:151:14
    |
151 |         let (builder, root_dir, temp_file) = before_each();
    |              ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_builder`
    |
    = note: `#[warn(unused_variables)]` on by default

warning: unused variable: `root_dir`
   --> mystudio-ide/src/ui/notebook/editor.rs:151:23
    |
151 |         let (builder, root_dir, temp_file) = before_each();
    |                       ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_root_dir`

warning: `mystudio-ide` (bin "mystudio-ide" test) generated 2 warnings
    Finished test [unoptimized + debuginfo] target(s) in 8.29s
     Running unittests src/main.rs (target/debug/deps/mystudio_ide-b03e5f831783b6a6)

running 3 tests
test ui::action_row::handler::tests::save_file_changes_test ... ok
test ui::notebook::editor::tests::get_editor_by_path_test ... FAILED
test ui::notebook::editor::tests::set_text_on_editor_test ... FAILED

failures:

---- ui::notebook::editor::tests::get_editor_by_path_test stdout ----
thread 'ui::notebook::editor::tests::get_editor_by_path_test' panicked at 'called `Result::unwrap()` on an `Err` value: BoolError { message: "Failed to acquire default main context", filename: "/home/suryateja/.cargo/registry/src/github.com-1ecc6299db9ec823/gtk-0.15.4/src/rt.rs", function: "gtk::rt", line: 129 }', mystudio-ide/src/ui/notebook/editor.rs:128:31
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- ui::notebook::editor::tests::set_text_on_editor_test stdout ----
thread 'ui::notebook::editor::tests::set_text_on_editor_test' panicked at 'called `Option::unwrap()` on a `None` value', mystudio-ide/src/ui/statusbar/line_indicator.rs:162:36


failures:
    ui::notebook::editor::tests::get_editor_by_path_test
    ui::notebook::editor::tests::set_text_on_editor_test

test result: FAILED. 1 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.15s

error: test failed, to rerun pass '-p mystudio-ide --bin mystudio-ide'

Please advise.

Cannot be used with gtk 0.15

gtk-test 0.14 does not work with gtk 0.15. When trying to use them in one project, I get the following errors:

$ cargo build
    Updating crates.io index
error: failed to select a version for `gtk-sys`.
    ... required by package `gtk v0.14.0`
    ... which satisfies dependency `gtk = "^0.14"` of package `gtk-test v0.14.0`
    ... which satisfies dependency `gtk-test = "^0.14.0"` of package `example-app v0.1.0 (/home/user/dev/project/example-app)`
versions that meet the requirements `^0.14.0` are: 0.14.0

the package `gtk-sys` links to the native library `gtk-3`, but it conflicts with a previous package which links to `gtk-3` as well:
package `gtk-sys v0.15.1`
    ... which satisfies dependency `ffi = "^0.15.1"` of package `gtk v0.15.2`
    ... which satisfies dependency `gtk = "^0.15.2"` of package `example-app v0.1.0 (/home/user/dev/project/example-app)`
Only one package in the dependency graph may specify the same links value. This helps ensure that only one copy of a native library is linked in the final binary. Try to adjust your dependencies so that only one package uses the links ='gtk-sys' value. For more information, see https://doc.rust-lang.org/cargo/reference/resolver.html#links.

failed to select a version for `gtk-sys` which could resolve this conflict

Support for gtk4

This crate currently can be used only with gtk3. Are there any plans to add support for gtk4 as well?

failed to select a version for `gtk`

Trying to build master (ca73663) results in the following error:

error: failed to select a version for `gtk`.
    ... required by package `gtk-test v0.2.0 (/home/jonas/dev/gtk-test)`
versions that meet the requirements `*` are: 0.5.0

the package `gtk-test` depends on `gtk`, with features: `v3_10` but `gtk` does not have these features.

This might have been caused by the git dependencies getting out of date.

Add 'crate' branch

Currently, the cargo manifest lists dependencies from crates.io. Most other gtk-rs projects only use crates.io dependencies on their crate branch. The master branch always depends on the depedants git master branch.
I'd like to see that here, too.

Sleep useless

Hi.
Also, the call to sleep is useless.
I've just removed it from relm-test which also allows to remove the dependency to glib-sys.
Thanks.

Cannot be used with gtk 0.17.0

When in my project I updated gtk to 0.17.0, the building doesn't work with the newest gtk-test 0.16.0:

$ cargo build
    Updating crates.io index
error: failed to select a version for `gtk-sys`.
    ... required by package `gtk v0.16.0`
    ... which satisfies dependency `gtk = "^0.16"` of package `gtk-test v0.16.0`
    ... which satisfies dependency `gtk-test = "^0.16.0"` of package `rusty-git-gui v0.1.0 (/home/user/dev/project/rusty-git-gui)`
versions that meet the requirements `^0.16` are: 0.16.0

the package `gtk-sys` links to the native library `gtk-3`, but it conflicts with a previous package which links to `gtk-3` as well:
package `gtk-sys v0.17.0`
    ... which satisfies dependency `ffi = "^0.17"` of package `gtk v0.17.0`
    ... which satisfies dependency `gtk = "^0.17.0"` of package `rusty-git-gui v0.1.0 (/home/user/dev/project/rusty-git-gui)`
Only one package in the dependency graph may specify the same links value. This helps ensure that only one copy of a native library is linked in the final binary. Try to adjust your dependencies so that only one package uses the links ='gtk-sys' value. For more information, see https://doc.rust-lang.org/cargo/reference/resolver.html#links.

failed to select a version for `gtk-sys` which could resolve this conflict

Publish new crate version

The gtk crates have been bumped up to version 0.16. Could you please publish a new version of this crate too so it can be used with the newly released gtk crates?

one gtk_test::click leads to two clicked events

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.