KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > db4ounit > jre11 > btree > BTreeNullKeyTestCase


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o.db4ounit.jre11.btree;
22
23 import com.db4o.*;
24 import com.db4o.db4ounit.common.btree.*;
25 import com.db4o.foundation.ArgumentNullException;
26 import com.db4o.inside.btree.*;
27
28 import db4ounit.*;
29
30
31
32 public class BTreeNullKeyTestCase extends BTreeTestCaseBase {
33
34     public void testKeysCantBeNull() {
35         final Integer JavaDoc value = null;
36         Assert.expect(ArgumentNullException.class, new CodeBlock() {
37             public void run() throws Exception JavaDoc {
38                 add(value);
39             }
40         });
41     }
42
43     public void testMultipleNullFieldIndexKeys() {
44         YapStream stream=trans().stream();
45         FieldIndexKeyHandler keyHandler = new FieldIndexKeyHandler(stream,new YInt(stream));
46         BTree btree=new BTree(trans(), 0, keyHandler, null, 7, stream.configImpl().bTreeCacheHeight());
47         
48         final Integer JavaDoc[] keys = new Integer JavaDoc[] { new Integer JavaDoc(1), null, new Integer JavaDoc(2), null, new Integer JavaDoc(3) };
49         for (int idx = 0; idx < keys.length; idx++) {
50             btree.add(trans(),new FieldIndexKey(42,keys[idx]));
51         }
52         commit();
53
54         BTreeRange range = btree.search(trans(), new FieldIndexKey(42,null));
55         Assert.areEqual(2,range.size());
56
57         BTreeNodeSearchResult lower=btree.searchLeaf(trans(), new FieldIndexKey(42,null),SearchTarget.LOWEST);
58         BTreeNodeSearchResult higher=btree.searchLeaf(trans(), new FieldIndexKey(42,null),SearchTarget.HIGHEST);
59         range=lower.createIncludingRange(higher);
60         Assert.areEqual(2,range.size());
61     }
62     
63     private void add(Object JavaDoc element) {
64         _btree.add(trans(), element);
65     }
66     
67     public static void main(String JavaDoc[] args) {
68         new BTreeNullKeyTestCase().runSolo();
69     }
70 }
71
Popular Tags