@@ -463,195 +463,3 @@ fn bytes_to_base64(bytes: &[u8]) -> String {
463463
464464 out
465465}
466-
467- #[ cfg( test) ]
468- mod tests {
469- use super :: { decode_xmlish_bytes, parse_boolish, parse_i64ish} ;
470-
471- fn push_utf ( buf : & mut Vec < u8 > , value : & str ) {
472- let len = u16:: try_from ( value. len ( ) ) . unwrap ( ) ;
473- buf. extend_from_slice ( & len. to_be_bytes ( ) ) ;
474- buf. extend_from_slice ( value. as_bytes ( ) ) ;
475- }
476-
477- fn push_utf_bytes ( buf : & mut Vec < u8 > , value : & [ u8 ] ) {
478- let len = u16:: try_from ( value. len ( ) ) . unwrap ( ) ;
479- buf. extend_from_slice ( & len. to_be_bytes ( ) ) ;
480- buf. extend_from_slice ( value) ;
481- }
482-
483- fn push_new_interned ( buf : & mut Vec < u8 > , value : & str ) {
484- buf. extend_from_slice ( & 0xFFFF_u16 . to_be_bytes ( ) ) ;
485- push_utf ( buf, value) ;
486- }
487-
488- fn push_interned_ref ( buf : & mut Vec < u8 > , index : u16 ) {
489- buf. extend_from_slice ( & index. to_be_bytes ( ) ) ;
490- }
491-
492- #[ test]
493- fn parse_boolish_handles_common_android_representations ( ) {
494- assert_eq ! ( parse_boolish( "true" ) , Some ( true ) ) ;
495- assert_eq ! ( parse_boolish( "False" ) , Some ( false ) ) ;
496- assert_eq ! ( parse_boolish( "1" ) , Some ( true ) ) ;
497- assert_eq ! ( parse_boolish( "0" ) , Some ( false ) ) ;
498- assert_eq ! ( parse_boolish( "maybe" ) , None ) ;
499- }
500-
501- #[ test]
502- fn parse_i64ish_understands_decimal_and_hex ( ) {
503- assert_eq ! ( parse_i64ish( "16" ) , Some ( 16 ) ) ;
504- assert_eq ! ( parse_i64ish( "0x10" ) , Some ( 16 ) ) ;
505- assert_eq ! ( parse_i64ish( "ff" ) , Some ( 255 ) ) ;
506- assert_eq ! ( parse_i64ish( "-0x10" ) , Some ( -16 ) ) ;
507- }
508-
509- #[ test]
510- fn android_binary_xml_is_decoded_to_text_xml ( ) {
511- let mut abx = Vec :: new ( ) ;
512- abx. extend_from_slice ( b"ABX\0 " ) ;
513- abx. push ( 0x00 ) ;
514-
515- abx. push ( 0x02 ) ;
516- push_new_interned ( & mut abx, "packages" ) ;
517-
518- abx. push ( 0x02 ) ;
519- push_new_interned ( & mut abx, "package" ) ;
520-
521- abx. push ( 0x2F ) ;
522- push_new_interned ( & mut abx, "name" ) ;
523- push_utf ( & mut abx, "com.example.app" ) ;
524-
525- abx. push ( 0x2F ) ;
526- push_new_interned ( & mut abx, "codePath" ) ;
527- push_utf ( & mut abx, "/data/app/~~abc/com.example.app/base.apk" ) ;
528-
529- abx. push ( 0x7F ) ;
530- push_new_interned ( & mut abx, "publicFlags" ) ;
531- abx. extend_from_slice ( & ( 0x10_i32 ) . to_be_bytes ( ) ) ;
532-
533- abx. push ( 0x03 ) ;
534- push_interned_ref ( & mut abx, 1 ) ;
535-
536- abx. push ( 0x03 ) ;
537- push_interned_ref ( & mut abx, 0 ) ;
538-
539- abx. push ( 0x01 ) ;
540-
541- let decoded = decode_xmlish_bytes ( & abx) . unwrap ( ) ;
542-
543- assert ! ( decoded. contains( "<package" ) ) ;
544- assert ! ( decoded. contains( r#"name="com.example.app""# ) ) ;
545- assert ! ( decoded. contains( r#"codePath="/data/app/~~abc/com.example.app/base.apk""# ) ) ;
546- assert ! ( decoded. contains( r#"publicFlags="0x10""# ) ) ;
547- }
548-
549- #[ test]
550- fn android_binary_xml_decodes_boolean_attributes ( ) {
551- let mut abx = Vec :: new ( ) ;
552- abx. extend_from_slice ( b"ABX\0 " ) ;
553- abx. push ( 0x00 ) ;
554-
555- abx. push ( 0x02 ) ;
556- push_new_interned ( & mut abx, "package-restrictions" ) ;
557-
558- abx. push ( 0x02 ) ;
559- push_new_interned ( & mut abx, "pkg" ) ;
560-
561- abx. push ( 0x2F ) ;
562- push_new_interned ( & mut abx, "name" ) ;
563- push_utf ( & mut abx, "com.example.alpha" ) ;
564-
565- abx. push ( 0xDF ) ;
566- push_new_interned ( & mut abx, "inst" ) ;
567-
568- abx. push ( 0x03 ) ;
569- push_interned_ref ( & mut abx, 1 ) ;
570-
571- abx. push ( 0x03 ) ;
572- push_interned_ref ( & mut abx, 0 ) ;
573-
574- abx. push ( 0x01 ) ;
575-
576- let decoded = decode_xmlish_bytes ( & abx) . unwrap ( ) ;
577-
578- assert ! ( decoded. contains( r#"<pkg name="com.example.alpha" inst="false">"# ) ) ;
579- }
580-
581- #[ test]
582- fn text_xml_utf16le_without_bom_is_detected ( ) {
583- let bytes = b"<root>ok</root>"
584- . iter ( )
585- . flat_map ( |byte| [ * byte, 0x00 ] )
586- . collect :: < Vec < _ > > ( ) ;
587-
588- let decoded = decode_xmlish_bytes ( & bytes) . unwrap ( ) ;
589-
590- assert_eq ! ( decoded, "<root>ok</root>" ) ;
591- }
592-
593- #[ test]
594- fn android_binary_xml_supports_art_modified_utf_with_four_byte_sequences ( ) {
595- let mut abx = Vec :: new ( ) ;
596- abx. extend_from_slice ( b"ABX\0 " ) ;
597- abx. push ( 0x00 ) ;
598-
599- abx. push ( 0x02 ) ;
600- push_new_interned ( & mut abx, "emoji" ) ;
601-
602- abx. push ( 0x24 ) ;
603- push_utf_bytes ( & mut abx, "😀" . as_bytes ( ) ) ;
604-
605- abx. push ( 0x03 ) ;
606- push_interned_ref ( & mut abx, 0 ) ;
607- abx. push ( 0x01 ) ;
608-
609- let decoded = decode_xmlish_bytes ( & abx) . unwrap ( ) ;
610-
611- assert_eq ! ( decoded, "<emoji>😀</emoji>" ) ;
612- }
613-
614- #[ test]
615- fn android_binary_xml_resolves_entity_refs_like_android ( ) {
616- let mut abx = Vec :: new ( ) ;
617- abx. extend_from_slice ( b"ABX\0 " ) ;
618- abx. push ( 0x00 ) ;
619-
620- abx. push ( 0x02 ) ;
621- push_new_interned ( & mut abx, "root" ) ;
622-
623- abx. push ( 0x26 ) ;
624- push_utf ( & mut abx, "amp" ) ;
625-
626- abx. push ( 0x03 ) ;
627- push_interned_ref ( & mut abx, 0 ) ;
628- abx. push ( 0x01 ) ;
629-
630- let decoded = decode_xmlish_bytes ( & abx) . unwrap ( ) ;
631-
632- assert_eq ! ( decoded, "<root>&</root>" ) ;
633- }
634-
635- #[ test]
636- fn android_binary_xml_base64_attributes_are_rendered_as_base64_text ( ) {
637- let mut abx = Vec :: new ( ) ;
638- abx. extend_from_slice ( b"ABX\0 " ) ;
639- abx. push ( 0x00 ) ;
640-
641- abx. push ( 0x02 ) ;
642- push_new_interned ( & mut abx, "root" ) ;
643-
644- abx. push ( 0x5F ) ;
645- push_new_interned ( & mut abx, "blob" ) ;
646- abx. extend_from_slice ( & ( 3_u16 ) . to_be_bytes ( ) ) ;
647- abx. extend_from_slice ( & [ 0x01 , 0x02 , 0x03 ] ) ;
648-
649- abx. push ( 0x03 ) ;
650- push_interned_ref ( & mut abx, 0 ) ;
651- abx. push ( 0x01 ) ;
652-
653- let decoded = decode_xmlish_bytes ( & abx) . unwrap ( ) ;
654-
655- assert_eq ! ( decoded, r#"<root blob="AQID"></root>"# ) ;
656- }
657- }
0 commit comments