Commit 92ae6815 authored by Jordan Petridis's avatar Jordan Petridis 🌱

Add gtk tests

Currently we only test the GtkBuilder files.
Also I can't find a way to get gtk to uninitialize and reinitialize
in a different thread.

Close #56
parent 3afa8c44
Pipeline #25852 passed with stages
in 31 minutes
......@@ -32,7 +32,7 @@ flatpak:
--env=CARGO_HOME="target/cargo-home" \
--env=CARGO_TARGET_DIR="target_test/" \
app ${MANIFEST_PATH} \
cargo test -- --test-threads=1
cargo test -j 1 -- --test-threads=1
# Create a flatpak bundle
- flatpak-builder --finish-only app ${MANIFEST_PATH}
......
......@@ -114,6 +114,21 @@ mod i18n;
use app::App;
#[cfg(test)]
fn init_gtk_tests() -> Result<(), failure::Error> {
// if gtk::is_initialized() {
// assert!(gtk::is_initialized_main_thread())
// } else {
// gtk::init()?;
// static_resource::init()?;
// }
gtk::init()?;
static_resource::init()?;
gst::init()?;
Ok(())
}
fn main() {
// TODO: make the the logger a cli -vv option
loggerv::init_with_level(Level::Info).expect("Error initializing loggerv.");
......@@ -132,3 +147,30 @@ fn main() {
App::run();
}
#[test]
// Even while running the tests with -j 1 and --test-threads=1,
// cargo seems to create new threads and gtk refuses to initialize again.
// So we run every gtk related test here.
fn test_stuff() -> Result<(), failure::Error> {
use headerbar::Header;
use widgets::*;
init_gtk_tests()?;
// If a widget does not exist in the `GtkBuilder`(.ui) file this should panic and fail.
Header::default();
ShowsView::default();
ShowWidget::default();
HomeView::default();
HomeEpisode::default();
EpisodeWidget::default();
EmptyView::default();
EmptyShow::default();
appnotif::InAppNotification::default();
show_menu::ShowMenu::default();
player::PlayerWidget::default();
Ok(())
}
......@@ -156,7 +156,7 @@ fn split(now: &DateTime<Utc>, epoch: i64) -> ListSplit {
}
#[derive(Debug, Clone)]
struct HomeEpisode {
pub(crate) struct HomeEpisode {
container: gtk::Box,
image: gtk::Image,
episode: gtk::Box,
......
......@@ -17,3 +17,6 @@ pub(crate) use self::home_view::HomeView;
pub(crate) use self::show::ShowWidget;
pub(crate) use self::show_menu::ShowMenu;
pub(crate) use self::shows_view::ShowsView;
#[cfg(test)]
pub(crate) use self::home_view::HomeEpisode;
......@@ -26,7 +26,7 @@ xvfb-run -a -s "-screen 0 1024x768x24" \
--env=CARGO_HOME="target/cargo-home" \
--env=CARGO_TARGET_DIR="target_test/" \
app ${MANIFEST_PATH} \
cargo test -- --test-threads=1
cargo test -j 1 -- --test-threads=1
# Create a flatpak bundle
# flatpak-builder --finish-only app ${MANIFEST_PATH}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment