summaryrefslogtreecommitdiffstats
path: root/runtime/tests/testlist.c
blob: 7086ff9bf3db2a2d4cc4aaa8a1e9cdfa8ebabf90 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "test.h"

/* testliat.c - DO NOT EDIT without updating the expected results in map.test. */

/* 
   Tests maps acting as Lists
*/



static void
map_dump (MAP map)
{
  struct map_node_str *ptr;
  foreach (map, ptr)
    printf ("map[%ld] = %s\n", key1int(ptr), ptr->str);
  printf ("\n");
}


int main ()
{
  char buf[32];
  int i;
  MAP map = _stp_list_new(10, STRING);

  for (i = 0; i < 10; i++)
    {
      sprintf (buf, "Item%d", i);
      _stp_list_add_str (map, buf);
    }

  map_dump(map);
  printf ("size is %d\n", _stp_list_size(map));

  /* we set a limit of 10 elements so these push */
  /* the first entries out of the list */
  for (i = 50; i < 55; i++)
    {
      sprintf (buf, "Item%d", i);
      _stp_list_add_str (map, buf);
    }

  map_dump(map);

  for (i = 0; i < 10; i++)
    {
      sprintf (buf, "Item%d", i);
      _stp_list_add_str (map, buf);
    }

  map_dump(map);
  _stp_list_clear (map);
  map_dump(map);
  for (i = 50; i < 55; i++)
    {
      sprintf (buf, "Item%d", i);
      _stp_list_add_str (map, buf);
    }
  map_dump(map);
  _stp_map_del (map);
  return 0;
}