Skip to content

Commit a74db25

Browse files
authored
Merge pull request #20 from derenv/initial_tests
Added initial testing support
2 parents 79b8f84 + 611d53d commit a74db25

File tree

4 files changed

+119
-39
lines changed

4 files changed

+119
-39
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ edition = "2021"
1010
adwaita = { version = "^0.1.1", package = "libadwaita" }
1111
gtk = { version = "^0.4.8", package = "gtk4" }
1212
gdk = { version = "^0.4.8", package = "gdk4" }
13+
gtk4_macros = { version = "^0.5.2", package = "gtk4-macros" }
1314

1415
#serde = { version = "1.0", features = ["derive"] }
1516
#serde_json = "1.0"

src/bin/main.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// SPDX-FileCopyrightText: 2022 Deren Vural
2+
// SPDX-License-Identifier: GPL-3.0-or-later
3+
4+
/**
5+
* Name:
6+
* gtk4-nvidia-monitor-rust
7+
*
8+
* Description:
9+
* GTK-rs app for monitoring Nvidia GPU statistics
10+
*
11+
* Made:
12+
* 12/09/2022
13+
*
14+
* Made by:
15+
* Deren Vural
16+
*
17+
* Notes:
18+
*
19+
*/
20+
// Declare module
21+
extern crate gtk4_nvidia_monitor_rust;
22+
23+
// Imports
24+
use adwaita::{prelude::ApplicationExtManual, Application};
25+
26+
/**
27+
* Name:
28+
* main
29+
*
30+
* Description:
31+
* Create application using lib.rs functions and run
32+
*
33+
* Made:
34+
* 13/09/2022
35+
*
36+
* Made by:
37+
* Deren Vural
38+
*
39+
* Notes:
40+
*
41+
*/
42+
fn main() {
43+
// Intialise GTK & Create a new application
44+
let app: Application = gtk4_nvidia_monitor_rust::create_app();
45+
46+
// Run the application
47+
println!("{}", app.run());
48+
}

src/main.rs renamed to src/lib.rs

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ mod custom_button;
3030
mod settingswindow;
3131

3232
// Imports
33-
use adwaita::{gio, prelude::*, Application};
33+
use adwaita::{gio, glib, prelude::*, Application};
3434
use gdk::Display;
3535
use gio::resources_register_include;
3636
use gtk::{CssProvider, StyleContext};
@@ -54,7 +54,7 @@ const APP_ID: &str = "com.gtk_d.NvidiaMonitorRust";
5454
* Notes:
5555
*
5656
*/
57-
fn main() {
57+
pub fn create_app() -> Application {
5858
// Resources
5959
resources_register_include!("nvidiamonitorrust.gresource")
6060
.expect("Failed to register resources.");
@@ -66,12 +66,12 @@ fn main() {
6666
let app: Application = Application::builder().application_id(APP_ID).build();
6767

6868
// Connect to signals of `app`
69-
//app.connect_startup(setup_shortcuts);
69+
app.connect_startup(setup_shortcuts);
7070
app.connect_startup(|_| load_css());
7171
app.connect_activate(build_ui);
7272

73-
// Run the application
74-
println!("{}", app.run());
73+
// Return the application
74+
app
7575
}
7676

7777
/**
@@ -91,14 +91,18 @@ fn main() {
9191
* <https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/todo/5/main.rs>
9292
* <https://gtk-rs.org/gtk4-rs/stable/latest/book/todo_3.html>
9393
*
94+
* https://gtk-rs.org/gtk4-rs/git/book/actions.html
95+
* https://gtk-rs.org/gtk4-rs/git/docs/gtk4/struct.Window.html#actions
9496
*/
95-
/*
9697
fn setup_shortcuts(app: &Application) {
97-
app.set_accels_for_action("win.filter('All')", &["<Ctrl>a"]);
98-
app.set_accels_for_action("win.filter('Open')", &["<Ctrl>o"]);
99-
app.set_accels_for_action("win.filter('Done')", &["<Ctrl>d"]);
98+
//app.set_accels_for_action("win.filter('All')", &["<Ctrl>a"]);
99+
//app.set_accels_for_action("win.filter('Open')", &["<Ctrl>o"]);
100+
//app.set_accels_for_action("win.filter('Done')", &["<Ctrl>d"]);
101+
//app.set_accels_for_action("win.filter('Close')", &["<Ctrl>q"])
102+
app.set_accels_for_action("window.close", &["<Ctrl>q"]);
103+
app.set_accels_for_action("window.toggle-maximized", &["<Ctrl>w"]);
104+
app.set_accels_for_action("window.minimize", &["<Ctrl>m"]);
100105
}
101-
*/
102106

103107
/**
104108
* Name:
@@ -149,44 +153,26 @@ fn build_ui(app: &Application) {
149153
// Create a new custom window and show it
150154
let window: MainWindow = MainWindow::new(app);
151155

156+
// Create custom action to close window (for shortcuts)
157+
// Was a "close" replica
158+
/*
159+
let action_close = SimpleAction::new("something", None);
160+
action_close.connect_activate(clone!(@weak window => move |_, _| {
161+
window.close();
162+
}));
163+
window.add_action(&action_close);
164+
*/
165+
152166
// Present window
153167
window.show();
154168

155169
/*
156-
// Menu Child
157-
let menu: Menu = Menu::new();
158-
let item: Menu = Menu::new();
159-
item.append(Some("Utilisation"), Some("app.util"));
160-
item.append(Some("Temperature"), Some("app.temp"));
161-
item.append(Some("Memory Usage"), Some("app.memo"));
162-
item.append(Some("Fan Speed"), Some("app.fans"));
163-
menu.append_submenu(Some("Item 1"), &item);
164-
menu.append(Some("SMI"), Some("app.smi"));
165-
menu.append(Some("Settings"), Some("app.settings"));
166-
app.set_menubar(Some(&menu));
167-
168170
// App Indicator
169171
//let mut indicator = AppIndicator::new("Nvidia App", "");
170172
//indicator.set_status(AppIndicatorStatus::Active);
171173
//let icon_path = Path::new(env!("CARGO_MANIFEST_DIR")).join("resources");
172174
//indicator.set_icon_theme_path(icon_path.to_str().unwrap());
173175
//indicator.set_icon_full("rust-logo", "icon");
174176
//indicator.set_menu(&mut menu);
175-
176-
// Create Parent window
177-
let window: ApplicationWindow = ApplicationWindow::new(app);
178-
window.set_title(Some("Nvidia App"));
179-
window.set_default_size(400, 400);
180-
window.set_show_menubar(true);
181-
182-
// Add children to window
183-
//window.set_child(Some(&button1));
184-
//window.set_child(Some(&button2));
185-
//window.set_child(Some(&button3));
186-
//window.set_child(Some(&button4));
187-
//window.set_child(Some(&button5));
188-
189-
// Present window
190-
window.show();
191-
*/
177+
*/
192178
}

tests/integration_tests_1.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// SPDX-FileCopyrightText: 2022 Deren Vural
2+
// SPDX-License-Identifier: GPL-3.0-or-later
3+
4+
/* *
5+
* Name:
6+
* integration_tests_1.rs
7+
*
8+
* Description:
9+
* Integration tests for Nvidia Gnome Extension (Rust)
10+
*
11+
* Made:
12+
* 26/11/2022
13+
*
14+
* Made by:
15+
* Deren Vural
16+
*
17+
* Notes:
18+
*
19+
*/
20+
21+
// Imports
22+
extern crate gtk4_macros;
23+
24+
// Declare module
25+
extern crate gtk4_nvidia_monitor_rust;
26+
27+
// Imports
28+
use adwaita::{prelude::ApplicationExtManual, Application};
29+
30+
pub fn init_ui() -> Application {
31+
// Intialise GTK & Create a new application
32+
gtk4_nvidia_monitor_rust::create_app()
33+
}
34+
35+
/*
36+
* Integration tests
37+
*/
38+
#[gtk::test]
39+
fn test_test() {
40+
// Intialise GTK & Create a new application
41+
let app: Application = init_ui();
42+
43+
// Run the application
44+
assert_eq!(app.run(), 0);
45+
}

0 commit comments

Comments
 (0)