summaryrefslogtreecommitdiff
path: root/rust/tests/initialization.rs
blob: 9847a73402054fd5eb9493c0665de7166bf9e97b (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
use binaryninja::binary_view::BinaryView;
use binaryninja::enterprise::release_license;
use binaryninja::file_metadata::FileMetadata;
use binaryninja::headless::{
    init, init_with_opts, shutdown, InitializationError, InitializationOptions,
};
use binaryninja::set_license;

// NOTE: Do not add any tests here, behavior will change (i.e. a failure might pass) if we initialize
// NOTE: The core in another test. The only test here should be `test_license_validation`.

#[test]
fn test_license_validation() {
    // Release floating license if we already have one, otherwise the failure will succeed.
    release_license();
    // Make sure we properly report invalid license.
    let options = InitializationOptions::default()
        .with_license_checkout(false)
        .with_license("blah blag");
    match init_with_opts(options) {
        Ok(_) => panic!("Expected license validation to fail, but it succeeded!"),
        Err(InitializationError::InvalidLicense) => {}
        Err(e) => panic!("Unexpected error: {:?}", e),
    }
    // Reset the license so that it actually can validate license.
    set_license::<String>(None);
    // Actually make sure we can initialize.
    init().expect("Failed to initialize, make sure you have a license before trying to run tests!");
    // Open an empty binary and make sure it succeeds.
    let view = BinaryView::from_data(&FileMetadata::new(), &[]);
    assert!(
        view.is_ok(),
        "Failed to open empty binary, core initialization failed!"
    );
    shutdown();
}