summaryrefslogtreecommitdiff
path: root/src/reclaim/test_reclaim_attribute.c
blob: f8faf8021a2f5749a9ca11bcb09f2b4e74e23866 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "platform.h"
#include "gnunet_common.h"
#include "gnunet_reclaim_lib.h"
#include "gnunet_container_lib.h"

int
main (int argc, char *argv[])
{
  struct GNUNET_RECLAIM_AttributeList *al;
  struct GNUNET_RECLAIM_AttributeList *al_two;
  struct GNUNET_RECLAIM_AttributeListEntry *ale;
  char attrname[100];
  char attrdata[100];
  size_t ser_len_claimed;
  size_t ser_len_actual;
  char *ser_data;
  int count = 0;

  al = GNUNET_new (struct GNUNET_RECLAIM_AttributeList);
  for (int i = 0; i < 12; i++)
  {
    memset (attrname, 0, 100);
    memset (attrdata, 0, 100);
    sprintf (attrname, "attr%d", i);
    sprintf (attrdata, "%d", i);
    ale = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry);
    ale->attribute = GNUNET_RECLAIM_attribute_new (attrname,
                                                   &GNUNET_RECLAIM_ID_ZERO,
                                                   GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING,
                                                   attrdata,
                                                   strlen (attrdata));
    GNUNET_CONTAINER_DLL_insert (al->list_head,
                                 al->list_tail,
                                 ale);
  }
  ser_len_claimed = GNUNET_RECLAIM_attribute_list_serialize_get_size (al);
  ser_data = GNUNET_malloc (ser_len_claimed);
  ser_len_actual = GNUNET_RECLAIM_attribute_list_serialize (al,
                                                            ser_data);
  GNUNET_assert (ser_len_claimed == ser_len_actual);
  al_two = GNUNET_RECLAIM_attribute_list_deserialize (ser_data,
                                                      ser_len_actual);
  for (ale = al_two->list_head; NULL != ale; ale = ale->next)
    count++;
  GNUNET_assert (12 == count);
  //GNUNET_assert (-1 != deser_len);
  GNUNET_free (ser_data);
  GNUNET_RECLAIM_attribute_list_destroy (al);
}