From cf55fc7bd7e53b0b15b241b5f9b894b9a051bb99 Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Sat, 15 Mar 2014 18:25:22 +1100 Subject: [PATCH] Add a test to validate that FLAC__MD5Final clears the MD5Context. Closes: https://sourceforge.net/p/flac/bugs/407/ --- src/test_libFLAC/Makefile.am | 4 ++- src/test_libFLAC/main.c | 6 ++-- src/test_libFLAC/md5.c | 61 ++++++++++++++++++++++++++++++++++++ src/test_libFLAC/md5.h | 26 +++++++++++++++ 4 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 src/test_libFLAC/md5.c create mode 100644 src/test_libFLAC/md5.h diff --git a/src/test_libFLAC/Makefile.am b/src/test_libFLAC/Makefile.am index d82651f1..407c8eaa 100644 --- a/src/test_libFLAC/Makefile.am +++ b/src/test_libFLAC/Makefile.am @@ -45,10 +45,12 @@ test_libFLAC_SOURCES = \ metadata.c \ metadata_manip.c \ metadata_object.c \ + md5.c \ bitwriter.h \ decoders.h \ encoders.h \ format.h \ - metadata.h + metadata.h \ + md5.h CLEANFILES = test_libFLAC.exe diff --git a/src/test_libFLAC/main.c b/src/test_libFLAC/main.c index b0c9febc..e23f2361 100644 --- a/src/test_libFLAC/main.c +++ b/src/test_libFLAC/main.c @@ -26,10 +26,12 @@ #include "encoders.h" #include "format.h" #include "metadata.h" +#include "md5.h" -int main(int argc, char *argv[]) +int main(void) { - (void)argc, (void)argv; + if(!test_md5()) + return 1; if(!test_bitwriter()) return 1; diff --git a/src/test_libFLAC/md5.c b/src/test_libFLAC/md5.c new file mode 100644 index 00000000..2b6d51bd --- /dev/null +++ b/src/test_libFLAC/md5.c @@ -0,0 +1,61 @@ +/* test_libFLAC - Unit tester for libFLAC + * Copyright (C) 2014 Xiph.Org Foundation + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#if HAVE_CONFIG_H +# include +#endif + +#include + +#include "FLAC/assert.h" +#include "share/compat.h" +#include "private/md5.h" +#include "md5.h" + + +FLAC__bool test_md5(void) +{ + FLAC__MD5Context ctx; + FLAC__byte digest[16]; + unsigned k ; + char * cptr; + + printf("\n+++ libFLAC unit test: md5\n\n"); + + printf("testing FLAC__MD5Init ... "); + FLAC__MD5Init (&ctx); + if (ctx.buf[0] != 0x67452301) { + printf("FAILED!\n"); + return false; + } + printf("OK\n"); + + printf("testing that FLAC__MD5Final clears the MD5Context ... "); + FLAC__MD5Final(digest, &ctx); + cptr = (char*) &ctx ; + for (k = 0 ; k < sizeof (ctx) ; k++) { + if (cptr [k]) { + printf("FAILED, MD5 ctx has not been cleared after FLAC__MD5Final\n"); + return false; + } + } + printf("OK\n"); + + printf("\nPASSED!\n"); + return true; +} diff --git a/src/test_libFLAC/md5.h b/src/test_libFLAC/md5.h new file mode 100644 index 00000000..b7ed057f --- /dev/null +++ b/src/test_libFLAC/md5.h @@ -0,0 +1,26 @@ +/* test_libFLAC - Unit tester for libFLAC + * Copyright (C) 2014 Xiph.Org Foundation + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef FLAC__TEST_LIBFLAC_MD5_H +#define FLAC__TEST_LIBFLAC_MD5_H + +#include "FLAC/ordinals.h" + +FLAC__bool test_md5(void); + +#endif