indentation
[oweals/gnunet.git] / src / block / test_block.c
1 /*
2      This file is part of GNUnet
3      (C) 2010 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 block/test_block.c
22  * @brief test for block.c
23  * @author Christian Grothoff
24  */
25 #include "platform.h"
26 #include "gnunet_block_lib.h"
27
28 #define DEBUG GNUNET_NO
29
30 #define VERBOSE GNUNET_NO
31
32 static int
33 test_fs (struct GNUNET_BLOCK_Context *ctx)
34 {
35   GNUNET_HashCode key;
36   char block[4];
37
38   memset (block, 1, sizeof (block));
39   if (GNUNET_OK !=
40       GNUNET_BLOCK_get_key (ctx,
41                             GNUNET_BLOCK_TYPE_FS_DBLOCK,
42                             block, sizeof (block), &key))
43     return 1;
44   if (GNUNET_BLOCK_EVALUATION_OK_LAST !=
45       GNUNET_BLOCK_evaluate (ctx,
46                              GNUNET_BLOCK_TYPE_FS_DBLOCK,
47                              &key, NULL, 0, NULL, 0, block, sizeof (block)))
48     return 2;
49   if (GNUNET_BLOCK_EVALUATION_REQUEST_VALID !=
50       GNUNET_BLOCK_evaluate (ctx,
51                              GNUNET_BLOCK_TYPE_FS_DBLOCK,
52                              &key, NULL, 0, NULL, 0, NULL, 0))
53     return 4;
54   GNUNET_log_skip (1, GNUNET_NO);
55   if (GNUNET_BLOCK_EVALUATION_REQUEST_INVALID !=
56       GNUNET_BLOCK_evaluate (ctx,
57                              GNUNET_BLOCK_TYPE_FS_DBLOCK,
58                              &key, NULL, 0, "bogus", 5, NULL, 0))
59     return 8;
60   GNUNET_log_skip (0, GNUNET_YES);
61   return 0;
62 }
63
64 int
65 main (int argc, char *argv[])
66 {
67   int ret;
68   struct GNUNET_BLOCK_Context *ctx;
69   struct GNUNET_CONFIGURATION_Handle *cfg;
70
71   GNUNET_log_setup ("test-block", "WARNING", NULL);
72   cfg = GNUNET_CONFIGURATION_create ();
73   GNUNET_CONFIGURATION_set_value_string (cfg, "block", "PLUGINS", "fs");
74   ctx = GNUNET_BLOCK_context_create (cfg);
75   ret = test_fs (ctx);
76   GNUNET_BLOCK_context_destroy (ctx);
77   GNUNET_CONFIGURATION_destroy (cfg);
78   if (ret != 0)
79     fprintf (stderr, "Tests failed: %d\n", ret);
80   return ret;
81 }