diff options
author | John Esmet <esmet@tokutek.com> | 2012-11-12 00:43:22 +0000 |
---|---|---|
committer | Yoni Fogel <yoni@tokutek.com> | 2013-04-17 00:01:15 -0400 |
commit | 9e4b3509ecbba7c2d8b169b2feae007601d294c0 (patch) | |
tree | 5b4404249fcbba841aa8e155741e2aeb9b1819be /ft/tests/comparator-test.cc | |
parent | 248d4480813f466c1fa76cf70f4ab9c16c29e0ef (diff) | |
download | mariadb-git-9e4b3509ecbba7c2d8b169b2feae007601d294c0.tar.gz |
fixes #5351 fixes #5528 merge the new locktree to main. the locktree, locktree manager, and blocking lock request api are implemented at the toplevel under locktree/ and the ydb layer has been modified to use the new API. some kruft has been deleted from various parts of the source tree and these merge also includes a change where we kill 'includes.h'
git-svn-id: file:///svn/toku/tokudb@49851 c7de825b-a66e-492c-adef-691d508d4ae1
Diffstat (limited to 'ft/tests/comparator-test.cc')
-rw-r--r-- | ft/tests/comparator-test.cc | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/ft/tests/comparator-test.cc b/ft/tests/comparator-test.cc new file mode 100644 index 00000000000..0277287d4d0 --- /dev/null +++ b/ft/tests/comparator-test.cc @@ -0,0 +1,73 @@ +/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: + +#include <stdlib.h> +#include <ft/comparator.h> + +static int MAGIC = 49; +static DBT dbt_a; +static DBT dbt_b; +static DESCRIPTOR expected_desc; + +static int magic_compare(DB *db, const DBT *a, const DBT *b) { + invariant(db && a && b); + invariant(db->cmp_descriptor == expected_desc); + invariant(a == &dbt_a); + invariant(b == &dbt_b); + return MAGIC; +} + +static void test_desc(void) { + int c; + toku::comparator cmp; + DESCRIPTOR_S d1, d2; + + // create with d1, make sure it gets used + cmp.create(magic_compare, &d1); + expected_desc = &d1; + c = cmp.compare(&dbt_a, &dbt_b); + invariant(c == MAGIC); + + // set desc to d2, make sure it gets used + cmp.set_descriptor(&d2); + expected_desc = &d2; + c = cmp.compare(&dbt_a, &dbt_b); + invariant(c == MAGIC); +} + +static int dont_compare_me_bro(DB *db, const DBT *a, const DBT *b) { + abort(); + return db && a && b; +} + +static void test_infinity(void) { + int c; + toku::comparator cmp; + cmp.create(dont_compare_me_bro, nullptr); + + // make sure infinity-valued end points compare as expected + // to an arbitrary (uninitialized!) dbt. the comparison function + // should never be called and thus the dbt never actually read. + DBT arbitrary_dbt; + + c = cmp.compare(&arbitrary_dbt, toku_dbt_positive_infinity()); + invariant(c < 0); + c = cmp.compare(toku_dbt_negative_infinity(), &arbitrary_dbt); + invariant(c < 0); + + c = cmp.compare(toku_dbt_positive_infinity(), &arbitrary_dbt); + invariant(c > 0); + c = cmp.compare(&arbitrary_dbt, toku_dbt_negative_infinity()); + invariant(c > 0); + + c = cmp.compare(toku_dbt_negative_infinity(), toku_dbt_negative_infinity()); + invariant(c == 0); + c = cmp.compare(toku_dbt_positive_infinity(), toku_dbt_positive_infinity()); + invariant(c == 0); +} + +int main(void) { + test_desc(); + test_infinity(); + return 0; +} |