[WIP patch 5/9] lib: add notmuch_metadata_move_to_next

David Bremner david at tethera.net
Sat Jan 9 18:51:37 PST 2016


---
 lib/metadata.cc       |  6 ++++++
 lib/notmuch.h         |  6 ++++++
 test/T590-metadata.sh | 12 +++++++-----
 3 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/lib/metadata.cc b/lib/metadata.cc
index 6236992..a355b75 100644
--- a/lib/metadata.cc
+++ b/lib/metadata.cc
@@ -239,3 +239,9 @@ notmuch_metadata_value (notmuch_metadata_t *metadata)
 
     return val;
 }
+
+void
+notmuch_metadata_move_to_next (notmuch_metadata_t *metadata)
+{
+    (*(metadata->iterator))++;
+}
diff --git a/lib/notmuch.h b/lib/notmuch.h
index dd359c8..b00126d 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -1879,6 +1879,12 @@ notmuch_metadata_key (notmuch_metadata_t *metadata);
 const char *
 notmuch_metadata_value (notmuch_metadata_t *metadata);
 
+/**
+ * move 'metadata' iterator to the next pair
+ */
+void
+notmuch_metadata_move_to_next (notmuch_metadata_t *metadata);
+
 /* @} */
 
 NOTMUCH_END_DECLS
diff --git a/test/T590-metadata.sh b/test/T590-metadata.sh
index d2326d4..4f37c09 100755
--- a/test/T590-metadata.sh
+++ b/test/T590-metadata.sh
@@ -55,21 +55,23 @@ testkey2 = testvalue2
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
-test_begin_subtest "notmuch_database_get_all_metadata first item"
+test_begin_subtest "get all metadata in one class"
 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
 {
    notmuch_metadata_t *meta;
    RUN(notmuch_database_get_all_metadata (db, NOTMUCH_METADATA_CONFIG, &meta));
-   printf("valid = %d\n", notmuch_metadata_valid (meta));
-   printf("key = %s\n", notmuch_metadata_key (meta));
-   printf("val = %s\n", notmuch_metadata_value (meta));
+   for (; notmuch_metadata_valid (meta); notmuch_metadata_move_to_next (meta)) {
+      printf("key = %s\n", notmuch_metadata_key (meta));
+      printf("val = %s\n", notmuch_metadata_value (meta));
+   }
 }
 EOF
 cat <<'EOF' >EXPECTED
 == stdout ==
-valid = 1
 key = testkey1
 val = testvalue1
+key = testkey2
+val = testvalue2
 == stderr ==
 EOF
 test_expect_equal_file EXPECTED OUTPUT
-- 
2.6.4



More information about the notmuch mailing list