diff options
author | Junio C Hamano <gitster@pobox.com> | 2021-12-07 12:44:49 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-12-07 12:44:49 -0800 |
commit | bb4921cf45e11d063e7bbe55f594adf8f0077d5d (patch) | |
tree | eae48e5666c03586904f835e45d70fe40d61977e /reftable/tree_test.c | |
parent | The first batch to start the current cycle (diff) | |
parent | Add "test-tool dump-reftable" command. (diff) | |
download | tgif-bb4921cf45e11d063e7bbe55f594adf8f0077d5d.tar.xz |
Merge branch 'hn/reftable' into hn/reftable-coverity-fixes
* hn/reftable:
Add "test-tool dump-reftable" command.
reftable: add dump utility
reftable: implement stack, a mutable database of reftable files.
reftable: implement refname validation
reftable: add merged table view
reftable: add a heap-based priority queue for reftable records
reftable: reftable file level tests
reftable: read reftable files
reftable: generic interface to tables
reftable: write reftable files
reftable: a generic binary tree implementation
reftable: reading/writing blocks
Provide zlib's uncompress2 from compat/zlib-compat.c
reftable: (de)serialization for the polymorphic record type.
reftable: add blocksource, an abstraction for random access reads
reftable: utility functions
reftable: add error related functionality
reftable: add LICENSE
hash.h: provide constants for the hash IDs
Diffstat (limited to 'reftable/tree_test.c')
-rw-r--r-- | reftable/tree_test.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/reftable/tree_test.c b/reftable/tree_test.c new file mode 100644 index 0000000000..cbff125588 --- /dev/null +++ b/reftable/tree_test.c @@ -0,0 +1,61 @@ +/* +Copyright 2020 Google LLC + +Use of this source code is governed by a BSD-style +license that can be found in the LICENSE file or at +https://developers.google.com/open-source/licenses/bsd +*/ + +#include "tree.h" + +#include "basics.h" +#include "record.h" +#include "test_framework.h" +#include "reftable-tests.h" + +static int test_compare(const void *a, const void *b) +{ + return (char *)a - (char *)b; +} + +struct curry { + void *last; +}; + +static void check_increasing(void *arg, void *key) +{ + struct curry *c = arg; + if (c->last) { + EXPECT(test_compare(c->last, key) < 0); + } + c->last = key; +} + +static void test_tree(void) +{ + struct tree_node *root = NULL; + + void *values[11] = { NULL }; + struct tree_node *nodes[11] = { NULL }; + int i = 1; + struct curry c = { NULL }; + do { + nodes[i] = tree_search(values + i, &root, &test_compare, 1); + i = (i * 7) % 11; + } while (i != 1); + + for (i = 1; i < ARRAY_SIZE(nodes); i++) { + EXPECT(values + i == nodes[i]->key); + EXPECT(nodes[i] == + tree_search(values + i, &root, &test_compare, 0)); + } + + infix_walk(root, check_increasing, &c); + tree_free(root); +} + +int tree_test_main(int argc, const char *argv[]) +{ + RUN_TEST(test_tree); + return 0; +} |