Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

6492 lines (5692 sloc) 269.593 kB
/**
* Copyright (C) 2005-2011 Christoph Rupp (chris@crupp.de).
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* See files COPYING.* for License information.
*/
#include "../src/config.h"
#include <stdexcept>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <ham/hamsterdb.h>
#include "../src/env.h"
#include "../src/cursor.h"
#include "../src/btree_cursor.h"
#include "../src/backend.h"
#include "bfc-testsuite.hpp"
#include "hamster_fixture.hpp"
using namespace bfc;
static bool
cursor_is_nil(Cursor *c, int what)
{
return (c->is_nil(what));
}
class BaseCursorTest : public hamsterDB_fixture
{
define_super(hamsterDB_fixture);
public:
BaseCursorTest(const char *name="BaseCursorTest")
: hamsterDB_fixture(name), m_txn(0)
{
}
protected:
ham_cursor_t *m_cursor;
ham_db_t *m_db;
ham_env_t *m_env;
ham_txn_t *m_txn;
public:
virtual ham_status_t createCursor(ham_cursor_t **p)
{
return (ham_cursor_create(m_db, 0, 0, p));
}
virtual void setup()
{
__super::setup();
BFC_ASSERT_EQUAL(0, ham_new(&m_db));
BFC_ASSERT_EQUAL(0, ham_env_new(&m_env));
BFC_ASSERT_EQUAL(0,
ham_env_create(m_env, BFC_OPATH(".test"),
HAM_ENABLE_DUPLICATES
|HAM_ENABLE_RECOVERY
|HAM_ENABLE_TRANSACTIONS, 0664));
BFC_ASSERT_EQUAL(0,
ham_env_create_db(m_env, m_db, 13, 0, 0));
BFC_ASSERT_EQUAL(0, createCursor(&m_cursor));
}
virtual void teardown()
{
__super::teardown();
if (m_cursor) {
BFC_ASSERT_EQUAL(0, ham_cursor_close(m_cursor));
m_cursor=0;
}
BFC_ASSERT_EQUAL(0,
ham_env_close(m_env, HAM_AUTO_CLEANUP));
ham_delete(m_db);
ham_env_delete(m_env);
}
void getDuplicateRecordSizeTest()
{
const int MAX=20;
ham_key_t key={0};
ham_record_t rec={0};
ham_cursor_t *c;
char data[16];
BFC_ASSERT_EQUAL(0, ham_cursor_create(m_db, m_txn, 0, &c));
for (int i=0; i<MAX; i++) {
rec.data=data;
rec.size=i;
::memset(&data, i+0x15, sizeof(data));
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(c, &key, &rec, HAM_DUPLICATE));
}
for (int i=0; i<MAX; i++) {
ham_offset_t size=0;
::memset(&key, 0, sizeof(key));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(c, &key, &rec,
i==0 ? HAM_CURSOR_FIRST : HAM_CURSOR_NEXT));
BFC_ASSERT_EQUAL(0,
ham_cursor_get_record_size(c, &size));
BFC_ASSERT_EQUAL(size, rec.size);
}
BFC_ASSERT_EQUAL(0, ham_cursor_close(c));
}
void getRecordSizeTest()
{
const int MAX=20;
ham_key_t key={0};
ham_record_t rec={0};
ham_cursor_t *c;
char data[16];
BFC_ASSERT_EQUAL(0, ham_cursor_create(m_db, m_txn, 0, &c));
for (int i=0; i<MAX; i++) {
key.data=data;
key.size=sizeof(data);
rec.data=data;
rec.size=i;
::memset(&data, i+0x15, sizeof(data));
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(c, &key, &rec, HAM_DUPLICATE));
}
for (int i=0; i<MAX; i++) {
ham_offset_t size=0;
key.data=data;
key.size=sizeof(data);
BFC_ASSERT_EQUAL(0,
ham_cursor_move(c, &key, &rec,
i==0 ? HAM_CURSOR_FIRST : HAM_CURSOR_NEXT));
BFC_ASSERT_EQUAL(0,
ham_cursor_get_record_size(c, &size));
BFC_ASSERT_EQUAL(size, rec.size);
}
BFC_ASSERT_EQUAL(0, ham_cursor_close(c));
}
void insertFindTest(void)
{
ham_key_t key={0};
ham_record_t rec={0};
key.data=(void *)"12345";
key.size=6;
rec.data=(void *)"abcde";
rec.size=6;
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
BFC_ASSERT_EQUAL(HAM_DUPLICATE_KEY,
ham_cursor_insert(m_cursor, &key, &rec, 0));
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, HAM_OVERWRITE));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key, &rec, 0));
BFC_ASSERT_EQUAL(1u,
((Cursor *)m_cursor)->get_dupecache_count());
}
void insertFindMultipleCursorsTest(void)
{
ham_cursor_t *c[5];
ham_key_t key={0};
ham_record_t rec={0};
key.data=(void *)"12345";
key.size=6;
rec.data=(void *)"abcde";
rec.size=6;
for (int i=0; i<5; i++)
BFC_ASSERT_EQUAL(0, createCursor(&c[i]));
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
for (int i=0; i<5; i++) {
BFC_ASSERT_EQUAL(0,
ham_cursor_find(c[i], &key, 0));
}
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key, &rec, 0));
BFC_ASSERT_EQUAL(0, strcmp("12345", (char *)key.data));
BFC_ASSERT_EQUAL(0, strcmp("abcde", (char *)rec.data));
for (int i=0; i<5; i++) {
BFC_ASSERT_EQUAL(0,
ham_cursor_move(c[i], &key, &rec, 0));
BFC_ASSERT_EQUAL(0, strcmp("12345", (char *)key.data));
BFC_ASSERT_EQUAL(0, strcmp("abcde", (char *)rec.data));
BFC_ASSERT_EQUAL(0, ham_cursor_close(c[i]));
}
}
void findInEmptyDatabaseTest(void)
{
ham_key_t key={0};
key.data=(void *)"12345";
key.size=6;
/* this looks up a key in an empty database */
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_find(m_cursor, &key, 0));
}
void nilCursorTest(void)
{
ham_key_t key={0};
ham_record_t rec={0};
key.data=(void *)"12345";
key.size=6;
rec.data=(void *)"abcde";
rec.size=6;
/* cursor is nil */
BFC_ASSERT_EQUAL(HAM_CURSOR_IS_NIL,
ham_cursor_move(m_cursor, &key, &rec, 0));
BFC_ASSERT_EQUAL(HAM_CURSOR_IS_NIL,
ham_cursor_overwrite(m_cursor, &rec, 0));
ham_cursor_t *clone;
BFC_ASSERT_EQUAL(0,
ham_cursor_clone(m_cursor, &clone));
BFC_ASSERT_EQUAL(true, cursor_is_nil((Cursor *)m_cursor, 0));
BFC_ASSERT_EQUAL(true, cursor_is_nil((Cursor *)clone, 0));
BFC_ASSERT_EQUAL(0, ham_cursor_close(clone));
}
};
class TempTxnCursorTest : public BaseCursorTest
{
define_super(hamsterDB_fixture);
public:
TempTxnCursorTest()
: BaseCursorTest("TempTxnCursorTest")
{
testrunner::get_instance()->register_fixture(this);
BFC_REGISTER_TEST(TempTxnCursorTest, insertFindTest);
BFC_REGISTER_TEST(TempTxnCursorTest, insertFindMultipleCursorsTest);
BFC_REGISTER_TEST(TempTxnCursorTest, findInEmptyDatabaseTest);
BFC_REGISTER_TEST(TempTxnCursorTest, nilCursorTest);
BFC_REGISTER_TEST(TempTxnCursorTest, cloneCoupledBtreeCursorTest);
BFC_REGISTER_TEST(TempTxnCursorTest, cloneUncoupledBtreeCursorTest);
BFC_REGISTER_TEST(TempTxnCursorTest, closeCoupledBtreeCursorTest);
BFC_REGISTER_TEST(TempTxnCursorTest, closeUncoupledBtreeCursorTest);
}
void cloneCoupledBtreeCursorTest(void)
{
ham_key_t key={0};
ham_record_t rec={0};
key.data=(void *)"12345";
key.size=6;
rec.data=(void *)"abcde";
rec.size=6;
ham_cursor_t *clone;
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
BFC_ASSERT_EQUAL(0,
ham_cursor_clone(m_cursor, &clone));
BFC_ASSERT_EQUAL(false, cursor_is_nil((Cursor *)clone,
Cursor::CURSOR_BTREE));
BFC_ASSERT_EQUAL(0, ham_cursor_close(clone));
}
void cloneUncoupledBtreeCursorTest(void)
{
ham_key_t key={0};
ham_record_t rec={0};
key.data=(void *)"12345";
key.size=6;
rec.data=(void *)"abcde";
rec.size=6;
Cursor *c=(Cursor *)m_cursor;
ham_cursor_t *clone;
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
BFC_ASSERT_EQUAL(0,
btree_cursor_uncouple(c->get_btree_cursor(), 0));
BFC_ASSERT_EQUAL(0,
ham_cursor_clone(m_cursor, &clone));
BFC_ASSERT_EQUAL(false, cursor_is_nil((Cursor *)clone,
Cursor::CURSOR_BTREE));
ham_key_t *k1=btree_cursor_get_uncoupled_key(
c->get_btree_cursor());
ham_key_t *k2=btree_cursor_get_uncoupled_key(
((Cursor *)clone)->get_btree_cursor());
BFC_ASSERT_EQUAL(0, strcmp((char *)k1->data, (char *)k2->data));
BFC_ASSERT_EQUAL(k1->size, k2->size);
BFC_ASSERT_EQUAL(0, ham_cursor_close(clone));
}
void closeCoupledBtreeCursorTest(void)
{
ham_key_t key={0};
ham_record_t rec={0};
key.data=(void *)"12345";
key.size=6;
rec.data=(void *)"abcde";
rec.size=6;
Cursor *c=(Cursor *)m_cursor;
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
BFC_ASSERT_EQUAL(0,
btree_cursor_uncouple(c->get_btree_cursor(), 0));
/* will close in teardown() */
}
void closeUncoupledBtreeCursorTest(void)
{
ham_key_t key={0};
ham_record_t rec={0};
key.data=(void *)"12345";
key.size=6;
rec.data=(void *)"abcde";
rec.size=6;
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
/* will close in teardown() */
}
};
class NoTxnCursorTest : public BaseCursorTest
{
define_super(hamsterDB_fixture);
public:
NoTxnCursorTest()
: BaseCursorTest("NoTxnCursorTest")
{
testrunner::get_instance()->register_fixture(this);
BFC_REGISTER_TEST(NoTxnCursorTest, insertFindTest);
BFC_REGISTER_TEST(NoTxnCursorTest, insertFindMultipleCursorsTest);
BFC_REGISTER_TEST(NoTxnCursorTest, findInEmptyDatabaseTest);
BFC_REGISTER_TEST(NoTxnCursorTest, nilCursorTest);
BFC_REGISTER_TEST(NoTxnCursorTest, moveFirstInEmptyDatabaseTest);
BFC_REGISTER_TEST(NoTxnCursorTest, getDuplicateRecordSizeTest);
BFC_REGISTER_TEST(NoTxnCursorTest, getRecordSizeTest);
}
virtual void setup()
{
BFC_ASSERT_EQUAL(0, ham_new(&m_db));
BFC_ASSERT_EQUAL(0, ham_env_new(&m_env));
BFC_ASSERT_EQUAL(0,
ham_env_create(m_env, BFC_OPATH(".test"),
HAM_ENABLE_DUPLICATES, 0664));
BFC_ASSERT_EQUAL(0,
ham_env_create_db(m_env, m_db, 13, 0, 0));
BFC_ASSERT_EQUAL(0, createCursor(&m_cursor));
}
void moveFirstInEmptyDatabaseTest(void)
{
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_move(m_cursor, 0, 0, HAM_CURSOR_FIRST));
}
};
class InMemoryCursorTest : public BaseCursorTest
{
define_super(hamsterDB_fixture);
public:
InMemoryCursorTest()
: BaseCursorTest("InMemoryCursorTest")
{
testrunner::get_instance()->register_fixture(this);
BFC_REGISTER_TEST(InMemoryCursorTest, getDuplicateRecordSizeTest);
BFC_REGISTER_TEST(InMemoryCursorTest, getRecordSizeTest);
}
virtual void setup()
{
BFC_ASSERT_EQUAL(0, ham_new(&m_db));
BFC_ASSERT_EQUAL(0, ham_env_new(&m_env));
BFC_ASSERT_EQUAL(0,
ham_env_create(m_env, BFC_OPATH(".test"),
HAM_IN_MEMORY_DB|HAM_ENABLE_DUPLICATES, 0664));
BFC_ASSERT_EQUAL(0,
ham_env_create_db(m_env, m_db, 13, 0, 0));
}
};
class LongTxnCursorTest : public BaseCursorTest
{
define_super(hamsterDB_fixture);
public:
virtual void setup()
{
BFC_ASSERT_EQUAL(0, ham_new(&m_db));
BFC_ASSERT_EQUAL(0, ham_env_new(&m_env));
BFC_ASSERT_EQUAL(0,
ham_env_create(m_env, BFC_OPATH(".test"),
HAM_ENABLE_DUPLICATES
|HAM_ENABLE_RECOVERY
|HAM_ENABLE_TRANSACTIONS, 0664));
BFC_ASSERT_EQUAL(0,
ham_env_create_db(m_env, m_db, 13, 0, 0));
BFC_ASSERT_EQUAL(0, ham_txn_begin(&m_txn, m_env, 0, 0, 0));
BFC_ASSERT_EQUAL(0, createCursor(&m_cursor));
}
virtual ham_status_t createCursor(ham_cursor_t **p)
{
return (ham_cursor_create(m_db, m_txn, 0, p));
}
LongTxnCursorTest()
: BaseCursorTest("LongTxnCursorTest")
{
testrunner::get_instance()->register_fixture(this);
BFC_REGISTER_TEST(LongTxnCursorTest, getDuplicateRecordSizeTest);
BFC_REGISTER_TEST(LongTxnCursorTest, getRecordSizeTest);
BFC_REGISTER_TEST(LongTxnCursorTest, insertFindTest);
BFC_REGISTER_TEST(LongTxnCursorTest, insertFindMultipleCursorsTest);
BFC_REGISTER_TEST(LongTxnCursorTest, findInEmptyDatabaseTest);
BFC_REGISTER_TEST(LongTxnCursorTest, findInEmptyTransactionTest);
BFC_REGISTER_TEST(LongTxnCursorTest, findInBtreeOverwrittenInTxnTest);
BFC_REGISTER_TEST(LongTxnCursorTest, findInTxnOverwrittenInTxnTest);
BFC_REGISTER_TEST(LongTxnCursorTest, findInTxnOverwrittenInTxnTest);
BFC_REGISTER_TEST(LongTxnCursorTest, eraseInTxnKeyFromBtreeTest);
BFC_REGISTER_TEST(LongTxnCursorTest, eraseInTxnKeyFromTxnTest);
BFC_REGISTER_TEST(LongTxnCursorTest, eraseInTxnOverwrittenKeyTest);
BFC_REGISTER_TEST(LongTxnCursorTest, eraseInTxnOverwrittenFindKeyTest);
BFC_REGISTER_TEST(LongTxnCursorTest, overwriteInEmptyTransactionTest);
BFC_REGISTER_TEST(LongTxnCursorTest, overwriteInTransactionTest);
BFC_REGISTER_TEST(LongTxnCursorTest, cloneCoupledTxnCursorTest);
BFC_REGISTER_TEST(LongTxnCursorTest, closeCoupledTxnCursorTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveFirstInEmptyTransactionTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveFirstInEmptyTransactionExtendedKeyTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveFirstInTransactionTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveFirstInTransactionExtendedKeyTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveFirstIdenticalTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveFirstSmallerInTransactionTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveFirstSmallerInTransactionExtendedKeyTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveFirstSmallerInBtreeTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveFirstSmallerInBtreeExtendedKeyTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveFirstErasedInTxnTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveFirstErasedInTxnExtendedKeyTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveFirstErasedInsertedInTxnTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveFirstSmallerInBtreeErasedInTxnTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveLastInEmptyTransactionTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveLastInEmptyTransactionExtendedKeyTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveLastInTransactionTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveLastInTransactionExtendedKeyTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveLastIdenticalTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveLastSmallerInTransactionTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveLastSmallerInTransactionExtendedKeyTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveLastSmallerInBtreeTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveLastSmallerInBtreeExtendedKeyTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveLastErasedInTxnTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveLastErasedInTxnExtendedKeyTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveLastErasedInsertedInTxnTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveLastSmallerInBtreeErasedInTxnTest);
BFC_REGISTER_TEST(LongTxnCursorTest, nilCursorTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveNextInEmptyTransactionTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveNextInEmptyBtreeTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveNextSmallerInTransactionTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveNextSmallerInBtreeTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveNextSmallerInTransactionSequenceTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveNextSmallerInBtreeSequenceTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveNextOverErasedItemTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveNextOverIdenticalItemsTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveBtreeThenNextOverIdenticalItemsTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveTxnThenNextOverIdenticalItemsTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveNextOverIdenticalItemsThenBtreeTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveNextOverIdenticalItemsThenTxnTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveNextOverSequencesOfIdenticalItemsTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveNextWhileInsertingBtreeTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveNextWhileInsertingTransactionTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveNextWhileInsertingMixedTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveNextWhileErasingTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
movePreviousInEmptyTransactionTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
movePreviousInEmptyBtreeTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
movePreviousSmallerInTransactionTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
movePreviousSmallerInBtreeTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
movePreviousSmallerInTransactionSequenceTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
movePreviousSmallerInBtreeSequenceTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
movePreviousOverErasedItemTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
movePreviousOverIdenticalItemsTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveBtreeThenPreviousOverIdenticalItemsTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveTxnThenPreviousOverIdenticalItemsTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
movePreviousOverIdenticalItemsThenBtreeTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
movePreviousOverIdenticalItemsThenTxnTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
movePreviousOverSequencesOfIdenticalItemsTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
movePreviousWhileInsertingBtreeTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
movePreviousWhileInsertingTransactionTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
movePreviousWhileInsertingMixedTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
switchDirectionsInBtreeTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
switchDirectionsInTransactionTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
switchDirectionsMixedStartInBtreeTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
switchDirectionsMixedStartInTxnTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
switchDirectionsMixedSequenceTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
findTxnThenMoveNextTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
findTxnThenMoveNext2Test);
BFC_REGISTER_TEST(LongTxnCursorTest,
findTxnThenMoveNext3Test);
BFC_REGISTER_TEST(LongTxnCursorTest,
findTxnThenMoveNext4Test);
BFC_REGISTER_TEST(LongTxnCursorTest,
findTxnThenMovePreviousTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
findTxnThenMovePrevious2Test);
BFC_REGISTER_TEST(LongTxnCursorTest,
findTxnThenMovePrevious3Test);
BFC_REGISTER_TEST(LongTxnCursorTest,
findTxnThenMovePrevious4Test);
BFC_REGISTER_TEST(LongTxnCursorTest,
findBtreeThenMoveNextTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
findBtreeThenMoveNext2Test);
BFC_REGISTER_TEST(LongTxnCursorTest,
findBtreeThenMoveNext3Test);
BFC_REGISTER_TEST(LongTxnCursorTest,
findBtreeThenMovePreviousTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
findBtreeThenMovePrevious2Test);
BFC_REGISTER_TEST(LongTxnCursorTest,
insertThenMoveNextTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
abortWhileCursorActiveTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
commitWhileCursorActiveTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
eraseKeyWithTwoCursorsTest);
//BFC_REGISTER_TEST(LongTxnCursorTest,
//eraseKeyWithTwoCursorsOverwriteTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
eraseWithThreeCursorsTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
eraseKeyWithoutCursorsTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
eraseKeyAndFlushTransactionsTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveLastThenInsertNewLastTest);
BFC_REGISTER_TEST(LongTxnCursorTest,
moveFirstThenInsertNewFirstTest);
}
void findInEmptyTransactionTest(void)
{
ham_key_t key={0};
ham_record_t rec={0};
key.data=(void *)"12345";
key.size=6;
rec.data=(void *)"abcde";
rec.size=6;
/* insert a key into the btree */
Backend *be=((Database *)m_db)->get_backend();
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* this looks up a key in an empty Transaction but with the btree */
BFC_ASSERT_EQUAL(0,
ham_cursor_find(m_cursor, &key, 0));
BFC_ASSERT_EQUAL(0, strcmp("12345", (char *)key.data));
BFC_ASSERT_EQUAL(0, strcmp("abcde", (char *)rec.data));
}
void findInBtreeOverwrittenInTxnTest(void)
{
ham_key_t key={0};
ham_record_t rec={0}, rec2={0};
key.data=(void *)"12345";
key.size=6;
rec.data=(void *)"abcde";
rec.size=6;
rec2.data=(void *)"22222";
rec2.size=6;
/* insert a key into the btree */
Backend *be=((Database *)m_db)->get_backend();
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* overwrite it in the Transaction */
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec2, HAM_OVERWRITE));
/* retrieve key and compare record */
BFC_ASSERT_EQUAL(0,
ham_cursor_find_ex(m_cursor, &key, &rec, 0));
BFC_ASSERT_EQUAL(0, strcmp("12345", (char *)key.data));
BFC_ASSERT_EQUAL(0, strcmp("22222", (char *)rec.data));
}
void findInTxnOverwrittenInTxnTest(void)
{
ham_key_t key={0};
ham_record_t rec={0}, rec2={0};
key.data=(void *)"12345";
key.size=6;
rec.data=(void *)"abcde";
rec.size=6;
rec2.data=(void *)"22222";
rec2.size=6;
/* insert a key into the txn */
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
/* overwrite it in the Transaction */
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec2, HAM_OVERWRITE));
/* retrieve key and compare record */
BFC_ASSERT_EQUAL(0,
ham_cursor_find_ex(m_cursor, &key, &rec, 0));
BFC_ASSERT_EQUAL(0, strcmp("12345", (char *)key.data));
BFC_ASSERT_EQUAL(0, strcmp("22222", (char *)rec.data));
}
void eraseInTxnKeyFromBtreeTest(void)
{
ham_key_t key={0};
ham_record_t rec={0};
key.data=(void *)"12345";
key.size=6;
rec.data=(void *)"abcde";
rec.size=6;
/* insert a key into the btree */
Backend *be=((Database *)m_db)->get_backend();
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* couple the cursor to this key */
BFC_ASSERT_EQUAL(0,
ham_cursor_find(m_cursor, &key, 0));
/* erase it in the Transaction */
BFC_ASSERT_EQUAL(0,
ham_cursor_erase(m_cursor, 0));
/* key is now nil */
BFC_ASSERT_EQUAL(true, cursor_is_nil((Cursor *)m_cursor,
Cursor::CURSOR_BTREE));
/* retrieve key - must fail */
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_find(m_cursor, &key, 0));
}
void eraseInTxnKeyFromTxnTest(void)
{
ham_key_t key={0};
ham_record_t rec={0};
key.data=(void *)"12345";
key.size=6;
rec.data=(void *)"abcde";
rec.size=6;
/* insert a key into the Transaction */
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
/* erase it in the Transaction */
BFC_ASSERT_EQUAL(0,
ham_cursor_erase(m_cursor, 0));
/* retrieve key - must fail */
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_find(m_cursor, &key, 0));
}
void eraseInTxnOverwrittenKeyTest(void)
{
ham_key_t key={0};
ham_record_t rec={0}, rec2={0};
key.data=(void *)"12345";
key.size=6;
rec.data=(void *)"abcde";
rec.size=6;
/* insert a key into the Transaction */
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
/* overwrite it in the Transaction */
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec2, HAM_OVERWRITE));
/* erase it in the Transaction */
BFC_ASSERT_EQUAL(0,
ham_cursor_erase(m_cursor, 0));
/* retrieve key - must fail */
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_find(m_cursor, &key, 0));
}
void eraseInTxnOverwrittenFindKeyTest(void)
{
ham_key_t key={0};
ham_record_t rec={0}, rec2={0};
key.data=(void *)"12345";
key.size=6;
rec.data=(void *)"abcde";
rec.size=6;
BFC_ASSERT_EQUAL(HAM_CURSOR_IS_NIL,
ham_cursor_erase(m_cursor, 0));
/* insert a key into the Transaction */
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
/* overwrite it in the Transaction */
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec2, HAM_OVERWRITE));
/* once more couple the cursor to this key */
BFC_ASSERT_EQUAL(0,
ham_cursor_find(m_cursor, &key, 0));
/* erase it in the Transaction */
BFC_ASSERT_EQUAL(0,
ham_cursor_erase(m_cursor, 0));
/* retrieve key - must fail */
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_find(m_cursor, &key, 0));
}
void overwriteInEmptyTransactionTest(void)
{
ham_key_t key={0};
ham_record_t rec={0}, rec2={0};
key.data=(void *)"12345";
key.size=6;
rec.data=(void *)"abcde";
rec.size=6;
rec2.data=(void *)"aaaaa";
rec2.size=6;
/* insert a key into the btree */
Backend *be=((Database *)m_db)->get_backend();
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* this looks up a key in an empty Transaction but with the btree */
BFC_ASSERT_EQUAL(0,
ham_cursor_find(m_cursor, &key, 0));
BFC_ASSERT_EQUAL(0,
ham_cursor_overwrite(m_cursor, &rec2, 0));
BFC_ASSERT_EQUAL(0,
ham_cursor_find_ex(m_cursor, &key, &rec, 0));
BFC_ASSERT_EQUAL(0, strcmp("12345", (char *)key.data));
BFC_ASSERT_EQUAL(0, strcmp("aaaaa", (char *)rec.data));
}
void overwriteInTransactionTest(void)
{
ham_key_t key={0};
ham_record_t rec={0}, rec2={0};
key.data=(void *)"12345";
key.size=6;
rec.data=(void *)"abcde";
rec.size=6;
rec2.data=(void *)"aaaaa";
rec2.size=6;
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
BFC_ASSERT_EQUAL(0,
ham_cursor_overwrite(m_cursor, &rec2, 0));
BFC_ASSERT_EQUAL(0,
ham_cursor_find_ex(m_cursor, &key, &rec, 0));
BFC_ASSERT_EQUAL(0, strcmp("12345", (char *)key.data));
BFC_ASSERT_EQUAL(0, strcmp("aaaaa", (char *)rec.data));
}
void cloneCoupledTxnCursorTest(void)
{
ham_key_t key={0};
ham_record_t rec={0};
key.data=(void *)"12345";
key.size=6;
rec.data=(void *)"abcde";
rec.size=6;
ham_cursor_t *clone;
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
BFC_ASSERT_EQUAL(0,
ham_cursor_clone(m_cursor, &clone));
Cursor *c=(Cursor *)m_cursor;
Cursor *cl=(Cursor *)clone;
BFC_ASSERT_EQUAL(false,
btree_cursor_is_nil((((Cursor *)clone)->get_btree_cursor())));
BFC_ASSERT_EQUAL(2u, txn_get_cursor_refcount((Transaction *)m_txn));
BFC_ASSERT_EQUAL(
txn_cursor_get_coupled_op(c->get_txn_cursor()),
txn_cursor_get_coupled_op(cl->get_txn_cursor()));
BFC_ASSERT_EQUAL(0, ham_cursor_close(clone));
BFC_ASSERT_EQUAL(1u, txn_get_cursor_refcount((Transaction *)m_txn));
}
void closeCoupledTxnCursorTest(void)
{
ham_key_t key={0};
ham_record_t rec={0};
key.data=(void *)"12345";
key.size=6;
rec.data=(void *)"abcde";
rec.size=6;
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
/* will be closed in teardown() */
}
void moveFirstInEmptyTransactionTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.data=(void *)"12345";
key.size=6;
rec.data=(void *)"abcde";
rec.size=6;
/* insert a key into the btree */
Backend *be=((Database *)m_db)->get_backend();
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* this moves the cursor to the first item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_FIRST));
BFC_ASSERT_EQUAL(0, strcmp("12345", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("abcde", (char *)rec2.data));
}
void moveFirstInEmptyTransactionExtendedKeyTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
const char *ext="123456789012345678901234567890";
key.data=(void *)ext;
key.size=31;
rec.data=(void *)"abcde";
rec.size=6;
/* insert a key into the btree */
Backend *be=((Database *)m_db)->get_backend();
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* this moves the cursor to the first item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_FIRST));
BFC_ASSERT_EQUAL(0, strcmp(ext, (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("abcde", (char *)rec2.data));
}
void moveFirstInTransactionTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.data=(void *)"12345";
key.size=6;
rec.data=(void *)"abcde";
rec.size=6;
/* insert a key into the Transaction */
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
/* this moves the cursor to the first item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_FIRST));
BFC_ASSERT_EQUAL(0, strcmp("12345", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("abcde", (char *)rec2.data));
}
void moveFirstInTransactionExtendedKeyTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
const char *ext="123456789012345678901234567890";
key.data=(void *)ext;
key.size=31;
rec.data=(void *)"abcde";
rec.size=6;
/* insert a key into the Transaction */
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
/* this moves the cursor to the first item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_FIRST));
BFC_ASSERT_EQUAL(0, strcmp(ext, (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("abcde", (char *)rec2.data));
}
void moveFirstIdenticalTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.data=(void *)"12345";
key.size=6;
rec.data=(void *)"abcde";
rec.size=6;
/* insert a key into the btree */
Backend *be=((Database *)m_db)->get_backend();
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* insert the same key into the Transaction */
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, HAM_OVERWRITE));
/* this moves the cursor to the first item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_FIRST));
BFC_ASSERT_EQUAL(0, strcmp("12345", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("abcde", (char *)rec2.data));
/* make sure that the cursor is coupled to the txn-op */
Cursor *c=(Cursor *)m_cursor;
BFC_ASSERT(c->is_coupled_to_txnop());
}
void moveFirstSmallerInTransactionTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
/* insert a large key into the btree */
Backend *be=((Database *)m_db)->get_backend();
key.data=(void *)"22222";
rec.data=(void *)"abcde";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* insert a smaller key into the Transaction */
key.data=(void *)"11111";
rec.data=(void *)"xyzab";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
/* this moves the cursor to the first item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_FIRST));
BFC_ASSERT_EQUAL(0, strcmp("11111", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("xyzab", (char *)rec2.data));
}
void moveFirstSmallerInTransactionExtendedKeyTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
const char *ext1="111111111111111111111111111111";
const char *ext2="222222222222222222222222222222";
key.size=31;
rec.size=6;
/* insert a large key into the btree */
Backend *be=((Database *)m_db)->get_backend();
key.data=(void *)ext2;
rec.data=(void *)"abcde";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* insert a smaller key into the Transaction */
key.data=(void *)ext1;
rec.data=(void *)"xyzab";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
/* this moves the cursor to the first item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_FIRST));
BFC_ASSERT_EQUAL(0, strcmp(ext1, (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("xyzab", (char *)rec2.data));
}
void moveFirstSmallerInBtreeTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
/* insert a small key into the btree */
Backend *be=((Database *)m_db)->get_backend();
key.data=(void *)"11111";
rec.data=(void *)"abcde";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* insert a greater key into the Transaction */
key.data=(void *)"22222";
rec.data=(void *)"xyzab";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
/* this moves the cursor to the first item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_FIRST));
BFC_ASSERT_EQUAL(0, strcmp("11111", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("abcde", (char *)rec2.data));
}
void moveFirstSmallerInBtreeExtendedKeyTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
const char *ext1="111111111111111111111111111111";
const char *ext2="222222222222222222222222222222";
key.size=31;
rec.size=6;
/* insert a small key into the btree */
Backend *be=((Database *)m_db)->get_backend();
key.data=(void *)ext1;
rec.data=(void *)"abcde";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* insert a greater key into the Transaction */
key.data=(void *)ext2;
rec.data=(void *)"xyzab";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
/* this moves the cursor to the first item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_FIRST));
BFC_ASSERT_EQUAL(0, strcmp(ext1, (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("abcde", (char *)rec2.data));
}
void moveFirstErasedInTxnTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
/* insert a key into the btree */
Backend *be=((Database *)m_db)->get_backend();
key.data=(void *)"11111";
rec.data=(void *)"abcde";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* erase it */
key.data=(void *)"11111";
BFC_ASSERT_EQUAL(0,
ham_cursor_find(m_cursor, &key, 0));
BFC_ASSERT_EQUAL(0,
ham_cursor_erase(m_cursor, 0));
/* this moves the cursor to the first item, but it was erased
* and therefore this fails */
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_FIRST));
}
void moveFirstErasedInTxnExtendedKeyTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
const char *ext1="111111111111111111111111111111";
key.size=31;
rec.size=6;
/* insert a key into the btree */
Backend *be=((Database *)m_db)->get_backend();
key.data=(void *)ext1;
rec.data=(void *)"abcde";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* erase it */
key.data=(void *)ext1;
BFC_ASSERT_EQUAL(0,
ham_cursor_find(m_cursor, &key, 0));
BFC_ASSERT_EQUAL(0,
ham_cursor_erase(m_cursor, 0));
/* this moves the cursor to the first item, but it was erased
* and therefore this fails */
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_FIRST));
/* we have to manually clear the changeset, otherwise ham_close will
* fail. The changeset was filled in be->insert(0, but this is an
* internal function which will not clear it. All other functions fail
* and therefore do not touch the changeset. */
((Environment *)m_env)->get_changeset().clear();
}
void moveFirstErasedInsertedInTxnTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
/* insert a key into the btree */
Backend *be=((Database *)m_db)->get_backend();
key.data=(void *)"11111";
rec.data=(void *)"abcde";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* erase it */
BFC_ASSERT_EQUAL(0,
ham_cursor_find(m_cursor, &key, 0));
BFC_ASSERT_EQUAL(0,
ham_cursor_erase(m_cursor, 0));
/* re-insert it */
rec.data=(void *)"10101";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
/* this moves the cursor to the first item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_FIRST));
BFC_ASSERT_EQUAL(0, strcmp("11111", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("10101", (char *)rec2.data));
}
void moveFirstSmallerInBtreeErasedInTxnTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
/* insert a small key into the btree */
Backend *be=((Database *)m_db)->get_backend();
key.data=(void *)"11111";
rec.data=(void *)"abcde";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* insert a greater key into the Transaction */
key.data=(void *)"22222";
rec.data=(void *)"xyzab";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
/* erase the smaller item */
key.data=(void *)"11111";
BFC_ASSERT_EQUAL(0,
ham_cursor_find(m_cursor, &key, 0));
BFC_ASSERT_EQUAL(0,
ham_cursor_erase(m_cursor, 0));
/* this moves the cursor to the second item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_FIRST));
BFC_ASSERT_EQUAL(0, strcmp("22222", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("xyzab", (char *)rec2.data));
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
}
void moveLastInEmptyTransactionTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.data=(void *)"12345";
key.size=6;
rec.data=(void *)"abcde";
rec.size=6;
/* insert a key into the btree */
Backend *be=((Database *)m_db)->get_backend();
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* this moves the cursor to the last item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_LAST));
BFC_ASSERT_EQUAL(0, strcmp("12345", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("abcde", (char *)rec2.data));
}
void moveLastInEmptyTransactionExtendedKeyTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
const char *ext="123456789012345678901234567890";
key.data=(void *)ext;
key.size=31;
rec.data=(void *)"abcde";
rec.size=6;
/* insert a key into the btree */
Backend *be=((Database *)m_db)->get_backend();
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* this moves the cursor to the last item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_LAST));
BFC_ASSERT_EQUAL(0, strcmp(ext, (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("abcde", (char *)rec2.data));
}
void moveLastInTransactionTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.data=(void *)"12345";
key.size=6;
rec.data=(void *)"abcde";
rec.size=6;
/* insert a key into the Transaction */
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
/* this moves the cursor to the last item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_LAST));
BFC_ASSERT_EQUAL(0, strcmp("12345", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("abcde", (char *)rec2.data));
}
void moveLastInTransactionExtendedKeyTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
const char *ext="123456789012345678901234567890";
key.data=(void *)ext;
key.size=31;
rec.data=(void *)"abcde";
rec.size=6;
/* insert a key into the Transaction */
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
/* this moves the cursor to the last item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_LAST));
BFC_ASSERT_EQUAL(0, strcmp(ext, (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("abcde", (char *)rec2.data));
}
void moveLastIdenticalTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.data=(void *)"12345";
key.size=6;
rec.data=(void *)"abcde";
rec.size=6;
/* insert a key into the btree */
Backend *be=((Database *)m_db)->get_backend();
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* insert the same key into the Transaction */
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, HAM_OVERWRITE));
/* this moves the cursor to the last item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_LAST));
BFC_ASSERT_EQUAL(0, strcmp("12345", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("abcde", (char *)rec2.data));
/* make sure that the cursor is coupled to the txn-op */
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
}
void moveLastSmallerInTransactionTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
/* insert a large key into the btree */
Backend *be=((Database *)m_db)->get_backend();
key.data=(void *)"22222";
rec.data=(void *)"abcde";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* insert a smaller key into the Transaction */
key.data=(void *)"11111";
rec.data=(void *)"xyzab";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
/* this moves the cursor to the last item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_LAST));
BFC_ASSERT_EQUAL(0, strcmp("22222", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("abcde", (char *)rec2.data));
}
void moveLastSmallerInTransactionExtendedKeyTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
const char *ext1="111111111111111111111111111111";
const char *ext2="222222222222222222222222222222";
key.size=31;
rec.size=6;
/* insert a large key into the btree */
Backend *be=((Database *)m_db)->get_backend();
key.data=(void *)ext2;
rec.data=(void *)"abcde";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* insert a smaller key into the Transaction */
key.data=(void *)ext1;
rec.data=(void *)"xyzab";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
/* this moves the cursor to the last item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_LAST));
BFC_ASSERT_EQUAL(0, strcmp(ext2, (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("abcde", (char *)rec2.data));
}
void moveLastSmallerInBtreeTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
/* insert a small key into the btree */
Backend *be=((Database *)m_db)->get_backend();
key.data=(void *)"11111";
rec.data=(void *)"abcde";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* insert a greater key into the Transaction */
key.data=(void *)"22222";
rec.data=(void *)"xyzab";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
/* this moves the cursor to the last item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_LAST));
BFC_ASSERT_EQUAL(0, strcmp("22222", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("xyzab", (char *)rec2.data));
}
void moveLastSmallerInBtreeExtendedKeyTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
const char *ext1="111111111111111111111111111111";
const char *ext2="222222222222222222222222222222";
key.size=31;
rec.size=6;
/* insert a small key into the btree */
Backend *be=((Database *)m_db)->get_backend();
key.data=(void *)ext1;
rec.data=(void *)"abcde";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* insert a greater key into the Transaction */
key.data=(void *)ext2;
rec.data=(void *)"xyzab";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
/* this moves the cursor to the last item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_LAST));
BFC_ASSERT_EQUAL(0, strcmp(ext2, (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("xyzab", (char *)rec2.data));
}
void moveLastErasedInTxnTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
/* insert a key into the btree */
Backend *be=((Database *)m_db)->get_backend();
key.data=(void *)"11111";
rec.data=(void *)"abcde";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* erase it */
key.data=(void *)"11111";
BFC_ASSERT_EQUAL(0,
ham_cursor_find(m_cursor, &key, 0));
BFC_ASSERT_EQUAL(0,
ham_cursor_erase(m_cursor, 0));
/* this moves the cursor to the last item, but it was erased
* and therefore this fails */
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_LAST));
}
void moveLastErasedInTxnExtendedKeyTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
const char *ext1="111111111111111111111111111111";
key.size=31;
rec.size=6;
/* insert a key into the btree */
Backend *be=((Database *)m_db)->get_backend();
key.data=(void *)ext1;
rec.data=(void *)"abcde";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* erase it */
key.data=(void *)ext1;
BFC_ASSERT_EQUAL(0,
ham_cursor_find(m_cursor, &key, 0));
BFC_ASSERT_EQUAL(0,
ham_cursor_erase(m_cursor, 0));
/* this moves the cursor to the last item, but it was erased
* and therefore this fails */
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_LAST));
/* we have to manually clear the changeset, otherwise ham_close will
* fail. The changeset was filled in be->insert(but this is an
* internal function which will not clear it. All other functions fail
* and therefore do not touch the changeset. */
((Environment *)m_env)->get_changeset().clear();
}
void moveLastErasedInsertedInTxnTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
/* insert a key into the btree */
Backend *be=((Database *)m_db)->get_backend();
key.data=(void *)"11111";
rec.data=(void *)"abcde";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* erase it */
key.data=(void *)"11111";
BFC_ASSERT_EQUAL(0,
ham_cursor_find(m_cursor, &key, 0));
BFC_ASSERT_EQUAL(0,
ham_cursor_erase(m_cursor, 0));
/* re-insert it */
rec.data=(void *)"10101";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
/* this moves the cursor to the last item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_LAST));
BFC_ASSERT_EQUAL(0, strcmp("11111", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("10101", (char *)rec2.data));
}
void moveLastSmallerInBtreeErasedInTxnTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
/* insert a small key into the btree */
Backend *be=((Database *)m_db)->get_backend();
key.data=(void *)"11111";
rec.data=(void *)"abcde";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* insert a greater key into the Transaction */
key.data=(void *)"22222";
rec.data=(void *)"xyzab";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
/* erase the smaller item */
key.data=(void *)"11111";
BFC_ASSERT_EQUAL(0,
ham_cursor_find(m_cursor, &key, 0));
BFC_ASSERT_EQUAL(0,
ham_cursor_erase(m_cursor, 0));
/* this moves the cursor to the second item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_LAST));
BFC_ASSERT_EQUAL(0, strcmp("22222", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("xyzab", (char *)rec2.data));
}
void moveNextInEmptyTransactionTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
/* insert a few keys into the btree */
Backend *be=((Database *)m_db)->get_backend();
key.data=(void *)"11111";
rec.data=(void *)"aaaaa";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"22222";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"33333";
rec.data=(void *)"ccccc";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* this moves the cursor to the first item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
BFC_ASSERT_EQUAL(0, strcmp("11111", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("aaaaa", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
BFC_ASSERT_EQUAL(0, strcmp("22222", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("bbbbb", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
BFC_ASSERT_EQUAL(0, strcmp("33333", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ccccc", (char *)rec2.data));
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
}
void moveNextInEmptyBtreeTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
/* insert a few keys into the btree */
key.data=(void *)"11111";
rec.data=(void *)"aaaaa";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
key.data=(void *)"22222";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
key.data=(void *)"33333";
rec.data=(void *)"ccccc";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
/* this moves the cursor to the first item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_FIRST));
BFC_ASSERT_EQUAL(0, strcmp("11111", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("aaaaa", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
BFC_ASSERT_EQUAL(0, strcmp("22222", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("bbbbb", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
BFC_ASSERT_EQUAL(0, strcmp("33333", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ccccc", (char *)rec2.data));
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
}
void moveNextSmallerInTransactionTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
/* insert a "small" key into the transaction */
key.data=(void *)"11111";
rec.data=(void *)"aaaaa";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
/* and a "greater" one in the btree */
key.data=(void *)"22222";
rec.data=(void *)"bbbbb";
Backend *be=((Database *)m_db)->get_backend();
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* this moves the cursor to the first item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_FIRST));
BFC_ASSERT_EQUAL(0, strcmp("11111", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("aaaaa", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
BFC_ASSERT_EQUAL(0, strcmp("22222", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("bbbbb", (char *)rec2.data));
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
}
void moveNextSmallerInBtreeTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
/* insert a "small" key into the btree */
key.data=(void *)"11111";
rec.data=(void *)"aaaaa";
Backend *be=((Database *)m_db)->get_backend();
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* and a "large" one in the txn */
key.data=(void *)"22222";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
/* this moves the cursor to the first item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_FIRST));
BFC_ASSERT_EQUAL(0, strcmp("11111", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("aaaaa", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
BFC_ASSERT_EQUAL(0, strcmp("22222", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("bbbbb", (char *)rec2.data));
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
}
void moveNextSmallerInTransactionSequenceTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
/* insert a few "small" keys into the transaction */
key.data=(void *)"11111";
rec.data=(void *)"aaaaa";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
key.data=(void *)"22222";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
key.data=(void *)"33333";
rec.data=(void *)"ccccc";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
Backend *be=((Database *)m_db)->get_backend();
/* and a few "large" keys in the btree */
key.data=(void *)"44444";
rec.data=(void *)"ddddd";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"55555";
rec.data=(void *)"eeeee";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"66666";
rec.data=(void *)"fffff";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* this moves the cursor to the first item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_FIRST));
BFC_ASSERT_EQUAL(0, strcmp("11111", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("aaaaa", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
BFC_ASSERT_EQUAL(0, strcmp("22222", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("bbbbb", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
BFC_ASSERT_EQUAL(0, strcmp("33333", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ccccc", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
BFC_ASSERT_EQUAL(0, strcmp("44444", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ddddd", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
BFC_ASSERT_EQUAL(0, strcmp("55555", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("eeeee", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
BFC_ASSERT_EQUAL(0, strcmp("66666", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("fffff", (char *)rec2.data));
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
}
void moveNextSmallerInBtreeSequenceTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
/* insert a few "small" keys into the btree */
Backend *be=((Database *)m_db)->get_backend();
key.data=(void *)"11111";
rec.data=(void *)"aaaaa";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"22222";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"33333";
rec.data=(void *)"ccccc";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* and a few "large" keys in the transaction */
key.data=(void *)"44444";
rec.data=(void *)"ddddd";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
key.data=(void *)"55555";
rec.data=(void *)"eeeee";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
key.data=(void *)"66666";
rec.data=(void *)"fffff";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
/* this moves the cursor to the first item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_FIRST));
BFC_ASSERT_EQUAL(0, strcmp("11111", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("aaaaa", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
BFC_ASSERT_EQUAL(0, strcmp("22222", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("bbbbb", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
BFC_ASSERT_EQUAL(0, strcmp("33333", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ccccc", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
BFC_ASSERT_EQUAL(0, strcmp("44444", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ddddd", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
BFC_ASSERT_EQUAL(0, strcmp("55555", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("eeeee", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
BFC_ASSERT_EQUAL(0, strcmp("66666", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("fffff", (char *)rec2.data));
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
}
void moveNextOverErasedItemTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
/* insert a few "small" keys into the btree */
Backend *be=((Database *)m_db)->get_backend();
key.data=(void *)"11111";
rec.data=(void *)"aaaaa";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"22222";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"33333";
rec.data=(void *)"ccccc";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* erase the one in the middle */
key.data=(void *)"22222";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0,
ham_erase(m_db, m_txn, &key, 0));
/* this moves the cursor to the first item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_FIRST));
BFC_ASSERT_EQUAL(0, strcmp("11111", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("aaaaa", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
BFC_ASSERT_EQUAL(0, strcmp("33333", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ccccc", (char *)rec2.data));
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
}
void moveNextOverIdenticalItemsTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
/* insert a few keys into the btree */
Backend *be=((Database *)m_db)->get_backend();
key.data=(void *)"11111";
rec.data=(void *)"aaaaa";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"22222";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"33333";
rec.data=(void *)"ccccc";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* overwrite the same keys in the transaction */
key.data=(void *)"11111";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0,
ham_insert(m_db, m_txn, &key, &rec, HAM_OVERWRITE));
key.data=(void *)"22222";
rec.data=(void *)"ccccc";
BFC_ASSERT_EQUAL(0,
ham_insert(m_db, m_txn, &key, &rec, HAM_OVERWRITE));
key.data=(void *)"33333";
rec.data=(void *)"ddddd";
BFC_ASSERT_EQUAL(0,
ham_insert(m_db, m_txn, &key, &rec, HAM_OVERWRITE));
/* this moves the cursor to the first item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_FIRST));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(0, strcmp("11111", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("bbbbb", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(0, strcmp("22222", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ccccc", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(0, strcmp("33333", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ddddd", (char *)rec2.data));
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
}
void moveBtreeThenNextOverIdenticalItemsTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
Backend *be=((Database *)m_db)->get_backend();
/* insert a few keys into the btree */
key.data=(void *)"00000";
rec.data=(void *)"xxxxx";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"11111";
rec.data=(void *)"aaaaa";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"22222";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"33333";
rec.data=(void *)"ccccc";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* skip the first key, and overwrite all others in the transaction */
key.data=(void *)"11111";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0,
ham_insert(m_db, m_txn, &key, &rec, HAM_OVERWRITE));
key.data=(void *)"22222";
rec.data=(void *)"ccccc";
BFC_ASSERT_EQUAL(0,
ham_insert(m_db, m_txn, &key, &rec, HAM_OVERWRITE));
key.data=(void *)"33333";
rec.data=(void *)"ddddd";
BFC_ASSERT_EQUAL(0,
ham_insert(m_db, m_txn, &key, &rec, HAM_OVERWRITE));
/* this moves the cursor to the first item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_FIRST));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_btree());
BFC_ASSERT_EQUAL(0, strcmp("00000", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("xxxxx", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(0, strcmp("11111", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("bbbbb", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(0, strcmp("22222", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ccccc", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(0, strcmp("33333", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ddddd", (char *)rec2.data));
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
}
void moveTxnThenNextOverIdenticalItemsTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
key.data=(void *)"00000";
rec.data=(void *)"xxxxx";
BFC_ASSERT_EQUAL(0, ham_insert(m_db, m_txn, &key, &rec, 0));
Backend *be=((Database *)m_db)->get_backend();
/* insert a few keys into the btree */
key.data=(void *)"11111";
rec.data=(void *)"aaaaa";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"22222";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"33333";
rec.data=(void *)"ccccc";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* skip the first key, and overwrite all others in the transaction */
key.data=(void *)"11111";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0,
ham_insert(m_db, m_txn, &key, &rec, HAM_OVERWRITE));
key.data=(void *)"22222";
rec.data=(void *)"ccccc";
BFC_ASSERT_EQUAL(0,
ham_insert(m_db, m_txn, &key, &rec, HAM_OVERWRITE));
key.data=(void *)"33333";
rec.data=(void *)"ddddd";
BFC_ASSERT_EQUAL(0,
ham_insert(m_db, m_txn, &key, &rec, HAM_OVERWRITE));
/* this moves the cursor to the first item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_FIRST));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(0, strcmp("00000", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("xxxxx", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(0, strcmp("11111", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("bbbbb", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(0, strcmp("22222", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ccccc", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(0, strcmp("33333", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ddddd", (char *)rec2.data));
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
}
void moveNextOverIdenticalItemsThenBtreeTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
Backend *be=((Database *)m_db)->get_backend();
/* insert a few keys into the btree */
key.data=(void *)"11111";
rec.data=(void *)"aaaaa";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"22222";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"33333";
rec.data=(void *)"ccccc";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"99999";
rec.data=(void *)"xxxxx";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* overwrite all keys but the last */
key.data=(void *)"11111";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0,
ham_insert(m_db, m_txn, &key, &rec, HAM_OVERWRITE));
key.data=(void *)"22222";
rec.data=(void *)"ccccc";
BFC_ASSERT_EQUAL(0,
ham_insert(m_db, m_txn, &key, &rec, HAM_OVERWRITE));
key.data=(void *)"33333";
rec.data=(void *)"ddddd";
BFC_ASSERT_EQUAL(0,
ham_insert(m_db, m_txn, &key, &rec, HAM_OVERWRITE));
/* this moves the cursor to the first item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_FIRST));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(0, strcmp("11111", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("bbbbb", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(0, strcmp("22222", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ccccc", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(0, strcmp("33333", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ddddd", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_btree());
BFC_ASSERT_EQUAL(0, strcmp("99999", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("xxxxx", (char *)rec2.data));
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
}
void moveNextOverIdenticalItemsThenTxnTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
Backend *be=((Database *)m_db)->get_backend();
/* insert a few keys into the btree */
key.data=(void *)"11111";
rec.data=(void *)"aaaaa";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"22222";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"33333";
rec.data=(void *)"ccccc";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"99999";
rec.data=(void *)"xxxxx";
BFC_ASSERT_EQUAL(0,
ham_insert(m_db, m_txn, &key, &rec, 0));
/* skip the first key, and overwrite all others in the transaction */
key.data=(void *)"11111";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0,
ham_insert(m_db, m_txn, &key, &rec, HAM_OVERWRITE));
key.data=(void *)"22222";
rec.data=(void *)"ccccc";
BFC_ASSERT_EQUAL(0,
ham_insert(m_db, m_txn, &key, &rec, HAM_OVERWRITE));
key.data=(void *)"33333";
rec.data=(void *)"ddddd";
BFC_ASSERT_EQUAL(0,
ham_insert(m_db, m_txn, &key, &rec, HAM_OVERWRITE));
/* this moves the cursor to the first item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_FIRST));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(0, strcmp("11111", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("bbbbb", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(0, strcmp("22222", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ccccc", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(0, strcmp("33333", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ddddd", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(0, strcmp("99999", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("xxxxx", (char *)rec2.data));
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_NEXT));
}
ham_status_t insertBtree(const char *key, const char *rec,
ham_u32_t flags=0)
{
ham_key_t k={0};
k.data=(void *)key;
k.size=strlen(key)+1;
ham_record_t r={0};
r.data=(void *)rec;
r.size=rec ? strlen(rec)+1 : 0;
Backend *be=((Database *)m_db)->get_backend();
return (be->insert(0, &k, &r, flags));
}
ham_status_t insertTxn(const char *key, const char *rec,
ham_u32_t flags=0, ham_cursor_t *cursor=0)
{
ham_key_t k={0};
k.data=(void *)key;
k.size=strlen(key)+1;
ham_record_t r={0};
r.data=(void *)rec;
r.size=rec ? strlen(rec)+1 : 0;
if (cursor)
return (ham_cursor_insert(cursor, &k, &r, flags));
else
return (ham_insert(m_db, m_txn, &k, &r, flags));
}
ham_status_t eraseTxn(const char *key)
{
ham_key_t k={0};
k.data=(void *)key;
k.size=strlen(key)+1;
return (ham_erase(m_db, m_txn, &k, 0));
}
#define BTREE 1
#define TXN 2
ham_status_t compare(const char *key, const char *rec, int where)
{
ham_key_t k={0};
ham_record_t r={0};
ham_status_t st;
st=ham_cursor_move(m_cursor, &k, &r, HAM_CURSOR_NEXT);
if (st)
return (st);
if (strcmp(key, (char *)k.data))
return (HAM_INTERNAL_ERROR);
if (strcmp(rec, (char *)r.data))
return (HAM_INTERNAL_ERROR);
if (where==BTREE) {
if (((Cursor *)m_cursor)->is_coupled_to_txnop())
return (HAM_INTERNAL_ERROR);
}
else {
if (((Cursor *)m_cursor)->is_coupled_to_btree())
return (HAM_INTERNAL_ERROR);
}
return (0);
}
ham_status_t comparePrev(const char *key, const char *rec, int where)
{
ham_key_t k={0};
ham_record_t r={0};
ham_status_t st;
st=ham_cursor_move(m_cursor, &k, &r, HAM_CURSOR_PREVIOUS);
if (st)
return (st);
if (strcmp(key, (char *)k.data))
return (HAM_INTERNAL_ERROR);
if (strcmp(rec, (char *)r.data))
return (HAM_INTERNAL_ERROR);
if (where==BTREE) {
if (((Cursor *)m_cursor)->is_coupled_to_txnop())
return (HAM_INTERNAL_ERROR);
}
else {
if (((Cursor *)m_cursor)->is_coupled_to_btree())
return (HAM_INTERNAL_ERROR);
}
return (0);
}
void moveNextOverSequencesOfIdenticalItemsTest(void)
{
BFC_ASSERT_EQUAL(0, insertBtree("11111", "aaaaa"));
BFC_ASSERT_EQUAL(0, insertBtree("11112", "aaaab"));
BFC_ASSERT_EQUAL(0, insertBtree("11113", "aaaac"));
BFC_ASSERT_EQUAL(0, insertTxn ("11113", "aaaaa", HAM_OVERWRITE));
BFC_ASSERT_EQUAL(0, insertTxn ("11114", "aaaab"));
BFC_ASSERT_EQUAL(0, insertTxn ("11115", "aaaac"));
BFC_ASSERT_EQUAL(0, insertBtree("11116", "aaaaa"));
BFC_ASSERT_EQUAL(0, insertBtree("11117", "aaaab"));
BFC_ASSERT_EQUAL(0, insertBtree("11118", "aaaac"));
BFC_ASSERT_EQUAL(0, insertTxn ("11116", "bbbba", HAM_OVERWRITE));
BFC_ASSERT_EQUAL(0, insertTxn ("11117", "bbbbb", HAM_OVERWRITE));
BFC_ASSERT_EQUAL(0, insertTxn ("11118", "bbbbc", HAM_OVERWRITE));
BFC_ASSERT_EQUAL(0, compare ("11111", "aaaaa", BTREE));
BFC_ASSERT_EQUAL(0, compare ("11112", "aaaab", BTREE));
BFC_ASSERT_EQUAL(0, compare ("11113", "aaaaa", TXN));
BFC_ASSERT_EQUAL(0, compare ("11114", "aaaab", TXN));
BFC_ASSERT_EQUAL(0, compare ("11115", "aaaac", TXN));
BFC_ASSERT_EQUAL(0, compare ("11116", "bbbba", TXN));
BFC_ASSERT_EQUAL(0, compare ("11117", "bbbbb", TXN));
BFC_ASSERT_EQUAL(0, compare ("11118", "bbbbc", TXN));
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND, compare(0, 0, 0));
}
void moveNextWhileInsertingBtreeTest(void)
{
BFC_ASSERT_EQUAL(0, insertBtree("11111", "aaaaa"));
BFC_ASSERT_EQUAL(0, insertBtree("11112", "aaaab"));
BFC_ASSERT_EQUAL(0, insertBtree("11113", "aaaac"));
BFC_ASSERT_EQUAL(0, insertBtree("11116", "aaaaa"));
BFC_ASSERT_EQUAL(0, insertBtree("11117", "aaaab"));
BFC_ASSERT_EQUAL(0, insertBtree("11118", "aaaac"));
BFC_ASSERT_EQUAL(0, compare ("11111", "aaaaa", BTREE));
BFC_ASSERT_EQUAL(0, compare ("11112", "aaaab", BTREE));
BFC_ASSERT_EQUAL(0, compare ("11113", "aaaac", BTREE));
BFC_ASSERT_EQUAL(0, insertBtree("11114", "aaaax"));
BFC_ASSERT_EQUAL(0, compare ("11114", "aaaax", BTREE));
BFC_ASSERT_EQUAL(0, insertBtree("00001", "aaaax"));
BFC_ASSERT_EQUAL(0, insertBtree("00002", "aaaax"));
BFC_ASSERT_EQUAL(0, compare ("11116", "aaaaa", BTREE));
BFC_ASSERT_EQUAL(0, insertBtree("22222", "aaaax"));
BFC_ASSERT_EQUAL(0, compare ("11117", "aaaab", BTREE));
BFC_ASSERT_EQUAL(0, compare ("11118", "aaaac", BTREE));
BFC_ASSERT_EQUAL(0, compare ("22222", "aaaax", BTREE));
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND, compare(0, 0, 0));
}
void moveNextWhileInsertingTransactionTest(void)
{
BFC_ASSERT_EQUAL(0, insertTxn("11111", "aaaaa"));
BFC_ASSERT_EQUAL(0, insertTxn("11112", "aaaab"));
BFC_ASSERT_EQUAL(0, insertTxn("11113", "aaaac"));
BFC_ASSERT_EQUAL(0, insertTxn("11116", "aaaaa"));
BFC_ASSERT_EQUAL(0, insertTxn("11117", "aaaab"));
BFC_ASSERT_EQUAL(0, insertTxn("11118", "aaaac"));
BFC_ASSERT_EQUAL(0, compare ("11111", "aaaaa", TXN));
BFC_ASSERT_EQUAL(0, compare ("11112", "aaaab", TXN));
BFC_ASSERT_EQUAL(0, compare ("11113", "aaaac", TXN));
BFC_ASSERT_EQUAL(0, insertTxn("11114", "aaaax"));
BFC_ASSERT_EQUAL(0, compare ("11114", "aaaax", TXN));
BFC_ASSERT_EQUAL(0, insertTxn("00001", "aaaax"));
BFC_ASSERT_EQUAL(0, insertTxn("00002", "aaaax"));
BFC_ASSERT_EQUAL(0, compare ("11116", "aaaaa", TXN));
BFC_ASSERT_EQUAL(0, insertTxn("22222", "aaaax"));
BFC_ASSERT_EQUAL(0, compare ("11117", "aaaab", TXN));
BFC_ASSERT_EQUAL(0, compare ("11118", "aaaac", TXN));
BFC_ASSERT_EQUAL(0, compare ("22222", "aaaax", TXN));
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND, compare(0, 0, 0));
}
void moveNextWhileInsertingMixedTest(void)
{
BFC_ASSERT_EQUAL(0, insertBtree("11111", "aaaaa"));
BFC_ASSERT_EQUAL(0, insertBtree("11112", "aaaab"));
BFC_ASSERT_EQUAL(0, insertBtree("11113", "aaaac"));
BFC_ASSERT_EQUAL(0, insertTxn ("11112", "aaaaa", HAM_OVERWRITE));
BFC_ASSERT_EQUAL(0, insertTxn ("11117", "aaaab"));
BFC_ASSERT_EQUAL(0, insertTxn ("11118", "aaaac"));
BFC_ASSERT_EQUAL(0, insertBtree("11119", "aaaac"));
BFC_ASSERT_EQUAL(0, compare ("11111", "aaaaa", BTREE));
BFC_ASSERT_EQUAL(0, compare ("11112", "aaaaa", TXN));
BFC_ASSERT_EQUAL(0, insertTxn ("11113", "xxxxx", HAM_OVERWRITE));
BFC_ASSERT_EQUAL(0, compare ("11113", "xxxxx", TXN));
BFC_ASSERT_EQUAL(0, compare ("11117", "aaaab", TXN));
BFC_ASSERT_EQUAL(0, compare ("11118", "aaaac", TXN));
BFC_ASSERT_EQUAL(0, compare ("11119", "aaaac", BTREE));
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND, compare(0, 0, 0));
}
void moveNextWhileErasingTest(void)
{
BFC_ASSERT_EQUAL(0, insertBtree("11111", "aaaaa"));
BFC_ASSERT_EQUAL(0, insertBtree("11112", "aaaab"));
BFC_ASSERT_EQUAL(0, insertBtree("11113", "aaaac"));
BFC_ASSERT_EQUAL(0, insertTxn ("11114", "aaaad"));
BFC_ASSERT_EQUAL(0, insertTxn ("11115", "aaaae"));
BFC_ASSERT_EQUAL(0, insertTxn ("11116", "aaaaf"));
BFC_ASSERT_EQUAL(0, compare ("11111", "aaaaa", BTREE));
BFC_ASSERT_EQUAL(0, compare ("11112", "aaaab", BTREE));
BFC_ASSERT_EQUAL(0, eraseTxn ("11112"));
BFC_ASSERT_EQUAL(true, cursor_is_nil((Cursor *)m_cursor, 0));
BFC_ASSERT_EQUAL(true, ((Cursor *)m_cursor)->is_first_use());
BFC_ASSERT_EQUAL(0, compare ("11111", "aaaaa", BTREE));
BFC_ASSERT_EQUAL(0, compare ("11113", "aaaac", BTREE));
BFC_ASSERT_EQUAL(0, eraseTxn ("11114"));
BFC_ASSERT_EQUAL(0, compare ("11115", "aaaae", TXN));
BFC_ASSERT_EQUAL(0, compare ("11116", "aaaaf", TXN));
BFC_ASSERT_EQUAL(0, eraseTxn ("11116"));
BFC_ASSERT_EQUAL(true, cursor_is_nil((Cursor *)m_cursor, 0));
}
void movePreviousInEmptyTransactionTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
/* insert a few keys into the btree */
Backend *be=((Database *)m_db)->get_backend();
key.data=(void *)"11111";
rec.data=(void *)"aaaaa";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"22222";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"33333";
rec.data=(void *)"ccccc";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* this moves the cursor to the first item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
BFC_ASSERT_EQUAL(0, strcmp("33333", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ccccc", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
BFC_ASSERT_EQUAL(0, strcmp("22222", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("bbbbb", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
BFC_ASSERT_EQUAL(0, strcmp("11111", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("aaaaa", (char *)rec2.data));
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
}
void movePreviousInEmptyBtreeTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
/* insert a few keys into the btree */
key.data=(void *)"11111";
rec.data=(void *)"aaaaa";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
key.data=(void *)"22222";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
key.data=(void *)"33333";
rec.data=(void *)"ccccc";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
/* this moves the cursor to the first item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_LAST));
BFC_ASSERT_EQUAL(0, strcmp("33333", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ccccc", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
BFC_ASSERT_EQUAL(0, strcmp("22222", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("bbbbb", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
BFC_ASSERT_EQUAL(0, strcmp("11111", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("aaaaa", (char *)rec2.data));
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
}
void movePreviousSmallerInTransactionTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
/* insert a "small" key into the transaction */
key.data=(void *)"11111";
rec.data=(void *)"aaaaa";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
/* and a "large" one in the btree */
key.data=(void *)"22222";
rec.data=(void *)"bbbbb";
Backend *be=((Database *)m_db)->get_backend();
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* this moves the cursor to the first item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_LAST));
BFC_ASSERT_EQUAL(0, strcmp("22222", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("bbbbb", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
BFC_ASSERT_EQUAL(0, strcmp("11111", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("aaaaa", (char *)rec2.data));
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
}
void movePreviousSmallerInBtreeTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
/* insert a "small" key into the btree */
key.data=(void *)"11111";
rec.data=(void *)"aaaaa";
Backend *be=((Database *)m_db)->get_backend();
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* and a "large" one in the txn */
key.data=(void *)"22222";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
/* this moves the cursor to the first item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_LAST));
BFC_ASSERT_EQUAL(0, strcmp("22222", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("bbbbb", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
BFC_ASSERT_EQUAL(0, strcmp("11111", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("aaaaa", (char *)rec2.data));
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
}
void movePreviousSmallerInTransactionSequenceTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
/* insert a few "small" keys into the transaction */
key.data=(void *)"11111";
rec.data=(void *)"aaaaa";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
key.data=(void *)"22222";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
key.data=(void *)"33333";
rec.data=(void *)"ccccc";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
Backend *be=((Database *)m_db)->get_backend();
/* and a few "large" keys in the btree */
key.data=(void *)"44444";
rec.data=(void *)"ddddd";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"55555";
rec.data=(void *)"eeeee";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"66666";
rec.data=(void *)"fffff";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* this moves the cursor to the first item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_LAST));
BFC_ASSERT_EQUAL(0, strcmp("66666", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("fffff", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
BFC_ASSERT_EQUAL(0, strcmp("55555", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("eeeee", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
BFC_ASSERT_EQUAL(0, strcmp("44444", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ddddd", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
BFC_ASSERT_EQUAL(0, strcmp("33333", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ccccc", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
BFC_ASSERT_EQUAL(0, strcmp("22222", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("bbbbb", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
BFC_ASSERT_EQUAL(0, strcmp("11111", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("aaaaa", (char *)rec2.data));
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
}
void movePreviousSmallerInBtreeSequenceTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
/* insert a few "small" keys into the btree */
Backend *be=((Database *)m_db)->get_backend();
key.data=(void *)"11111";
rec.data=(void *)"aaaaa";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"22222";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"33333";
rec.data=(void *)"ccccc";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* and a few "large" keys in the transaction */
key.data=(void *)"44444";
rec.data=(void *)"ddddd";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
key.data=(void *)"55555";
rec.data=(void *)"eeeee";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
key.data=(void *)"66666";
rec.data=(void *)"fffff";
BFC_ASSERT_EQUAL(0,
ham_cursor_insert(m_cursor, &key, &rec, 0));
/* this moves the cursor to the first item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_LAST));
BFC_ASSERT_EQUAL(0, strcmp("66666", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("fffff", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
BFC_ASSERT_EQUAL(0, strcmp("55555", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("eeeee", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
BFC_ASSERT_EQUAL(0, strcmp("44444", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ddddd", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
BFC_ASSERT_EQUAL(0, strcmp("33333", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ccccc", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
BFC_ASSERT_EQUAL(0, strcmp("22222", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("bbbbb", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
BFC_ASSERT_EQUAL(0, strcmp("11111", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("aaaaa", (char *)rec2.data));
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
}
void movePreviousOverErasedItemTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
/* insert a few "small" keys into the btree */
Backend *be=((Database *)m_db)->get_backend();
key.data=(void *)"11111";
rec.data=(void *)"aaaaa";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"22222";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"33333";
rec.data=(void *)"ccccc";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* erase the one in the middle */
key.data=(void *)"22222";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0,
ham_erase(m_db, m_txn, &key, 0));
/* this moves the cursor to the first item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_LAST));
BFC_ASSERT_EQUAL(0, strcmp("33333", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ccccc", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
BFC_ASSERT_EQUAL(0, strcmp("11111", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("aaaaa", (char *)rec2.data));
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
}
void movePreviousOverIdenticalItemsTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
/* insert a few keys into the btree */
Backend *be=((Database *)m_db)->get_backend();
key.data=(void *)"11111";
rec.data=(void *)"aaaaa";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"22222";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"33333";
rec.data=(void *)"ccccc";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* overwrite the same keys in the transaction */
key.data=(void *)"11111";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0,
ham_insert(m_db, m_txn, &key, &rec, HAM_OVERWRITE));
key.data=(void *)"22222";
rec.data=(void *)"ccccc";
BFC_ASSERT_EQUAL(0,
ham_insert(m_db, m_txn, &key, &rec, HAM_OVERWRITE));
key.data=(void *)"33333";
rec.data=(void *)"ddddd";
BFC_ASSERT_EQUAL(0,
ham_insert(m_db, m_txn, &key, &rec, HAM_OVERWRITE));
/* this moves the cursor to the last item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_LAST));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(0, strcmp("33333", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ddddd", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(0, strcmp("22222", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ccccc", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
BFC_ASSERT_EQUAL(0, strcmp("11111", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("bbbbb", (char *)rec2.data));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
}
void moveBtreeThenPreviousOverIdenticalItemsTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
Backend *be=((Database *)m_db)->get_backend();
/* insert a few keys into the btree */
key.data=(void *)"00000";
rec.data=(void *)"xxxxx";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"11111";
rec.data=(void *)"aaaaa";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"22222";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"33333";
rec.data=(void *)"ccccc";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* skip the first key, and overwrite all others in the transaction */
key.data=(void *)"11111";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0,
ham_insert(m_db, m_txn, &key, &rec, HAM_OVERWRITE));
key.data=(void *)"22222";
rec.data=(void *)"ccccc";
BFC_ASSERT_EQUAL(0,
ham_insert(m_db, m_txn, &key, &rec, HAM_OVERWRITE));
key.data=(void *)"33333";
rec.data=(void *)"ddddd";
BFC_ASSERT_EQUAL(0,
ham_insert(m_db, m_txn, &key, &rec, HAM_OVERWRITE));
/* this moves the cursor to the last item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_LAST));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(0, strcmp("33333", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ddddd", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(0, strcmp("22222", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ccccc", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(0, strcmp("11111", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("bbbbb", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_btree());
BFC_ASSERT_EQUAL(0, strcmp("00000", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("xxxxx", (char *)rec2.data));
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
}
void moveTxnThenPreviousOverIdenticalItemsTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
key.data=(void *)"00000";
rec.data=(void *)"xxxxx";
BFC_ASSERT_EQUAL(0, ham_insert(m_db, m_txn, &key, &rec, 0));
Backend *be=((Database *)m_db)->get_backend();
/* insert a few keys into the btree */
key.data=(void *)"11111";
rec.data=(void *)"aaaaa";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"22222";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"33333";
rec.data=(void *)"ccccc";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* skip the first key, and overwrite all others in the transaction */
key.data=(void *)"11111";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0,
ham_insert(m_db, m_txn, &key, &rec, HAM_OVERWRITE));
key.data=(void *)"22222";
rec.data=(void *)"ccccc";
BFC_ASSERT_EQUAL(0,
ham_insert(m_db, m_txn, &key, &rec, HAM_OVERWRITE));
key.data=(void *)"33333";
rec.data=(void *)"ddddd";
BFC_ASSERT_EQUAL(0,
ham_insert(m_db, m_txn, &key, &rec, HAM_OVERWRITE));
/* this moves the cursor to the last item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_LAST));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(0, strcmp("33333", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ddddd", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
BFC_ASSERT_EQUAL(0, strcmp("22222", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ccccc", (char *)rec2.data));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(0, strcmp("11111", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("bbbbb", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(0, strcmp("00000", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("xxxxx", (char *)rec2.data));
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
}
void movePreviousOverIdenticalItemsThenBtreeTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
Backend *be=((Database *)m_db)->get_backend();
/* insert a few keys into the btree */
key.data=(void *)"11111";
rec.data=(void *)"aaaaa";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"22222";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"33333";
rec.data=(void *)"ccccc";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"99999";
rec.data=(void *)"xxxxx";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
/* skip the last key, and overwrite all others in the transaction */
key.data=(void *)"11111";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0,
ham_insert(m_db, m_txn, &key, &rec, HAM_OVERWRITE));
key.data=(void *)"22222";
rec.data=(void *)"ccccc";
BFC_ASSERT_EQUAL(0,
ham_insert(m_db, m_txn, &key, &rec, HAM_OVERWRITE));
key.data=(void *)"33333";
rec.data=(void *)"ddddd";
BFC_ASSERT_EQUAL(0,
ham_insert(m_db, m_txn, &key, &rec, HAM_OVERWRITE));
/* this moves the cursor to the last item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_LAST));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_btree());
BFC_ASSERT_EQUAL(0, strcmp("99999", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("xxxxx", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(0, strcmp("33333", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ddddd", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(0, strcmp("22222", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ccccc", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(0, strcmp("11111", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("bbbbb", (char *)rec2.data));
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
}
void movePreviousOverIdenticalItemsThenTxnTest(void)
{
ham_key_t key={0}, key2={0};
ham_record_t rec={0}, rec2={0};
key.size=6;
rec.size=6;
Backend *be=((Database *)m_db)->get_backend();
/* insert a few keys into the btree */
key.data=(void *)"11111";
rec.data=(void *)"aaaaa";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"22222";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"33333";
rec.data=(void *)"ccccc";
BFC_ASSERT_EQUAL(0, be->insert(0, &key, &rec, 0));
key.data=(void *)"99999";
rec.data=(void *)"xxxxx";
BFC_ASSERT_EQUAL(0,
ham_insert(m_db, m_txn, &key, &rec, 0));
/* skip the first key, and overwrite all others in the transaction */
key.data=(void *)"11111";
rec.data=(void *)"bbbbb";
BFC_ASSERT_EQUAL(0,
ham_insert(m_db, m_txn, &key, &rec, HAM_OVERWRITE));
key.data=(void *)"22222";
rec.data=(void *)"ccccc";
BFC_ASSERT_EQUAL(0,
ham_insert(m_db, m_txn, &key, &rec, HAM_OVERWRITE));
key.data=(void *)"33333";
rec.data=(void *)"ddddd";
BFC_ASSERT_EQUAL(0,
ham_insert(m_db, m_txn, &key, &rec, HAM_OVERWRITE));
/* this moves the cursor to the last item */
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_LAST));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(0, strcmp("99999", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("xxxxx", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(0, strcmp("33333", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ddddd", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(0, strcmp("22222", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("ccccc", (char *)rec2.data));
BFC_ASSERT_EQUAL(0,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
BFC_ASSERT(((Cursor *)m_cursor)->is_coupled_to_txnop());
BFC_ASSERT_EQUAL(0, strcmp("11111", (char *)key2.data));
BFC_ASSERT_EQUAL(0, strcmp("bbbbb", (char *)rec2.data));
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
ham_cursor_move(m_cursor, &key2, &rec2, HAM_CURSOR_PREVIOUS));
}
void movePreviousOverSequencesOfIdenticalItemsTest(void)
{
BFC_ASSERT_EQUAL(0, insertBtree("11111", "aaaaa"));
BFC_ASSERT_EQUAL(0, insertBtree("11112", "aaaab"));
BFC_ASSERT_EQUAL(0, insertBtree("11113", "aaaac"));
BFC_ASSERT_EQUAL(0, insertTxn ("11113", "aaaaa", HAM_OVERWRITE));
BFC_ASSERT_EQUAL(0, insertTxn ("11114", "aaaab"));
BFC_ASSERT_EQUAL(0, insertTxn ("11115", "aaaac"));
BFC_ASSERT_EQUAL(0, insertBtree("11116", "aaaaa"));
BFC_ASSERT_EQUAL(0, insertBtree("11117", "aaaab"));
BFC_ASSERT_EQUAL(0, insertBtree("11118", "aaaac"));
BFC_ASSERT_EQUAL(0, insertTxn ("11116", "bbbba", HAM_OVERWRITE));
BFC_ASSERT_EQUAL(0, insertTxn ("11117", "bbbbb", HAM_OVERWRITE));
BFC_ASSERT_EQUAL(0, insertTxn ("11118", "bbbbc", HAM_OVERWRITE));
BFC_ASSERT_EQUAL(0, comparePrev("11118", "bbbbc", TXN));
BFC_ASSERT_EQUAL(0, comparePrev("11117", "bbbbb", TXN));
BFC_ASSERT_EQUAL(0, comparePrev("11116", "bbbba", TXN));
BFC_ASSERT_EQUAL(0, comparePrev("11115", "aaaac", TXN));
BFC_ASSERT_EQUAL(0, comparePrev("11114", "aaaab", TXN));
BFC_ASSERT_EQUAL(0, comparePrev("11113", "aaaaa", TXN));
BFC_ASSERT_EQUAL(0, comparePrev("11112", "aaaab", BTREE));
BFC_ASSERT_EQUAL(0, comparePrev("11111", "aaaaa", BTREE));
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND, comparePrev(0, 0, 0));
}
void movePreviousWhileInsertingBtreeTest(void)
{
BFC_ASSERT_EQUAL(0, insertBtree("11111", "aaaaa"));
BFC_ASSERT_EQUAL(0, insertBtree("11112", "aaaab"));
BFC_ASSERT_EQUAL(0, insertBtree("11113", "aaaac"));
BFC_ASSERT_EQUAL(0, insertBtree("11116", "aaaaa"));
BFC_ASSERT_EQUAL(0, insertBtree("11117", "aaaab"));
BFC_ASSERT_EQUAL(0, insertBtree("11118", "aaaac"));
BFC_ASSERT_EQUAL(0, comparePrev("11118", "aaaac", BTREE));
BFC_ASSERT_EQUAL(0, comparePrev("11117", "aaaab", BTREE));
BFC_ASSERT_EQUAL(0, comparePrev("11116", "aaaaa", BTREE));
BFC_ASSERT_EQUAL(0, insertBtree("11114", "aaaax"));
BFC_ASSERT_EQUAL(0, comparePrev("11114", "aaaax", BTREE));
BFC_ASSERT_EQUAL(0, comparePrev("11113", "aaaac", BTREE));
BFC_ASSERT_EQUAL(0, comparePrev("11112", "aaaab", BTREE));
BFC_ASSERT_EQUAL(0, comparePrev("11111", "aaaaa", BTREE));
BFC_ASSERT_EQUAL(0, insertBtree("00000", "aaaax"));
BFC_ASSERT_EQUAL(0, comparePrev("00000", "aaaax", BTREE));
BFC_ASSERT_EQUAL(0, insertBtree("00001", "aaaax"));
BFC_ASSERT_EQUAL(0, insertBtree("00002", "aaaax"));
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND, comparePrev(0, 0, 0));
}
void movePreviousWhileInsertingTransactionTest(void)
{
BFC_ASSERT_EQUAL(0, insertTxn ("11111", "aaaaa"));
BFC_ASSERT_EQUAL(0, insertTxn ("11112", "aaaab"));
BFC_ASSERT_EQUAL(0, insertTxn ("11113", "aaaac"));
BFC_ASSERT_EQUAL(0, insertTxn ("11116", "aaaaa"));
BFC_ASSERT_EQUAL(0, insertTxn ("11117", "aaaab"));
BFC_ASSERT_EQUAL(0, insertTxn ("11118", "aaaac"));
BFC_ASSERT_EQUAL(0, comparePrev("11118", "aaaac", TXN));
BFC_ASSERT_EQUAL(0, comparePrev("11117", "aaaab", TXN));
BFC_ASSERT_EQUAL(0, comparePrev("11116", "aaaaa", TXN));
BFC_ASSERT_EQUAL(0, insertTxn ("11114", "aaaax"));
BFC_ASSERT_EQUAL(0, comparePrev("11114", "aaaax", TXN));
BFC_ASSERT_EQUAL(0, comparePrev("11113", "aaaac", TXN));
BFC_ASSERT_EQUAL(0, comparePrev("11112", "aaaab", TXN));
BFC_ASSERT_EQUAL(0, comparePrev("11111", "aaaaa", TXN));
BFC_ASSERT_EQUAL(0, insertTxn ("00000", "aaaax"));
BFC_ASSERT_EQUAL(0, comparePrev("00000", "aaaax", TXN));
BFC_ASSERT_EQUAL(0, insertTxn ("00001", "aaaax"));
BFC_ASSERT_EQUAL(0, insertTxn ("00002", "aaaax"));
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND, comparePrev(0, 0, 0));
}
void movePreviousWhileInsertingMixedTest(void)
{
BFC_ASSERT_EQUAL(0, insertBtree("11111", "aaaaa"));
BFC_ASSERT_EQUAL(0, insertBtree("11112", "aaaab"));
BFC_ASSERT_EQUAL(0, insertBtree("11113", "aaaac"));
BFC_ASSERT_EQUAL(0, insertTxn ("11112", "aaaaa", HAM_OVERWRITE));
BFC_ASSERT_EQUAL(0, insertTxn ("11117", "aaaab"));
BFC_ASSERT_EQUAL(0, insertTxn ("11118", "aaaac"));
BFC_ASSERT_EQUAL(0, insertBtree("11119", "aaaac"));
BFC_ASSERT_EQUAL(0, comparePrev("11119", "aaaac", BTREE));
BFC_ASSERT_EQUAL(0, comparePrev("11118", "aaaac", TXN));
BFC_ASSERT_EQUAL(0, comparePrev("11117", "aaaab", TXN));
BFC_ASSERT_EQUAL(0, insertTxn ("11113", "xxxxx", HAM_OVERWRITE));
BFC_ASSERT_EQUAL(0, comparePrev("11113", "xxxxx", TXN));
BFC_ASSERT_EQUAL(0, comparePrev("11112", "aaaaa", TXN));
BFC_ASSERT_EQUAL(0, comparePrev("11111", "aaaaa", BTREE));
BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND, comparePrev(0, 0, 0));
}
void switchDirectionsInBtreeTest(void)
{
BFC_ASSERT_EQUAL(0, insertBtree("11111", "aaaaa"));
BFC_ASSERT_EQUAL(0, insertBtree("11112", "aaaab"));
BFC_ASSERT_EQUAL(0, insertBtree("11113", "aaaac"));
BFC_ASSERT_EQUAL(0, insertBtree("11114", "aaaad"));
BFC_ASSERT_EQUAL(0, insertBtree("11115", "aaaae"));
BFC_ASSERT_EQUAL(0, insertBtree("11116", "aaaaf"));
BFC_ASSERT_EQUAL(0, insertBtree("11116", "aaaag", HAM_OVERWRITE));
BFC_ASSERT_EQUAL(0, insertBtree("11117", "aaaah"));
BFC_ASSERT_EQUAL(0, insertBtree("11118", "aaaai"));
BFC_ASSERT_EQUAL(0, insertBtree("11119", "aaaaj"));
BFC_ASSERT_EQUAL(0, compare ("11111", "aaaaa", BTREE));
BFC_ASSERT_EQUAL(0, compare ("11112", "aaaab", BTREE));
BFC_ASSERT_EQUAL(0, comparePrev("11111", "aaaaa", BTREE));
BFC_ASSERT_EQUAL(0, compare ("11112", "aaaab", BTREE));
BFC_ASSERT_EQUAL(0, compare ("11113", "aaaac", BTREE));
BFC_ASSERT_EQUAL(0, compare ("11114", "aaaad", BTREE));
BFC_ASSERT_EQUAL(0, comparePrev("11113", "aaaac", BTREE));
BFC_ASSERT_EQUAL(0, comparePrev("11112", "aaaab", BTREE));
BFC_ASSERT_EQUAL(0, compare ("11113", "aaaac", BTREE));
BFC_ASSERT_EQUAL(0, compare ("11114", "aaaad", BTREE));
BFC_ASSERT_EQUAL(0, compare ("11115", "aaaae", BTREE));
BFC_ASSERT_EQUAL(0, compare ("11116", "aaaag", BTREE));
BFC_ASSERT_EQUAL(0, compare ("11117", "aaaah", BTREE));
BFC_ASSERT_EQUAL(0, compare ("11118", "aaaai", BTREE));
BFC_ASSERT_EQUAL(0, compare ("11119", "aaaaj", BTREE));
BFC_ASSERT_EQUAL(0, comparePrev("11118", "aaaai", BTREE));
BFC_ASSERT_EQUAL(0, comparePrev("11117", "aaaah", BTREE));
BFC_ASSERT_EQUAL(0, comparePrev("11116", "aaaag", BTREE));
}
void switchDirectionsInTransactionTest(void)
{
BFC_ASSERT_EQUAL(0, insertTxn ("11111", "aaaaa"));
BFC_ASSERT_EQUAL(0, insertTxn ("11112", "aaaab"));
BFC_ASSERT_EQUAL(0, insertTxn ("11113", "aaaac"));
BFC_ASSERT_EQUAL(0, insertTxn ("11114", "aaaad"));
BFC_ASSERT_EQUAL(0, insertTxn ("11115", "aaaae"));
BFC_ASSERT_EQUAL(0, insertTxn ("11116", "aaaaf"));
BFC_ASSERT_EQUAL(0, insertTxn ("11116", "aaaag", HAM_OVERWRITE));
BFC_ASSERT_EQUAL(0, insertTxn ("11117", "aaaah"));
BFC_ASSERT_EQUAL(0, insertTxn ("11118", "aaaai"));
BFC_ASSERT_EQUAL(0, insertTxn ("11119", "aaaaj"));
BFC_ASSERT_EQUAL(0, compare ("11111", "aaaaa", TXN));
BFC_ASSERT_EQUAL(0, compare ("11112", "aaaab", TXN));
BFC_ASSERT_EQUAL(0, comparePrev("11111", "aaaaa", TXN));
BFC_ASSERT_EQUAL(0, compare ("11112", "aaaab", TXN));
BFC_ASSERT_EQUAL(0, compare ("11113", "aaaac", TXN));
BFC_ASSERT_EQUAL(0, compare ("11114", "aaaad", TXN));
BFC_ASSERT_EQUAL(0, comparePrev("11113", "aaaac", TXN));
BFC_ASSERT_EQUAL(0, comparePrev("11112", "aaaab", TXN));
BFC_ASSERT_EQUAL(0, compare ("11113", "aaaac", TXN));
BFC_ASSERT_EQUAL(0, compare ("11114", "aaaad", TXN));
BFC_ASSERT_EQUAL(0, compare ("11115", "aaaae", TXN));
BFC_ASSERT_EQUAL(0, compare ("11116", "aaaag", TXN));
BFC_ASSERT_EQUAL(0, compare ("11117", "aaaah", TXN));
BFC_ASSERT_EQUAL(0, compare ("11118", "aaaai", TXN));
BFC_ASSERT_EQUAL(0, compare ("11119", "aaaaj", TXN));
BFC_ASSERT_EQUAL(0, comparePrev("11118", "aaaai", TXN));
BFC_ASSERT_EQUAL(0, comparePrev("11117", "aaaah", TXN));
BFC_ASSERT_EQUAL(0, comparePrev("11116", "aaaag", TXN));
}
void switchDirectionsMixedStartInBtreeTest(void)
{
BFC_ASSERT_EQUAL(0, insertBtree("11111", "aaaaa"));
BFC_ASSERT_EQUAL(0, insertTxn ("11112", "aaaab"));
BFC_ASSERT_EQUAL(0, insertBtree("11113", "aaaac"));
BFC_ASSERT_EQUAL(0, insertTxn ("11114", "aaaad"));
BFC_ASSERT_EQUAL(0, insertBtree("11115", "aaaae"));
BFC_ASSERT_EQUAL(0, insertTxn ("11116", "aaaaf"));
BFC_ASSERT_EQUAL(0, insertTxn ("11116", "aaaag", HAM_OVERWRITE));
BFC_ASSERT_EQUAL(0, insertBtree("11117", "aaaah"));
BFC_ASSERT_EQUAL(0, insertTxn ("11118", "aaaai"));
BFC_ASSERT_EQUAL(0, insertBtree("11119", "aaaaj"));
BFC_ASSERT_EQUAL(0, insertTxn ("11119", "aaaak", HAM_OVERWRITE));
BFC_ASSERT_EQUAL(0, compare ("11111", "aaaaa", BTREE));
BFC_ASSERT_EQUAL(0, compare ("11112", "aaaab", TXN));
BFC_ASSERT_EQUAL(0, comparePrev("11111", "aaaaa", BTREE));
BFC_ASSERT_EQUAL(0, compare ("11112", "aaaab", TXN));
BFC_ASSERT_EQUAL(0, compare ("11113", "aaaac", BTREE));
BFC_ASSERT_EQUAL(0, compare ("11114", "aaaad", TXN));
BFC_ASSERT_EQUAL(0, comparePrev("11113", "aaaac", BTREE));
BFC_ASSERT_EQUAL(0, comparePrev("11112", "aaaab", TXN));
BFC_ASSERT_EQUAL(0, compare ("11113", "aaaac", BTREE));
BFC_ASSERT_EQUAL(0, compare ("11114", "aaaad", TXN));
BFC_ASSERT_EQUAL(0, compare ("11115", "aaaae", BTREE));
BFC_ASSERT_EQUAL(0, compare ("11116", "aaaag", TXN));
BFC_ASSERT_EQUAL(0, compare ("11117", "aaaah", BTREE));
BFC_ASSERT_EQUAL(0, compare ("11118", "aaaai", TXN));
BFC_ASSERT_EQUAL(0, compare ("11119", "aaaak", TXN));
BFC_ASSERT_EQUAL(0, comparePrev("11118", "aaaai", TXN));
BFC_ASSERT_EQUAL(0, comparePrev("11117", "aaaah", BTREE));
BFC_ASSERT_EQUAL(0, comparePrev("11116", "aaaag", TXN));
}
void switchDirectionsMixedStartInTxnTest(void)
{
BFC_ASSERT_EQUAL(0, insertTxn ("11111", "aaaaa"));
BFC_ASSERT_EQUAL(0, insertBtree("11112", "aaaab"));
BFC_ASSERT_EQUAL(0, insertTxn ("11113", "aaaac"));
BFC_ASSERT_EQUAL(0, insertBtree("11114", "aaaad"));
BFC_ASSERT_EQUAL(0, insertTxn ("11115", "aaaae"));
BFC_ASSERT_EQUAL(0, insertBtree("11116", "aaaaf"));
BFC_ASSERT_EQUAL(0, insertTxn ("11116", "aaaag", HAM_OVERWRITE));
BFC_ASSERT_EQUAL(0, insertTxn ("11117", "aaaah"));
BFC_ASSERT_EQUAL(0, insertTxn ("11118", "aaaai"));
BFC_ASSERT_EQUAL(0, insertBtree("11119", "aaaaj"));
BFC_ASSERT_EQUAL(0, compare ("11111", "aaaaa", TXN));
BFC_ASSERT_EQUAL(0, compare ("11112", "aaaab", BTREE));
BFC_ASSERT_EQUAL(0, comparePrev("11111", "aaaaa", TXN));
BFC_ASSERT_EQUAL(0, compare ("11112", "aaaab", BTREE));
BFC_ASSERT_EQUAL(0, compare ("11113", "aaaac", TXN));
BFC_ASSERT_EQUAL(0, compare ("11114", "aaaad", BTREE));
BFC_ASSERT_EQUAL(0, comparePrev("11113", "aaaac", TXN));
BFC_ASSERT_EQUAL(0, comparePrev("11112", "aaaab", BTREE));
BFC_ASSERT_EQUAL(0, compare ("11113", "aaaac", TXN));
BFC_ASSERT_EQUAL(0, compare ("11114", "aaaad", BTREE));
BFC_ASSERT_EQUAL(0, compare ("11115", "aaaae", TXN));
BFC_ASSERT_EQUAL(0, compare ("11116", "aaaag", TXN));
BFC_ASSERT_EQUAL(0, compare ("11117", "aaaah", TXN));
BFC_ASSERT_EQUAL(0, compare ("11118", "aaaai", TXN));
BFC_ASSERT_EQUAL(0, compare ("11119", "aaaaj", BTREE));
BFC_ASSERT_EQUAL(0, comparePrev("11118", "aaaai", TXN));
BFC_ASSERT_EQUAL(0, comparePrev("11117", "aaaah", TXN));
BFC_ASSERT_EQUAL(0, comparePrev("11116", "aaaag", TXN));
}
void switchDirectionsMixedSequenceTest(void)
{
BFC_ASSERT_EQUAL(0, insertBtree("11111", "aaaaa"));
BFC_ASSERT_EQUAL(0, insertBtree("11112", "aaaab"));
BFC_ASSERT_EQUAL(0, insertBtree("11113", "aaaac"));
BFC_ASSERT_EQUAL(0, insertBtree("11114", "aaaad"));
BFC_ASSERT_EQUAL(0, insertTxn ("11113", "aaaae", HAM_OVERWRITE));
BFC_ASSERT_EQUAL(0, insertTxn ("11114", "aaaaf", HAM_OVERWRITE));
BFC_ASSERT_EQUAL(0, insertTxn ("11115", "aaaag", HAM_OVERWRITE));
BFC_ASSERT_EQUAL(0, insertTxn ("11116", "aaaah"));
BFC_ASSERT_EQUAL(0, insertTxn ("11117", "aaaai"));
BFC_ASSERT_EQUAL(0, insertBtree("11118", "aaaaj"));
BFC_ASSERT_EQUAL(0, insertBtree("11119", "aaaak"));
BFC_ASSERT_EQUAL(0, insertBtree("11120", "aaaal"));
BFC_ASSERT_EQUAL(0, insertBtree("11121", "aaaam"));
BFC_ASSERT_EQUAL(0, insertTxn ("11120", "aaaan", HAM_OVERWRITE));
BFC_ASSERT_EQUAL(0, insertTxn ("11121", "aaaao", HAM_OVERWRITE));
BFC_ASSERT_EQUAL(0, insertTxn ("11122", "aaaap"));
BFC_ASSERT_EQUAL(0, compare ("11111", "aaaaa", BTREE));
BFC_ASSERT_EQUAL(0, compare ("11112", "aaaab", BTREE));
BFC_ASSERT_EQUAL(0, compare ("11113"