01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: *
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18: package org.apache.harmony.rmi.server;
19:
20: import java.io.ByteArrayOutputStream;
21: import java.io.PrintStream;
22: import java.rmi.server.LogStream;
23: import junit.framework.TestCase;
24:
25: public class LogStreamTest extends TestCase {
26: /**
27: * Test for java.rmi.server.LogStream.write(int b)
28: */
29: public void testWriteI() throws Exception {
30: //regression test for HARMONY-1271
31: LogStream.log("tst").write((int) '\n');
32:
33: //regression test for HARMONY-994
34: LogStream.log("tst").write(0);
35: }
36:
37: public void testSetOutputStreamBad() throws Exception {
38: // Regression test HARMONY-1198
39: try {
40: LogStream ls = LogStream.log("proba");
41: ls.setOutputStream(null);
42: fail("Expected NPE");
43: } catch (NullPointerException e) {
44: // expected
45: }
46: }
47:
48: /**
49: * Test for java.rmi.server.LogStream.write(byte[], int, int)
50: * testing invalid offsets/lengths.
51: */
52: public void testWriteArrInvalidOffLen() throws Exception {
53: // Regression test for HARMONY-1691
54: // list of invalid offsets/lengths pairs
55: int[][] invalidPairs = new int[][] { { -2, 1 }, { 0, -6 },
56: { 6, 1 }, { 0, 6 } };
57:
58: // store original default stream for LogStream
59: PrintStream prevOut = LogStream.getDefaultStream();
60:
61: try {
62: // set empty default stream to not print garbage to System.out/err
63: LogStream.setDefaultStream(new PrintStream(
64: new ByteArrayOutputStream()));
65: LogStream ls = LogStream.log("test");
66:
67: for (int i = 0; i < invalidPairs.length; ++i) {
68: try {
69: ls.write(new byte[] { 1, 1 }, invalidPairs[i][0],
70: invalidPairs[i][1]);
71: fail("IndexOutOfBoundsException "
72: + "is not thrown when off = "
73: + invalidPairs[i][0] + ", len = "
74: + invalidPairs[i][1]);
75: } catch (IndexOutOfBoundsException e) {
76: //expected
77: }
78: }
79: } finally {
80: // restore original stream
81: LogStream.setDefaultStream(prevOut);
82: }
83: }
84: }
|