[FFmpeg-devel] [PATCH] remove unused and broken test program in libavutil/base64.c
Michael Niedermayer
michaelni
Fri Jan 30 17:06:22 CET 2009
On Fri, Jan 30, 2009 at 12:46:36AM +0100, Stefano Sabatini wrote:
> On date Thursday 2009-01-29 03:11:32 +0100, Michael Niedermayer encoded:
> > On Thu, Jan 29, 2009 at 12:21:09AM +0100, Stefano Sabatini wrote:
> > > On date Wednesday 2009-01-28 23:24:39 +0100, Michael Niedermayer encoded:
> > > > On Wed, Jan 28, 2009 at 11:02:32PM +0100, Stefano Sabatini wrote:
> > > [...]
> > > > the code is not factorized out, its still containing 2 seperate pages
> > > > of code that check equality and print stuff
> > > >
> > > > you want a function, a single function that decodes, encodes, tests, and
> > > > prints that then is feeded with random and not random data
> > >
> > > Round 4:
> > > ------------------------------------------8<-------------------------------
> > > #ifdef TEST
> > > #include "mem.h"
> > > #include "lfg.h"
> > >
> > > #undef printf
> > >
> > > #define SHOW_STUFF(stuff) show_stuff ? (const char *)stuff : "[...]"
> > >
> > > int test_encode_decode(const char *data, unsigned int data_size, const char *encoded_ref, int show_stuff)
> > > {
> > > unsigned int encoded_size = data_size * 4 / 3 + 12;
> > > char *encoded = 0;
> > > uint8_t *data2 = 0;
> > > int size, data2_size, ret = -1;
> > >
> > > printf("Encoding data with size %d bytes '%s'... ", data_size, SHOW_STUFF(data));
> >
> > > if (!(encoded = av_malloc(encoded_size))) {
> > > printf("failed: cannot allocate the buffer for the encoded string\n");
> > > goto the_end;
> > > }
> >
> > encoded[MAX_SIZE]
> >
> >
> > > if (!av_base64_encode(encoded, encoded_size, data, data_size)) {
> > > printf("failed: cannot encode the input data\n");
> > > goto the_end;
> > > }
> >
> > > printf("encoded as '%s'... ", SHOW_STUFF(encoded));
> > > if (encoded_ref && (strlen(encoded) != strlen(encoded_ref) || strcmp(encoded, encoded_ref))) {
> > > printf("failed: differs from reference '%s'\n", SHOW_STUFF(encoded_ref));
> > > goto the_end;
> > > }
> >
> > its enough to print it when it differs
> > whats the strlen() check supposed to do?
> >
> >
> > >
> > > size = data_size + 10; // try without 10 as well
> > > if (!(data2 = av_malloc(size))) {
> > > printf("failed: cannot allocate the buffer for the decoded data\n");
> > > goto the_end;
> > > }
> >
> > get rid of all malloc() please this is supposed to be a small test program not a big
> > bloated thing that supports everything it will never be feeded with
> >
> >
> > >
> > > data2_size = av_base64_decode(data2, encoded, size);
> >
> > > if (data2_size < 0) {
> > > printf("failed: cannot decode the encoded string '%s'\n", SHOW_STUFF(encoded));
> > > goto the_end;
> > > }
> > > if (data2_size != data_size) {
> > > printf("failed: decoded/encoded size mismatch (%d != %d)\n", data2_size, data_size);
> > > goto the_end;
> > > }
> >
> > i assume data_size is not <0 so the 2nd check is enough
> >
> >
> > > if (memcmp(data2, data, data_size)) {
> > > printf("failed: data differs\n");
> > > goto the_end;
> > > }
> > > printf("passed!\n");
> > > ret = 0;
> > >
> > > the_end:
> > > av_free(data2);
> > > av_free(encoded);
> > > return ret;
> > > }
> > >
> > > int main(void)
> > > {
> > > int error_count = 0;
> > >
> > > struct test {
> > > const uint8_t *data;
> > > int data_size;
> > > const char *encoded_ref;
> > > } *t, tests[] = {
> > > { "", 0, ""},
> > > { "1", 1, "MQ=="},
> > > { "22", 2, "MjI="},
> > > { "333", 3, "MzMz"},
> > > { "4444", 4, "NDQ0NA=="},
> > > { "55555", 5, "NTU1NTU="},
> > > { "666666", 6, "NjY2NjY2"},
> > > { "abc:def", 7, "YWJjOmRlZg=="},
> > > { NULL}
> > > };
> > >
> > > printf("Encoding/decoding tests on constant data with reference\n");
> > > for (t = tests; t->data; t++)
> > > if (test_encode_decode(t->data, t->data_size, t->encoded_ref, 1))
> > > error_count++;
> >
> > error_count += func();
> >
> >
> > >
> > > printf("\nEncoding/decoding tests on random data\n");
> > > {
> > > int test_count;
> > > AVLFG lfg;
> > > av_lfg_init(&lfg, 123456);
> > > for (test_count = 0; test_count < 100; test_count++) {
> > > uint8_t data[1024];
> > ^^^^
> > #define SOME_WISE_NAME_TAT_MEANS_MAX_OF_THE_THING
> > no not the one starting with V ;)
> >
> >
> > > int data_size = av_lfg_get(&lfg) % (sizeof(data) + 1);
> > > for (int i = 0; i < data_size; i++)
> > > data[i] = av_lfg_get(&lfg) % 255;
> >
> > this will just use 0..254
> >
> >
> > >
> > > if (test_encode_decode(data, data_size, NULL, 0))
> > > error_count++;
> > > }
> > > }
> > >
> > > printf("\nDecoding tests on constant invalid data\n");
> > > {
> > > uint8_t data[32];
> > > int i;
> > > const char *encoded[] = { "M", "M=M=", "MQ===" };
> > >
> > > for (i=0; i < FF_ARRAY_ELEMS(encoded); i++) {
> > > printf("Decoding invalid encoded string '%s'... ", encoded[i]);
> > > if (av_base64_decode(data, encoded[i], sizeof(data)) >= 0) {
> > > printf("failed: data considered valid!\n");
> > > error_count++;
> > > }
> > > else
> > > printf("passed: data considered invalid!\n");
> > > }
> > > }
> >
> > next try to factorize the code
> > hint:
> >
> > for(counter){
> > if(counter < C1){
> > ret= test_encode_decode(table[counter])
> > if(counter < C0)
> > ret= !ret;
> > }else{
> > for()
> > temp[]= random
> > ret= test_encode_decode(temp)
> > }
> > if(ret)
> > printf("error blah blah this and that happened and we expected that")
> > }
>
> I think I addressed all the points.
>
> Round 5:
> ------------------8<----------------------8<-------------------------
> #ifdef TEST
> #include "mem.h"
> #include "lfg.h"
>
> #undef printf
>
> #define MAX_DATA_SIZE 1024
> #define MAX_ENCODED_SIZE 2048
>
> #define SHOW_STUFF(stuff) show_stuff ? (const char *)stuff : "[...]"
please explain wat this is supposed to be good for?
[...]
> printf("\nDecoding tests on invalid data\n");
> {
> uint8_t data[32];
> const char *encoded[] = { "M", "M=M=", "MQ===" };
why is this splited off and not in the main table?
>
> for (int i=0; i < FF_ARRAY_ELEMS(encoded); i++) {
> printf("Decoding invalid encoded string '%s'... ", encoded[i]);
> if (av_base64_decode(data, encoded[i], sizeof(data)) >= 0) {
> printf("failed: data considered valid!\n");
> error_count++;
> }
> else
this is not K&R style
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Old school: Use the lowest level language in which you can solve the problem
conveniently.
New school: Use the highest level language in which the latest supercomputer
can solve the problem without the user falling asleep waiting.
-------------- 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/20090130/e573a7b9/attachment.pgp>
More information about the ffmpeg-devel
mailing list