summaryrefslogtreecommitdiffstats
path: root/test/btree2.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2005-02-17 00:37:04 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2005-02-17 00:37:04 (GMT)
commit27dbdb8c7197b30c2683f4be2b9ef7b703d81d5f (patch)
tree36a72b479a22979060a6ccd4b663ccc0cb0cafc9 /test/btree2.c
parenta68c4c7981ba4224e72f64556483f3707be94ffc (diff)
downloadhdf5-27dbdb8c7197b30c2683f4be2b9ef7b703d81d5f.zip
hdf5-27dbdb8c7197b30c2683f4be2b9ef7b703d81d5f.tar.gz
hdf5-27dbdb8c7197b30c2683f4be2b9ef7b703d81d5f.tar.bz2
[svn-r10020] Purpose:
New feature Description: Add code to iterate over all the records in a v2 B-tree. Platforms tested: FreeBSD 4.11 (sleipnir) Solaris 2.9 (shanti)
Diffstat (limited to 'test/btree2.c')
-rw-r--r--test/btree2.c52
1 files changed, 51 insertions, 1 deletions
diff --git a/test/btree2.c b/test/btree2.c
index 365dacf..9593dc9 100644
--- a/test/btree2.c
+++ b/test/btree2.c
@@ -37,6 +37,36 @@ const char *FILENAME[] = {
/*-------------------------------------------------------------------------
+ * Function: iter_cb
+ *
+ * Purpose: v2 B-tree iterator callback
+ *
+ * Return: Success: 0
+ *
+ * Failure: 1
+ *
+ * Programmer: Quincey Koziol
+ * Wednesday, February 16, 2005
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+iter_cb(const void *_record, void *_op_data)
+{
+ const hsize_t *record = (const hsize_t *)_record;
+ hsize_t *idx = (hsize_t *)_op_data;
+
+ if(*record != *idx)
+ return(H5B2_ITER_ERROR);
+
+ (*idx)++;
+ return(H5B2_ITER_CONT);
+}
+
+
+/*-------------------------------------------------------------------------
* Function: test_insert_basic
*
* Purpose: Basic tests for the B-tree v2 code
@@ -59,6 +89,7 @@ test_insert_basic(hid_t fapl)
char filename[1024];
H5F_t *f=NULL;
hsize_t record; /* Record to insert into tree */
+ hsize_t idx; /* Index within B-tree, for iterator */
haddr_t bt2_addr; /* Address of B-tree created */
h5_fixname(FILENAME[0], fapl, filename, sizeof filename);
@@ -83,6 +114,16 @@ test_insert_basic(hid_t fapl)
}
PASSED();
+ /* Attempt to iterate over a B-tree with no records */
+ idx = 0;
+ if(H5B2_iterate(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, iter_cb, &idx)<0) {
+ H5_FAILED();
+ H5Eprint_stack(H5E_DEFAULT, stdout);
+ goto error;
+ }
+ /* Make certain that the index hasn't changed */
+ if(idx != 0) TEST_ERROR;
+
/*
* Test inserting record into v2 B-tree
*/
@@ -163,6 +204,7 @@ test_insert_split_root(hid_t fapl)
char filename[1024];
H5F_t *f=NULL;
hsize_t record; /* Record to insert into tree */
+ hsize_t idx; /* Index within B-tree, for iterator */
haddr_t bt2_addr; /* Address of B-tree created */
unsigned u; /* Local index variable */
@@ -192,7 +234,7 @@ test_insert_split_root(hid_t fapl)
TESTING("B-tree many - split root");
for(u=0; u<INSERT_SPLIT_ROOT_NREC; u++) {
- record=u+10;
+ record=u+2;
if (H5B2_insert(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, &record)<0) {
H5_FAILED();
H5Eprint_stack(H5E_DEFAULT, stdout);
@@ -212,6 +254,14 @@ test_insert_split_root(hid_t fapl)
goto error;
}
+ /* Iterate over B-tree to check records have been inserted correctly */
+ idx = 0;
+ if(H5B2_iterate(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, iter_cb, &idx)<0) {
+ H5_FAILED();
+ H5Eprint_stack(H5E_DEFAULT, stdout);
+ goto error;
+ }
+
PASSED();
if (H5Fclose(file)<0) TEST_ERROR;