Statistics
| Branch: | Revision:

grapes / som / Tests / chunkidset_test.c @ f3480090

History | View | Annotate | Download (1.89 KB)

1 c22e4acd Luca Abeni
/*
2
 *  Copyright (c) 2009 Luca Abeni
3
 *
4
 *  This is free software; see GPL.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 f3480090 CsabaKiraly
  printf("Add %d ---> Result=%d\tSize=%d\n", n, res, chunkID_set_size(c));
29 c22e4acd Luca Abeni
}
30
31
static void print_set(struct chunkID_set *c)
32
{
33 f3480090 CsabaKiraly
  int i, size = chunkID_set_size(c);
34 c22e4acd Luca Abeni
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 8e2e9adf Luca Abeni
static void populate(struct chunkID_set *cset)
45 c22e4acd Luca Abeni
{
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 8e2e9adf Luca Abeni
}
53
54
static void simple_test(void)
55
{
56
  struct chunkID_set *cset;
57 c22e4acd Luca Abeni
58 8e2e9adf Luca Abeni
  cset = chunkID_set_init(0);
59 f3480090 CsabaKiraly
  printf("Chunk ID Set initialised: size is %d\n", chunkID_set_size(cset));
60 8e2e9adf Luca Abeni
  populate(cset);
61 c22e4acd Luca Abeni
  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 f3480090 CsabaKiraly
  chunkID_set_clear(cset, 0);
69 c22e4acd Luca Abeni
  free(cset);
70 8e2e9adf Luca Abeni
}
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 f3480090 CsabaKiraly
  chunkID_set_clear(cset, 0);
84 8e2e9adf Luca Abeni
  free(cset);
85
  
86
  cset1 = decodeChunkSignaling(&meta, &meta_len, buff, res);
87
  print_set(cset1);
88 f3480090 CsabaKiraly
  chunkID_set_clear(cset1, 0);
89 8e2e9adf Luca Abeni
  free(cset1);
90
}
91
92
int main(int argc, char *argv[])
93
{
94
  simple_test();
95
  encoding_test();
96 c22e4acd Luca Abeni
97
  return 0;
98
}