* maps/keys.c: New file. Tests specific to _stp_key_get_*().
* maps/iiss2.c (main): Add some comments to make clear expected
results.
* maps/is2.c (main): _stp_map_get_*s() now returns "" instead
of NULL when lookup fails. _stp_map_set_*s() now deletes a node
when setting to "" (as well as NULL).
* maps/setadd.c (main): Ditto.
* maps/map.test: update results.
+2005-10-28 Martin Hunt <hunt@redhat.com>
+ * maps/keys.c: New file. Tests specific to _stp_key_get_*().
+
+ * maps/iiss2.c (main): Add some comments to make clear expected
+ results.
+ * maps/is2.c (main): _stp_map_get_*s() now returns "" instead
+ of NULL when lookup fails. _stp_map_set_*s() now deletes a node
+ when setting to "" (as well as NULL).
+ * maps/setadd.c (main): Ditto.
+ * maps/map.test: update results.
+
2005-10-26 Martin Hunt <hunt@redhat.com>
* maps/map.test: Add results for iiiiii and ssssss.
_stp_map_set_iiss (map, 5,6,"Washington", "Olympia" );
_stp_map_print (map, "map[%1d, %2d, %3s] = %s");
+ /* delete */
_stp_map_set_iiss (map, -9,-10,"Nevada", 0);
_stp_map_print (map, "map[%1d, %2d, %3s] = %s");
+ /* should add nothing */
_stp_map_set_iiss(map, 0,0,"", "");
_stp_map_print (map, "map[%1d, %2d, %3s] = %s");
_stp_map_print(map,"map[%1d] = %s");
- /* check that unset values are 0 */
- if (_stp_map_get_is(map, 5))
- printf("ERROR: unset key has nonzero value\n");
+ /* check that unset values are "" */
+ if (*_stp_map_get_is(map, 5))
+ printf("ERROR: unset key has nonempty value\n");
/* map[5] = "five" */
_stp_map_set_is (map, 5, "five");
_stp_map_print(map,"map[%1d] = %s");
- /* test empty string */
+ /* test empty string (should delete)*/
_stp_map_set_is (map, 5, "");
_stp_map_print(map,"map[%1d] = %s");
--- /dev/null
+#include "runtime.h"
+
+/* test of reading key values */
+#define VALUE_TYPE INT64
+#define KEY1_TYPE INT64
+#define KEY2_TYPE STRING
+#define KEY3_TYPE STRING
+#define KEY4_TYPE INT64
+#include "map-gen.c"
+
+#include "map.c"
+
+int main ()
+{
+ struct map_node *ptr;
+ MAP map = _stp_map_new_issii(4);
+
+ _stp_map_set_issii (map, 0, "Boston", "MA", 1970, 5224303 );
+ _stp_map_set_issii (map, 1, "Chicago", "IL", 2000, 8272768 );
+ _stp_map_set_issii (map, -1, "unknown", "", 2010, 1000000000 );
+
+ foreach (map, ptr)
+ printf ("map[%lld, %s, %s, %lld] = %lld\n",
+ _stp_key_get_int64(ptr,1),
+ _stp_key_get_str(ptr,2),
+ _stp_key_get_str(ptr,3),
+ _stp_key_get_int64(ptr,4),
+ _stp_get_int64(ptr));
+
+ /* get all the key and value types wrong */
+ foreach (map, ptr)
+ printf ("map[%s, %lld, %lld, %s] = %s\n",
+ _stp_key_get_str(ptr,1),
+ _stp_key_get_int64(ptr,2),
+ _stp_key_get_int64(ptr,3),
+ _stp_key_get_str(ptr,4),
+ _stp_get_str(ptr));
+
+ _stp_map_del (map);
+ return 0;
+}
map[1] = one
map[3] = three
-map[5] =
map[6] = value of 6
map[7] = value of 7
map[3, 4, California] = Sacramento
map[5, 6, Washington] = Olympia
map[7, 8, Oregon] = Salem
-map[0, 0, ] =
}
test setadd {Test of setting and adding values} -setup {
maps[3] = value of 3*****
maps[4] = value of 4*****
+maps[1] = value of 1*****
+maps[2] = value of 2*****
+maps[3] = value of 3*****
+maps[4] = value of 4*****
+
mapx[1] = count:3 sum:3 avg:1 min:0 max:2
mapx[2] = count:3 sum:6 avg:2 min:0 max:4
mapx[3] = count:3 sum:9 avg:3 min:0 max:6
mapx[4] = count:3 sum:12 avg:4 min:0 max:8
+Add 'X' to strings
+maps[1] = value of 1*****X
+maps[2] = value of 2*****X
+maps[3] = value of 3*****X
+maps[4] = value of 4*****X
+
setting everything to 0
+
Adding 0
+
mapx[1] = count:1 sum:0 avg:0 min:0 max:0
mapx[2] = count:1 sum:0 avg:0 min:0 max:0
mapx[3] = count:1 sum:0 avg:0 min:0 max:0
1XYZ and 2XYZ and 3XYZ and 4XYZ and 5XYZ ---> 999
}
-
-
-
+test keys {Test reading keys} -setup {
+ exec gcc $CFLAGS -I $KPATH -I $PATH -I $MPATH -o test keys.c
+} -body {
+ exec ./test
+} -result {map[0, Boston, MA, 1970] = 5224303
+map[1, Chicago, IL, 2000] = 8272768
+map[-1, unknown, , 2010] = 1000000000
+map[bad type, 0, 0, bad type] = bad type
+map[bad type, 0, 0, bad type] = bad type
+map[bad type, 0, 0, bad type] = bad type}
catch {exec rm test}
for (i = 1; i < 5; i++)
{
- char buf[32];
- sprintf(buf, "*****", i);
- res = _stp_map_add_is (maps, i, buf);
+ res = _stp_map_add_is (maps, i, "*****");
if (res)
printf("ERROR: got result of %d when expected 0\n", res);
}
if (res)
printf("ERROR: got result of %d when expected 0\n", res);
}
+ _stp_map_print(maps,"maps[%1d] = %s");
+
+ /* adding NULL should be same as adding "" for string values */
for (i = 1; i < 5; i++)
{
res = _stp_map_add_is (maps, i, 0);
}
_stp_map_print (mapx, "mapx[%1d] = count:%C sum:%S avg:%A min:%m max:%M");
+ /*************** now add X to strings *******************/
+ printf ("Add 'X' to strings\n");
+ for (i = 1; i < 5; i++)
+ {
+ res = _stp_map_add_is (maps, i, "X");
+ if (res)
+ printf("ERROR: got result of %d when expected 0\n", res);
+ }
+ _stp_map_print(maps,"maps[%1d] = %s");
+
/*************** now set to 0 (clear) *******************/
printf ("setting everything to 0\n");
for (i = 1; i < 5; i++)
}
_stp_map_print(mapi,"mapi[%1d] = %d");
+ for (i = 1; i < 5; i++)
+ {
+ res = _stp_map_set_is (maps, i, "");
+ if (res)
+ printf("ERROR: got result of %d when expected 0\n", res);
+ }
+ _stp_map_print(maps,"maps[%1d] = %s");
+
+ /* set it back to something */
+ for (i = 1; i < 5; i++)
+ {
+ char buf[32];
+ sprintf(buf, "%d", i);
+ res = _stp_map_set_is (maps, i, buf);
+ if (res)
+ printf("ERROR: got result of %d when expected 0\n", res);
+ }
+
+ /* setting to NULL also deletes */
for (i = 1; i < 5; i++)
{
res = _stp_map_set_is (maps, i, 0);
if (res)
printf("ERROR: got result of %d when expected 0\n", res);
}
+ _stp_map_print(maps,"maps[%1d] = %s");
+
for (i = 1; i < 5; i++)
{
- res = _stp_map_add_is (maps, i, 0);
+ res = _stp_map_add_is (maps, i, "");
if (res)
printf("ERROR: got result of %d when expected 0\n", res);
}