ref: 733b47f31cfa72eb31323dc8b3dd1ba16074a106
parent: 135d1c9848cb5114f485c02d969fd1717045dcef
author: Gregory Maxwell <[email protected]>
date: Mon Nov 18 18:25:20 EST 2013
Add opus_packet_(un)pad tests.
--- a/tests/test_opus_api.c
+++ b/tests/test_opus_api.c
@@ -1446,9 +1446,9 @@
packet=malloc(max_out);
if(packet==NULL)test_failed();
- po=malloc(max_out);
- if(po==NULL)test_failed();
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();
@@ -1550,6 +1550,14 @@
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)
@@ -1649,6 +1657,14 @@
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)
@@ -1661,9 +1677,23 @@
}
}
+ 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_packet_pad .............................. OK.\n");
+ fprintf(stdout," opus_packet_unpad ............................ OK.\n");
opus_repacketizer_destroy(rp);
cfgs++;
--- a/tests/test_opus_encode.c
+++ b/tests/test_opus_encode.c
@@ -130,7 +130,7 @@
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;
@@ -268,6 +268,21 @@
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();
@@ -317,6 +332,21 @@
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();