LD-Uninstaller/src-tauri/tests/unit_tests.rs

93 lines
4 KiB
Rust
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

use ld_uninstaller_lib::models::ConfidenceLevel;
use ld_uninstaller_lib::services::{SafetyBlacklist, Sift4};
use ld_uninstaller_lib::state::AppState;
#[test]
fn test_safety_blacklist_critical_system_paths() {
assert!(SafetyBlacklist::is_dangerous_file_path("C:\\Windows"));
assert!(SafetyBlacklist::is_dangerous_file_path("C:\\Windows\\System32"));
assert!(SafetyBlacklist::is_dangerous_file_path("C:\\Windows\\WinSxS"));
assert!(SafetyBlacklist::is_dangerous_file_path("C:\\"));
assert!(SafetyBlacklist::is_dangerous_file_path("D:\\"));
assert!(SafetyBlacklist::is_dangerous_file_path("C:"));
assert!(SafetyBlacklist::is_dangerous_file_path("c:/"));
assert!(SafetyBlacklist::is_dangerous_file_path("C:\\Program Files\\WindowsApps"));
assert!(SafetyBlacklist::is_dangerous_file_path("C:\\ProgramData\\Package Cache"));
}
#[test]
fn test_safety_blacklist_safe_application_paths() {
assert!(!SafetyBlacklist::is_dangerous_file_path("C:\\Program Files\\Notepad++"));
assert!(!SafetyBlacklist::is_dangerous_file_path("C:\\Program Files (x86)\\Steam\\steamapps\\common\\Counter-Strike"));
assert!(!SafetyBlacklist::is_dangerous_file_path("C:\\Users\\User\\AppData\\Local\\Discord"));
}
#[test]
fn test_safety_blacklist_registry() {
assert!(SafetyBlacklist::is_dangerous_registry_path("HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"));
assert!(SafetyBlacklist::is_dangerous_registry_path("HKLM\\SYSTEM"));
assert!(SafetyBlacklist::is_dangerous_registry_path("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer"));
assert!(SafetyBlacklist::is_dangerous_registry_path("HKEY_LOCAL_MACHINE\\SAM"));
assert!(SafetyBlacklist::is_dangerous_registry_path("HKCR"));
// Güvenli uygulama anahtarları
assert!(!SafetyBlacklist::is_dangerous_registry_path("HKCU\\Software\\Valve\\Steam"));
assert!(!SafetyBlacklist::is_dangerous_registry_path("HKLM\\Software\\WOW6432Node\\VideoLAN\\VLC"));
}
#[test]
fn test_sift4_distance() {
assert_eq!(Sift4::distance("notepad", "notepad", 5), 0);
assert_eq!(Sift4::distance("vlc", "vlc player", 5), 7);
assert!(Sift4::distance("photoshop", "photoshp", 5) <= 1);
assert_eq!(Sift4::distance("", "", 5), 0);
assert_eq!(Sift4::distance("test", "", 5), 4);
}
#[test]
fn test_sift4_tokenize() {
let tokens = Sift4::tokenize("Google Chrome Setup Pro x64");
assert_eq!(tokens, vec!["chrome"]);
let vlc_tokens = Sift4::tokenize("VideoLAN VLC Media Player");
assert!(vlc_tokens.contains(&"videolan".to_string()));
assert!(vlc_tokens.contains(&"vlc".to_string()));
assert!(vlc_tokens.contains(&"media".to_string()));
assert!(vlc_tokens.contains(&"player".to_string()));
let empty_tokens = Sift4::tokenize("--- !!! ???");
assert!(empty_tokens.is_empty());
}
#[test]
fn test_sift4_contains_word_boundary() {
assert!(Sift4::contains_word_boundary("C:\\Program Files\\Mozilla Firefox", "firefox"));
assert!(Sift4::contains_word_boundary("Google Chrome (64-bit)", "chrome"));
assert!(!Sift4::contains_word_boundary("C:\\Photostudio\\app.exe", "studio"));
assert!(!Sift4::contains_word_boundary("C:\\SteamEngine\\game.exe", "steam"));
assert!(Sift4::contains_word_boundary("C:\\Games\\Steam-Games\\App", "steam"));
assert!(!Sift4::contains_word_boundary("", "test"));
assert!(!Sift4::contains_word_boundary("test", ""));
}
#[test]
fn test_app_state_exclusions() {
let state = AppState::new();
let safe_folder = "C:\\Program Files\\MySpecialTool";
assert!(!state.is_excluded(safe_folder));
let _ = state.add_exclusion(safe_folder.to_string());
assert!(state.is_excluded(safe_folder));
assert!(state.is_excluded("C:\\Program Files\\MySpecialTool\\subfolder"));
let _ = state.remove_exclusion(safe_folder);
assert!(!state.is_excluded(safe_folder));
}
#[test]
fn test_confidence_level_ordering() {
assert!(ConfidenceLevel::High > ConfidenceLevel::Medium);
assert!(ConfidenceLevel::Medium > ConfidenceLevel::Low);
assert!(ConfidenceLevel::Low > ConfidenceLevel::Bad);
}