aboutsummaryrefslogtreecommitdiff
path: root/src/lib/gnsrecord/test_gnsrecord_block_expiration.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/gnsrecord/test_gnsrecord_block_expiration.c')
-rw-r--r--src/lib/gnsrecord/test_gnsrecord_block_expiration.c118
1 files changed, 118 insertions, 0 deletions
diff --git a/src/lib/gnsrecord/test_gnsrecord_block_expiration.c b/src/lib/gnsrecord/test_gnsrecord_block_expiration.c
new file mode 100644
index 000000000..14b2acd97
--- /dev/null
+++ b/src/lib/gnsrecord/test_gnsrecord_block_expiration.c
@@ -0,0 +1,118 @@
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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/**
21 * @file gnsrecord/test_gnsrecord_crypto.c
22 * @brief testcase for block creation, verification and decryption
23 */
24#include "platform.h"
25#include "gnunet_util_lib.h"
26#include "gnunet_gnsrecord_lib.h"
27
28#define RECORDS 5
29
30#define TEST_RECORD_TYPE 1234
31
32#define TEST_RECORD_DATALEN 123
33
34#define TEST_RECORD_DATA 'a'
35
36#define TEST_REMOVE_RECORD_TYPE 4321
37
38#define TEST_REMOVE_RECORD_DATALEN 255
39
40#define TEST_REMOVE_RECORD_DATA 'b'
41
42static int res;
43
44
45static void
46run (void *cls, char *const *args, const char *cfgfile,
47 const struct GNUNET_CONFIGURATION_Handle *cfg)
48{
49 struct GNUNET_GNSRECORD_Data rd[2];
50 struct GNUNET_TIME_Absolute expiration_abs;
51 struct GNUNET_TIME_Absolute expiration_abs_shadow;
52 char *tmp_data0;
53 char *tmp_data1;
54
55 expiration_abs.abs_value_us = GNUNET_TIME_absolute_get ().abs_value_us
56 + GNUNET_TIME_UNIT_SECONDS.rel_value_us;
57 expiration_abs_shadow.abs_value_us = GNUNET_TIME_absolute_get ().abs_value_us
58 + GNUNET_TIME_UNIT_MINUTES.rel_value_us;
59
60 /* create record */
61 rd[0].expiration_time = expiration_abs.abs_value_us;
62 rd[0].record_type = TEST_RECORD_TYPE;
63 rd[0].data_size = TEST_RECORD_DATALEN;
64 tmp_data0 = GNUNET_malloc (TEST_RECORD_DATALEN);
65 rd[0].data = tmp_data0;
66 rd[0].flags = GNUNET_GNSRECORD_RF_NONE;
67 memset ((char *) rd[0].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
68
69 rd[1].expiration_time = expiration_abs.abs_value_us;
70 rd[1].record_type = TEST_RECORD_TYPE;
71 rd[1].data_size = TEST_RECORD_DATALEN;
72 tmp_data1 = GNUNET_malloc (TEST_RECORD_DATALEN);
73 rd[1].data = tmp_data1;
74 rd[1].flags = GNUNET_GNSRECORD_RF_NONE;
75 memset ((char *) rd[1].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
76
77 GNUNET_assert (expiration_abs.abs_value_us ==
78 GNUNET_GNSRECORD_record_get_expiration_time (2,
79 rd,
80 GNUNET_TIME_UNIT_ZERO_ABS).abs_value_us);
81
82 rd[1].expiration_time = expiration_abs_shadow.abs_value_us;
83 rd[1].record_type = TEST_RECORD_TYPE;
84 rd[1].data_size = TEST_RECORD_DATALEN;
85 GNUNET_free (tmp_data1);
86 tmp_data1 = GNUNET_malloc (TEST_RECORD_DATALEN);
87 rd[1].data = tmp_data1;
88 rd[1].flags = GNUNET_GNSRECORD_RF_SHADOW;
89 memset ((char *) rd[1].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
90
91 GNUNET_assert (expiration_abs_shadow.abs_value_us ==
92 GNUNET_GNSRECORD_record_get_expiration_time (2,
93 rd,
94 GNUNET_TIME_UNIT_ZERO_ABS).abs_value_us);
95 GNUNET_free (tmp_data0);
96 GNUNET_free (tmp_data1);
97 res = 0;
98}
99
100
101int
102main (int argc, char *argv[])
103{
104 static char *const argvx[] = { "test-gnsrecord-crypto",
105 NULL };
106 static struct GNUNET_GETOPT_CommandLineOption options[] = {
107 GNUNET_GETOPT_OPTION_END
108 };
109
110 res = 1;
111 GNUNET_PROGRAM_run ((sizeof(argvx) / sizeof(char *)) - 1, argvx,
112 "test-namestore-api",
113 "nohelp", options, &run, &res);
114 return res;
115}
116
117
118/* end of test_gnsrecord_crypto.c */