summaryrefslogtreecommitdiff
path: root/plugins/warp/tests/processor.rs
blob: 835b33ec55327d85ba2087be51bebb95d2b05a49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use std::path::PathBuf;
use tempdir::TempDir;
use warp_ninja::processor::WarpFileProcessor;

// These are the target files present in OUT_DIR
// Add the files to fixtures/bin
static BIN_TARGET_FILES: [&str; 9] = [
    "_ctype.obj",
    "_fptostr.obj",
    "_mbslen.obj",
    "_memicmp.obj",
    "_strnicm.obj",
    "_wctype.obj",
    "atof.obj",
    "atoldbl.obj",
    "atox.obj",
];

#[test]
fn test_processor() {
    let out_dir = env!("OUT_DIR").parse::<PathBuf>().unwrap();
    let _headless_session =
        binaryninja::headless::Session::new().expect("Failed to initialize session");

    let processor = WarpFileProcessor::new();

    // All files should process and not error.
    for file_name in BIN_TARGET_FILES {
        let path = out_dir.join(file_name);
        processor.process_path(path).unwrap();
    }

    // We should be able to process a warp file.
    let warp_path = out_dir.join("random.warp");
    processor.process_path(warp_path).unwrap();
}

#[test]
fn test_caching() {
    let out_dir = env!("OUT_DIR").parse::<PathBuf>().unwrap();
    let cache_dir = TempDir::new("tmp_cache").unwrap();
    let _headless_session =
        binaryninja::headless::Session::new().expect("Failed to initialize session");

    let processor = WarpFileProcessor::new().with_cache_path(cache_dir.path().to_path_buf());

    // Go through files, this should cache the databases.
    for file_name in BIN_TARGET_FILES {
        let path = out_dir.join(file_name);
        processor.process_path(path).unwrap();
    }

    // Verify the databases were saved to the cache.
    let mut cached_paths = Vec::new();
    for entry in std::fs::read_dir(cache_dir.path()).expect("Failed to read cache dir") {
        let entry = entry.expect("Failed to read cache dir entry");
        let path = entry.path();
        assert!(path.is_file());
        cached_paths.push(path);
    }
    assert_eq!(BIN_TARGET_FILES.len(), cached_paths.len());
}