81 lines
3.4 KiB
Rust
81 lines
3.4 KiB
Rust
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:\\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"));
|
||
|
||
// 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);
|
||
}
|
||
|
||
#[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()));
|
||
}
|
||
|
||
#[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"));
|
||
}
|
||
|
||
#[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);
|
||
}
|