summaryrefslogtreecommitdiffstats
path: root/runtime/tests/maps/si.c
diff options
context:
space:
mode:
authorhunt <hunt>2005-05-17 06:58:05 +0000
committerhunt <hunt>2005-05-17 06:58:05 +0000
commitca7d122b7b3fb57d6cabdbdc5da9c1ecc60de5d8 (patch)
tree7272af5f7bfb67412fbdbfa2a9cc7f63e8fa09c3 /runtime/tests/maps/si.c
parente96dd1fa4e4ba81198e92f7abd340124ba126258 (diff)
downloadsystemtap-steved-ca7d122b7b3fb57d6cabdbdc5da9c1ecc60de5d8.tar.gz
systemtap-steved-ca7d122b7b3fb57d6cabdbdc5da9c1ecc60de5d8.tar.xz
systemtap-steved-ca7d122b7b3fb57d6cabdbdc5da9c1ecc60de5d8.zip
Restructuring of tests. New tests for new maps.
Diffstat (limited to 'runtime/tests/maps/si.c')
-rw-r--r--runtime/tests/maps/si.c112
1 files changed, 112 insertions, 0 deletions
diff --git a/runtime/tests/maps/si.c b/runtime/tests/maps/si.c
new file mode 100644
index 00000000..4f3e3f35
--- /dev/null
+++ b/runtime/tests/maps/si.c
@@ -0,0 +1,112 @@
+#include "runtime.h"
+
+/* test of maps with keys of string and value of int64 */
+
+#define KEY1_TYPE STRING
+#include "map-keys.c"
+
+#define VALUE_TYPE INT64
+#include "map-values.c"
+
+#include "map.c"
+
+int main ()
+{
+ MAP map = _stp_map_new_str(4, INT64);
+
+ /* map[Ohio] = 1 */
+ _stp_map_key_str (map, "Ohio");
+ _stp_map_set_int64 (map, 1);
+ printf ("map[%s]=%lld\n", key1str(map->key), _stp_map_get_int64(map));
+ _stp_map_print(map,"map");
+
+ /* map[Washington] = 2 */
+ /* try it with macros this time */
+ _stp_map_key (map, "Washington");
+ _stp_map_set (map, 2);
+ _stp_map_print (map, "map");
+
+ /* now try to confuse things */
+ /* These won't do anything useful, but shouldn't crash */
+ _stp_map_key_str (map, "");
+ _stp_map_key_del (map);
+ _stp_map_key_str (map, "77");
+ _stp_map_key_del (map);
+ _stp_map_key_del (map);
+ _stp_map_set_int64 (map,1000000);
+
+ _stp_map_print (map, "map");
+
+ /* create and delete a key */
+ _stp_map_key_str (map, "1024");
+ _stp_map_set_int64 (map, 2048);
+ _stp_map_key_str (map, "1024");
+ _stp_map_key_del (map);
+
+ _stp_map_print (map, "map");
+
+ /* create and delete a key again*/
+ _stp_map_key_str (map, "1024");
+ _stp_map_set_int64 (map, 2048);
+ _stp_map_key_del (map);
+
+ _stp_map_print (map, "map");
+
+ /* check that unset values are 0 */
+ _stp_map_key_str (map, "California");
+ printf ("map[%lld]=%lld\n", key1int(map->key), _stp_map_get_int64(map));
+
+ /* map[California] = 3 */
+ _stp_map_set (map, 3);
+ _stp_map_print (map, "map");
+
+ /* test an empty string as key */
+ _stp_map_key (map, "");
+ _stp_map_set_int64 (map, 7777);
+ _stp_map_print (map, "map");
+ _stp_map_key (map, "");
+ _stp_map_set_int64 (map, 8888);
+ _stp_map_print (map, "map");
+
+ /* add 4 new entries, pushing the others out */
+ int i;
+ for (i = 6; i < 10; i++)
+ {
+ char buf[32];
+ sprintf (buf, "String %d", i);
+ _stp_map_key (map, buf);
+ _stp_map_set_int64 (map, 100 + i);
+ }
+
+ _stp_map_print (map, "map");
+
+
+ /* 5, 382, 526, and 903 all hash to the same value (23) */
+ /* use them to test the hash chain */
+ _stp_map_key (map, "5"); _stp_map_set_int64 (map, 1005);
+ _stp_map_key (map, "382"); _stp_map_set_int64 (map, 1382);
+ _stp_map_key (map, "526"); _stp_map_set_int64 (map, 1526);
+ _stp_map_key (map, "903"); _stp_map_set_int64 (map, 1903);
+
+ _stp_map_print (map, "map");
+
+ /* now delete all 4 nodes, one by one */
+ _stp_map_key (map, "382"); _stp_map_key_del (map);
+
+ _stp_map_print (map, "map");
+
+ _stp_map_key (map, "5"); _stp_map_key_del (map);
+
+ _stp_map_print (map, "map");
+
+ _stp_map_key (map, "903"); _stp_map_key_del (map);
+
+ _stp_map_print (map, "map");
+
+ _stp_map_key (map, "526"); _stp_map_key_del (map);
+
+ _stp_map_print (map, "map");
+
+ _stp_map_del (map);
+ return 0;
+}