Home | History | Annotate | Download | only in charset
      1 /* Licensed to the Apache Software Foundation (ASF) under one or more
      2  * contributor license agreements.  See the NOTICE file distributed with
      3  * this work for additional information regarding copyright ownership.
      4  * The ASF licenses this file to You under the Apache License, Version 2.0
      5  * (the "License"); you may not use this file except in compliance with
      6  * the License.  You may obtain a copy of the License at
      7  *
      8  *     http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package tests.api.java.nio.charset;
     18 
     19 import java.nio.CharBuffer;
     20 import java.nio.charset.CharacterCodingException;
     21 import java.nio.charset.Charset;
     22 
     23 /**
     24  * TODO type def
     25  */
     26 public class UTF16LECharsetEncoderTest extends CharsetEncoderTest {
     27 
     28 	// charset for utf-16le
     29 	private static final Charset CS = Charset.forName("utf-16le");
     30 
     31 	/*
     32 	 * @see CharsetEncoderTest#setUp()
     33 	 */
     34 	protected void setUp() throws Exception {
     35 		cs = CS;
     36 		specifiedReplacement = new byte[] { -3, -1 };
     37 
     38 		unibytes = new byte[] { 32, 0, 98, 0, 117, 0, 102, 0, 102, 0, 101, 0,
     39 				114, 0 };
     40 
     41 		// unibytesWithRep = new byte[] {(byte)0xfd, (byte)0xff, 32, 0, 98, 0,
     42 		// 117, 0, 102, 0, 102, 0, 101, 0, 114 ,0};
     43 
     44 		super.setUp();
     45 	}
     46 
     47 	/*
     48 	 * @see CharsetEncoderTest#tearDown()
     49 	 */
     50 	protected void tearDown() throws Exception {
     51 		super.tearDown();
     52 	}
     53 
     54 	public void testCharsetEncoderCharsetfloatfloat() {
     55 		// this constructor is invalid for UTF16LE CharsetEncoder
     56 	}
     57 
     58 	public void testCanEncodechar() throws CharacterCodingException {
     59 		// normal case for utfCS
     60 		assertTrue(encoder.canEncode('\u0077'));
     61 		assertTrue(encoder.canEncode('\uc2a3'));
     62 
     63 		// for non-mapped char
     64 		assertTrue(encoder.canEncode('\uc2c0'));
     65 	}
     66 
     67 	public void testCanEncodeCharSequence() {
     68 		// normal case for utfCS
     69 		assertTrue(encoder.canEncode("\u0077"));
     70 		assertTrue(encoder.canEncode("\uc2a3"));
     71 		assertTrue(encoder.canEncode(""));
     72 
     73 		// for non-mapped char
     74 		assertTrue(encoder.canEncode("\uc2c0"));
     75 
     76 		// surrogate char for unicode
     77 		// 1st byte: d800-dbff
     78 		// 2nd byte: dc00-dfff
     79 		// valid surrogate pair
     80 		assertTrue(encoder.canEncode("\ud800\udc00"));
     81 		// invalid surrogate pair
     82 		assertFalse(encoder.canEncode("\ud800\udb00"));
     83 	}
     84 
     85 	public void testCanEncodeICUBug() {
     86 		assertFalse(encoder.canEncode("\ud800"));
     87 	}
     88 
     89 	public void testSpecificDefaultValue() {
     90 		assertEquals(2, encoder.averageBytesPerChar(), 0.001);
     91 		assertEquals(2, encoder.maxBytesPerChar(), 0.001);
     92 	}
     93 
     94 	public void testIsLegalReplacementEmptyArray() {
     95 		assertTrue(encoder.isLegalReplacement(new byte[0]));
     96 	}
     97 
     98 	CharBuffer getMalformedCharBuffer() {
     99 		return CharBuffer.wrap("\ud800 buffer");
    100 	}
    101 
    102 	CharBuffer getUnmapCharBuffer() {
    103 		return null;
    104 	}
    105 
    106 	CharBuffer getExceptionCharBuffer() {
    107 		return null;
    108 	}
    109 
    110 	protected byte[] getIllegalByteArray() {
    111 		return new byte[] { 0x00 };
    112 	}
    113 
    114 	protected byte[] getLegalByteArray() {
    115 		return new byte[] { (byte) 0xd8, 0x00 };
    116 	}
    117 
    118 }
    119