Skip to content

Commit

Permalink
gtk tests under ci
Browse files Browse the repository at this point in the history
  • Loading branch information
misson20000 committed Sep 26, 2023
1 parent 005c169 commit 3f6b6b4
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 42 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ jobs:
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
uses: coactions/setup-xvfb@v1
with:
run: cargo test --verbose
117 changes: 108 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ tracing-subscriber = "0.3.17"
[dev-dependencies]
pretty_assertions = "1.4.0"
assert_matches = "1.5"
rusty-fork = "0.3.0"

[[bin]]
name = "gtk"
Expand Down
68 changes: 36 additions & 32 deletions src/view/hierarchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,8 @@ impl RootListModel {
#[cfg(test)]
mod tests {
use super::*;

use rusty_fork::rusty_fork_test;

fn assert_tlr_node_correct(document: &sync::Arc<document::Document>, node: &sync::Arc<structure::Node>, iter: &mut impl std::iter::Iterator<Item = gtk::TreeListRow>) {
let tlr = iter.next().expect("tree list model ended early");
let item = tlr.item().unwrap().downcast::<NodeItem>().unwrap();
Expand Down Expand Up @@ -519,39 +520,42 @@ mod tests {
fn tree_list_node_items_iter(tlm: &gtk::TreeListModel) -> impl std::iter::Iterator<Item = NodeItem> + '_ {
tlm.iter::<gtk::TreeListRow>().map(|tlr| tlr.unwrap().item().unwrap().downcast::<NodeItem>().unwrap())
}

#[test]
fn test_reexpand() {
gtk::init().unwrap();

let root = structure::Node::builder()
.name("root")
.size(0x40)
.child(0x0, |b| b
.name("container")
.size(0x40)
.child(0x0, |b| b
.name("child0")
.size(0x8))
.child(0x8, |b| b
.name("child1")
.size(0x8)))
.build();

let document_host = sync::Arc::new(document::DocumentHost::new(document::Document::new_for_structure_test(root)));
let mut document = document_host.get();

let tlm = create_tree_list_model(document_host.clone(), document.clone(), true);
assert_tlm_correct(&document, &tlm);

document = document_host.change(document.delete_range(structure::SiblingRange::new(vec![0], 0, 0))).unwrap();
tlm.model().downcast::<RootListModel>().unwrap().update_document(&document);
assert_tlm_correct(&document, &tlm);
/* GTK doesn't like being initialized in a process more than once. */
rusty_fork_test! {
#[test]
fn test_reexpand() {
gtk::init().unwrap();

let root = structure::Node::builder()
.name("root")
.size(0x40)
.child(0x0, |b| b
.name("container")
.size(0x40)
.child(0x0, |b| b
.name("child0")
.size(0x8))
.child(0x8, |b| b
.name("child1")
.size(0x8)))
.build();

let document_host = sync::Arc::new(document::DocumentHost::new(document::Document::new_for_structure_test(root)));
let mut document = document_host.get();

let tlm = create_tree_list_model(document_host.clone(), document.clone(), true);
assert_tlm_correct(&document, &tlm);

tlm.item(1).unwrap().downcast::<gtk::TreeListRow>().unwrap().set_expanded(false);
assert_tlm_correct(&document, &tlm);
document = document_host.change(document.delete_range(structure::SiblingRange::new(vec![0], 0, 0))).unwrap();
tlm.model().downcast::<RootListModel>().unwrap().update_document(&document);
assert_tlm_correct(&document, &tlm);

tlm.item(1).unwrap().downcast::<gtk::TreeListRow>().unwrap().set_expanded(true);
assert_tlm_correct(&document, &tlm);
tlm.item(1).unwrap().downcast::<gtk::TreeListRow>().unwrap().set_expanded(false);
assert_tlm_correct(&document, &tlm);

tlm.item(1).unwrap().downcast::<gtk::TreeListRow>().unwrap().set_expanded(true);
assert_tlm_correct(&document, &tlm);
}
}
}

0 comments on commit 3f6b6b4

Please sign in to comment.