diff options
Diffstat (limited to 'src/reclaim/test_reclaim_attribute.c')
-rw-r--r-- | src/reclaim/test_reclaim_attribute.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/reclaim/test_reclaim_attribute.c b/src/reclaim/test_reclaim_attribute.c new file mode 100644 index 000000000..f71d86b56 --- /dev/null +++ b/src/reclaim/test_reclaim_attribute.c | |||
@@ -0,0 +1,51 @@ | |||
1 | #include "platform.h" | ||
2 | #include "gnunet_common.h" | ||
3 | #include "gnunet_reclaim_lib.h" | ||
4 | #include "gnunet_container_lib.h" | ||
5 | |||
6 | int | ||
7 | main (int argc, char *argv[]) | ||
8 | { | ||
9 | struct GNUNET_RECLAIM_AttributeList *al; | ||
10 | struct GNUNET_RECLAIM_AttributeList *al_two; | ||
11 | struct GNUNET_RECLAIM_AttributeListEntry *ale; | ||
12 | struct GNUNET_RECLAIM_Attribute *attr; | ||
13 | char attrname[100]; | ||
14 | char attrdata[100]; | ||
15 | size_t ser_len_claimed; | ||
16 | size_t ser_len_actual; | ||
17 | ssize_t deser_len; | ||
18 | char *ser_data; | ||
19 | int count = 0; | ||
20 | |||
21 | al = GNUNET_new (struct GNUNET_RECLAIM_AttributeList); | ||
22 | for (int i = 0; i < 12; i++) | ||
23 | { | ||
24 | memset (attrname, 0, 100); | ||
25 | memset (attrdata, 0, 100); | ||
26 | sprintf (attrname, "attr%d", i); | ||
27 | sprintf (attrdata, "%d", i); | ||
28 | ale = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry); | ||
29 | ale->attribute = GNUNET_RECLAIM_attribute_new (attrname, | ||
30 | &GNUNET_RECLAIM_ID_ZERO, | ||
31 | GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING, | ||
32 | attrdata, | ||
33 | strlen (attrdata)); | ||
34 | GNUNET_CONTAINER_DLL_insert (al->list_head, | ||
35 | al->list_tail, | ||
36 | ale); | ||
37 | } | ||
38 | ser_len_claimed = GNUNET_RECLAIM_attribute_list_serialize_get_size (al); | ||
39 | ser_data = GNUNET_malloc (ser_len_claimed); | ||
40 | ser_len_actual = GNUNET_RECLAIM_attribute_list_serialize (al, | ||
41 | ser_data); | ||
42 | GNUNET_assert (ser_len_claimed == ser_len_actual); | ||
43 | al_two = GNUNET_RECLAIM_attribute_list_deserialize (ser_data, | ||
44 | ser_len_actual); | ||
45 | for (ale = al_two->list_head; NULL != ale; ale = ale->next) | ||
46 | count++; | ||
47 | GNUNET_assert (12 == count); | ||
48 | //GNUNET_assert (-1 != deser_len); | ||
49 | GNUNET_free (ser_data); | ||
50 | GNUNET_RECLAIM_attribute_list_destroy (al); | ||
51 | } | ||