1
use chuffed_rs::bindings::{
2
    get_idx, new_dummy_problem, p_addVars, p_setcallback, vec, ConLevel_CL_DEF, IntVar,
3
    VarBranch_VAR_INORDER, VarBranch_VAR_MIN_MIN,
4
};
5
use chuffed_rs::wrappers::{
6
    all_different_wrapper, branch_wrapper, create_vars, output_vars_wrapper, var_sym_break_wrapper,
7
};
8

            
9
/// Creates the variable for the test problem and posts some constraints and
10
/// branchings on it.
11
unsafe fn post_constraints(_n: i32) -> *mut vec<*mut IntVar> {
12
    // Create constant
13
    let n: i32 = _n;
14
    // Create some variables
15
    let x: *mut vec<*mut IntVar> = create_vars(n, 0, n, false);
16

            
17
    // Post some constraints
18
    all_different_wrapper(x, ConLevel_CL_DEF);
19

            
20
    // Post some branchings
21
    branch_wrapper(x as _, VarBranch_VAR_INORDER, VarBranch_VAR_MIN_MIN);
22

            
23
    // Declare output variables (optional)
24
    output_vars_wrapper(x);
25

            
26
    // Declare symmetries (optional)
27
    var_sym_break_wrapper(x);
28

            
29
    // Return the variable
30
    x
31
}
32

            
33
/// Custom printing function for this test problem
34
#[no_mangle]
35
pub unsafe extern "C" fn callback(x: *mut vec<*mut IntVar>) {
36
    print!("First output is: {}", get_idx(x, 0));
37
}
38

            
39
/// Basic test to make sure that running the ffi bindings and wrappers does not
40
/// crash
41
#[test]
42
fn run_basic_problem() {
43
    let args: Vec<String> = std::env::args().collect();
44

            
45
    if args.len() != 2 {
46
        println!("Invalid number of arguments");
47
        return;
48
    }
49

            
50
    let n: i32 = args[1].parse().expect("Invalid input");
51

            
52
    unsafe {
53
        let x = post_constraints(n);
54
        // make new dummy problem
55
        let p = new_dummy_problem();
56
        // Call problem.addvars()
57
        p_addVars(p, x);
58
        // Call problem.setcallback()
59
        p_setcallback(p, Some(callback));
60
        // Commented out currently as trying to print causes the assertion of
61
        // isFixed() in IntVar::getVal() to fail.
62
        // p_print(p);
63

            
64
        // Pass test if no crash occurs
65
        assert!(true);
66
    }
67
}