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
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
//! Functions for generating Java glue code.

mod jni;
mod types;

use crate::common::{
    self, append_output, check_no_mangle, is_array_arg, is_array_arg_barefn, is_user_data_arg,
    is_user_data_arg_barefn, parse_attr, retrieve_docstring, take_out_pat,
    transform_fnarg_to_argcap, FilterMode, Outputs,
};
use crate::java::types::{callback_name, java_type_to_str, rust_to_java, struct_to_java_classname};
use crate::struct_field::{transform_struct_fields, StructField};
use crate::{Error, Level};
use ::jni::signature::JavaType;
use ::rustfmt::{self, format_input};
use inflector::Inflector;
use quote::*;
use std::collections::{BTreeSet, HashMap, HashSet};
use unwrap::unwrap;

pub struct LangJava {
    context: Context,
    filter: HashSet<String>,
    filter_mode: FilterMode,
}

pub struct Context {
    /// Native library name
    lib_name: String,
    /// Namespace
    namespace: String,
    /// Model namespace (structures go into this one)
    namespace_model: String,
    /// Maps types from Rust to Java
    type_map: HashMap<&'static str, JavaType>,
    /// Keeps track of which JNI callback functions has been generated already
    generated_jni_cbs: BTreeSet<String>,
}

impl Default for Context {
    fn default() -> Self {
        Self {
            lib_name: "safe".to_string(),
            namespace: "net.maidsafe.dummy".to_string(),
            namespace_model: "net.maidsafe.dummy".to_string(),
            type_map: Default::default(),
            generated_jni_cbs: Default::default(),
        }
    }
}

impl LangJava {
    pub fn new(type_map: HashMap<&'static str, JavaType>) -> Self {
        LangJava {
            filter: Default::default(),
            filter_mode: FilterMode::Blacklist,
            context: Context {
                type_map,
                lib_name: "backend".to_owned(),
                namespace: "net.maidsafe.bindings".to_owned(),
                namespace_model: "net.maidsafe.model".to_owned(),
                generated_jni_cbs: BTreeSet::new(),
            },
        }
    }

    /// Set the name of the native library. This also sets the class name.
    pub fn set_lib_name<T: Into<String>>(&mut self, name: T) {
        self.context.lib_name = name.into();
    }

    /// Set the namespace to put the NativeBindings class in.
    pub fn set_namespace<T: Into<String>>(&mut self, namespace: T) {
        self.context.namespace = namespace.into();
    }

    /// Set the namespace to put all structures/classes in.
    pub fn set_model_namespace<T: Into<String>>(&mut self, namespace: T) {
        self.context.namespace_model = namespace.into();
    }

    /// Applies rustfmt to JNI code to improve debuggability
    fn format_jni_output(&self, input: &mut String) {
        let mut output: Vec<u8> = Vec::with_capacity(input.len() * 2);
        let mut cfg = rustfmt::config::Config::default();
        cfg.set().write_mode(rustfmt::config::WriteMode::Plain);
        let (_summary, _, report) =
            format_input(rustfmt::Input::Text(input.clone()), &cfg, Some(&mut output)).unwrap();

        *input = String::from_utf8(output)
            .unwrap_or_else(|_| panic!("Invalid Rustfmt output found: {}", report));
    }

    /// Adds package info to the NativeBindings Java module and indents lines
    fn format_native_functions(&self, funcs: &mut String) {
        // Indent lines
        let lines = funcs.lines().fold(String::new(), |mut output, line| {
            output.push_str(&format!("\t{}\n", line));
            output
        });
        *funcs = format!(
            "package {namespace};\n\n
                         public class NativeBindings {{\n
                         {lines}\n
                         }}",
            namespace = self.context.namespace,
            lines = lines
        );
    }

    /// Add the identifier to the filter.
    /// If the filter mode is `Blacklist` (the default), the identifiers in the
    /// filter are ignored.
    /// If it is `Whitelist`, the identifiers not in the filter are ignored.
    pub fn filter<T: Into<String>>(&mut self, ident: T) {
        let _ = self.filter.insert(ident.into());
    }

    /// Clears the current filter and sets the filter mode.
    pub fn reset_filter(&mut self, filter_mode: FilterMode) {
        self.filter.clear();
        self.filter_mode = filter_mode;
    }

    fn is_ignored(&self, ident: &str) -> bool {
        match self.filter_mode {
            FilterMode::Blacklist => self.filter.contains(ident),
            FilterMode::Whitelist => !self.filter.contains(ident),
        }
    }
}

impl common::Lang for LangJava {
    fn parse_const(
        &mut self,
        _item: &syn::ItemConst,
        _module: &[String],
        _outputs: &mut Outputs,
    ) -> Result<(), Error> {
        Ok(())
    }

    fn parse_ty(
        &mut self,
        _item: &syn::ItemType,
        _module: &[String],
        _outputs: &mut Outputs,
    ) -> Result<(), Error> {
        Ok(())
    }

    fn parse_enum(
        &mut self,
        _item: &syn::ItemEnum,
        _module: &[String],
        _outputs: &mut Outputs,
    ) -> Result<(), Error> {
        Ok(())
    }

    /// Convert a Rust function declaration into Java.
    fn parse_fn(
        &mut self,
        item: &syn::ItemFn,
        _module: &[String],
        outputs: &mut Outputs,
    ) -> Result<(), Error> {
        let ident = &item.ident;
        let name = format!("{}", quote!(#ident));
        if self.is_ignored(name.as_str()) {
            return Ok(());
        }

        let (no_mangle, docs) = parse_attr(&item.attrs[..], check_no_mangle, |attr| {
            retrieve_docstring(attr, "")
        });
        // If it's not #[no_mangle] then it can't be called from C.
        if !no_mangle {
            return Ok(());
        }
        if !common::is_extern(unwrap!(item.to_owned().abi)) {
            // If it doesn't have a C ABI it can't be called from C.
            return Ok(());
        }

        if !item.decl.generics.params.is_empty() {
            return Err(Error {
                level: Level::Error,
                span: None, //NONE FOR NOW
                message: "cheddar cannot handle parameterized extern functions".into(),
            });
        }

        transform_native_fn(
            *item.to_owned().decl,
            &item.attrs[..],
            &docs,
            &name,
            outputs,
            &mut self.context,
        )?;

        Ok(())
    }

    /// Convert a Rust struct into a Java class.
    fn parse_struct(
        &mut self,
        item: &syn::ItemStruct,
        _module: &[String],
        outputs: &mut Outputs,
    ) -> Result<(), Error> {
        let name = item.ident.to_string();
        if self.is_ignored(&name) {
            return Ok(());
        }
        let (repr_c, docs) = parse_attr(&item.attrs, common::check_repr_c, |attr| {
            retrieve_docstring(attr, "")
        });
        // If it's not #[repr(C)] then it can't be called from C.
        if !repr_c {
            return Ok(());
        }

        let mut buffer = String::new();
        buffer.push_str(&format!("package {};\n\n", self.context.namespace));
        buffer.push_str(&docs);

        let orig_name = item.ident.to_owned().to_string();
        let name = struct_to_java_classname(&*orig_name);
        buffer.push_str(&format!("public class {}", name));

        if !item.generics.params.is_empty() {
            return Err(Error {
                level: Level::Error,
                span: None, // NONE FOR NOW
                message: "cheddar cannot handle parameterized `#[repr(C)]` structs".into(),
            });
        }

        let mut vec = vec![];
        for x in item.fields.iter() {
            vec.push(x.clone());
        }
        let struct_fields = transform_struct_fields(vec.as_slice());
        let fields = transform_struct_into_class_fields(&struct_fields, &self.context)?;

        buffer.push_str(" {\n");

        // Class fields
        buffer.push_str(&generate_class_fields(&fields)?);
        buffer.push_str("\n");

        // Default constructor that should initialise object fields
        buffer.push_str(&generate_default_constructor(&name, &fields)?);

        // Parametrised constructor
        buffer.push_str(&generate_parametrised_constructor(&name, &fields)?);

        // Getters & setters
        buffer.push_str(&generate_getters_setters(&fields)?);
        buffer.push_str("}");

        let jni = jni::generate_struct(&struct_fields, &orig_name, &name, &self.context);
        append_output(jni, "jni.rs", outputs);

        buffer.push_str("\n\n");

        outputs.insert(format!("{}.java", name), buffer);

        Ok(())
    }

    fn finalise_output(&mut self, outputs: &mut Outputs) -> Result<(), Error> {
        match outputs.get_mut("jni.rs") {
            Some(input) => {
                self.format_jni_output(input);
            }
            None => {
                return Err(Error {
                    level: Level::Error,
                    span: None, //NONE FOR NOW
                    message: "no jni bindings generated?".to_owned(),
                });
            }
        }

        match outputs.get_mut("NativeBindings.java") {
            Some(input) => {
                self.format_native_functions(input);
                Ok(())
            }
            None => Err(Error {
                level: Level::Error,
                span: None, //NONE FOR NOW
                message: "no native bindings generated?".to_owned(),
            }),
        }
    }
}

/// Contains all information necessary to construct a Java class
/// field, transformed from `StructField`.
struct JavaClassField {
    name: String,
    ty: JavaType,
    ty_str: String,
}

/// Transforms a list of struct fields into Java class fields
fn transform_struct_into_class_fields(
    fields: &[StructField],
    context: &Context,
) -> Result<Vec<JavaClassField>, Error> {
    let mut class_fields = Vec::new();

    for field in fields {
        let name = field.name().to_camel_case();
        let struct_field = field.struct_field().clone();
        let mut ty = rust_to_java(&struct_field.ty, context)?;
        if let StructField::Array { .. } = *field {
            // Wrap a type into an array
            ty = JavaType::Array(Box::new(ty));
        }
        let ty_str = java_type_to_str(&ty)?;

        class_fields.push(JavaClassField { name, ty, ty_str });
    }

    Ok(class_fields)
}

/// Generates getters and setters for a struct transformed into a Java class
fn generate_getters_setters(fields: &[JavaClassField]) -> Result<String, Error> {
    let mut buffer = String::new();

    for field in fields {
        buffer.push_str(&format!(
            "\tpublic {ty} get{capitalized}() {{\n\t\treturn {name};\n\t}}\n\n",
            ty = field.ty_str,
            name = field.name,
            capitalized = field.name.to_class_case(),
        ));
        buffer.push_str(&format!(
            "\tpublic void set{capitalized}(final {ty} val) {{\n\t\tthis.{name} \
             = val;\n\t}}\n\n",
            ty = field.ty_str,
            name = field.name,
            capitalized = field.name.to_class_case(),
        ));
    }

    Ok(buffer)
}

/// Generates fields for a struct transformed into a Java class
fn generate_class_fields(fields: &[JavaClassField]) -> Result<String, Error> {
    let mut buffer = String::new();

    for field in fields {
        buffer.push_str(&format!("\tprivate {} {};\n", field.ty_str, field.name));
    }

    Ok(buffer)
}

/// Generates code for the default constructor initialising class fields with
/// default values
fn generate_default_constructor(
    class_name: &str,
    fields: &[JavaClassField],
) -> Result<String, Error> {
    let mut default_obj_fields = Vec::new();

    for field in fields {
        // Initialise object and array fields with default values to prevent them from being null
        match field.ty {
            JavaType::Array(..) => {
                default_obj_fields.push(format!(
                    "\t\tthis.{name} = new {ty} {{}};",
                    name = field.name,
                    ty = field.ty_str
                ));
            }
            JavaType::Object(ref obj) => {
                default_obj_fields.push(format!(
                    "\t\tthis.{name} = new {obj}();",
                    name = field.name,
                    obj = obj
                ));
            }
            _ => (),
        }
    }
    Ok(format!(
        "\tpublic {name}() {{\n{default_obj_fields}\n\t}}\n",
        name = class_name,
        default_obj_fields = default_obj_fields.join("\n")
    ))
}

/// Generates code for the parametrised constructor (which is taking arguments to
/// initialise default values)
fn generate_parametrised_constructor(
    class_name: &str,
    fields: &[JavaClassField],
) -> Result<String, Error> {
    let mut constructor_fields = Vec::new();
    let mut constructor_assignments = Vec::new();

    for field in fields {
        constructor_fields.push(format!("{} {}", field.ty_str, field.name));
        constructor_assignments.push(format!("\t\tthis.{name} = {name};", name = field.name));
    }

    Ok(format!(
        "\tpublic {name}({constructor_fields}) {{\n{constructor_assignments}\n\t}}\n",
        name = class_name,
        constructor_fields = constructor_fields.join(", "),
        constructor_assignments = constructor_assignments.join("\n")
    ))
}

/// Transform a Rust FFI function into a Java native function
pub fn transform_native_fn(
    fn_decl: syn::FnDecl,
    attrs: &[syn::Attribute],
    docs: &str,
    name: &str,
    outputs: &mut Outputs,
    context: &mut Context,
) -> Result<(), Error> {
    let mut args_str = Vec::new();

    let mut fn_args = fn_decl
        .inputs
        .iter()
        .filter(|arg| !is_user_data_arg(&unwrap!(transform_fnarg_to_argcap(*arg))))
        .peekable();

    while let Some(arg) = fn_args.next() {
        let pat = take_out_pat(&unwrap!(transform_fnarg_to_argcap(arg)).pat);
        let arg_name = unwrap!(pat).ident.to_string();

        // Generate function arguments
        let mut java_type = rust_to_java(&unwrap!(transform_fnarg_to_argcap(arg)).ty, context)?;
        let next_arg: Option<&syn::ArgCaptured> = if fn_args.peek().is_some() {
            Some(unwrap!(transform_fnarg_to_argcap(unwrap!(fn_args.peek()))))
        } else {
            None
        };
        if is_array_arg(unwrap!(transform_fnarg_to_argcap(arg)), next_arg) {
            // Skip the length args - e.g. for a case of `ptr: *const u8, ptr_len: usize`
            // we're going to skip the `len` part.
            java_type = JavaType::Array(Box::new(java_type));
            fn_args.next();
        }

        let java_type = java_type_to_str(&java_type)?;
        args_str.push(format!("{} {}", java_type, arg_name.to_camel_case()));
        let argcap = unwrap!(transform_fnarg_to_argcap(arg));
        // Generate a callback class - if it wasn't generated already
        if let syn::Type::BareFn(ref bare_fn) = argcap.ty {
            let mut vec = vec![];
            for input in bare_fn.inputs.to_owned() {
                vec.push(input);
            }
            let cb_class = callback_name(&vec.as_slice(), context)?;
            let cb_file = format!("{}.java", cb_class);

            if outputs.get(&cb_file).is_none() {
                eprintln!("Generating CB {}", cb_class);

                let cb_output = transform_callback(&argcap.ty, &cb_class, context)?;
                let _ = outputs.insert(cb_file, cb_output);

                // Generate JNI callback fn
                let jni_cb_name = format!("call_{}", cb_class);
                if !context.generated_jni_cbs.contains(&jni_cb_name) {
                    let mut jni = jni::generate_jni_callback(bare_fn, &jni_cb_name, context);
                    jni.push_str("\n");

                    append_output(jni, "jni.rs", outputs);
                    context.generated_jni_cbs.insert(jni_cb_name);
                }
            }
        }
    }

    let output_type = &fn_decl.output;
    let return_type = match &*output_type {
        syn::ReturnType::Type(_, ref ty) if check_type_never(&*ty) => {
            return Err(Error {
                level: Level::Error,
                span: None, //NONE FOR NOW
                message: "panics across a C boundary are naughty!".into(),
            });
        }
        syn::ReturnType::Default => String::from("public static native void"),
        syn::ReturnType::Type(_, ref ty) => {
            java_type_to_str(&unwrap!(rust_to_java(&*ty, context)))?
        }
    };

    let java_name = name.to_camel_case();
    let func_decl = format!(
        "{} {}({})",
        return_type,
        &java_name,
        args_str.as_slice().join(", ")
    );

    let mut buffer = String::new();
    buffer.push_str("/**\n");
    buffer.push_str(&docs.replace("///", " *"));
    buffer.push_str(" */\n");
    buffer.push_str(&func_decl);
    buffer.push_str(";\n\n");

    append_output(buffer, "NativeBindings.java", outputs);

    // Append the function declaration to import it as an "extern fn"
    let mut fn_attrs = String::new();
    for attr in attrs {
        if attr.into_token_stream().to_owned().to_string() == "cfg" {
            fn_attrs.push_str(&attr.into_token_stream().to_owned().to_string());
        }
    }
    let args: Vec<_> = fn_decl
        .inputs
        .iter()
        .map(|arg| {
            unwrap!(transform_fnarg_to_argcap(arg))
                .into_token_stream()
                .to_string()
        })
        .collect();

    let fn_declaration = format!("fn {}({})", name, args.join(", "));

    let mut jni = format!(
        "\n{attrs}#[link(name = \"{libname}\")]\nextern {{ {fndecl}; }}\n",
        attrs = fn_attrs,
        libname = context.lib_name,
        fndecl = fn_declaration,
    );
    let vec: Vec<_> = fn_decl.inputs.iter().cloned().collect();
    // Generate the JNI part of the interface
    jni.push_str(&jni::generate_jni_function(
        &vec, attrs, name, &java_name, context, outputs,
    ));
    jni.push_str("\n");
    append_output(jni, "jni.rs", outputs);

    Ok(())
}

fn check_type_never(ty: &syn::Type) -> bool {
    matches!(ty, syn::Type::Never(ref _never))
}

/// Turn a Rust callback function type into a Java interface.
pub fn transform_callback<S: AsRef<str>>(
    ty: &syn::Type,
    class_name: S,
    context: &Context,
) -> Result<String, Error> {
    match ty {
        syn::Type::BareFn(ref bare_fn) => Ok(format!(
            "package {namespace};\n\n\
             public interface {name} {{\n\
             \tpublic void call({types});\n}}\n",
            namespace = context.namespace_model,
            name = class_name.as_ref(),
            types = callback_to_java(bare_fn, context)?,
        )),
        // All other types just have a name associated with them.
        _ => Err(Error {
            level: Level::Error,
            span: None, //NONE FOR NOW
            message: "Invalid callback type".into(),
        }),
    }
}

/// Transform a Rust FFI callback into Java function signature
fn callback_to_java(fn_ty: &syn::TypeBareFn, context: &Context) -> Result<String, Error> {
    match unwrap!(unwrap!(fn_ty.to_owned().abi).name).value().as_str() {
        // If it doesn't have a C ABI it can't be called from C.
        "C" | "Cdecl" | "Stdcall" | "Fastcall" | "System" => {}
        _ => {
            return Err(Error {
                level: Level::Error,
                span: None, //NONE FOR NOW
                message: "callbacks that don't have C ABI are not supported".into(),
            });
        }
    }

    if fn_ty.to_owned().lifetimes.is_some() {
        return Err(Error {
            level: Level::Error,
            span: None, //NONE FOR NOW
            message: "cannot handle lifetimes".into(),
        });
    }

    let mut args = Vec::new();

    let mut args_iter = fn_ty
        .inputs
        .iter()
        .filter(|arg| !is_user_data_arg_barefn(arg))
        .peekable();

    while let Some(arg) = args_iter.next() {
        let arg_name = unwrap!(arg.to_owned().name)
            .0
            .into_token_stream()
            .to_string();
        let mut java_type = rust_to_java(&arg.ty, context)?;

        if is_array_arg_barefn(arg, args_iter.peek().cloned()) {
            // Detect array ptrs: skip the length args and add array to the type sig
            java_type = JavaType::Array(Box::new(java_type));
            args_iter.next();
        }

        let java_type = java_type_to_str(&java_type)?;
        args.push(format!("{} {}", java_type, arg_name.to_camel_case()));
    }

    Ok(args.join(", "))
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn cb_names() {
        fn get_inputs(source: &str) -> Vec<syn::BareFnArg> {
            let item: syn::TypeBareFn = unwrap!(syn::parse_str(source));
            item.inputs.into_iter().collect()
        }

        let context = Context {
            type_map: HashMap::new(),
            lib_name: "backend".to_owned(),
            namespace: "net.maidsafe.bindings".to_owned(),
            namespace_model: "net.maidsafe.model".to_owned(),
            generated_jni_cbs: BTreeSet::new(),
        };

        let inputs = get_inputs("fn ()");
        assert_eq!("CallbackVoid", unwrap!(callback_name(&inputs, &context)));

        let inputs = get_inputs("fn (user_data: *mut c_void, result: *const FfiResult)");
        assert_eq!("CallbackResult", unwrap!(callback_name(&inputs, &context)));

        let inputs =
            get_inputs("fn (user_data: *mut c_void, result: *const FfiResult, b: u64, c: u32)");
        assert_eq!(
            "CallbackResultLongInt",
            unwrap!(callback_name(&inputs, &context))
        );

        let inputs =
            get_inputs("fn (user_data: *mut c_void, result: *const FfiResult, b: *const MyStruct)");
        assert_eq!(
            "CallbackResultMyStruct",
            unwrap!(callback_name(&inputs, &context))
        );

        let inputs =
            get_inputs("fn (user_data: *mut c_void, result: *const FfiResult, b: *const c_char)");
        assert_eq!(
            "CallbackResultString",
            unwrap!(callback_name(&inputs, &context))
        );

        let inputs = get_inputs(
            "fn (user_data: *mut c_void, result: *const FfiResult, a: *const Foo, a_len: usize)",
        );
        assert_eq!(
            "CallbackResultFooArrayLen",
            unwrap!(callback_name(&inputs, &context))
        );
    }
}