import { BitMatrix } from '@zxing/library' ; import { assertEquals , assertArrayEquals , assertThrow } from '../../../core/util/AssertUtils' ; import { ResultPoint } from '@zxing/library' ; import { AztecDecoder } from '@zxing/library' ; import { AztecDetectorResult } from '@zxing/library' ; import { FormatException } from '@zxing/library' ; /**
 * Tests  Decoder .
  describe ( 'DecoderTest' , ( ) => { const NO_POINTS = [ ] ; Test throws it ( 'testAztecResult' , ( ) => { const matrix = BitMatrix . parseFromString ( 'X X X X X     X X X       X X X     X X X     \n' + 'X X X     X X X     X X X X     X X X     X X \n' + '  X   X X       X   X   X X X X     X     X X \n' + '  X   X X     X X     X     X   X       X   X \n' + '  X X   X X         X               X X     X \n' + '  X X   X X X X X X X X X X X X X X X     X   \n' + '  X X X X X                       X   X X X   \n' + '  X   X   X   X X X X X X X X X   X X X   X X \n' + '  X   X X X   X               X   X X       X \n' + '  X X   X X   X   X X X X X   X   X X X X   X \n' + '  X X   X X   X   X       X   X   X   X X X   \n' + '  X   X   X   X   X   X   X   X   X   X   X   \n' + '  X X X   X   X   X       X   X   X X   X X   \n' + '  X X X X X   X   X X X X X   X   X X X   X X \n' + 'X X   X X X   X               X   X   X X   X \n' + '  X       X   X X X X X X X X X   X   X     X \n' + '  X X   X X                       X X   X X   \n' + '  X X X   X X X X X X X X X X X X X X   X X   \n' + 'X     X     X     X X   X X               X X \n' + 'X   X X X X X   X X X X X     X   X   X     X \n' + 'X X X   X X X X           X X X       X     X \n' + 'X X     X X X     X X X X     X X X     X X   \n' + '    X X X     X X X       X X X     X X X X   \n' , 'X ' , '  ' ) ; const r = new AztecDetectorResult ( matrix , NO_POINTS , false , 30 , 2 ) ; const result = new AztecDecoder ( ) . decode ( r ) ; assertEquals ( '88888TTTTTTTTTTTTTTTTTTTTTTTTTTTTTT' , result . getText ( ) ) ; assertArrayEquals ( new Uint8Array ( [ - 11 , 85 , 85 , 117 , 107 , 90 , - 42 , - 75 , - 83 , 107 , 90 , - 42 , - 75 , - 83 , 107 , 90 , - 42 , - 75 , - 83 , 107 , 90 , - 42 , - 80 ] ) , result . getRawBytes ( ) ) ; assertEquals ( 180 , result . getNumBits ( ) ) ; } ) ; Test it ( 'testDecodeTooManyErrors' , ( ) => { const matrix = BitMatrix . parseFromString ( '' + 'X X . X . . . X X . . . X . . X X X . X . X X X X X . \n' + 'X X . . X X . . . . . X X . . . X X . . . X . X . . X \n' + 'X . . . X X . . X X X . X X . X X X X . X X . . X . . \n' + '. . . . X . X X . . X X . X X . X . X X X X . X . . X \n' + 'X X X . . X X X X X . . . . . X X . . . X . X . X . X \n' + 'X X . . . . . . . . X . . . X . X X X . X . . X . . . \n' + 'X X . . X . . . . . X X . . . . . X . . . . X . . X X \n' + '. . . X . X . X . . . . . X X X X X X . . . . . . X X \n' + 'X . . . X . X X X X X X . . X X X . X . X X X X X X . \n' + 'X . . X X X . X X X X X X X X X X X X X . . . X . X X \n' + '. . . . X X . . . X . . . . . . . X X . . . X X . X . \n' + '. . . X X X . . X X . X X X X X . X . . X . . . . . . \n' + 'X . . . . X . X . X . X . . . X . X . X X . X X . X X \n' + 'X . X . . X . X . X . X . X . X . X . . . . . X . X X \n' + 'X . X X X . . X . X . X . . . X . X . X X X . . . X X \n' + 'X X X X X X X X . X . X X X X X . X . X . X . X X X . \n' + '. . . . . . . X . X . . . . . . . X X X X . . . X X X \n' + 'X X . . X . . X . X X X X X X X X X X X X X . . X . X \n' + 'X X X . X X X X . . X X X X . . X . . . . X . . X X X \n' + '. . . . X . X X X . . . . X X X X . . X X X X . . . . \n' + '. . X . . X . X . . . X . X X . X X . X . . . X . X . \n' + 'X X . . X . . X X X X X X X . . X . X X X X X X X . . \n' + 'X . X X . . X X . . . . . X . . . . . . X X . X X X . \n' + 'X . . X X . . X X . X . X . . . . X . X . . X . . X . \n' + 'X . X . X . . X . X X X X X X X X . X X X X . . X X . \n' + 'X X X X . . . X . . X X X . X X . . X . . . . X X X . \n' + 'X X . X . X . . . X . X . . . . X X . X . . X X . . . \n' , 'X ' , '. ' ) ; const r = new AztecDetectorResult ( matrix , NO_POINTS , true , 16 , 4 ) ; assertThrow ( ( ) => new AztecDecoder ( ) . decode ( r ) , FormatException ) ; } ) ; Test throws it ( 'testDecodeTooManyErrors2' , ( ) => { const matrix = BitMatrix . parseFromString ( '' + '. X X . . X . X X . . . X . . X X X . . . X X . X X . \n' + 'X X . X X . . X . . . X X . . . X X . X X X . X . X X \n' + '. . . . X . . . X X X . X X . X X X X . X X . . X . . \n' + 'X . X X . . X . . . X X . X X . X . X X . . . . . X . \n' + 'X X . X . . X . X X . . . . . X X . . . . . X . . . X \n' + 'X . . X . . . . . . X . . . X . X X X X X X X . . . X \n' + 'X . . X X . . X . . X X . . . . . X . . . . . X X X . \n' + '. . X X X X . X . . . . . X X X X X X . . . . . . X X \n' + 'X . . . X . X X X X X X . . X X X . X . X X X X X X . \n' + 'X . . X X X . X X X X X X X X X X X X X . . . X . X X \n' + '. . . . X X . . . X . . . . . . . X X . . . X X . X . \n' + '. . . X X X . . X X . X X X X X . X . . X . . . . . . \n' + 'X . . . . X . X . X . X . . . X . X . X X . X X . X X \n' + 'X . X . . X . X . X . X . X . X . X . . . . . X . X X \n' + 'X . X X X . . X . X . X . . . X . X . X X X . . . X X \n' + 'X X X X X X X X . X . X X X X X . X . X . X . X X X . \n' + '. . . . . . . X . X . . . . . . . X X X X . . . X X X \n' + 'X X . . X . . X . X X X X X X X X X X X X X . . X . X \n' + 'X X X . X X X X . . X X X X . . X . . . . X . . X X X \n' + '. . X X X X X . X . . . . X X X X . . X X X . X . X . \n' + '. . X X . X . X . . . X . X X . X X . . . . X X . . . \n' + 'X . . . X . X . X X X X X X . . X . X X X X X . X . . \n' + '. X . . . X X X . . . . . X . . . . . X X X X X . X . \n' + 'X . . X . X X X X . X . X . . . . X . X X . X . . X . \n' + 'X . . . X X . X . X X X X X X X X . X X X X . . X X . \n' + '. X X X X . . X . . X X X . X X . . X . . . . X X X . \n' + 'X X . . . X X . . X . X . . . . X X . X . . X . X . X \n' , 'X ' , '. ' ) ; const r = new AztecDetectorResult ( matrix , NO_POINTS , true , 16 , 4 ) ; assertThrow ( ( ) => new AztecDecoder ( ) . decode ( r ) , FormatException ) ; } ) ; Test it ( 'testRawBytes' , ( ) => { let bool0 = [ ] ; let bool1 = [ true ] ; let bool7 = [ true , false , true , false , true , false , true ] ; let bool8 = [ true , false , true , false , true , false , true , false ] ; let bool9 = [ true , false , true , false , true , false , true , false , true ] ; let bool16 = [ false , true , true , false , false , false , true , true , true , true , false , false , false , false , false , true ] ; let byte0 = new Uint8Array ( [ ] ) ; let byte1 = new Uint8Array ( [ - 128 ] ) ; let byte7 = new Uint8Array ( [ - 86 ] ) ; let byte8 = new Uint8Array ( [ - 86 ] ) ; let byte9 = new Uint8Array ( [ - 86 , - 128 ] ) ; let byte16 = new Uint8Array ( [ 99 , - 63 ] ) ; assertArrayEquals ( byte0 , AztecDecoder . convertBoolArrayToByteArray ( bool0 ) ) ; assertArrayEquals ( byte1 , AztecDecoder . convertBoolArrayToByteArray ( bool1 ) ) ; assertArrayEquals ( byte7 , AztecDecoder . convertBoolArrayToByteArray ( bool7 ) ) ; assertArrayEquals ( byte8 , AztecDecoder . convertBoolArrayToByteArray ( bool8 ) ) ; assertArrayEquals ( byte9 , AztecDecoder . convertBoolArrayToByteArray ( bool9 ) ) ; assertArrayEquals ( byte16 , AztecDecoder . convertBoolArrayToByteArray ( bool16 ) ) ; } ) ; } ) ;