5bb14cdbc7e833e46d3f352978beea677fb1b22a
[oweals/gnunet.git] / src / gnsrecord / test_gnsrecord_block_expiration.c
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2013 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your 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      Affero General Public License for more details.
14     
15      You should have received a copy of the GNU Affero General Public License
16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 /**
19  * @file gnsrecord/test_gnsrecord_crypto.c
20  * @brief testcase for block creation, verification and decryption
21  */
22 #include "platform.h"
23 #include "gnunet_util_lib.h"
24 #include "gnunet_gnsrecord_lib.h"
25
26 #define RECORDS 5
27
28 #define TEST_RECORD_TYPE 1234
29
30 #define TEST_RECORD_DATALEN 123
31
32 #define TEST_RECORD_DATA 'a'
33
34 #define TEST_REMOVE_RECORD_TYPE 4321
35
36 #define TEST_REMOVE_RECORD_DATALEN 255
37
38 #define TEST_REMOVE_RECORD_DATA 'b'
39
40 static int res;
41
42
43
44 static void
45 run (void *cls, char *const *args, const char *cfgfile,
46      const struct GNUNET_CONFIGURATION_Handle *cfg)
47 {
48   struct GNUNET_GNSRECORD_Data rd[2];
49   struct GNUNET_TIME_Absolute expiration_abs;
50   struct GNUNET_TIME_Absolute expiration_abs_shadow;
51
52   expiration_abs.abs_value_us = GNUNET_TIME_absolute_get().abs_value_us +
53       GNUNET_TIME_UNIT_SECONDS.rel_value_us;
54   expiration_abs_shadow.abs_value_us = GNUNET_TIME_absolute_get().abs_value_us +
55       GNUNET_TIME_UNIT_MINUTES.rel_value_us;
56
57   /* create record */
58   rd[0].expiration_time = expiration_abs.abs_value_us;
59   rd[0].record_type = TEST_RECORD_TYPE;
60   rd[0].data_size = TEST_RECORD_DATALEN;
61   rd[0].data = GNUNET_malloc(TEST_RECORD_DATALEN);
62   rd[0].flags = GNUNET_GNSRECORD_RF_NONE;
63   memset ((char *) rd[0].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
64
65   rd[1].expiration_time = expiration_abs.abs_value_us;
66   rd[1].record_type = TEST_RECORD_TYPE;
67   rd[1].data_size = TEST_RECORD_DATALEN;
68   rd[1].data = GNUNET_malloc(TEST_RECORD_DATALEN);
69   rd[1].flags = GNUNET_GNSRECORD_RF_NONE;
70   memset ((char *) rd[1].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
71
72   GNUNET_assert (expiration_abs.abs_value_us == GNUNET_GNSRECORD_record_get_expiration_time(2, rd).abs_value_us);
73
74   rd[1].expiration_time = expiration_abs_shadow.abs_value_us;
75   rd[1].record_type = TEST_RECORD_TYPE;
76   rd[1].data_size = TEST_RECORD_DATALEN;
77   rd[1].data = GNUNET_malloc(TEST_RECORD_DATALEN);
78   rd[1].flags = GNUNET_GNSRECORD_RF_SHADOW_RECORD;
79   memset ((char *) rd[1].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
80
81   GNUNET_assert (expiration_abs_shadow.abs_value_us == GNUNET_GNSRECORD_record_get_expiration_time(2, rd).abs_value_us);
82   res = 0;
83 }
84
85
86 int
87 main (int argc, char *argv[])
88 {
89   static char *const argvx[] = { "test-gnsrecord-crypto",
90     NULL
91   };
92   static struct GNUNET_GETOPT_CommandLineOption options[] = {
93     GNUNET_GETOPT_OPTION_END
94   };
95
96   res = 1;
97   GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx, "test-namestore-api",
98                       "nohelp", options, &run, &res);
99   return res;
100 }
101
102 /* end of test_gnsrecord_crypto.c */