glitch in the license text detected by hyazinthe, thank you!
[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 /**
16  * @file gnsrecord/test_gnsrecord_crypto.c
17  * @brief testcase for block creation, verification and decryption
18  */
19 #include "platform.h"
20 #include "gnunet_util_lib.h"
21 #include "gnunet_gnsrecord_lib.h"
22
23 #define RECORDS 5
24
25 #define TEST_RECORD_TYPE 1234
26
27 #define TEST_RECORD_DATALEN 123
28
29 #define TEST_RECORD_DATA 'a'
30
31 #define TEST_REMOVE_RECORD_TYPE 4321
32
33 #define TEST_REMOVE_RECORD_DATALEN 255
34
35 #define TEST_REMOVE_RECORD_DATA 'b'
36
37 static int res;
38
39
40
41 static void
42 run (void *cls, char *const *args, const char *cfgfile,
43      const struct GNUNET_CONFIGURATION_Handle *cfg)
44 {
45   struct GNUNET_GNSRECORD_Data rd[2];
46   struct GNUNET_TIME_Absolute expiration_abs;
47   struct GNUNET_TIME_Absolute expiration_abs_shadow;
48
49   expiration_abs.abs_value_us = GNUNET_TIME_absolute_get().abs_value_us +
50       GNUNET_TIME_UNIT_SECONDS.rel_value_us;
51   expiration_abs_shadow.abs_value_us = GNUNET_TIME_absolute_get().abs_value_us +
52       GNUNET_TIME_UNIT_MINUTES.rel_value_us;
53
54   /* create record */
55   rd[0].expiration_time = expiration_abs.abs_value_us;
56   rd[0].record_type = TEST_RECORD_TYPE;
57   rd[0].data_size = TEST_RECORD_DATALEN;
58   rd[0].data = GNUNET_malloc(TEST_RECORD_DATALEN);
59   rd[0].flags = GNUNET_GNSRECORD_RF_NONE;
60   memset ((char *) rd[0].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
61
62   rd[1].expiration_time = expiration_abs.abs_value_us;
63   rd[1].record_type = TEST_RECORD_TYPE;
64   rd[1].data_size = TEST_RECORD_DATALEN;
65   rd[1].data = GNUNET_malloc(TEST_RECORD_DATALEN);
66   rd[1].flags = GNUNET_GNSRECORD_RF_NONE;
67   memset ((char *) rd[1].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
68
69   GNUNET_assert (expiration_abs.abs_value_us == GNUNET_GNSRECORD_record_get_expiration_time(2, rd).abs_value_us);
70
71   rd[1].expiration_time = expiration_abs_shadow.abs_value_us;
72   rd[1].record_type = TEST_RECORD_TYPE;
73   rd[1].data_size = TEST_RECORD_DATALEN;
74   rd[1].data = GNUNET_malloc(TEST_RECORD_DATALEN);
75   rd[1].flags = GNUNET_GNSRECORD_RF_SHADOW_RECORD;
76   memset ((char *) rd[1].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
77
78   GNUNET_assert (expiration_abs_shadow.abs_value_us == GNUNET_GNSRECORD_record_get_expiration_time(2, rd).abs_value_us);
79   res = 0;
80 }
81
82
83 int
84 main (int argc, char *argv[])
85 {
86   static char *const argvx[] = { "test-gnsrecord-crypto",
87     NULL
88   };
89   static struct GNUNET_GETOPT_CommandLineOption options[] = {
90     GNUNET_GETOPT_OPTION_END
91   };
92
93   res = 1;
94   GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx, "test-namestore-api",
95                       "nohelp", options, &run, &res);
96   return res;
97 }
98
99 /* end of test_gnsrecord_crypto.c */