@@ -9,7 +9,7 @@ use crate::{BoxStr, MapInput, Result, TestGenerator, TranslationError};
9
9
#[ derive( Template , Clone ) ]
10
10
#[ template( path = "test.rs" ) ]
11
11
pub ( crate ) struct RustTestTemplate {
12
- pub ( crate ) template : TestTemplate ,
12
+ pub template : TestTemplate ,
13
13
}
14
14
15
15
impl RustTestTemplate {
@@ -27,8 +27,8 @@ impl RustTestTemplate {
27
27
#[ derive( Template , Clone ) ]
28
28
#[ template( path = "test.c" ) ]
29
29
pub ( crate ) struct CTestTemplate {
30
- pub ( crate ) template : TestTemplate ,
31
- pub ( crate ) headers : Vec < String > ,
30
+ pub template : TestTemplate ,
31
+ pub headers : Vec < String > ,
32
32
}
33
33
34
34
impl CTestTemplate {
@@ -46,9 +46,9 @@ impl CTestTemplate {
46
46
/// Stores all information necessary for generation of tests for all items.
47
47
#[ derive( Clone , Debug , Default ) ]
48
48
pub ( 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 > ,
52
52
}
53
53
54
54
impl TestTemplate {
@@ -71,37 +71,34 @@ impl TestTemplate {
71
71
let mut const_tests = vec ! [ ] ;
72
72
let mut const_cstr_tests = vec ! [ ] ;
73
73
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)
90
86
} else {
91
87
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 ( ) ,
97
94
} ;
98
95
const_tests. push ( item)
99
96
}
100
97
}
101
98
102
99
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 ( ) ) ) ;
105
102
106
103
Ok ( Self {
107
104
const_cstr_tests,
@@ -111,23 +108,35 @@ impl TestTemplate {
111
108
}
112
109
}
113
110
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
+
114
122
/// Information required to test a constant CStr.
115
123
#[ 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 ,
121
129
}
122
130
123
131
/// Information required to test a constant.
124
132
#[ derive( Clone , Debug ) ]
125
133
pub ( 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 ,
131
140
}
132
141
133
142
/// The Rust name of the cstr test.
0 commit comments