-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/shm11C3/hardware-monitor …
…into develop
- Loading branch information
Showing
19 changed files
with
407 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
use crate::commands::background_image::*; | ||
|
||
#[tokio::test] | ||
async fn test_save_background_image_invalid_data() { | ||
let invalid_base64 = "invalid_base64_data"; | ||
|
||
let result = save_background_image(invalid_base64.to_string()).await; | ||
assert!(result.is_err()); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_get_background_image_nonexistent_file() { | ||
let file_id = "nonexistent_file_id"; | ||
|
||
let result = get_background_image(file_id.to_string()).await; | ||
assert!(result.is_err()); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_delete_background_image_nonexistent_file() { | ||
let file_id = "nonexistent_file_id"; | ||
|
||
let result = delete_background_image(file_id.to_string()).await; | ||
assert!(result.is_err()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use std::fs; | ||
use tempfile::TempDir; | ||
|
||
use crate::commands::config::*; | ||
use crate::enums::{self, hardware}; | ||
use crate::services::language; | ||
use crate::utils; | ||
|
||
#[test] | ||
fn test_default_settings() { | ||
// デフォルト設定が正しいか確認 | ||
let settings = Settings::default(); | ||
|
||
assert_eq!( | ||
settings.version, | ||
utils::tauri::get_app_version(&utils::tauri::get_config()) | ||
); | ||
assert_eq!(settings.language, language::get_default_language()); | ||
assert_eq!(settings.theme, enums::config::Theme::Dark); | ||
assert_eq!( | ||
settings.display_targets, | ||
vec![ | ||
hardware::HardwareType::CPU, | ||
hardware::HardwareType::Memory, | ||
hardware::HardwareType::GPU | ||
] | ||
); | ||
assert!(settings.line_graph_border); | ||
assert!(settings.line_graph_fill); | ||
} | ||
|
||
#[test] | ||
fn test_set_language() { | ||
let mut settings = Settings::default(); | ||
let new_language = "es".to_string(); | ||
|
||
assert!(settings.set_language(new_language.clone()).is_ok()); | ||
assert_eq!(settings.language, new_language); | ||
} | ||
|
||
#[test] | ||
fn test_set_theme() { | ||
let mut settings = Settings::default(); | ||
let new_theme = enums::config::Theme::Light; | ||
|
||
assert!(settings.set_theme(new_theme.clone()).is_ok()); | ||
assert_eq!(settings.theme, new_theme); | ||
} | ||
|
||
#[test] | ||
fn test_set_display_targets() { | ||
let mut settings = Settings::default(); | ||
let targets = vec![hardware::HardwareType::GPU, hardware::HardwareType::Memory]; | ||
assert!(settings.set_display_targets(targets.clone()).is_ok()); | ||
assert_eq!(settings.display_targets, targets); | ||
} | ||
|
||
#[test] | ||
fn test_set_graph_size() { | ||
let mut settings = Settings::default(); | ||
assert!(settings | ||
.set_graph_size(enums::config::GraphSize::SM) | ||
.is_ok()); | ||
assert_eq!(settings.graph_size, enums::config::GraphSize::SM); | ||
} | ||
|
||
#[test] | ||
fn test_set_line_graph_border() { | ||
let mut settings = Settings::default(); | ||
assert!(settings.set_line_graph_border(false).is_ok()); | ||
assert!(!settings.line_graph_border); | ||
} | ||
|
||
#[test] | ||
fn test_set_line_graph_fill() { | ||
let mut settings = Settings::default(); | ||
assert!(settings.set_line_graph_fill(false).is_ok()); | ||
assert!(!settings.line_graph_fill); | ||
} | ||
|
||
#[test] | ||
fn test_set_line_graph_color() { | ||
let mut settings = Settings::default(); | ||
let new_color = "#ff0000".to_string(); | ||
|
||
assert!(settings | ||
.set_line_graph_color(hardware::HardwareType::CPU, new_color.clone()) | ||
.is_ok()); | ||
assert_eq!(settings.line_graph_color.cpu, [255, 0, 0]); | ||
} | ||
|
||
#[test] | ||
fn test_set_invalid_line_graph_color() { | ||
let mut settings = Settings::default(); | ||
let invalid_color = "invalid_color".to_string(); | ||
|
||
assert!(settings | ||
.set_line_graph_color(hardware::HardwareType::CPU, invalid_color) | ||
.is_err()); | ||
} | ||
|
||
#[test] | ||
fn test_set_line_graph_color_invalid() { | ||
let mut settings = Settings::default(); | ||
let new_color = "invalid_color".to_string(); | ||
assert!(settings | ||
.set_line_graph_color(hardware::HardwareType::CPU, new_color) | ||
.is_err()); | ||
} | ||
|
||
#[test] | ||
fn test_set_line_graph_mix() { | ||
let mut settings = Settings::default(); | ||
assert!(settings.set_line_graph_mix(false).is_ok()); | ||
assert!(!settings.line_graph_mix); | ||
} | ||
|
||
#[test] | ||
fn test_set_line_graph_show_legend() { | ||
let mut settings = Settings::default(); | ||
assert!(settings.set_line_graph_show_legend(false).is_ok()); | ||
assert!(!settings.line_graph_show_legend); | ||
} | ||
|
||
#[test] | ||
fn test_set_line_graph_show_scale() { | ||
let mut settings = Settings::default(); | ||
assert!(settings.set_line_graph_show_scale(false).is_ok()); | ||
assert!(!settings.line_graph_show_scale); | ||
} | ||
|
||
#[test] | ||
fn test_set_background_img_opacity() { | ||
let mut settings = Settings::default(); | ||
assert!(settings.set_background_img_opacity(100).is_ok()); | ||
assert_eq!(settings.background_img_opacity, 100); | ||
} | ||
|
||
#[test] | ||
fn test_set_selected_background_img() { | ||
let mut settings = Settings::default(); | ||
let img_path = Some("path/to/image.png".to_string()); | ||
assert!(settings | ||
.set_selected_background_img(img_path.clone()) | ||
.is_ok()); | ||
assert_eq!(settings.selected_background_img, img_path); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
use std::collections::{HashMap, VecDeque}; | ||
use std::sync::{Arc, Mutex}; | ||
use sysinfo::System; | ||
use tauri::Manager; | ||
|
||
use crate::commands::hardware::*; | ||
|
||
/// | ||
/// Test the get_process_list function | ||
/// | ||
#[test] | ||
fn test_get_process_list() { | ||
let app = tauri::test::mock_app(); | ||
|
||
// Mock | ||
let mut mock_system = System::new_all(); | ||
mock_system.refresh_all(); | ||
|
||
let mock_pid = 12345; | ||
let mock_process_name = "TestProcess".to_string(); | ||
let mock_cpu_usage = 50.0; | ||
let mock_memory_usage = 1024.0; | ||
|
||
let mut cpu_histories = HashMap::new(); | ||
cpu_histories.insert(mock_pid.into(), VecDeque::from(vec![mock_cpu_usage; 5])); | ||
|
||
let mut memory_histories = HashMap::new(); | ||
memory_histories.insert(mock_pid.into(), VecDeque::from(vec![mock_memory_usage; 5])); | ||
|
||
let app_state = AppState { | ||
system: Arc::new(Mutex::new(mock_system)), | ||
cpu_history: Arc::new(Mutex::new(VecDeque::new())), | ||
memory_history: Arc::new(Mutex::new(VecDeque::new())), | ||
gpu_history: Arc::new(Mutex::new(VecDeque::new())), | ||
gpu_usage: Arc::new(Mutex::new(0.0)), | ||
process_cpu_histories: Arc::new(Mutex::new(cpu_histories)), | ||
process_memory_histories: Arc::new(Mutex::new(memory_histories)), | ||
}; | ||
|
||
app.manage(app_state); | ||
|
||
// Act | ||
let process_list = get_process_list(app.state()); | ||
|
||
// Assert | ||
assert_eq!(process_list.len(), 1); | ||
let process = &process_list[0]; | ||
assert_eq!(process.pid, mock_pid as i32); | ||
assert_eq!(process.name, mock_process_name); | ||
assert_eq!(process.cpu_usage, mock_cpu_usage); | ||
assert_eq!(process.memory_usage, mock_memory_usage / 1024.0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#[cfg(test)] | ||
pub mod background_image; | ||
#[cfg(test)] | ||
pub mod config; | ||
//#[cfg(test)] | ||
//pub mod hardware; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#[cfg(test)] | ||
pub mod commands; | ||
#[cfg(test)] | ||
pub mod utils; |
Oops, something went wrong.