@@ -9,7 +9,7 @@ use crate::{BoxStr, MapInput, Result, TestGenerator, TranslationError};
99#[ derive( Template , Clone ) ]
1010#[ template( path = "test.rs" ) ]
1111pub ( crate ) struct RustTestTemplate {
12- pub ( crate ) template : TestTemplate ,
12+ pub template : TestTemplate ,
1313}
1414
1515impl RustTestTemplate {
@@ -27,8 +27,8 @@ impl RustTestTemplate {
2727#[ derive( Template , Clone ) ]
2828#[ template( path = "test.c" ) ]
2929pub ( crate ) struct CTestTemplate {
30- pub ( crate ) template : TestTemplate ,
31- pub ( crate ) headers : Vec < String > ,
30+ pub template : TestTemplate ,
31+ pub headers : Vec < String > ,
3232}
3333
3434impl CTestTemplate {
@@ -46,9 +46,9 @@ impl CTestTemplate {
4646/// Stores all information necessary for generation of tests for all items.
4747#[ derive( Clone , Debug , Default ) ]
4848pub ( crate ) struct TestTemplate {
49- pub ( crate ) const_cstr_tests : Vec < TestCstr > ,
50- pub ( crate ) const_tests : Vec < TestConst > ,
51- pub ( crate ) test_idents : Vec < BoxStr > ,
49+ pub const_cstr_tests : Vec < TestCStr > ,
50+ pub const_tests : Vec < TestConst > ,
51+ pub test_idents : Vec < BoxStr > ,
5252}
5353
5454impl TestTemplate {
@@ -71,37 +71,34 @@ impl TestTemplate {
7171 let mut const_tests = vec ! [ ] ;
7272 let mut const_cstr_tests = vec ! [ ] ;
7373 for constant in ffi_items. constants ( ) {
74- if let syn:: Type :: Ptr ( ptr) = & constant. ty {
75- let is_const_c_char_ptr = matches ! (
76- & * ptr. elem,
77- syn:: Type :: Path ( path)
78- if path. path. segments. last( ) . unwrap( ) . ident == "c_char"
79- && ptr. mutability. is_none( )
80- ) ;
81- if is_const_c_char_ptr {
82- let item = TestCstr {
83- test_ident : cstr_test_ident ( constant. ident ( ) ) ,
84- rust_ident : constant. ident ( ) . into ( ) ,
85- c_ident : helper. c_ident ( constant) . into ( ) ,
86- c_type : helper. c_type ( constant) ?. into ( ) ,
87- } ;
88- const_cstr_tests. push ( item)
89- }
74+ if let syn:: Type :: Ptr ( ptr) = & constant. ty
75+ && let syn:: Type :: Path ( path) = & * ptr. elem
76+ && path. path . segments . last ( ) . unwrap ( ) . ident == "c_char"
77+ && ptr. mutability . is_none ( )
78+ {
79+ let item = TestCStr {
80+ id : constant. ident ( ) . into ( ) ,
81+ test_name : cstr_test_ident ( constant. ident ( ) ) ,
82+ rust_val : constant. ident ( ) . into ( ) ,
83+ c_val : helper. c_ident ( constant) . into ( ) ,
84+ } ;
85+ const_cstr_tests. push ( item)
9086 } else {
9187 let item = TestConst {
92- test_ident : const_test_ident ( constant. ident ( ) ) ,
93- rust_ident : constant. ident . clone ( ) ,
94- rust_type : constant. ty . to_token_stream ( ) . to_string ( ) . into_boxed_str ( ) ,
95- c_ident : helper. c_ident ( constant) . into ( ) ,
96- c_type : helper. c_type ( constant) ?. into ( ) ,
88+ id : constant. ident ( ) . into ( ) ,
89+ test_name : const_test_ident ( constant. ident ( ) ) ,
90+ rust_val : constant. ident . clone ( ) ,
91+ rust_ty : constant. ty . to_token_stream ( ) . to_string ( ) . into_boxed_str ( ) ,
92+ c_val : helper. c_ident ( constant) . into ( ) ,
93+ c_ty : helper. c_type ( constant) ?. into ( ) ,
9794 } ;
9895 const_tests. push ( item)
9996 }
10097 }
10198
10299 let mut test_idents = vec ! [ ] ;
103- test_idents. extend ( const_cstr_tests. iter ( ) . map ( |test| test. test_ident . clone ( ) ) ) ;
104- test_idents. extend ( const_tests. iter ( ) . map ( |test| test. test_ident . clone ( ) ) ) ;
100+ test_idents. extend ( const_cstr_tests. iter ( ) . map ( |test| test. test_name . clone ( ) ) ) ;
101+ test_idents. extend ( const_tests. iter ( ) . map ( |test| test. test_name . clone ( ) ) ) ;
105102
106103 Ok ( Self {
107104 const_cstr_tests,
@@ -111,23 +108,35 @@ impl TestTemplate {
111108 }
112109}
113110
111+ /* Many test structures have the following fields:
112+ *
113+ * - `test_name`: The function name.
114+ * - `id`: An identifier that can be used to create functions related to this type without conflict,
115+ * usually also part of `test_name`.
116+ * - `rust_val`: Identifier for a Rust value, with path qualifications if needed.
117+ * - `rust_ty`: The Rust type of the relevant item, with path qualifications if needed.
118+ * - `c_val`: Identifier for a C value (e.g. `#define`)
119+ * - `c_ty`: The C type of the constant, qualified with `struct` or `union` if needed.
120+ */
121+
114122/// Information required to test a constant CStr.
115123#[ derive( Clone , Debug ) ]
116- pub ( crate ) struct TestCstr {
117- pub ( crate ) test_ident : BoxStr ,
118- pub ( crate ) rust_ident : BoxStr ,
119- pub ( crate ) c_ident : BoxStr ,
120- pub ( crate ) c_type : BoxStr ,
124+ pub ( crate ) struct TestCStr {
125+ pub test_name : BoxStr ,
126+ pub id : BoxStr ,
127+ pub rust_val : BoxStr ,
128+ pub c_val : BoxStr ,
121129}
122130
123131/// Information required to test a constant.
124132#[ derive( Clone , Debug ) ]
125133pub ( crate ) struct TestConst {
126- pub ( crate ) test_ident : BoxStr ,
127- pub ( crate ) rust_ident : BoxStr ,
128- pub ( crate ) rust_type : BoxStr ,
129- pub ( crate ) c_ident : BoxStr ,
130- pub ( crate ) c_type : BoxStr ,
134+ pub test_name : BoxStr ,
135+ pub id : BoxStr ,
136+ pub rust_val : BoxStr ,
137+ pub c_val : BoxStr ,
138+ pub rust_ty : BoxStr ,
139+ pub c_ty : BoxStr ,
131140}
132141
133142/// The Rust name of the cstr test.
0 commit comments