KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > util > test > FastOutputStreamTest


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: FastOutputStreamTest.java,v 1.4 2006/10/30 21:14:55 bostic Exp $
7  */

8
9 package com.sleepycat.util.test;
10
11 import junit.framework.Test;
12 import junit.framework.TestCase;
13 import junit.framework.TestSuite;
14
15 import com.sleepycat.collections.test.DbTestUtil;
16 import com.sleepycat.util.FastOutputStream;
17
18 /**
19  * @author Mark Hayes
20  */

21 public class FastOutputStreamTest extends TestCase {
22
23     public static void main(String JavaDoc[] args)
24         throws Exception JavaDoc {
25
26         junit.framework.TestResult tr =
27             junit.textui.TestRunner.run(suite());
28         if (tr.errorCount() > 0 ||
29             tr.failureCount() > 0) {
30             System.exit(1);
31         } else {
32             System.exit(0);
33         }
34     }
35
36     public static Test suite()
37         throws Exception JavaDoc {
38
39         TestSuite suite = new TestSuite(FastOutputStreamTest.class);
40         return suite;
41     }
42
43     public FastOutputStreamTest(String JavaDoc name) {
44
45         super(name);
46     }
47
48     public void setUp() {
49
50         DbTestUtil.printTestName("FastOutputStreamTest." + getName());
51     }
52
53     public void testBufferSizing()
54         throws Exception JavaDoc {
55
56         FastOutputStream fos = new FastOutputStream();
57         assertEquals
58             (FastOutputStream.DEFAULT_INIT_SIZE, fos.getBufferBytes().length);
59
60         /* Write X+1 bytes, expect array size 2X+1 */
61         fos.write(new byte[FastOutputStream.DEFAULT_INIT_SIZE + 1]);
62         assertEquals
63             ((FastOutputStream.DEFAULT_INIT_SIZE * 2) + 1,
64              fos.getBufferBytes().length);
65
66         /* Write X+1 bytes, expect array size 4X+3 = (2(2X+1) + 1) */
67         fos.write(new byte[FastOutputStream.DEFAULT_INIT_SIZE + 1]);
68         assertEquals
69             ((FastOutputStream.DEFAULT_INIT_SIZE * 4) + 3,
70              fos.getBufferBytes().length);
71     }
72 }
73
Popular Tags