summaryrefslogtreecommitdiffstats
path: root/runtime/tests/teststrstrstr.c
blob: 95ffc1a282773355df678d2f1c31d5b9c3bf5acc (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "test.h"

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

/* 
   key - str,str
   val - str
*/



static void
map_dump (MAP map)
{
  struct map_node_str *ptr;
  printf ("\n");
  for (ptr = (struct map_node_str *)map_start(map); ptr; 
       ptr = (struct map_node_str *)map_iter (map, (struct map_node *)ptr))
    printf ("map[%s,%s] = %s\n", key1str(ptr), key2str(ptr), ptr->str);
  printf ("\n");
}

static void m_print (MAP map)
{
  struct map_node_str *m = (struct map_node_str *)map->key;
  printf ("map[%s,%s]=%s\n", key1str(m), key2str(m), map_get_str(map));
}
int main ()
{
  MAP mymap = map_new(4, STRING);

  _stp_map_key2 (mymap, "two", "2" );
  _stp_map_set (mymap, "four");
  m_print (mymap);

  _stp_map_key2 (mymap, "eighty-four", "nineteen hundred");
  _stp_map_set (mymap, "nineteen hundred and eighty-three");

  _stp_map_key2 (mymap, "two-two-one-B", "Baker Street");
  _stp_map_set (mymap, "7% solution");

  m_print (mymap);
  _stp_map_key2 (mymap, "two", "2");  
  m_print (mymap);
  _stp_map_key2 (mymap, "eighty-four", "nineteen hundred");
  m_print (mymap);

  _stp_map_set (mymap, "nineteen hundred and eighty-four");
  m_print (mymap);


  /* now try to confuse things */
  /* These won't do anything useful, but shouldn't crash */
  _stp_map_key2 (mymap, NULL, NULL);  
  map_key_del (mymap);

  _stp_map_key2 (mymap, "0123456789", "4444");  
  _stp_map_set (mymap,"1000000");

  map_dump (mymap);

  _stp_map_key2 (mymap, "77", "66");  
  map_key_del (mymap);
  map_key_del (mymap);
  _stp_map_set (mymap,"99999999");

  /* create and delete a key */
  _stp_map_key2 (mymap, "2048", "2");
  _stp_map_set (mymap, "4096");

  _stp_map_key2 (mymap, "2048", "2");
  m_print (mymap);
  map_key_del (mymap);

  printf ("mymap[2048,2]=%s\n", map_get_str(mymap));
  _stp_map_key2 (mymap, "six", "10");
  printf ("mymap[six,10]=%s\n", map_get_str(mymap));

  map_dump(mymap);

  _stp_map_key2 (mymap, "two-two-one-B", "Baker Street"); map_key_del (mymap);
  map_dump(mymap);


  _stp_map_key2 (mymap, "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", NULL); 
  _stp_map_set (mymap, "TESTING 1,2,3");

  _stp_map_key2 (mymap, "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZhiasdhgfiudsgfiusdgfisdugfisdugfsdiufgsdfiugsdifugsdiufgsdiufgisdugfisdugfigsdfiusdgfiugsdifu sdfigsdifugsdifugsdiufgsdiufgisdugfiudsgfisudgfiusdgfiusdgfisdugfisdufgiusdfgsdiufgdsiufgsdiufgsdiufgsdiufgwiugfw89e4rf98yf897ywef98wyef98wyf98wyf89ys9d8yfsd sdfysd98fy9s8fyds98fy98dsfy89sdfy", "yw98fty98sfts98d7fts89d7f9sdfoooooooooooooooooooooooooooooooooooooooooooof8eo7stfew87fwet8tw87rf7fpowft7ewfptpwefpwetfpwepwfwetfp8we");

  _stp_map_set (mymap, "TESTING 1,2,3 ***************************************************************************************************************************************************************************************************************************************************************************** 4,5,6");
  map_dump(mymap);

  /* add 4 new entries, pushing "Ohio" out */
  int i;
  for (i = 2; i < 6; i++)
    {
      char buf[32], buf2[32], buf3[32];
      sprintf (buf, "test_number_%d", i);
      sprintf (buf2, "TEST_NUMBER_%d", i*i);
      sprintf (buf3, "TEST_NUMBER_%d", i*i*i);
      _stp_map_key2 (mymap, buf, buf2);
      _stp_map_set_str (mymap, buf3);
    }
  map_dump (mymap);

  /* delete all entries */
  for (i = 2; i < 6; i++)
    {
      char buf[32], buf2[32], buf3[32];
      sprintf (buf, "test_number_%d", i);
      sprintf (buf2, "TEST_NUMBER_%d", i*i);
      sprintf (buf3, "TEST_NUMBER_%d", i*i*i);
      _stp_map_key2 (mymap, buf, buf2);
      map_key_del (mymap);
    }

  printf ("Should be empty: ");
  map_dump (mymap);
  _stp_map_del (mymap);
  return 0;
}