@@ -51,6 +51,7 @@ impl CTestTemplate {
51
51
/// Stores all information necessary for generation of tests for all items.
52
52
#[ derive( Clone , Debug , Default ) ]
53
53
pub ( crate ) struct TestTemplate {
54
+ pub foreign_static_tests : Vec < TestForeignStatic > ,
54
55
pub field_ptr_tests : Vec < TestFieldPtr > ,
55
56
pub field_size_offset_tests : Vec < TestFieldSizeOffset > ,
56
57
pub roundtrip_tests : Vec < TestRoundtrip > ,
@@ -78,6 +79,7 @@ impl TestTemplate {
78
79
template. populate_field_ptr_tests ( & helper) ?;
79
80
template. populate_roundtrip_tests ( & helper) ?;
80
81
template. populate_foreign_fn_tests ( & helper) ?;
82
+ template. populate_foreign_static_tests ( & helper) ?;
81
83
82
84
Ok ( template)
83
85
}
@@ -415,6 +417,28 @@ impl TestTemplate {
415
417
416
418
Ok ( ( ) )
417
419
}
420
+
421
+ /// Populates tests for foreign statics, keeping track of the names of each test.
422
+ fn populate_foreign_static_tests (
423
+ & mut self ,
424
+ helper : & TranslateHelper ,
425
+ ) -> Result < ( ) , TranslationError > {
426
+ for static_ in helper. ffi_items . foreign_statics ( ) {
427
+ let rust_ty = static_. ty . to_token_stream ( ) . to_string ( ) . into_boxed_str ( ) ;
428
+
429
+ let item = TestForeignStatic {
430
+ test_name : static_test_ident ( static_. ident ( ) ) ,
431
+ id : static_. ident ( ) . into ( ) ,
432
+ c_val : helper. c_ident ( static_) . into_boxed_str ( ) ,
433
+ rust_ty,
434
+ } ;
435
+
436
+ self . foreign_static_tests . push ( item. clone ( ) ) ;
437
+ self . test_idents . push ( item. test_name ) ;
438
+ }
439
+
440
+ Ok ( ( ) )
441
+ }
418
442
}
419
443
420
444
/* Many test structures have the following fields:
@@ -499,6 +523,14 @@ pub(crate) struct TestForeignFn {
499
523
pub id : BoxStr ,
500
524
}
501
525
526
+ #[ derive( Clone , Debug ) ]
527
+ pub ( crate ) struct TestForeignStatic {
528
+ pub test_name : BoxStr ,
529
+ pub id : BoxStr ,
530
+ pub c_val : BoxStr ,
531
+ pub rust_ty : BoxStr ,
532
+ }
533
+
502
534
fn signededness_test_ident ( ident : & str ) -> BoxStr {
503
535
format ! ( "ctest_signededness_{ident}" ) . into ( )
504
536
}
@@ -531,6 +563,10 @@ fn foreign_fn_test_ident(ident: &str) -> BoxStr {
531
563
format ! ( "ctest_foreign_fn_{ident}" ) . into ( )
532
564
}
533
565
566
+ fn static_test_ident ( ident : & str ) -> BoxStr {
567
+ format ! ( "ctest_static_{ident}" ) . into ( )
568
+ }
569
+
534
570
/// Wrap methods that depend on both ffi items and the generator.
535
571
pub ( crate ) struct TranslateHelper < ' a > {
536
572
filtered_ffi_items : FfiItems ,
0 commit comments