Basic iteration: count all docs, PK non-null.
| 7131 | |
| 7132 | // Basic iteration: count all docs, PK non-null. |
| 7133 | void test_iterator_basic(void) { |
| 7134 | TEST_START(); |
| 7135 | char dir[] = "./zvec_test_c_iter_basic"; |
| 7136 | zvec_test_delete_dir(dir); |
| 7137 | |
| 7138 | zvec_collection_schema_t *schema = zvec_test_create_temp_schema(); |
| 7139 | TEST_ASSERT(schema != NULL); |
| 7140 | |
| 7141 | zvec_collection_t *collection = NULL; |
| 7142 | zvec_error_code_t err = |
| 7143 | zvec_collection_create_and_open(dir, schema, NULL, &collection); |
| 7144 | TEST_ASSERT(err == ZVEC_OK && collection != NULL); |
| 7145 | |
| 7146 | const int N = 20; |
| 7147 | iter_insert_docs(collection, schema, N); |
| 7148 | |
| 7149 | zvec_doc_iterator_t *iter = NULL; |
| 7150 | err = zvec_collection_create_iterator(collection, NULL, &iter); |
| 7151 | TEST_ASSERT(err == ZVEC_OK && iter != NULL); |
| 7152 | |
| 7153 | int count = 0; |
| 7154 | while (1) { |
| 7155 | zvec_doc_t *doc = NULL; |
| 7156 | err = zvec_doc_iterator_next(iter, &doc); |
| 7157 | TEST_ASSERT(err == ZVEC_OK); |
| 7158 | if (err != ZVEC_OK) break; |
| 7159 | if (doc == NULL) break; // EOF |
| 7160 | |
| 7161 | const char *pk = zvec_doc_get_pk_pointer(doc); |
| 7162 | TEST_ASSERT(pk != NULL && strlen(pk) > 0); |
| 7163 | zvec_doc_destroy(doc); |
| 7164 | count++; |
| 7165 | } |
| 7166 | TEST_ASSERT(count == N); |
| 7167 | |
| 7168 | zvec_doc_iterator_close(iter); |
| 7169 | zvec_collection_destroy(collection); |
| 7170 | zvec_collection_schema_destroy(schema); |
| 7171 | zvec_test_delete_dir(dir); |
| 7172 | TEST_END(); |
| 7173 | } |
| 7174 | |
| 7175 | // Flush is unaffected by open iterators, and closing the iterator handle |
| 7176 | // only releases the handle itself. |
no test coverage detected