// Rust test file autogenerated with cargo build (src/build_spectests.rs).
// Please do NOT modify it by hand, as it will be reseted on next build.
// Test based on spectests/func_ptrs.wast
#![allow(
    warnings,
    dead_code
)]
use std::panic;
use wabt::wat2wasm;

use crate::webassembly::{instantiate, compile, ImportObject, ResultObject, Instance, Export};
use super::_common::{
    spectest_importobject,
    NaNCheck,
};


// Line 1
fn create_module_1() -> ResultObject {
    let module_str = "(module
      (type (;0;) (func))
      (type (;1;) (func))
      (type (;2;) (func))
      (type (;3;) (func (result i32)))
      (type (;4;) (func (result i32)))
      (type (;5;) (func (param i32) (result i32)))
      (type (;6;) (func (param i32)))
      (import \"spectest\" \"print_i32\" (func (;0;) (type 6)))
      (func (;1;) (type 0))
      (func (;2;) (type 1))
      (func (;3;) (type 4) (result i32)
        i32.const 13)
      (func (;4;) (type 5) (param i32) (result i32)
        get_local 0
        i32.const 1
        i32.add)
      (func (;5;) (type 5) (param i32) (result i32)
        get_local 0
        i32.const 2
        i32.sub)
      (func (;6;) (type 6) (param i32)
        get_local 0
        call 0)
      (export \"one\" (func 3))
      (export \"two\" (func 4))
      (export \"three\" (func 5))
      (export \"four\" (func 6)))
    ";
    let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
    instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
}

fn start_module_1(result_object: &ResultObject) {
    result_object.instance.start();
}

// Line 27
fn c1_l27_action_invoke(result_object: &ResultObject) {
    println!("Executing function {}", "c1_l27_action_invoke");
    let func_index = match result_object.module.info.exports.get("one") {
        Some(&Export::Function(index)) => index,
        _ => panic!("Function not found"),
    };
    let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index);
    let result = invoke_fn(&result_object.instance);
    assert_eq!(result, 13 as i32);
}

// Line 28
fn c2_l28_action_invoke(result_object: &ResultObject) {
    println!("Executing function {}", "c2_l28_action_invoke");
    let func_index = match result_object.module.info.exports.get("two") {
        Some(&Export::Function(index)) => index,
        _ => panic!("Function not found"),
    };
    let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index);
    let result = invoke_fn(13 as i32, &result_object.instance);
    assert_eq!(result, 14 as i32);
}

// Line 29
fn c3_l29_action_invoke(result_object: &ResultObject) {
    println!("Executing function {}", "c3_l29_action_invoke");
    let func_index = match result_object.module.info.exports.get("three") {
        Some(&Export::Function(index)) => index,
        _ => panic!("Function not found"),
    };
    let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index);
    let result = invoke_fn(13 as i32, &result_object.instance);
    assert_eq!(result, 11 as i32);
}

// Line 30
fn c4_l30_action_invoke(result_object: &ResultObject) {
    println!("Executing function {}", "c4_l30_action_invoke");
    let func_index = match result_object.module.info.exports.get("four") {
        Some(&Export::Function(index)) => index,
        _ => panic!("Function not found"),
    };
    let invoke_fn: fn(i32, &Instance) = get_instance_function!(result_object.instance, func_index);
    let result = invoke_fn(83 as i32, &result_object.instance);
    
}

// Line 32
#[test]
fn c5_l32_assert_invalid() {
    let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 9, 6, 1, 0, 65, 0, 11, 0];
    let compilation = compile(wasm_binary.to_vec());
    assert!(compilation.is_err(), "WASM should not compile as is invalid");
}

// Line 33
#[test]
fn c6_l33_assert_invalid() {
    let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 9, 7, 1, 0, 65, 0, 11, 1, 0, 10, 4, 1, 2, 0, 11];
    let compilation = compile(wasm_binary.to_vec());
    assert!(compilation.is_err(), "WASM should not compile as is invalid");
}

// Line 36
#[test]
fn c7_l36_assert_invalid() {
    let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 4, 4, 1, 112, 0, 1, 9, 6, 1, 0, 66, 0, 11, 0];
    let compilation = compile(wasm_binary.to_vec());
    assert!(compilation.is_err(), "WASM should not compile as is invalid");
}

// Line 40
#[test]
fn c8_l40_assert_invalid() {
    let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 4, 4, 1, 112, 0, 1, 9, 7, 1, 0, 65, 0, 104, 11, 0];
    let compilation = compile(wasm_binary.to_vec());
    assert!(compilation.is_err(), "WASM should not compile as is invalid");
}

// Line 44
#[test]
fn c9_l44_assert_invalid() {
    let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 4, 4, 1, 112, 0, 1, 9, 5, 1, 0, 1, 11, 0];
    let compilation = compile(wasm_binary.to_vec());
    assert!(compilation.is_err(), "WASM should not compile as is invalid");
}

// Line 48
#[test]
fn c10_l48_assert_invalid() {
    let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 3, 2, 1, 42, 10, 4, 1, 2, 0, 11];
    let compilation = compile(wasm_binary.to_vec());
    assert!(compilation.is_err(), "WASM should not compile as is invalid");
}

// Line 49
#[test]
fn c11_l49_assert_invalid() {
    let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 2, 22, 1, 8, 115, 112, 101, 99, 116, 101, 115, 116, 9, 112, 114, 105, 110, 116, 95, 105, 51, 50, 0, 43];
    let compilation = compile(wasm_binary.to_vec());
    assert!(compilation.is_err(), "WASM should not compile as is invalid");
}

// Line 51

#[test]
fn test_module_1() {
    let result_object = create_module_1();
    // We group the calls together
    start_module_1(&result_object);
    c1_l27_action_invoke(&result_object);
    c2_l28_action_invoke(&result_object);
    c3_l29_action_invoke(&result_object);
    c4_l30_action_invoke(&result_object);
}
fn create_module_2() -> ResultObject {
    let module_str = "(module
      (type (;0;) (func (result i32)))
      (type (;1;) (func (result i32)))
      (type (;2;) (func (param i32) (result i32)))
      (func (;0;) (type 0) (result i32)
        i32.const 1)
      (func (;1;) (type 0) (result i32)
        i32.const 2)
      (func (;2;) (type 0) (result i32)
        i32.const 3)
      (func (;3;) (type 1) (result i32)
        i32.const 4)
      (func (;4;) (type 1) (result i32)
        i32.const 5)
      (func (;5;) (type 2) (param i32) (result i32)
        get_local 0
        call_indirect (type 0))
      (func (;6;) (type 2) (param i32) (result i32)
        get_local 0
        call_indirect (type 1))
      (table (;0;) 7 7 anyfunc)
      (export \"callt\" (func 5))
      (export \"callu\" (func 6))
      (elem (;0;) (i32.const 0) 0 1 2 3 4 0 2))
    ";
    let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
    instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
}

fn start_module_2(result_object: &ResultObject) {
    result_object.instance.start();
}

// Line 71
fn c13_l71_action_invoke(result_object: &ResultObject) {
    println!("Executing function {}", "c13_l71_action_invoke");
    let func_index = match result_object.module.info.exports.get("callt") {
        Some(&Export::Function(index)) => index,
        _ => panic!("Function not found"),
    };
    let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index);
    let result = invoke_fn(0 as i32, &result_object.instance);
    assert_eq!(result, 1 as i32);
}

// Line 72
fn c14_l72_action_invoke(result_object: &ResultObject) {
    println!("Executing function {}", "c14_l72_action_invoke");
    let func_index = match result_object.module.info.exports.get("callt") {
        Some(&Export::Function(index)) => index,
        _ => panic!("Function not found"),
    };
    let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index);
    let result = invoke_fn(1 as i32, &result_object.instance);
    assert_eq!(result, 2 as i32);
}

// Line 73
fn c15_l73_action_invoke(result_object: &ResultObject) {
    println!("Executing function {}", "c15_l73_action_invoke");
    let func_index = match result_object.module.info.exports.get("callt") {
        Some(&Export::Function(index)) => index,
        _ => panic!("Function not found"),
    };
    let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index);
    let result = invoke_fn(2 as i32, &result_object.instance);
    assert_eq!(result, 3 as i32);
}

// Line 74
fn c16_l74_action_invoke(result_object: &ResultObject) {
    println!("Executing function {}", "c16_l74_action_invoke");
    let func_index = match result_object.module.info.exports.get("callt") {
        Some(&Export::Function(index)) => index,
        _ => panic!("Function not found"),
    };
    let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index);
    let result = invoke_fn(3 as i32, &result_object.instance);
    assert_eq!(result, 4 as i32);
}

// Line 75
fn c17_l75_action_invoke(result_object: &ResultObject) {
    println!("Executing function {}", "c17_l75_action_invoke");
    let func_index = match result_object.module.info.exports.get("callt") {
        Some(&Export::Function(index)) => index,
        _ => panic!("Function not found"),
    };
    let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index);
    let result = invoke_fn(4 as i32, &result_object.instance);
    assert_eq!(result, 5 as i32);
}

// Line 76
fn c18_l76_action_invoke(result_object: &ResultObject) {
    println!("Executing function {}", "c18_l76_action_invoke");
    let func_index = match result_object.module.info.exports.get("callt") {
        Some(&Export::Function(index)) => index,
        _ => panic!("Function not found"),
    };
    let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index);
    let result = invoke_fn(5 as i32, &result_object.instance);
    assert_eq!(result, 1 as i32);
}

// Line 77
fn c19_l77_action_invoke(result_object: &ResultObject) {
    println!("Executing function {}", "c19_l77_action_invoke");
    let func_index = match result_object.module.info.exports.get("callt") {
        Some(&Export::Function(index)) => index,
        _ => panic!("Function not found"),
    };
    let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index);
    let result = invoke_fn(6 as i32, &result_object.instance);
    assert_eq!(result, 3 as i32);
}

// Line 78
fn c20_l78_action_invoke(result_object: &ResultObject) {
    println!("Executing function {}", "c20_l78_action_invoke");
    let func_index = match result_object.module.info.exports.get("callt") {
        Some(&Export::Function(index)) => index,
        _ => panic!("Function not found"),
    };
    let invoke_fn: fn(i32, &Instance) = get_instance_function!(result_object.instance, func_index);
    let result = invoke_fn(7 as i32, &result_object.instance);
    
}

#[test]
fn c20_l78_assert_trap() {
    let result_object = create_module_2();
    let result = panic::catch_unwind(|| {
        c20_l78_action_invoke(&result_object);
    });
    assert!(result.is_err());
}

// Line 79
fn c21_l79_action_invoke(result_object: &ResultObject) {
    println!("Executing function {}", "c21_l79_action_invoke");
    let func_index = match result_object.module.info.exports.get("callt") {
        Some(&Export::Function(index)) => index,
        _ => panic!("Function not found"),
    };
    let invoke_fn: fn(i32, &Instance) = get_instance_function!(result_object.instance, func_index);
    let result = invoke_fn(100 as i32, &result_object.instance);
    
}

#[test]
fn c21_l79_assert_trap() {
    let result_object = create_module_2();
    let result = panic::catch_unwind(|| {
        c21_l79_action_invoke(&result_object);
    });
    assert!(result.is_err());
}

// Line 80
fn c22_l80_action_invoke(result_object: &ResultObject) {
    println!("Executing function {}", "c22_l80_action_invoke");
    let func_index = match result_object.module.info.exports.get("callt") {
        Some(&Export::Function(index)) => index,
        _ => panic!("Function not found"),
    };
    let invoke_fn: fn(i32, &Instance) = get_instance_function!(result_object.instance, func_index);
    let result = invoke_fn(-1 as i32, &result_object.instance);
    
}

#[test]
fn c22_l80_assert_trap() {
    let result_object = create_module_2();
    let result = panic::catch_unwind(|| {
        c22_l80_action_invoke(&result_object);
    });
    assert!(result.is_err());
}

// Line 82
fn c23_l82_action_invoke(result_object: &ResultObject) {
    println!("Executing function {}", "c23_l82_action_invoke");
    let func_index = match result_object.module.info.exports.get("callu") {
        Some(&Export::Function(index)) => index,
        _ => panic!("Function not found"),
    };
    let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index);
    let result = invoke_fn(0 as i32, &result_object.instance);
    assert_eq!(result, 1 as i32);
}

// Line 83
fn c24_l83_action_invoke(result_object: &ResultObject) {
    println!("Executing function {}", "c24_l83_action_invoke");
    let func_index = match result_object.module.info.exports.get("callu") {
        Some(&Export::Function(index)) => index,
        _ => panic!("Function not found"),
    };
    let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index);
    let result = invoke_fn(1 as i32, &result_object.instance);
    assert_eq!(result, 2 as i32);
}

// Line 84
fn c25_l84_action_invoke(result_object: &ResultObject) {
    println!("Executing function {}", "c25_l84_action_invoke");
    let func_index = match result_object.module.info.exports.get("callu") {
        Some(&Export::Function(index)) => index,
        _ => panic!("Function not found"),
    };
    let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index);
    let result = invoke_fn(2 as i32, &result_object.instance);
    assert_eq!(result, 3 as i32);
}

// Line 85
fn c26_l85_action_invoke(result_object: &ResultObject) {
    println!("Executing function {}", "c26_l85_action_invoke");
    let func_index = match result_object.module.info.exports.get("callu") {
        Some(&Export::Function(index)) => index,
        _ => panic!("Function not found"),
    };
    let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index);
    let result = invoke_fn(3 as i32, &result_object.instance);
    assert_eq!(result, 4 as i32);
}

// Line 86
fn c27_l86_action_invoke(result_object: &ResultObject) {
    println!("Executing function {}", "c27_l86_action_invoke");
    let func_index = match result_object.module.info.exports.get("callu") {
        Some(&Export::Function(index)) => index,
        _ => panic!("Function not found"),
    };
    let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index);
    let result = invoke_fn(4 as i32, &result_object.instance);
    assert_eq!(result, 5 as i32);
}

// Line 87
fn c28_l87_action_invoke(result_object: &ResultObject) {
    println!("Executing function {}", "c28_l87_action_invoke");
    let func_index = match result_object.module.info.exports.get("callu") {
        Some(&Export::Function(index)) => index,
        _ => panic!("Function not found"),
    };
    let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index);
    let result = invoke_fn(5 as i32, &result_object.instance);
    assert_eq!(result, 1 as i32);
}

// Line 88
fn c29_l88_action_invoke(result_object: &ResultObject) {
    println!("Executing function {}", "c29_l88_action_invoke");
    let func_index = match result_object.module.info.exports.get("callu") {
        Some(&Export::Function(index)) => index,
        _ => panic!("Function not found"),
    };
    let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index);
    let result = invoke_fn(6 as i32, &result_object.instance);
    assert_eq!(result, 3 as i32);
}

// Line 89
fn c30_l89_action_invoke(result_object: &ResultObject) {
    println!("Executing function {}", "c30_l89_action_invoke");
    let func_index = match result_object.module.info.exports.get("callu") {
        Some(&Export::Function(index)) => index,
        _ => panic!("Function not found"),
    };
    let invoke_fn: fn(i32, &Instance) = get_instance_function!(result_object.instance, func_index);
    let result = invoke_fn(7 as i32, &result_object.instance);
    
}

#[test]
fn c30_l89_assert_trap() {
    let result_object = create_module_2();
    let result = panic::catch_unwind(|| {
        c30_l89_action_invoke(&result_object);
    });
    assert!(result.is_err());
}

// Line 90
fn c31_l90_action_invoke(result_object: &ResultObject) {
    println!("Executing function {}", "c31_l90_action_invoke");
    let func_index = match result_object.module.info.exports.get("callu") {
        Some(&Export::Function(index)) => index,
        _ => panic!("Function not found"),
    };
    let invoke_fn: fn(i32, &Instance) = get_instance_function!(result_object.instance, func_index);
    let result = invoke_fn(100 as i32, &result_object.instance);
    
}

#[test]
fn c31_l90_assert_trap() {
    let result_object = create_module_2();
    let result = panic::catch_unwind(|| {
        c31_l90_action_invoke(&result_object);
    });
    assert!(result.is_err());
}

// Line 91
fn c32_l91_action_invoke(result_object: &ResultObject) {
    println!("Executing function {}", "c32_l91_action_invoke");
    let func_index = match result_object.module.info.exports.get("callu") {
        Some(&Export::Function(index)) => index,
        _ => panic!("Function not found"),
    };
    let invoke_fn: fn(i32, &Instance) = get_instance_function!(result_object.instance, func_index);
    let result = invoke_fn(-1 as i32, &result_object.instance);
    
}

#[test]
fn c32_l91_assert_trap() {
    let result_object = create_module_2();
    let result = panic::catch_unwind(|| {
        c32_l91_action_invoke(&result_object);
    });
    assert!(result.is_err());
}

// Line 93

#[test]
fn test_module_2() {
    let result_object = create_module_2();
    // We group the calls together
    start_module_2(&result_object);
    c13_l71_action_invoke(&result_object);
    c14_l72_action_invoke(&result_object);
    c15_l73_action_invoke(&result_object);
    c16_l74_action_invoke(&result_object);
    c17_l75_action_invoke(&result_object);
    c18_l76_action_invoke(&result_object);
    c19_l77_action_invoke(&result_object);
    c23_l82_action_invoke(&result_object);
    c24_l83_action_invoke(&result_object);
    c25_l84_action_invoke(&result_object);
    c26_l85_action_invoke(&result_object);
    c27_l86_action_invoke(&result_object);
    c28_l87_action_invoke(&result_object);
    c29_l88_action_invoke(&result_object);
}
fn create_module_3() -> ResultObject {
    let module_str = "(module
      (type (;0;) (func (result i32)))
      (type (;1;) (func (param i32) (result i32)))
      (func (;0;) (type 0) (result i32)
        i32.const 1)
      (func (;1;) (type 0) (result i32)
        i32.const 2)
      (func (;2;) (type 1) (param i32) (result i32)
        get_local 0
        call_indirect (type 0))
      (table (;0;) 2 2 anyfunc)
      (export \"callt\" (func 2))
      (elem (;0;) (i32.const 0) 0 1))
    ";
    let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
    instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
}

fn start_module_3(result_object: &ResultObject) {
    result_object.instance.start();
}

// Line 105
fn c34_l105_action_invoke(result_object: &ResultObject) {
    println!("Executing function {}", "c34_l105_action_invoke");
    let func_index = match result_object.module.info.exports.get("callt") {
        Some(&Export::Function(index)) => index,
        _ => panic!("Function not found"),
    };
    let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index);
    let result = invoke_fn(0 as i32, &result_object.instance);
    assert_eq!(result, 1 as i32);
}

// Line 106
fn c35_l106_action_invoke(result_object: &ResultObject) {
    println!("Executing function {}", "c35_l106_action_invoke");
    let func_index = match result_object.module.info.exports.get("callt") {
        Some(&Export::Function(index)) => index,
        _ => panic!("Function not found"),
    };
    let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index);
    let result = invoke_fn(1 as i32, &result_object.instance);
    assert_eq!(result, 2 as i32);
}

#[test]
fn test_module_3() {
    let result_object = create_module_3();
    // We group the calls together
    start_module_3(&result_object);
    c34_l105_action_invoke(&result_object);
    c35_l106_action_invoke(&result_object);
}
