[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r1582 - Extractor/src/main
From: |
grothoff |
Subject: |
[GNUnet-SVN] r1582 - Extractor/src/main |
Date: |
Tue, 19 Jul 2005 03:37:55 -0700 (PDT) |
Author: grothoff
Date: 2005-07-19 03:37:49 -0700 (Tue, 19 Jul 2005)
New Revision: 1582
Added:
Extractor/src/main/test_binary.c
Modified:
Extractor/src/main/Makefile.am
Extractor/src/main/extractor.c
Log:
decode buffer of size 0 should return success
Modified: Extractor/src/main/Makefile.am
===================================================================
--- Extractor/src/main/Makefile.am 2005-07-18 21:50:29 UTC (rev 1581)
+++ Extractor/src/main/Makefile.am 2005-07-19 10:37:49 UTC (rev 1582)
@@ -49,3 +49,14 @@
getopt.h \
getopt1.c
+
+check_PROGRAMS = \
+ test_binary
+
+TESTS = $(check_PROGRAMS)
+
+test_binary_SOURCES = \
+ test_binary.c
+test_binary_LDADD = \
+ $(top_builddir)/src/main/libextractor.la
+
Modified: Extractor/src/main/extractor.c
===================================================================
--- Extractor/src/main/extractor.c 2005-07-18 21:50:29 UTC (rev 1581)
+++ Extractor/src/main/extractor.c 2005-07-19 10:37:49 UTC (rev 1582)
@@ -991,7 +991,7 @@
if (inSize == 0) {
*out = NULL;
*outSize = 0;
- return 1;
+ return 0;
}
buf = malloc(inSize); /* slightly more than needed ;-) */
Added: Extractor/src/main/test_binary.c
===================================================================
--- Extractor/src/main/test_binary.c 2005-07-18 21:50:29 UTC (rev 1581)
+++ Extractor/src/main/test_binary.c 2005-07-19 10:37:49 UTC (rev 1582)
@@ -0,0 +1,66 @@
+/*
+ This file is part of libextractor.
+ (C) 2005 Vidyut Samanta and Christian Grothoff
+
+ libextractor 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, or (at your
+ option) any later version.
+
+ libextractor 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 libextractor; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+
+#include "platform.h"
+#include "extractor.h"
+
+static int test(const char * buf,
+ size_t size) {
+ char * enc;
+ unsigned char * dec;
+ size_t out;
+
+ enc = EXTRACTOR_binaryEncode(buf,
+ size);
+ if (0 != EXTRACTOR_binaryDecode(enc,
+ &dec,
+ &out)) {
+ free(enc);
+ return 0;
+ }
+ free(enc);
+ if (out != size) {
+ free(dec);
+ return 0;
+ }
+ if (0 != memcmp(buf,
+ dec,
+ size)) {
+ free(dec);
+ return 0;
+ }
+ free(dec);
+ return 1;
+}
+
+int main(int argc,
+ char * argv[]) {
+ unsigned int i;
+ char buf[2048];
+
+ for (i=0;i<2048;i++) {
+ buf[i] = (char) rand();
+ if (! test(buf, i)) {
+ printf("Failed: %u\n", i);
+ return -1;
+ }
+ }
+ return 0;
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r1582 - Extractor/src/main,
grothoff <=