01: /*
02: * $Id: TestPageCursor.java,v 1.3 2003/09/21 15:49:02 boisvert Exp $
03: *
04: * Unit tests for PageCursor class
05: *
06: * Simple db toolkit
07: * Copyright (C) 1999, 2000 Cees de Groot <cg@cdegroot.com>
08: *
09: * This library is free software; you can redistribute it and/or
10: * modify it under the terms of the GNU Library General Public License
11: * as published by the Free Software Foundation; either version 2
12: * of the License, or (at your option) any later version.
13: *
14: * This library is distributed in the hope that it will be useful,
15: * but WITHOUT ANY WARRANTY; without even the implied warranty of
16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17: * Library General Public License for more details.
18: *
19: * You should have received a copy of the GNU Library General Public License
20: * along with this library; if not, write to the Free Software Foundation,
21: * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
22: */
23: package jdbm.recman;
24:
25: import junit.framework.*;
26:
27: /**
28: * This class contains all Unit tests for {@link PageCursor}.
29: */
30: public class TestPageCursor extends TestCase {
31:
32: public TestPageCursor(String name) {
33: super (name);
34: }
35:
36: public void setUp() {
37: System.out.println("TestPageCursor.setUp");
38: TestRecordFile.deleteTestFile();
39: }
40:
41: public void tearDown() {
42: System.out.println("TestPageCursor.tearDown");
43: TestRecordFile.deleteTestFile();
44: }
45:
46: /**
47: * Test constructor
48: */
49: public void testCtor() throws Exception {
50: System.out.println("TestPageCursor.testCtor");
51: RecordFile f = new RecordFile(TestRecordFile.testFileName);
52: PageManager pm = new PageManager(f);
53: PageCursor curs = new PageCursor(pm, 0);
54:
55: f.forceClose();
56: }
57:
58: /**
59: * Test basics
60: */
61: public void testBasics() throws Exception {
62: System.out.println("TestPageCursor.testBasics");
63: RecordFile f = new RecordFile(TestRecordFile.testFileName);
64: PageManager pm = new PageManager(f);
65:
66: // add a bunch of pages
67: long[] recids = new long[10];
68: for (int i = 0; i < 10; i++) {
69: recids[i] = pm.allocate(Magic.USED_PAGE);
70: }
71:
72: PageCursor curs = new PageCursor(pm, Magic.USED_PAGE);
73: for (int i = 0; i < 10; i++) {
74: assertEquals("record " + i, recids[i], curs.next());
75: }
76:
77: f.forceClose();
78: }
79:
80: /**
81: * Runs all tests in this class
82: */
83: public static void main(String[] args) {
84: junit.textui.TestRunner
85: .run(new TestSuite(TestPageCursor.class));
86: }
87: }
|