test(tests): Update `expected.md` files

This commit is contained in:
Benedikt Peetz 2024-03-27 22:26:21 +01:00
parent a766149521
commit 5a9de1ac0a
Signed by: bpeetz
GPG Key ID: A5E94010C3A642AD
9 changed files with 420 additions and 144 deletions

View File

@ -19,15 +19,29 @@ pub mod trinitrix {
}
}
/* C API */
pub mod trinitrix_c {}
pub mod trinitrix_c {
#[allow(unused_imports)]
use crate::callback_function;
}
#[no_mangle]
pub extern "C" fn trinitrix_hi(
output: *mut trixy::types::String,
name: String,
name: trixy::types::String,
) -> core::ffi::c_int {
let output_val: trixy::types::String = {
let (tx, rx) = trixy::oneshot::channel();
callback_function(trinitrix_hi);
callback_function(
Commands::Trinitrix(crate::trinitrix::Trinitrix::hi {
trixy_output: tx,
name: match name.try_into() {
Ok(ok) => ok,
Err(err) => {
trixy::types::traits::errno::set(err.into());
return 0;
}
},
}),
);
let recv = rx
.recv()
.expect("The channel should not be closed until this value is received");

View File

@ -19,15 +19,29 @@ pub mod trinitrix {
}
}
/* C API */
pub mod trinitrix_c {}
pub mod trinitrix_c {
#[allow(unused_imports)]
use crate::callback_function;
}
#[no_mangle]
pub extern "C" fn trinitrix_hi(
output: *mut trixy::types::String,
name: String,
name: trixy::types::String,
) -> core::ffi::c_int {
let output_val: trixy::types::String = {
let (tx, rx) = trixy::oneshot::channel();
callback_function(trinitrix_hi);
callback_function(
Commands::Trinitrix(crate::trinitrix::Trinitrix::hi {
trixy_output: tx,
name: match name.try_into() {
Ok(ok) => ok,
Err(err) => {
trixy::types::traits::errno::set(err.into());
return 0;
}
},
}),
);
let recv = rx
.recv()
.expect("The channel should not be closed until this value is received");

View File

@ -17,7 +17,10 @@ pub mod test {
pub enum Test {}
}
/* C API */
pub mod test_c {}
pub mod test_c {
#[allow(unused_imports)]
use crate::callback_function;
}
// vim: filetype=rust
```

View File

@ -9,7 +9,9 @@ File path: `out/dir/api.rs`
pub enum Commands {
/// Call out an outstanding person
#[allow(non_camel_case_types)]
call_me_back_outstanding { callback: fn(String) -> String },
call_me_back_outstanding {
callback: extern "C" fn(trixy::types::String) -> trixy::types::String,
},
One(one::One),
}
pub mod one {
@ -17,21 +19,44 @@ pub mod one {
pub enum One {
/// Call out a person
#[allow(non_camel_case_types)]
call_me_back { callback: fn(u32) },
call_me_back { callback: extern "C" fn(trixy::types::u32) },
}
}
/* C API */
#[no_mangle]
pub extern "C" fn call_me_back_outstanding(
callback: fn(String) -> String,
callback: extern "C" fn(trixy::types::String) -> trixy::types::String,
) -> core::ffi::c_int {
callback_function(call_me_back_outstanding);
callback_function(crate::Commands::call_me_back_outstanding {
callback: match callback.try_into() {
Ok(ok) => ok,
Err(err) => {
trixy::types::traits::errno::set(err.into());
return 0;
}
},
});
return 1;
}
pub mod one_c {}
pub mod one_c {
#[allow(unused_imports)]
use crate::callback_function;
}
#[no_mangle]
pub extern "C" fn one_call_me_back(callback: fn(u32)) -> core::ffi::c_int {
callback_function(one_call_me_back);
pub extern "C" fn one_call_me_back(
callback: extern "C" fn(trixy::types::u32),
) -> core::ffi::c_int {
callback_function(
crate::Commands::One(crate::one::One::call_me_back {
callback: match callback.try_into() {
Ok(ok) => ok,
Err(err) => {
trixy::types::traits::errno::set(err.into());
return 0;
}
},
}),
);
return 1;
}
// vim: filetype=rust
@ -61,7 +86,7 @@ extern int one_call_me_back (void (*callback) (uint32_t));
struct one
{
int (*call_me_back) ();
int (*call_me_back) (void (*callback) (uint32_t));
};
const struct one one = {

View File

@ -22,15 +22,29 @@ pub mod trinitrix {
}
}
/* C API */
pub mod trinitrix_c {}
pub mod trinitrix_c {
#[allow(unused_imports)]
use crate::callback_function;
}
#[no_mangle]
pub extern "C" fn trinitrix_hi(
output: *mut trixy::types::String,
name: String,
name: trixy::types::String,
) -> core::ffi::c_int {
let output_val: trixy::types::String = {
let (tx, rx) = trixy::oneshot::channel();
callback_function(trinitrix_hi);
callback_function(
Commands::Trinitrix(crate::trinitrix::Trinitrix::hi {
trixy_output: tx,
name: match name.try_into() {
Ok(ok) => ok,
Err(err) => {
trixy::types::traits::errno::set(err.into());
return 0;
}
},
}),
);
let recv = rx
.recv()
.expect("The channel should not be closed until this value is received");

View File

@ -12,7 +12,7 @@ pub enum Commands {
pub mod trinitrix {
#[derive(Debug)]
pub enum Trinitrix {
Std(std::Std),
Stdi(stdi::Stdi),
Api(api::Api),
}
/// Language specific functions, which mirror the `trinitrix.api` namespace.
@ -20,9 +20,9 @@ pub mod trinitrix {
/// one as it will most likely be more high-level and easier to use (as it isn't abstracted
/// over multiple languages). Feel free to drop down to the lower level api, if you feel
/// like that more, it should be as stable and user-oriented as the `std` functions
pub mod std {
pub mod stdi {
#[derive(Debug)]
pub enum Std {}
pub enum Stdi {}
}
/// General API to change stuff in Trinitrix
pub mod api {
@ -54,9 +54,9 @@ pub mod trinitrix {
impl From<crate::trinitrix_c::api_c::ui_c::Mode_c> for Mode {
fn from(value: crate::trinitrix_c::api_c::ui_c::Mode_c) -> Self {
match value {
Mode_c::Normal => Self::Normal,
Mode_c::Insert => Self::Insert,
Mode_c::Command => Self::Command,
crate::trinitrix_c::api_c::ui_c::Mode_c::Normal => Self::Normal,
crate::trinitrix_c::api_c::ui_c::Mode_c::Insert => Self::Insert,
crate::trinitrix_c::api_c::ui_c::Mode_c::Command => Self::Command,
}
}
}
@ -105,7 +105,7 @@ pub mod trinitrix {
pub enum Keymaps {
/// Add a new keymapping
#[allow(non_camel_case_types)]
add { mode: String, key: String, callback: fn() },
add { mode: String, key: String, callback: extern "C" fn() },
/// Remove a keymapping
///
/// Does nothing, if the keymapping doesn't exists yet
@ -147,20 +147,19 @@ pub mod trinitrix {
}
}
/* C API */
pub mod trinitrix_c {}
pub mod std_c {}
pub mod api_c {}
#[no_mangle]
pub extern "C" fn trinitrix_api_exit() -> core::ffi::c_int {
callback_function(trinitrix_api_exit);
return 1;
}
#[no_mangle]
pub extern "C" fn trinitrix_api_room_message_send(message: String) -> core::ffi::c_int {
callback_function(trinitrix_api_room_message_send);
return 1;
pub mod trinitrix_c {
#[allow(unused_imports)]
use crate::callback_function;
pub mod stdi_c {
#[allow(unused_imports)]
use crate::callback_function;
}
pub mod api_c {
#[allow(unused_imports)]
use crate::callback_function;
pub mod ui_c {
#[allow(unused_imports)]
use crate::callback_function;
#[allow(non_camel_case_types)]
#[repr(C)]
#[derive(Debug)]
@ -175,76 +174,252 @@ pub mod ui_c {
impl From<crate::trinitrix::api::ui::Mode> for Mode_c {
fn from(value: crate::trinitrix::api::ui::Mode) -> Self {
match value {
Mode::Normal => Self::Normal,
Mode::Insert => Self::Insert,
Mode::Command => Self::Command,
crate::trinitrix::api::ui::Mode::Normal => Self::Normal,
crate::trinitrix::api::ui::Mode::Insert => Self::Insert,
crate::trinitrix::api::ui::Mode::Command => Self::Command,
}
}
}
}
#[no_mangle]
pub extern "C" fn trinitrix_api_ui_set_mode(
mode: crate::trinitrix::api::ui::Mode,
mode: crate::trinitrix_c::api_c::ui_c::Mode_c,
) -> core::ffi::c_int {
callback_function(trinitrix_api_ui_set_mode);
callback_function(
crate::Commands::Trinitrix(
crate::trinitrix::Trinitrix::Api(
crate::trinitrix::api::Api::Ui(crate::trinitrix::api::ui::Ui::set_mode {
mode: match mode.try_into() {
Ok(ok) => ok,
Err(err) => {
trixy::types::traits::errno::set(err.into());
return 0;
}
},
}),
),
),
);
return 1;
}
#[no_mangle]
pub extern "C" fn trinitrix_api_ui_cycle_planes() -> core::ffi::c_int {
callback_function(trinitrix_api_ui_cycle_planes);
callback_function(
crate::Commands::Trinitrix(
crate::trinitrix::Trinitrix::Api(
crate::trinitrix::api::Api::Ui(
crate::trinitrix::api::ui::Ui::cycle_planes,
),
),
),
);
return 1;
}
#[no_mangle]
pub extern "C" fn trinitrix_api_ui_cycle_planes_rev() -> core::ffi::c_int {
callback_function(trinitrix_api_ui_cycle_planes_rev);
callback_function(
crate::Commands::Trinitrix(
crate::trinitrix::Trinitrix::Api(
crate::trinitrix::api::Api::Ui(
crate::trinitrix::api::ui::Ui::cycle_planes_rev,
),
),
),
);
return 1;
}
pub mod keymaps_c {}
pub mod keymaps_c {
#[allow(unused_imports)]
use crate::callback_function;
}
#[no_mangle]
pub extern "C" fn trinitrix_api_keymaps_add(
mode: String,
key: String,
callback: fn(),
mode: trixy::types::String,
key: trixy::types::String,
callback: extern "C" fn(),
) -> core::ffi::c_int {
callback_function(trinitrix_api_keymaps_add);
callback_function(
crate::Commands::Trinitrix(
crate::trinitrix::Trinitrix::Api(
crate::trinitrix::api::Api::Keymaps(crate::trinitrix::api::keymaps::Keymaps::add {
mode: match mode.try_into() {
Ok(ok) => ok,
Err(err) => {
trixy::types::traits::errno::set(err.into());
return 0;
}
},
key: match key.try_into() {
Ok(ok) => ok,
Err(err) => {
trixy::types::traits::errno::set(err.into());
return 0;
}
},
callback: match callback.try_into() {
Ok(ok) => ok,
Err(err) => {
trixy::types::traits::errno::set(err.into());
return 0;
}
},
}),
),
),
);
return 1;
}
#[no_mangle]
pub extern "C" fn trinitrix_api_keymaps_remove(
mode: String,
key: String,
mode: trixy::types::String,
key: trixy::types::String,
) -> core::ffi::c_int {
callback_function(trinitrix_api_keymaps_remove);
callback_function(
crate::Commands::Trinitrix(
crate::trinitrix::Trinitrix::Api(
crate::trinitrix::api::Api::Keymaps(crate::trinitrix::api::keymaps::Keymaps::remove {
mode: match mode.try_into() {
Ok(ok) => ok,
Err(err) => {
trixy::types::traits::errno::set(err.into());
return 0;
}
},
key: match key.try_into() {
Ok(ok) => ok,
Err(err) => {
trixy::types::traits::errno::set(err.into());
return 0;
}
},
}),
),
),
);
return 1;
}
#[no_mangle]
pub extern "C" fn trinitrix_api_keymaps_get(mode: String) -> core::ffi::c_int {
callback_function(trinitrix_api_keymaps_get);
pub extern "C" fn trinitrix_api_keymaps_get(
mode: trixy::types::String,
) -> core::ffi::c_int {
callback_function(
crate::Commands::Trinitrix(
crate::trinitrix::Trinitrix::Api(
crate::trinitrix::api::Api::Keymaps(crate::trinitrix::api::keymaps::Keymaps::get {
mode: match mode.try_into() {
Ok(ok) => ok,
Err(err) => {
trixy::types::traits::errno::set(err.into());
return 0;
}
},
}),
),
),
);
return 1;
}
pub mod raw_c {}
pub mod raw_c {
#[allow(unused_imports)]
use crate::callback_function;
pub mod __private_c {
#[allow(unused_imports)]
use crate::callback_function;
}
}
#[no_mangle]
pub extern "C" fn trinitrix_api_raw_raise_error(
error_message: String,
error_message: trixy::types::String,
) -> core::ffi::c_int {
callback_function(trinitrix_api_raw_raise_error);
callback_function(
crate::Commands::Trinitrix(
crate::trinitrix::Trinitrix::Api(
crate::trinitrix::api::Api::Raw(crate::trinitrix::api::raw::Raw::raise_error {
error_message: match error_message.try_into() {
Ok(ok) => ok,
Err(err) => {
trixy::types::traits::errno::set(err.into());
return 0;
}
},
}),
),
),
);
return 1;
}
#[no_mangle]
pub extern "C" fn trinitrix_api_raw_display_output(
output_message: String,
output_message: trixy::types::String,
) -> core::ffi::c_int {
callback_function(trinitrix_api_raw_display_output);
callback_function(
crate::Commands::Trinitrix(
crate::trinitrix::Trinitrix::Api(
crate::trinitrix::api::Api::Raw(crate::trinitrix::api::raw::Raw::display_output {
output_message: match output_message.try_into() {
Ok(ok) => ok,
Err(err) => {
trixy::types::traits::errno::set(err.into());
return 0;
}
},
}),
),
),
);
return 1;
}
#[no_mangle]
pub extern "C" fn trinitrix_api_raw_send_input_unprocessed(
input: String,
input: trixy::types::String,
) -> core::ffi::c_int {
callback_function(trinitrix_api_raw_send_input_unprocessed);
callback_function(
crate::Commands::Trinitrix(
crate::trinitrix::Trinitrix::Api(
crate::trinitrix::api::Api::Raw(crate::trinitrix::api::raw::Raw::send_input_unprocessed {
input: match input.try_into() {
Ok(ok) => ok,
Err(err) => {
trixy::types::traits::errno::set(err.into());
return 0;
}
},
}),
),
),
);
return 1;
}
pub mod __private_c {}
}
#[no_mangle]
pub extern "C" fn trinitrix_api_exit() -> core::ffi::c_int {
callback_function(
crate::Commands::Trinitrix(
crate::trinitrix::Trinitrix::Api(crate::trinitrix::api::Api::exit),
),
);
return 1;
}
#[no_mangle]
pub extern "C" fn trinitrix_api_room_message_send(
message: trixy::types::String,
) -> core::ffi::c_int {
callback_function(
crate::Commands::Trinitrix(
crate::trinitrix::Trinitrix::Api(crate::trinitrix::api::Api::room_message_send {
message: match message.try_into() {
Ok(ok) => ok,
Err(err) => {
trixy::types::traits::errno::set(err.into());
return 0;
}
},
}),
),
);
return 1;
}
}
// vim: filetype=rust
```
@ -347,7 +522,7 @@ extern int trinitrix_api_raw_send_input_unprocessed (const char *input);
* the lower level api, if you feel like that more, it should be as stable and
* user-oriented as the `std` functions
*/
struct std
struct stdi
{
};
@ -356,7 +531,7 @@ struct std
*/
struct ui
{
int (*set_mode) ();
int (*set_mode) (enum Mode);
int (*cycle_planes) (void);
int (*cycle_planes_rev) (void);
};
@ -392,9 +567,9 @@ struct ui
*/
struct keymaps
{
int (*add) ();
int (*remove) ();
int (*get) ();
int (*add) (const char *, const char *, void (*callback) ());
int (*remove) (const char *, const char *);
int (*get) (const char *);
};
/**
@ -413,9 +588,9 @@ struct __private
*/
struct raw
{
int (*raise_error) ();
int (*display_output) ();
int (*send_input_unprocessed) ();
int (*raise_error) (const char *);
int (*display_output) (const char *);
int (*send_input_unprocessed) (const char *);
struct __private __private;
};
@ -425,7 +600,7 @@ struct raw
struct api
{
int (*exit) (void);
int (*room_message_send) ();
int (*room_message_send) (const char *);
struct ui ui;
struct keymaps keymaps;
struct raw raw;
@ -433,11 +608,11 @@ struct api
struct trinitrix
{
struct std std;
struct stdi stdi;
struct api api;
};
const struct std std = {};
const struct stdi stdi = {};
const struct ui ui = {
.set_mode = trinitrix_api_ui_set_mode,
.cycle_planes = trinitrix_api_ui_cycle_planes,
@ -463,7 +638,7 @@ const struct api api = {
.raw = raw,
};
const struct trinitrix trinitrix = {
.std = std,
.stdi = stdi,
.api = api,
};

View File

@ -33,7 +33,7 @@ mod trinitrix {
/// one as it will most likely be more high-level and easier to use (as it isn't abstracted
/// over multiple languages). Feel free to drop down to the lower level api, if you feel
/// like that more, it should be as stable and user-oriented as the `std` functions
mod std {}
mod stdi {}
/// General API to change stuff in Trinitrix
mod api {

View File

@ -15,7 +15,7 @@ pub mod test {
#[derive(Debug)]
pub struct Callback {
/// Very important field
pub func: fn(String) -> String,
pub func: extern "C" fn(trixy::types::String) -> trixy::types::String,
/// Very important field for keeping time constant
pub timeout: u32,
}
@ -58,9 +58,9 @@ pub mod test {
impl From<crate::test_c::CallbackPriority_c> for CallbackPriority {
fn from(value: crate::test_c::CallbackPriority_c) -> Self {
match value {
CallbackPriority_c::High => Self::High,
CallbackPriority_c::Medium => Self::Medium,
CallbackPriority_c::Low => Self::Low,
crate::test_c::CallbackPriority_c::High => Self::High,
crate::test_c::CallbackPriority_c::Medium => Self::Medium,
crate::test_c::CallbackPriority_c::Low => Self::Low,
}
}
}
@ -75,6 +75,8 @@ pub mod test {
}
/* C API */
pub mod test_c {
#[allow(unused_imports)]
use crate::callback_function;
/// Same thing as above (and a enum doc comment test)
#[allow(non_camel_case_types)]
#[repr(C)]
@ -92,9 +94,9 @@ pub mod test_c {
impl From<crate::test::CallbackPriority> for CallbackPriority_c {
fn from(value: crate::test::CallbackPriority) -> Self {
match value {
CallbackPriority::High => Self::High,
CallbackPriority::Medium => Self::Medium,
CallbackPriority::Low => Self::Low,
crate::test::CallbackPriority::High => Self::High,
crate::test::CallbackPriority::Medium => Self::Medium,
crate::test::CallbackPriority::Low => Self::Low,
}
}
}
@ -104,17 +106,43 @@ pub mod test_c {
#[derive(Debug)]
pub struct Callback_c {
/// Very important field
pub func: fn(String) -> String,
pub func: extern "C" fn(trixy::types::String) -> trixy::types::String,
/// Very important field for keeping time constant
pub timeout: trixy::types::u32,
}
impl TryFrom<crate::test::Callback> for Callback_c {
type Error = trixy::types::error::TypeConversionError;
fn try_from(value: crate::test::Callback) -> Result<Self, Self::Error> {
Ok(Self {
func: value.func.try_into()?,
timeout: value.timeout.try_into()?,
})
}
}
}
#[no_mangle]
pub extern "C" fn test_execute_callback(
callback: crate::test::Callback,
priority: crate::test::CallbackPriority,
callback: crate::test_c::Callback_c,
priority: crate::test_c::CallbackPriority_c,
) -> core::ffi::c_int {
callback_function(test_execute_callback);
callback_function(
crate::Commands::Test(crate::test::Test::execute_callback {
callback: match callback.try_into() {
Ok(ok) => ok,
Err(err) => {
trixy::types::traits::errno::set(err.into());
return 0;
}
},
priority: match priority.try_into() {
Ok(ok) => ok,
Err(err) => {
trixy::types::traits::errno::set(err.into());
return 0;
}
},
}),
);
return 1;
}
// vim: filetype=rust
@ -173,7 +201,7 @@ extern int test_execute_callback (struct Callback callback,
struct test
{
int (*execute_callback) ();
int (*execute_callback) (struct Callback, enum CallbackPriority);
};
const struct test test = {

View File

@ -17,7 +17,10 @@ pub mod trinitrix {
pub enum Trinitrix {}
}
/* C API */
pub mod trinitrix_c {}
pub mod trinitrix_c {
#[allow(unused_imports)]
use crate::callback_function;
}
// vim: filetype=rust
```