mirror of
https://github.com/fluencelabs/marine-rs-sdk-test
synced 2024-12-04 15:20:18 +00:00
add initial tests version
This commit is contained in:
parent
c2fec5939f
commit
bff0b7b5d3
175
tests/test_files/arrays_passing.rs
Normal file
175
tests/test_files/arrays_passing.rs
Normal file
@ -0,0 +1,175 @@
|
||||
use fluence::fce;
|
||||
|
||||
pub fn main() {}
|
||||
|
||||
#[fce]
|
||||
pub fn byte_type(mut arg: Vec<u8>) -> Vec<u8> {
|
||||
arg.push(0);
|
||||
|
||||
let mut arg = unsafe { effector::byte_type(arg) };
|
||||
|
||||
arg.push(2);
|
||||
arg
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn inner_arrays_1(mut arg: Vec<Vec<Vec<Vec<u8>>>>) -> Vec<Vec<Vec<Vec<u8>>>> {
|
||||
arg.push(vec![vec![vec![0]]]);
|
||||
|
||||
let mut arg = unsafe { effector::inner_arrays_1(arg) };
|
||||
|
||||
arg.push(vec![vec![vec![2]]]);
|
||||
arg
|
||||
}
|
||||
|
||||
#[fce]
|
||||
#[derive(Default)]
|
||||
pub struct TestRecord {
|
||||
pub field_0: i32,
|
||||
pub field_1: Vec<Vec<u8>>,
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn inner_arrays_2(mut arg: Vec<Vec<Vec<Vec<TestRecord>>>>) -> Vec<Vec<Vec<Vec<TestRecord>>>> {
|
||||
arg.push(vec![vec![vec![
|
||||
TestRecord {
|
||||
field_0: 0,
|
||||
field_1: vec![vec![1]],
|
||||
},
|
||||
TestRecord::default(),
|
||||
]]]);
|
||||
|
||||
let mut arg = unsafe { effector::inner_arrays_2(arg) };
|
||||
|
||||
arg.push(vec![vec![vec![
|
||||
TestRecord {
|
||||
field_0: 1,
|
||||
field_1: vec![vec![2]],
|
||||
},
|
||||
TestRecord::default(),
|
||||
]]]);
|
||||
|
||||
arg
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn string_type(mut arg: Vec<String>) -> Vec<String> {
|
||||
arg.push(String::from("fce"));
|
||||
|
||||
let mut arg = unsafe { effector::string_type(arg) };
|
||||
|
||||
arg.push(String::from("test"));
|
||||
arg
|
||||
}
|
||||
|
||||
/*
|
||||
#[fce]
|
||||
pub fn bool_type(arg: Vec<bool>) -> Vec<bool> {
|
||||
let mut arg = unsafe { effector::bool_type(arg) };
|
||||
|
||||
arg.push(false);
|
||||
arg
|
||||
}
|
||||
*/
|
||||
|
||||
#[fce]
|
||||
pub fn f32_type(mut arg: Vec<f32>) -> Vec<f32> {
|
||||
arg.push(0.0);
|
||||
|
||||
let mut arg = unsafe { effector::f32_type(arg) };
|
||||
|
||||
arg.push(1.0);
|
||||
arg
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn f64_type(mut arg: Vec<f64>) -> Vec<f64> {
|
||||
arg.push(0.0);
|
||||
|
||||
let mut arg = unsafe { effector::f64_type(arg) };
|
||||
|
||||
arg.push(1.0);
|
||||
arg
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn u32_type(mut arg: Vec<u32>) -> Vec<u32> {
|
||||
arg.push(0);
|
||||
|
||||
let mut arg = unsafe { effector::u32_type(arg) };
|
||||
|
||||
arg.push(2);
|
||||
arg
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn u64_type(mut arg: Vec<u64>) -> Vec<u64> {
|
||||
arg.push(0);
|
||||
|
||||
let mut arg = unsafe { effector::u64_type(arg) };
|
||||
|
||||
arg.push(2);
|
||||
arg
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn i32_type(mut arg: Vec<i32>) -> Vec<i32> {
|
||||
arg.push(0);
|
||||
|
||||
let mut arg = unsafe { effector::i32_type(arg) };
|
||||
|
||||
arg.push(2);
|
||||
arg
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn i64_type(mut arg: Vec<i64>) -> Vec<i64> {
|
||||
arg.push(0);
|
||||
|
||||
let mut arg = unsafe { effector::i64_type(arg) };
|
||||
|
||||
arg.push(1);
|
||||
arg
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn empty_type() -> Vec<String> {
|
||||
unsafe { effector::empty_type() }
|
||||
}
|
||||
|
||||
mod effector {
|
||||
use fluence::fce;
|
||||
use super::TestRecord;
|
||||
|
||||
#[fce]
|
||||
#[link(wasm_import_module = "arrays_passing_effector")]
|
||||
extern "C" {
|
||||
pub fn inner_arrays_1(arg: Vec<Vec<Vec<Vec<u8>>>>) -> Vec<Vec<Vec<Vec<u8>>>>;
|
||||
|
||||
pub fn inner_arrays_2(
|
||||
arg: Vec<Vec<Vec<Vec<TestRecord>>>>,
|
||||
) -> Vec<Vec<Vec<Vec<TestRecord>>>>;
|
||||
|
||||
pub fn string_type(arg: Vec<String>) -> Vec<String>;
|
||||
|
||||
pub fn byte_type(arg: Vec<u8>) -> Vec<u8>;
|
||||
|
||||
/*
|
||||
pub fn bool_type(arg: Vec<bool>) -> Vec<bool>;
|
||||
*/
|
||||
|
||||
pub fn f32_type(arg: Vec<f32>) -> Vec<f32>;
|
||||
|
||||
pub fn f64_type(arg: Vec<f64>) -> Vec<f64>;
|
||||
|
||||
pub fn u32_type(arg: Vec<u32>) -> Vec<u32>;
|
||||
|
||||
pub fn u64_type(arg: Vec<u64>) -> Vec<u64>;
|
||||
|
||||
pub fn i32_type(arg: Vec<i32>) -> Vec<i32>;
|
||||
|
||||
pub fn i64_type(arg: Vec<i64>) -> Vec<i64>;
|
||||
|
||||
pub fn empty_type() -> Vec<String>;
|
||||
}
|
||||
}
|
153
tests/test_files/basic_argument_passing.rs
Normal file
153
tests/test_files/basic_argument_passing.rs
Normal file
@ -0,0 +1,153 @@
|
||||
#![allow(improper_ctypes)]
|
||||
|
||||
use fluence::fce;
|
||||
|
||||
pub fn main() {}
|
||||
|
||||
#[fce]
|
||||
pub fn all_types(
|
||||
arg_0: i8,
|
||||
arg_1: i16,
|
||||
arg_2: i32,
|
||||
arg_3: i64,
|
||||
arg_4: u8,
|
||||
arg_5: u16,
|
||||
arg_6: u32,
|
||||
arg_7: u64,
|
||||
arg_8: f32,
|
||||
arg_9: f64,
|
||||
arg_10: String,
|
||||
arg_11: Vec<u8>,
|
||||
) -> Vec<u8> {
|
||||
let mut result = unsafe {
|
||||
effector::all_types(
|
||||
arg_0,
|
||||
arg_1,
|
||||
arg_2,
|
||||
arg_3,
|
||||
arg_4,
|
||||
arg_5,
|
||||
arg_6,
|
||||
arg_7,
|
||||
arg_8,
|
||||
arg_9,
|
||||
arg_10.clone(),
|
||||
arg_11.clone(),
|
||||
)
|
||||
};
|
||||
|
||||
result.push(arg_0 as u8);
|
||||
result.extend(safe_transmute::transmute_one_to_bytes(&arg_1));
|
||||
result.extend(safe_transmute::transmute_one_to_bytes(&arg_2));
|
||||
result.extend(safe_transmute::transmute_one_to_bytes(&arg_3));
|
||||
result.extend(safe_transmute::transmute_one_to_bytes(&arg_4));
|
||||
result.extend(safe_transmute::transmute_one_to_bytes(&arg_5));
|
||||
result.extend(safe_transmute::transmute_one_to_bytes(&arg_6));
|
||||
result.extend(safe_transmute::transmute_one_to_bytes(&arg_7));
|
||||
result.extend(&arg_8.to_be_bytes());
|
||||
result.extend(&arg_9.to_be_bytes());
|
||||
result.extend(arg_10.into_bytes());
|
||||
result.extend(arg_11);
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn string_type(arg: String) -> String {
|
||||
let arg = unsafe { effector::string_type(arg) };
|
||||
|
||||
format!("{}_{}", arg, arg)
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn bytearray_type(arg: Vec<u8>) -> Vec<u8> {
|
||||
let mut arg = unsafe { effector::bytearray_type(arg) };
|
||||
|
||||
arg.push(1);
|
||||
arg
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn bool_type(arg: bool) -> bool {
|
||||
unsafe { effector::bool_type(arg) }
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn f32_type(arg: f32) -> f32 {
|
||||
let arg = unsafe { effector::f32_type(arg) };
|
||||
arg + 1.0
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn f64_type(arg: f64) -> f64 {
|
||||
let arg = unsafe { effector::f64_type(arg) };
|
||||
arg + 1.0
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn u32_type(arg: u32) -> u32 {
|
||||
let arg = unsafe { effector::u32_type(arg) };
|
||||
arg + 1
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn u64_type(arg: u64) -> u64 {
|
||||
let arg = unsafe { effector::u64_type(arg) };
|
||||
arg + 1
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn i32_type(arg: i32) -> i32 {
|
||||
let arg = unsafe { effector::i32_type(arg) };
|
||||
arg + 1
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn i64_type(arg: i64) -> i64 {
|
||||
let arg = unsafe { effector::i64_type(arg) };
|
||||
arg + 1
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn empty_type() -> String {
|
||||
unsafe { effector::empty_type() }
|
||||
}
|
||||
|
||||
mod effector {
|
||||
use fluence::fce;
|
||||
|
||||
#[fce]
|
||||
#[link(wasm_import_module = "arguments_passing_effector")]
|
||||
extern "C" {
|
||||
pub fn all_types(
|
||||
arg_0: i8,
|
||||
arg_1: i16,
|
||||
arg_2: i32,
|
||||
arg_3: i64,
|
||||
arg_4: u8,
|
||||
arg_5: u16,
|
||||
arg_6: u32,
|
||||
arg_7: u64,
|
||||
arg_8: f32,
|
||||
arg_9: f64,
|
||||
arg_10: String,
|
||||
arg_11: Vec<u8>,
|
||||
) -> Vec<u8>;
|
||||
|
||||
pub fn string_type(arg: String) -> String;
|
||||
pub fn bytearray_type(arg: Vec<u8>) -> Vec<u8>;
|
||||
|
||||
pub fn bool_type(arg: bool) -> bool;
|
||||
|
||||
pub fn f32_type(arg: f32) -> f32;
|
||||
pub fn f64_type(arg: f64) -> f64;
|
||||
|
||||
pub fn u32_type(arg: u32) -> u32;
|
||||
pub fn u64_type(arg: u64) -> u64;
|
||||
|
||||
pub fn i32_type(arg: i32) -> i32;
|
||||
pub fn i64_type(arg: i64) -> i64;
|
||||
|
||||
pub fn empty_type() -> String;
|
||||
}
|
||||
}
|
0
tests/test_files/records.rs
Normal file
0
tests/test_files/records.rs
Normal file
Loading…
Reference in New Issue
Block a user