コード例 #1
0
        public void TestAddKeyFirst()
        {
            BTreeDatabase db;
            BTreeCursor   cursor;
            KeyValuePair <DatabaseEntry, DatabaseEntry> pair;

            testName = "TestAddKeyFirst";
            SetUpTest(true);

            // Add record("key", "data") into database.
            CursorTest.GetCursorInBtreeDBWithoutEnv(
                testHome, testName, out db, out cursor);
            CursorTest.AddOneByCursor(db, cursor);

            // Add record("key","data1") as the first of the data item of "key".
            pair = new KeyValuePair <DatabaseEntry, DatabaseEntry>(
                new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("key")),
                new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("data1")));
            cursor.Add(pair, Cursor.InsertLocation.FIRST);

            // Confirm the record is added as the first of the data item of "key".
            cursor.Move(new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("key")), true);
            Assert.AreEqual(ASCIIEncoding.ASCII.GetBytes("data1"),
                            cursor.Current.Value.Data);

            cursor.Close();
            db.Close();
        }
コード例 #2
0
        public void TestInsertAfter()
        {
            BTreeDatabase db;
            BTreeCursor   cursor;
            DatabaseEntry data;
            KeyValuePair <DatabaseEntry, DatabaseEntry> pair;

            testName = "TestInsertAfter";
            SetUpTest(true);

            // Add record("key", "data") into database.
            CursorTest.GetCursorInBtreeDBWithoutEnv(testHome, testName,
                                                    out db, out cursor);
            CursorTest.AddOneByCursor(db, cursor);

            // Insert the new record("key","data1") after the record("key", "data").
            data = new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("data1"));
            cursor.Insert(data, Cursor.InsertLocation.AFTER);

            /*
             * Move the cursor to the record("key", "data") and confirm that
             * the next record is the one just inserted.
             */
            pair = new KeyValuePair <DatabaseEntry, DatabaseEntry>(
                new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("key")),
                new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("data")));
            Assert.IsTrue(cursor.Move(pair, true));
            Assert.IsTrue(cursor.MoveNext());
            Assert.AreEqual(ASCIIEncoding.ASCII.GetBytes("key"), cursor.Current.Key.Data);
            Assert.AreEqual(ASCIIEncoding.ASCII.GetBytes("data1"), cursor.Current.Value.Data);

            cursor.Close();
            db.Close();
        }
コード例 #3
0
        public void TestInsertBefore()
        {
            BTreeDatabase db;
            BTreeCursor   cursor;
            DatabaseEntry data;
            KeyValuePair <DatabaseEntry, DatabaseEntry> pair;

            testName = "TestInsertBefore";
            testHome = testFixtureHome + "/" + testName;

            Configuration.ClearDir(testHome);

            // Add record("key", "data") into database.
            CursorTest.GetCursorInBtreeDBWithoutEnv(
                testHome, testName, out db, out cursor);
            CursorTest.AddOneByCursor(db, cursor);

            // Insert the new record("key","data1") before the record("key", "data").
            data = new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("data1"));
            cursor.Insert(data, Cursor.InsertLocation.BEFORE);

            /*
             * Move the cursor to the record("key", "data") and confirm
             * that the previous record is the one just inserted.
             */
            pair = new KeyValuePair <DatabaseEntry, DatabaseEntry>(
                new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("key")),
                new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("data")));
            Assert.IsTrue(cursor.Move(pair, true));
            Assert.IsTrue(cursor.MovePrev());
            Assert.AreEqual(ASCIIEncoding.ASCII.GetBytes("key"), cursor.Current.Key.Data);
            Assert.AreEqual(ASCIIEncoding.ASCII.GetBytes("data1"), cursor.Current.Value.Data);

            cursor.Close();
            db.Close();
        }