156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes/* Licensed to the Apache Software Foundation (ASF) under one or more 256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * contributor license agreements. See the NOTICE file distributed with 356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * this work for additional information regarding copyright ownership. 456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * The ASF licenses this file to You under the Apache License, Version 2.0 556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * (the "License"); you may not use this file except in compliance with 656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * the License. You may obtain a copy of the License at 756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * 856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * http://www.apache.org/licenses/LICENSE-2.0 956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * 1056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * Unless required by applicable law or agreed to in writing, software 1156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * distributed under the License is distributed on an "AS IS" BASIS, 1256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * See the License for the specific language governing permissions and 1456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * limitations under the License. 1556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes */ 1656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 1756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughespackage tests.api.java.nio.charset; 1856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 1956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughesimport java.io.UnsupportedEncodingException; 2056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughesimport java.nio.ByteBuffer; 2156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughesimport java.nio.charset.Charset; 2256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 2356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes/** 2456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * test utf-8 decoder 2556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes */ 2656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughespublic class UTFCharsetDecoderTest extends CharsetDecoderTest { 2756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 2856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes protected void setUp() throws Exception { 2956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes cs = Charset.forName("utf-8"); 3056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes super.setUp(); 3156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 3256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 3356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes /* 3456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * @see CharsetDecoderTest#tearDown() 3556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes */ 3656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes protected void tearDown() throws Exception { 3756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes super.tearDown(); 3856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 3956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 4056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes // FIXME: give up this tests 4156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes // public void testDefaultCharsPerByte(){ 4256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes // assertEquals(decoder.averageCharsPerByte(), 0.333, 0.001); 4356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes // assertEquals(decoder.maxCharsPerByte(), 2, 0.001); 4456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes // // assertEquals(1, decoder.averageCharsPerByte()); 4556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes // // assertEquals(1, decoder.maxCharsPerByte()); 4656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes // } 4756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 4856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes ByteBuffer getUnmappedByteBuffer() throws UnsupportedEncodingException { 4956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes return null; 5056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 5156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 5256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes ByteBuffer getMalformedByteBuffer() throws UnsupportedEncodingException { 5356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes ByteBuffer buffer = ByteBuffer.allocate(getByteBuffer().remaining() + 1); 5456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes buffer.put((byte) 0xd8); 5556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes buffer.put(getByteBuffer()); 5656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes buffer.flip(); 5756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes return buffer; 5856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 5956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 6056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes ByteBuffer getExceptionByteArray() throws UnsupportedEncodingException { 6156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes return null; 6256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 6356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 6456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes protected String getString() { 6556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes return " buffer \u041c\u0430\u0441\u044e\u043b\u044f \u611b"; 6656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 6756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 6856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes protected ByteBuffer getByteBuffer() { 6956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes return ByteBuffer.wrap(new byte[] { 32, 98, 117, 102, 102, 101, 114, 7056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 32, (byte) 0xd0, (byte) 0x9c, (byte) 0xd0, (byte) 0xb0, 7156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes (byte) 0xd1, (byte) 0x81, (byte) 0xd1, (byte) 0x8e, 7256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes (byte) 0xd0, (byte) 0xbb, (byte) 0xd1, (byte) 0x8f, 32, 7356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes (byte) 0xe6, (byte) 0x84, (byte) 0x9b }); 7456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 7556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 7656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes} 77