Statistics
| Branch: | Revision:

grapes / som / Tests / chunkidset_test.c @ 8ab58ec7

History | View | Annotate | Download (1.89 KB)

1
/*
2
 *  Copyright (c) 2009 Luca Abeni
3
 *
4
 *  This is free software; see gpl-3.0.txt
5
 */
6

    
7
#include <stdint.h>
8
#include <stdlib.h>
9
#include <stdio.h>
10
#include "chunkidset.h"
11
#include "trade_sig_la.h"
12

    
13
static void check_chunk(struct chunkID_set *c, int n)
14
{
15
  printf("Is %d in the Chunk ID Set?\t", n);
16
  if (chunkID_set_check(c, n) >= 0) {
17
    printf("Yes\n");
18
  } else {
19
    printf("No\n");
20
  }
21
}
22

    
23
static void add_chunk(struct chunkID_set *c, int n)
24
{
25
  int res;
26

    
27
  res = chunkID_set_add_chunk(c, n);
28
  printf("Add %d ---> Result=%d\tSize=%d\n", n, res, chunkID_set_size(c));
29
}
30

    
31
static void print_set(struct chunkID_set *c)
32
{
33
  int i, size = chunkID_set_size(c);
34

    
35
  printf("Chunk ID Set size: %d\n", size);
36
  printf("Chunks (in priority order): ");
37
  for (i = 0; i < size; i++) {
38
    printf(" %d", chunkID_set_get_chunk(c, i));
39
  }
40

    
41
  printf("\n");
42
}
43

    
44
static void populate(struct chunkID_set *cset)
45
{
46
  add_chunk(cset, 2);
47
  add_chunk(cset, 1);
48
  add_chunk(cset, 3);
49
  add_chunk(cset, 5);
50
  add_chunk(cset, 7);
51
  add_chunk(cset, 11);
52
}
53

    
54
static void simple_test(void)
55
{
56
  struct chunkID_set *cset;
57

    
58
  cset = chunkID_set_init(0);
59
  printf("Chunk ID Set initialised: size is %d\n", chunkID_set_size(cset));
60
  populate(cset);
61
  print_set(cset);
62

    
63
  check_chunk(cset, 4);
64
  check_chunk(cset, 2);
65
  check_chunk(cset, 3);
66
  check_chunk(cset, 9);
67

    
68
  chunkID_set_clear(cset, 0);
69
  free(cset);
70
}
71

    
72
static void encoding_test(void)
73
{
74
  struct chunkID_set *cset, *cset1;
75
  static uint8_t buff[1024];
76
  int res, meta_len;
77
  void *meta;
78

    
79
  cset = chunkID_set_init(0);
80
  populate(cset);
81
  res = encodeChunkSignaling(cset, NULL, 0, buff, sizeof(buff));
82
  printf("Encoding Result: %d\n", res);
83
  chunkID_set_clear(cset, 0);
84
  free(cset);
85
  
86
  cset1 = decodeChunkSignaling(&meta, &meta_len, buff, res);
87
  print_set(cset1);
88
  chunkID_set_clear(cset1, 0);
89
  free(cset1);
90
}
91

    
92
int main(int argc, char *argv[])
93
{
94
  simple_test();
95
  encoding_test();
96

    
97
  return 0;
98
}