File tree Expand file tree Collapse file tree
crates/cxx-qt-lib/src/core/qvariant Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -294,3 +294,37 @@ unsafe impl ExternType for QVariant {
294294 type Id = type_id ! ( "QVariant" ) ;
295295 type Kind = cxx:: kind:: Trivial ;
296296}
297+
298+ #[ cfg( test) ]
299+ mod tests {
300+ use super :: * ;
301+ use crate :: { QList , QString } ;
302+
303+ #[ test]
304+ fn test_type_name ( ) {
305+ let variant = QVariant :: from ( & true ) ;
306+ assert_eq ! ( variant. type_name( ) , "bool" ) ;
307+
308+ let variant = QVariant :: from ( & 123_i32 ) ;
309+ assert_eq ! ( variant. type_name( ) , "int" ) ;
310+
311+ let variant = QVariant :: from ( & 0.25f32 ) ;
312+ assert_eq ! ( variant. type_name( ) , "float" ) ;
313+
314+ let variant = QVariant :: from ( & 0.75f64 ) ;
315+ assert_eq ! ( variant. type_name( ) , "double" ) ;
316+
317+ let variant = QVariant :: from ( & QList :: < i32 > :: from_iter ( & [ 1 , 2 , 3 ] ) ) ;
318+ assert_eq ! ( variant. type_name( ) , "QList<int>" ) ;
319+
320+ let variant = QVariant :: from ( & QString :: from ( "ABC" ) ) ;
321+ assert_eq ! ( variant. type_name( ) , "QString" ) ;
322+ }
323+
324+ #[ test]
325+ fn qvariant_type_name_invalid ( ) {
326+ let variant = QVariant :: default ( ) ;
327+ assert ! ( !variant. is_valid( ) ) ;
328+ assert_eq ! ( variant. type_name( ) , "" ) ;
329+ }
330+ }
You can’t perform that action at this time.
0 commit comments