001: /**
002:
003: * JDBM LICENSE v1.00
004:
005: *
006:
007: * Redistribution and use of this software and associated documentation
008:
009: * ("Software"), with or without modification, are permitted provided
010:
011: * that the following conditions are met:
012:
013: *
014:
015: * 1. Redistributions of source code must retain copyright
016:
017: * statements and notices. Redistributions must also contain a
018:
019: * copy of this document.
020:
021: *
022:
023: * 2. Redistributions in binary form must reproduce the
024:
025: * above copyright notice, this list of conditions and the
026:
027: * following disclaimer in the documentation and/or other
028:
029: * materials provided with the distribution.
030:
031: *
032:
033: * 3. The name "JDBM" must not be used to endorse or promote
034:
035: * products derived from this Software without prior written
036:
037: * permission of Cees de Groot. For written permission,
038:
039: * please contact cg@cdegroot.com.
040:
041: *
042:
043: * 4. Products derived from this Software may not be called "JDBM"
044:
045: * nor may "JDBM" appear in their names without prior written
046:
047: * permission of Cees de Groot.
048:
049: *
050:
051: * 5. Due credit should be given to the JDBM Project
052:
053: * (http://jdbm.sourceforge.net/).
054:
055: *
056:
057: * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
058:
059: * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
060:
061: * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
062:
063: * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
064:
065: * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
066:
067: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
068:
069: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
070:
071: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
072:
073: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
074:
075: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
076:
077: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
078:
079: * OF THE POSSIBILITY OF SUCH DAMAGE.
080:
081: *
082:
083: * Copyright 2000 (C) Cees de Groot. All Rights Reserved.
084:
085: * Contributions are Copyright (C) 2000 by their associated contributors.
086:
087: *
088:
089: */package jdbm.btree;
090:
091: import jdbm.RecordManager;
092:
093: import jdbm.RecordManagerFactory;
094:
095: import jdbm.recman.TestRecordFile;
096:
097: import jdbm.helper.StringComparator;
098:
099: import jdbm.helper.Tuple;
100:
101: import jdbm.helper.TupleBrowser;
102:
103: import java.io.IOException;
104:
105: import junit.framework.*;
106:
107: /**
108:
109: * This class contains all Unit tests for {@link Bpage}.
110:
111: *
112:
113: * @author <a href="mailto:boisvert@exoffice.com">Alex Boisvert</a>
114:
115: * @version $Id: TestBPage.java,v 1.5 2003/09/21 15:49:02 boisvert Exp $
116:
117: */
118:
119: public class TestBPage extends TestCase {
120:
121: public TestBPage(String name) {
122:
123: super (name);
124:
125: }
126:
127: public void setUp() {
128:
129: TestRecordFile.deleteTestFile();
130:
131: }
132:
133: public void tearDown() {
134:
135: TestRecordFile.deleteTestFile();
136:
137: }
138:
139: /**
140:
141: * Basic tests
142:
143: */
144:
145: public void testBasics() throws IOException {
146:
147: RecordManager recman;
148:
149: String test, test1, test2, test3;
150:
151: test = "test";
152:
153: test1 = "test1";
154:
155: test2 = "test2";
156:
157: test3 = "test3";
158:
159: recman = RecordManagerFactory
160: .createRecordManager(TestRecordFile.testFileName);
161:
162: BTree tree = BTree.createInstance(recman,
163: new StringComparator(), null, null, 32);
164:
165: BPage page = new BPage(tree, test, test);
166:
167: TupleBrowser browser;
168:
169: Tuple tuple = new Tuple();
170:
171: // test insertion
172:
173: page.insert(1, test2, test2, false);
174:
175: page.insert(1, test3, test3, false);
176:
177: page.insert(1, test1, test1, false);
178:
179: // test binary search
180:
181: browser = page.find(1, test2);
182:
183: if (browser.getNext(tuple) == false) {
184:
185: throw new IllegalStateException(
186: "Browser didn't have 'test2'");
187:
188: }
189:
190: if (!tuple.getKey().equals(test2)) {
191:
192: throw new IllegalStateException("Tuple key is not 'test2'");
193:
194: }
195:
196: if (!tuple.getValue().equals(test2)) {
197:
198: throw new IllegalStateException(
199: "Tuple value is not 'test2'");
200:
201: }
202:
203: recman.close();
204:
205: recman = null;
206:
207: }
208:
209: /**
210:
211: * Runs all tests in this class
212:
213: */
214:
215: public static void main(String[] args) {
216:
217: junit.textui.TestRunner.run(new TestSuite(TestBPage.class));
218:
219: }
220:
221: }
|