summaryrefslogtreecommitdiff
path: root/tests/test_opus_encode.c
diff options
context:
space:
mode:
authorGregory Maxwell <greg@xiph.org>2012-10-27 13:42:48 -0400
committerGregory Maxwell <greg@xiph.org>2012-10-27 13:42:48 -0400
commitde95da9bf1c98b80368cf643e3b7da45f3ca108b (patch)
tree9c24769c3c7d414a07294a1931781535bccb79ca /tests/test_opus_encode.c
parent6930d90c341fca347f3fdc1e10c43f3265174aed (diff)
downloadopus-de95da9bf1c98b80368cf643e3b7da45f3ca108b.tar.gz
Fix several issues with multistream argument validation.
As reported by Mark Warner opus_multistream_*_create were depending on the behavior of malloc(0) in order to correctly report some kinds of argument errors. Bad arguments could be incorrectly reported as allocation failures. This changes multistream to explicitly check the arguments like the single stream _create functions. The unit tests were enough to catch this on systems where malloc(0) returns NULL but didn't catch it on other systems because the later _init call would catch the bad arguments and trigger the correct error if and only if the malloc didn't return a null pointer. In multistream_encoder_init failures of the internal non-multistream init calls were not being caught and propagated. Decode didn't have this problem. This propagates the errors and adds additional tests (the multistream encoder api is sill under tested) that would have detected this error. Plus add some stronger tests for things like error==NULL for the _create functions that take a pointer for error output.
Diffstat (limited to 'tests/test_opus_encode.c')
-rw-r--r--tests/test_opus_encode.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/test_opus_encode.c b/tests/test_opus_encode.c
index a9a1c58b..61e0dec1 100644
--- a/tests/test_opus_encode.c
+++ b/tests/test_opus_encode.c
@@ -144,6 +144,29 @@ int run_test1(int no_fuzz)
enc = opus_encoder_create(48000, 2, OPUS_APPLICATION_VOIP, &err);
if(err != OPUS_OK || enc==NULL)test_failed();
+ for(i=0;i<2;i++)
+ {
+ int *ret_err;
+ ret_err = i?0:&err;
+ MSenc = opus_multistream_encoder_create(8000, 2, 2, 0, mapping, OPUS_UNIMPLEMENTED, ret_err);
+ if((ret_err && *ret_err != OPUS_BAD_ARG) || MSenc!=NULL)test_failed();
+
+ MSenc = opus_multistream_encoder_create(8000, 0, 1, 0, mapping, OPUS_APPLICATION_VOIP, ret_err);
+ if((ret_err && *ret_err != OPUS_BAD_ARG) || MSenc!=NULL)test_failed();
+
+ MSenc = opus_multistream_encoder_create(44100, 2, 2, 0, mapping, OPUS_APPLICATION_VOIP, ret_err);
+ if((ret_err && *ret_err != OPUS_BAD_ARG) || MSenc!=NULL)test_failed();
+
+ MSenc = opus_multistream_encoder_create(8000, 2, 2, 3, mapping, OPUS_APPLICATION_VOIP, ret_err);
+ if((ret_err && *ret_err != OPUS_BAD_ARG) || MSenc!=NULL)test_failed();
+
+ MSenc = opus_multistream_encoder_create(8000, 2, -1, 0, mapping, OPUS_APPLICATION_VOIP, ret_err);
+ if((ret_err && *ret_err != OPUS_BAD_ARG) || MSenc!=NULL)test_failed();
+
+ MSenc = opus_multistream_encoder_create(8000, 256, 2, 0, mapping, OPUS_APPLICATION_VOIP, ret_err);
+ if((ret_err && *ret_err != OPUS_BAD_ARG) || MSenc!=NULL)test_failed();
+ }
+
MSenc = opus_multistream_encoder_create(8000, 2, 2, 0, mapping, OPUS_APPLICATION_AUDIO, &err);
if(err != OPUS_OK || MSenc==NULL)test_failed();