7397735583e7dfb02dc8774597a26804b5b22bc2
[oweals/gnunet.git] / src / util / test_strings_to_data.c
1 /*
2      This file is part of GNUnet.
3      (C) 2009 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20 /**
21  * @file util/test_strings_to_data.c
22  * @brief testcase for strings.c
23  */
24 #include "platform.h"
25 #include "gnunet_common.h"
26 #include "gnunet_crypto_lib.h"
27 #include "gnunet_strings_lib.h"
28
29
30 int
31 main (int argc, char *argv[])
32 {
33   char buf[1024];
34   char *end;
35   char src[128];
36   char dst[128];
37   unsigned int i;
38   int ret = 0;
39   
40   GNUNET_log_setup ("util", "DEBUG", NULL);
41   for (i=0;i<sizeof(src);i++)
42   {
43     memset (src, i, sizeof (src));
44     memset (dst, i+1, sizeof (dst));
45
46     end = GNUNET_STRINGS_data_to_string (&src, i, buf, sizeof (buf));
47     end[0] = '\0';
48     if (GNUNET_OK != 
49         GNUNET_STRINGS_string_to_data (buf, strlen (buf), dst, i))
50     {
51       fprintf (stderr, "%u failed decode (%u bytes)\n", i, (unsigned int) strlen (buf));
52       ret = 1;
53     } else if (0 != memcmp (src, dst, i))
54     {
55       fprintf (stderr, "%u wrong decode (%u bytes)\n", i, (unsigned int) strlen (buf));
56       ret = 1;
57     }
58   }
59   return ret;
60 }
61
62
63 /* end of test_strings_to_data.c */