[FFmpeg-devel] [PATCH] remove unused and broken test program in libavutil/base64.c

Michael Niedermayer michaelni
Wed Jan 28 20:58:32 CET 2009


On Wed, Jan 28, 2009 at 08:44:09PM +0100, Stefano Sabatini wrote:
> On date Wednesday 2009-01-28 18:15:14 +0100, Michael Niedermayer encoded:
> > On Wed, Jan 28, 2009 at 12:02:34AM +0100, Stefano Sabatini wrote:
> > > On date Tuesday 2009-01-27 03:01:01 +0100, Michael Niedermayer encoded:
> > > > On Mon, Jan 26, 2009 at 11:28:18PM +0100, Stefano Sabatini wrote:
> > > [...]
> > > > > > > It turned out in a semi-complete rewrite of the test program, anyway I
> > > > > > > don't feel like to send a patch and discuss every single change, if
> > > > > > > it's possible to simply replace the new code I'll happily do it.
> > > > 
> > > > you know likely (after actually thinking about it at least)
> > > > that diffing old code against rewritten codeis not that usefull
> > > > for the purpose of reading/reviewing
> > > 
> > > Here it is:
> > > 
> > > -----8<-----8<------------------------------------------------------
> > > #ifdef TEST
> > > #include "log.h"
> > > #include "mem.h"
> > > 
> > > #undef printf
> > 
> > > #undef srand
> > > #undef rand
> > 
> > is there a problem with our random number generators?
> > 
> > 
> > > 
> > > int main(void)
> > > {
> > >     int numerr = 0;
> > > 
> > >     struct test {
> > 
> > >         void *data;
> > 
> > looks like const char
> 
> OK to use const uint8_t to stress the fact that it is generic data
> rather than a string?

fine


>  
> > >         int data_size;
> > >         const char *encoded;
> > >     } *t, tests[] = {
> > >         { "", 0, ""},
> > >         { "1", 1, "MQ=="},
> > >         { "22", 2, "MjI="},
> > >         { "333", 3, "MzMz"},
> > >         { "4444", 4, "NDQ0NA=="},
> > >         { "55555", 5, "NTU1NTU="},
> > >         { "abc:def", 7, "YWJjOmRlZg=="},
> > >         { NULL}
> > >     };
> > > 
> > >     printf("Encoding/decoding tests on constant data\n");
> > >     for (t = tests; t->data; t++) {
> > >         char encoded[1024];
> > >         uint8_t data[1024];
> > >         int data_size;
> > > 
> > >         printf("Encoding '%s'... ", (char *)t->data);
> > >         if (av_base64_encode(encoded, sizeof(encoded), t->data, t->data_size)) {
> > >             printf("encoded to '%s'\n", encoded);
> > 
> > >             if (strcmp(encoded, t->encoded) != 0) {
> > 
> > superflous != 0
> > 
> > 
> > [...]
> > >     printf("\n");
> > > 
> > >     printf("Encoding/decoding tests on random data\n");
> > 
> > can be merged
> > 
> > 
> > >     {
> > >         int test_count;
> > >         srand(123141);          // time(NULL));
> > >         for (test_count = 0; test_count < 100; test_count++) {
> > >             int data_size = rand() % 1024;
> > >             char *encoded[2048];
> > 
> > >             uint8_t *data = (uint8_t *)av_malloc(data_size);
> > 
> > useless cast
> 
> New version:
[...]
>         if (av_base64_encode(encoded, sizeof(encoded), t->data, t->data_size)) {
>             printf("encoded to '%s'\n", encoded);
>             if (strcmp(encoded, t->encoded)) {
>                 printf("failed: '%s' != '%s'\n", encoded, t->encoded);
>                 numerr++;
>             }
>         }
>         printf("Decoding '%s'... ", t->encoded);
>         data_size = av_base64_decode(data, t->encoded, sizeof(data));
>         if (data_size != t->data_size) {
>             printf("failed: len %d != %d\n", data_size, t->data_size);
>             numerr++;
>         } else if (memcmp(data, t->data, t->data_size)) {
>             printf("failed: data differs\n");
>             numerr++;
>         } else {
>             printf("decoded to '%s'\n", t->data);
>         }
[...]
>             if (!av_base64_encode(encoded, sizeof(encoded), data, data_size)) {
>                 printf("failed: cannot encode the input data\n");
>                 numerr++;
>             } else {
>                 int size = data_size + 10;     // try without 10 as well
>                 uint8_t *data2 = av_malloc(size);
>                 if (data2) {
>                     int data2_size = av_base64_decode(data2, encoded, size);
>                     if (data2_size < 0) {
>                         printf("failed: cannot decode the encoded string '%s'\n", encoded);
>                         numerr++;
>                     } else if (data2_size != data_size) {
>                         printf("failed: decoded/encoded size mismatch (%d != %d)\n", data2_size, data_size);
>                     } else {
>                         if (memcmp(data2, data, data_size)) {
>                             printf("failed: data differs!\n");
>                             numerr++;
>                         } else {
>                             printf("passed!\n");
>                         }
>                     }
>                     av_free(data2);
>                 }
>             }
>             av_free(data);

duplicate encode/decode test

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

While the State exists there can be no freedom; when there is freedom there
will be no State. -- Vladimir Lenin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090128/402b9182/attachment.pgp>



More information about the ffmpeg-devel mailing list