01: /*-
02: * See the file LICENSE for redistribution information.
03: *
04: * Copyright (c) 2002,2008 Oracle. All rights reserved.
05: *
06: * $Id: FastOutputStreamTest.java,v 1.4.2.2 2008/01/07 15:14:36 cwl Exp $
07: */
08:
09: 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[] args) throws Exception {
24:
25: junit.framework.TestResult tr = junit.textui.TestRunner
26: .run(suite());
27: if (tr.errorCount() > 0 || tr.failureCount() > 0) {
28: System.exit(1);
29: } else {
30: System.exit(0);
31: }
32: }
33:
34: public static Test suite() throws Exception {
35:
36: TestSuite suite = new TestSuite(FastOutputStreamTest.class);
37: return suite;
38: }
39:
40: public FastOutputStreamTest(String name) {
41:
42: super (name);
43: }
44:
45: public void setUp() {
46:
47: DbTestUtil.printTestName("FastOutputStreamTest." + getName());
48: }
49:
50: public void testBufferSizing() throws Exception {
51:
52: FastOutputStream fos = new FastOutputStream();
53: assertEquals(FastOutputStream.DEFAULT_INIT_SIZE, fos
54: .getBufferBytes().length);
55:
56: /* Write X+1 bytes, expect array size 2X+1 */
57: fos.write(new byte[FastOutputStream.DEFAULT_INIT_SIZE + 1]);
58: assertEquals((FastOutputStream.DEFAULT_INIT_SIZE * 2) + 1, fos
59: .getBufferBytes().length);
60:
61: /* Write X+1 bytes, expect array size 4X+3 = (2(2X+1) + 1) */
62: fos.write(new byte[FastOutputStream.DEFAULT_INIT_SIZE + 1]);
63: assertEquals((FastOutputStream.DEFAULT_INIT_SIZE * 4) + 3, fos
64: .getBufferBytes().length);
65: }
66: }
|