Add opus_packet_(un)pad tests.
authorGregory Maxwell <greg@xiph.org>
Tue, 19 Nov 2013 07:25:20 +0000 (23:25 -0800)
committerGregory Maxwell <greg@xiph.org>
Tue, 19 Nov 2013 07:25:20 +0000 (23:25 -0800)
tests/test_opus_api.c
tests/test_opus_encode.c

index 204cb2d..17b9629 100644 (file)
@@ -1446,9 +1446,9 @@ int test_repacketizer_api(void)
 
    packet=malloc(max_out);
    if(packet==NULL)test_failed();
 
    packet=malloc(max_out);
    if(packet==NULL)test_failed();
-   po=malloc(max_out);
-   if(po==NULL)test_failed();
    memset(packet,0,max_out);
    memset(packet,0,max_out);
+   po=malloc(max_out+256);
+   if(po==NULL)test_failed();
 
    i=opus_repacketizer_get_size();
    if(i<=0)test_failed();
 
    i=opus_repacketizer_get_size();
    if(i<=0)test_failed();
@@ -1550,6 +1550,14 @@ int test_repacketizer_api(void)
                   cfgs++;
                   if(opus_repacketizer_out(rp,po,len)!=len)test_failed();
                   cfgs++;
                   cfgs++;
                   if(opus_repacketizer_out(rp,po,len)!=len)test_failed();
                   cfgs++;
+                  if(opus_packet_unpad(po,len)!=len)test_failed();
+                  cfgs++;
+                  if(opus_packet_pad(po,len,len+1)!=OPUS_OK)test_failed();
+                  cfgs++;
+                  if(opus_packet_pad(po,len+1,len+256)!=OPUS_OK)test_failed();
+                  cfgs++;
+                  if(opus_packet_unpad(po,len+256)!=len)test_failed();
+                  cfgs++;
                   if(opus_repacketizer_out(rp,po,len-1)!=OPUS_BUFFER_TOO_SMALL)test_failed();
                   cfgs++;
                   if(len>1)
                   if(opus_repacketizer_out(rp,po,len-1)!=OPUS_BUFFER_TOO_SMALL)test_failed();
                   cfgs++;
                   if(len>1)
@@ -1649,6 +1657,14 @@ int test_repacketizer_api(void)
          cfgs++;
          if(opus_repacketizer_out(rp,po,len)!=len)test_failed();
          cfgs++;
          cfgs++;
          if(opus_repacketizer_out(rp,po,len)!=len)test_failed();
          cfgs++;
+         if(opus_packet_unpad(po,len)!=len)test_failed();
+         cfgs++;
+         if(opus_packet_pad(po,len,len+1)!=OPUS_OK)test_failed();
+         cfgs++;
+         if(opus_packet_pad(po,len+1,len+256)!=OPUS_OK)test_failed();
+         cfgs++;
+         if(opus_packet_unpad(po,len+256)!=len)test_failed();
+         cfgs++;
          if(opus_repacketizer_out(rp,po,len-1)!=OPUS_BUFFER_TOO_SMALL)test_failed();
          cfgs++;
          if(len>1)
          if(opus_repacketizer_out(rp,po,len-1)!=OPUS_BUFFER_TOO_SMALL)test_failed();
          cfgs++;
          if(len>1)
@@ -1661,9 +1677,23 @@ int test_repacketizer_api(void)
       }
    }
 
       }
    }
 
+   po[0]='O';
+   po[1]='p';
+   if(opus_packet_pad(po,4,5)!=OPUS_BAD_ARG)test_failed();
+   cfgs++;
+   if(opus_packet_unpad(po,4)!=OPUS_INVALID_PACKET)test_failed();
+   cfgs++;
+   po[0]=0;
+   po[1]=0;
+   po[2]=0;
+   if(opus_packet_pad(po,5,4)!=OPUS_BAD_ARG)test_failed();
+   cfgs++;
+
    fprintf(stdout,"    opus_repacketizer_cat ........................ OK.\n");
    fprintf(stdout,"    opus_repacketizer_out ........................ OK.\n");
    fprintf(stdout,"    opus_repacketizer_out_range .................. OK.\n");
    fprintf(stdout,"    opus_repacketizer_cat ........................ OK.\n");
    fprintf(stdout,"    opus_repacketizer_out ........................ OK.\n");
    fprintf(stdout,"    opus_repacketizer_out_range .................. OK.\n");
+   fprintf(stdout,"    opus_packet_pad .............................. OK.\n");
+   fprintf(stdout,"    opus_packet_unpad ............................ OK.\n");
 
    opus_repacketizer_destroy(rp);
    cfgs++;
 
    opus_repacketizer_destroy(rp);
    cfgs++;
index 6c1d023..4a2a3dd 100644 (file)
@@ -130,7 +130,7 @@ int run_test1(int no_fuzz)
    short *outbuf;
    short *out2buf;
    opus_int32 bitrate_bps;
    short *outbuf;
    short *out2buf;
    opus_int32 bitrate_bps;
-   unsigned char packet[MAX_PACKET];
+   unsigned char packet[MAX_PACKET+257];
    opus_uint32 enc_final_range;
    opus_uint32 dec_final_range;
    int fswitch;
    opus_uint32 enc_final_range;
    opus_uint32 dec_final_range;
    int fswitch;
@@ -268,6 +268,21 @@ int run_test1(int no_fuzz)
             len = opus_encode(enc, &inbuf[i<<1], frame_size, packet, MAX_PACKET);
             if(len<0 || len>MAX_PACKET)test_failed();
             if(opus_encoder_ctl(enc, OPUS_GET_FINAL_RANGE(&enc_final_range))!=OPUS_OK)test_failed();
             len = opus_encode(enc, &inbuf[i<<1], frame_size, packet, MAX_PACKET);
             if(len<0 || len>MAX_PACKET)test_failed();
             if(opus_encoder_ctl(enc, OPUS_GET_FINAL_RANGE(&enc_final_range))!=OPUS_OK)test_failed();
+            if((fast_rand()&3)==0)
+            {
+               if(opus_packet_pad(packet,len,len+1)!=OPUS_OK)test_failed();
+               len++;
+            }
+            if((fast_rand()&7)==0)
+            {
+               if(opus_packet_pad(packet,len,len+256)!=OPUS_OK)test_failed();
+               len+=256;
+            }
+            if((fast_rand()&3)==0)
+            {
+               len=opus_packet_unpad(packet,len);
+               if(len<1)test_failed();
+            }
             out_samples = opus_decode(dec, packet, len, &outbuf[i<<1], MAX_FRAME_SAMP, 0);
             if(out_samples!=frame_size)test_failed();
             if(opus_decoder_ctl(dec, OPUS_GET_FINAL_RANGE(&dec_final_range))!=OPUS_OK)test_failed();
             out_samples = opus_decode(dec, packet, len, &outbuf[i<<1], MAX_FRAME_SAMP, 0);
             if(out_samples!=frame_size)test_failed();
             if(opus_decoder_ctl(dec, OPUS_GET_FINAL_RANGE(&dec_final_range))!=OPUS_OK)test_failed();
@@ -317,6 +332,21 @@ int run_test1(int no_fuzz)
             len = opus_multistream_encode(MSenc, &inbuf[i<<1], frame_size, packet, MAX_PACKET);
             if(len<0 || len>MAX_PACKET)test_failed();
             if(opus_multistream_encoder_ctl(MSenc, OPUS_GET_FINAL_RANGE(&enc_final_range))!=OPUS_OK)test_failed();
             len = opus_multistream_encode(MSenc, &inbuf[i<<1], frame_size, packet, MAX_PACKET);
             if(len<0 || len>MAX_PACKET)test_failed();
             if(opus_multistream_encoder_ctl(MSenc, OPUS_GET_FINAL_RANGE(&enc_final_range))!=OPUS_OK)test_failed();
+            if((fast_rand()&3)==0)
+            {
+               if(opus_multistream_packet_pad(packet,len,len+1,2)!=OPUS_OK)test_failed();
+               len++;
+            }
+            if((fast_rand()&7)==0)
+            {
+               if(opus_multistream_packet_pad(packet,len,len+256,2)!=OPUS_OK)test_failed();
+               len+=256;
+            }
+            if((fast_rand()&3)==0)
+            {
+               len=opus_multistream_packet_unpad(packet,len,2);
+               if(len<1)test_failed();
+            }
             out_samples = opus_multistream_decode(MSdec, packet, len, out2buf, MAX_FRAME_SAMP, 0);
             if(out_samples!=frame_size*6)test_failed();
             if(opus_multistream_decoder_ctl(MSdec, OPUS_GET_FINAL_RANGE(&dec_final_range))!=OPUS_OK)test_failed();
             out_samples = opus_multistream_decode(MSdec, packet, len, out2buf, MAX_FRAME_SAMP, 0);
             if(out_samples!=frame_size*6)test_failed();
             if(opus_multistream_decoder_ctl(MSdec, OPUS_GET_FINAL_RANGE(&dec_final_range))!=OPUS_OK)test_failed();