summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGregory Maxwell <greg@xiph.org>2013-11-18 23:25:20 -0800
committerGregory Maxwell <greg@xiph.org>2013-11-18 23:25:20 -0800
commit733b47f31cfa72eb31323dc8b3dd1ba16074a106 (patch)
treec572e9c9b97ae15abd444874eb8dce59e88664c0 /tests
parent135d1c9848cb5114f485c02d969fd1717045dcef (diff)
downloadopus-733b47f31cfa72eb31323dc8b3dd1ba16074a106.tar.gz
Add opus_packet_(un)pad tests.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_opus_api.c34
-rw-r--r--tests/test_opus_encode.c32
2 files changed, 63 insertions, 3 deletions
diff --git a/tests/test_opus_api.c b/tests/test_opus_api.c
index 204cb2d2..17b96293 100644
--- a/tests/test_opus_api.c
+++ b/tests/test_opus_api.c
@@ -1446,9 +1446,9 @@ int test_repacketizer_api(void)
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 @@ int test_repacketizer_api(void)
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 @@ int test_repacketizer_api(void)
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 @@ 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_packet_pad .............................. OK.\n");
+ fprintf(stdout," opus_packet_unpad ............................ OK.\n");
opus_repacketizer_destroy(rp);
cfgs++;
diff --git a/tests/test_opus_encode.c b/tests/test_opus_encode.c
index 6c1d0238..4a2a3dd0 100644
--- a/tests/test_opus_encode.c
+++ b/tests/test_opus_encode.c
@@ -130,7 +130,7 @@ int run_test1(int no_fuzz)
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 @@ 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();
+ 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 @@ 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();
+ 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();