@@ -37,7 +37,7 @@ limitations under the License.
3737using namespace std ;
3838using namespace kanzi ;
3939
40- static const int BS_VERSION = 7 ;
40+ static const int BS_VERSION = 6 ;
4141
4242static void writeInt16LE (kanzi::byte buf[], int value)
4343{
@@ -632,73 +632,40 @@ static int testTransformCapacityValidation()
632632 {
633633 LZXCodec<false > tf;
634634 kanzi::byte lzSrc[128 ];
635- kanzi::byte lzDst[256 ];
635+ kanzi::byte lzEncoded[256 ];
636+ kanzi::byte lzDecoded[128 ];
636637
637638 for (int i = 0 ; i < 128 ; i++)
638- lzSrc[i] = kanzi::byte (i);
639-
640- SliceArray<kanzi::byte> input (lzSrc, 128 , 1 );
641- SliceArray<kanzi::byte> output (lzDst, 256 , 0 );
642- const int savedIIdx = input._index ;
643- const int savedOIdx = output._index ;
639+ lzSrc[i] = kanzi::byte (i & 3 );
644640
645- if (tf. forward (input, output, 128 ) != false ) {
646- cout << " LZX forward should reject oversized remaining input count " << endl ;
647- return 1 ;
648- }
641+ memset (lzEncoded, 0 , sizeof (lzEncoded));
642+ memset (lzDecoded, 0x7E , sizeof (lzDecoded)) ;
643+ SliceArray<kanzi::byte> input (lzSrc, 128 , 0 ) ;
644+ SliceArray<kanzi::byte> encoded (lzEncoded, int ( sizeof (lzEncoded)), 0 );
649645
650- if ((input. _index != savedIIdx) || (output. _index != savedOIdx) ) {
651- cout << " LZX forward input capacity failure moved indexes " << endl;
646+ if (tf. forward (input, encoded, 128 ) == false ) {
647+ cout << " LZX setup encoding failed " << endl;
652648 return 1 ;
653649 }
654- }
655650
656- {
657- LZXCodec<false > tf;
658- kanzi::byte lzSrc[128 ];
659- kanzi::byte lzDst[176 ];
660-
661- for (int i = 0 ; i < 128 ; i++)
662- lzSrc[i] = kanzi::byte (i);
663-
664- memset (lzDst, 0x7E , sizeof (lzDst));
665- SliceArray<kanzi::byte> input (lzSrc, 128 , 0 );
666- SliceArray<kanzi::byte> output (lzDst, int (sizeof (lzDst)), 32 );
651+ const int encodedSize = encoded._index ;
652+ SliceArray<kanzi::byte> exactInput (lzEncoded, encodedSize, 0 );
653+ SliceArray<kanzi::byte> output (lzDecoded, 128 , 0 );
667654
668- if (tf.forward (input , output, 128 ) != false ) {
669- cout << " LZX forward should reject incompressible input" << endl;
655+ if (tf.inverse (exactInput , output, encodedSize ) != false ) {
656+ cout << " LZX should reject input without the read-length guard " << endl;
670657 return 1 ;
671658 }
672659
673- if ((output ._index != 32 ) || (lzDst[ 32 ] != kanzi::byte ( 0x7E ) )) {
674- cout << " LZX final-size check wrote output on failure " << endl;
660+ if ((exactInput ._index != 0 ) || (output. _index != 0 )) {
661+ cout << " LZX guard failure moved slice indexes " << endl;
675662 return 1 ;
676663 }
677- }
678664
679- {
680- Context v7ctx;
681- v7ctx.putInt (" bsVersion" , 7 );
682- LZXCodec<false > encoder (v7ctx);
683- LZXCodec<false > decoder (v7ctx);
684- kanzi::byte lzSrc[256 ];
685- vector<kanzi::byte> lzEncoded (encoder.getMaxEncodedLength (256 ));
686- kanzi::byte lzDecoded[512 ];
687-
688- for (int i = 0 ; i < 256 ; i++)
689- lzSrc[i] = kanzi::byte (i & 3 );
690-
691- SliceArray<kanzi::byte> input (lzSrc, 256 , 0 );
692- SliceArray<kanzi::byte> encoded (&lzEncoded[0 ], int (lzEncoded.size ()), 0 );
693- SliceArray<kanzi::byte> output (lzDecoded, 512 , 0 );
694-
695- const bool encodedOk = encoder.forward (input, encoded, 256 );
696- const int encodedSize = encoded._index ;
697- SliceArray<kanzi::byte> encodedInput (&lzEncoded[0 ], encodedSize, 0 );
698- const bool decodedOk = decoder.inverse (encodedInput, output, encodedSize);
665+ SliceArray<kanzi::byte> paddedInput (lzEncoded, int (sizeof (lzEncoded)), 0 );
699666
700- if (!encodedOk || !decodedOk || (output. _index != 256 ) || ( memcmp (lzSrc, lzDecoded, 256 ) != 0 ) ) {
701- cout << " LZX v7 round trip failed " << endl;
667+ if (tf. inverse (paddedInput, output, encodedSize) == false ) {
668+ cout << " LZX should accept input with the read-length guard " << endl;
702669 return 1 ;
703670 }
704671 }
0 commit comments