[PATCH 03/12] test: add initial tests for string-map

David Bremner david at tethera.net
Fri Jun 22 18:42:38 PDT 2018


These test every non-destroy function, albeit lightly.
---
 test/T710-string-map.sh | 117 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 117 insertions(+)
 create mode 100755 test/T710-string-map.sh

diff --git a/test/T710-string-map.sh b/test/T710-string-map.sh
new file mode 100755
index 00000000..b2f65381
--- /dev/null
+++ b/test/T710-string-map.sh
@@ -0,0 +1,117 @@
+#!/usr/bin/env bash
+test_description='string-map unit tests'
+. $(dirname "$0")/test-lib.sh || exit 1
+
+cat <<'EOF' > c_head
+#include <stdlib.h>
+#include <talloc.h>
+#include <string.h>
+#include "string-map.h"
+static void
+dump_map(notmuch_string_map_t *map)
+{
+    int count=0;
+    for (notmuch_string_map_iterator_t *i=_notmuch_string_map_iterator_create (map, "", false);
+         _notmuch_string_map_iterator_valid (i);
+         _notmuch_string_map_iterator_move_to_next (i), count++) {
+        printf("key[%d]=%s\nval[%d]=%s\n", count, _notmuch_string_map_iterator_key(i),
+                                     count, _notmuch_string_map_iterator_value(i));
+    }
+}
+int main (int argc, char** argv)
+{
+    void *ctx = talloc_new (NULL);
+EOF
+
+cat <<EOF > c_tail
+}
+EOF
+
+test_begin_subtest "empty map"
+cat c_head - c_tail <<'EOF' | test_C $
+{
+    notmuch_string_map_t *map = _notmuch_string_map_create(ctx);
+    dump_map (map);
+}
+EOF
+cat<<EOF > EXPECTED
+== stdout ==
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "single pair"
+cat c_head - c_tail <<'EOF' | test_C $
+{
+    notmuch_string_map_t *map = _notmuch_string_map_create(ctx);
+    _notmuch_string_map_append (map, "testkey1", "testval1");
+    dump_map (map);
+}
+EOF
+cat<<EOF > EXPECTED
+== stdout ==
+key[0]=testkey1
+val[0]=testval1
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "two pairs"
+cat c_head - c_tail <<'EOF' | test_C $
+{
+    notmuch_string_map_t *map = _notmuch_string_map_create(ctx);
+    _notmuch_string_map_append (map, "testkey1", "testval1");
+    _notmuch_string_map_append (map, "testkey2", "testval2");
+    dump_map (map);
+}
+EOF
+cat<<EOF > EXPECTED
+== stdout ==
+key[0]=testkey1
+val[0]=testval1
+key[1]=testkey2
+val[1]=testval2
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "duplicate key, sorting"
+cat c_head - c_tail <<'EOF' | test_C $
+{
+    notmuch_string_map_t *map = _notmuch_string_map_create(ctx);
+    _notmuch_string_map_append (map, "testkey1", "testval1");
+    _notmuch_string_map_append (map, "testkey2", "testval2");
+    _notmuch_string_map_append (map, "testkey1", "testval3");
+    dump_map (map);
+}
+EOF
+cat<<EOF > EXPECTED
+== stdout ==
+key[0]=testkey1
+val[0]=testval1
+key[1]=testkey1
+val[1]=testval3
+key[2]=testkey2
+val[2]=testval2
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "get first"
+cat c_head - c_tail <<'EOF' | test_C $
+{
+    notmuch_string_map_t *map = _notmuch_string_map_create(ctx);
+    _notmuch_string_map_append (map, "testkey1", "testval1");
+    _notmuch_string_map_append (map, "testkey2", "testval2");
+    _notmuch_string_map_append (map, "testkey1", "testval3");
+    printf ("%s\n",_notmuch_string_map_get (map, "testkey1"));
+}
+EOF
+cat<<EOF > EXPECTED
+== stdout ==
+testval1
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
+test_done
-- 
2.17.1



More information about the notmuch mailing list