@@ -51,6 +51,7 @@ impl CTestTemplate {
5151/// Stores all information necessary for generation of tests for all items.
5252#[ derive( Clone , Debug , Default ) ]
5353pub ( crate ) struct TestTemplate {
54+ pub foreign_static_tests : Vec < TestForeignStatic > ,
5455 pub field_ptr_tests : Vec < TestFieldPtr > ,
5556 pub field_size_offset_tests : Vec < TestFieldSizeOffset > ,
5657 pub roundtrip_tests : Vec < TestRoundtrip > ,
@@ -78,6 +79,7 @@ impl TestTemplate {
7879 template. populate_field_ptr_tests ( & helper) ?;
7980 template. populate_roundtrip_tests ( & helper) ?;
8081 template. populate_foreign_fn_tests ( & helper) ?;
82+ template. populate_foreign_static_tests ( & helper) ?;
8183
8284 Ok ( template)
8385 }
@@ -415,6 +417,28 @@ impl TestTemplate {
415417
416418 Ok ( ( ) )
417419 }
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+ }
418442}
419443
420444/* Many test structures have the following fields:
@@ -499,6 +523,14 @@ pub(crate) struct TestForeignFn {
499523 pub id : BoxStr ,
500524}
501525
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+
502534fn signededness_test_ident ( ident : & str ) -> BoxStr {
503535 format ! ( "ctest_signededness_{ident}" ) . into ( )
504536}
@@ -531,6 +563,10 @@ fn foreign_fn_test_ident(ident: &str) -> BoxStr {
531563 format ! ( "ctest_foreign_fn_{ident}" ) . into ( )
532564}
533565
566+ fn static_test_ident ( ident : & str ) -> BoxStr {
567+ format ! ( "ctest_static_{ident}" ) . into ( )
568+ }
569+
534570/// Wrap methods that depend on both ffi items and the generator.
535571pub ( crate ) struct TranslateHelper < ' a > {
536572 filtered_ffi_items : FfiItems ,
0 commit comments