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 * test case specific activity of gb18030 charset encoder 25 */ 26 public class GBCharsetEncoderTest extends CharsetEncoderTest { 27 28 // charset for gb180303 29 private static final Charset CS = Charset.forName("gb18030"); 30 31 /* 32 * @see CharsetEncoderTest#setUp() 33 */ 34 protected void setUp() throws Exception { 35 cs = CS; 36 super.setUp(); 37 } 38 39 /* 40 * @see CharsetEncoderTest#tearDown() 41 */ 42 protected void tearDown() throws Exception { 43 super.tearDown(); 44 } 45 46 public void testCanEncodechar() { 47 // normal case for utfCS 48 assertTrue(encoder.canEncode('\u0077')); 49 assertTrue(encoder.canEncode('\uc2a3')); 50 51 // for non-mapped char 52 assertTrue(encoder.canEncode('\uc2c0')); 53 } 54 55 /* 56 * Class under test for boolean canEncode(CharSequence) 57 */ 58 public void testCanEncodeCharSequence() { 59 assertTrue(encoder.canEncode("")); 60 // surrogate char 61 62 // valid surrogate pair 63 //assertTrue(encoder.canEncode("\ud800\udc00")); 64 // invalid surrogate pair 65 assertFalse(encoder.canEncode("\ud800\udb00")); 66 assertFalse(encoder.canEncode("\ud800")); 67 } 68 69 public void testSpecificDefaultValue() { 70 // FIXME: different here! 71 assertEquals(4.0, encoder.maxBytesPerChar(), 0.0); 72 assertEquals(4.0, encoder.averageBytesPerChar(), 0.0); 73 74 // assertTrue(encoder.averageBytesPerChar() == 3); 75 // assertTrue(encoder.maxBytesPerChar() == 2); 76 77 } 78 79 CharBuffer getMalformedCharBuffer() { 80 return CharBuffer.wrap("\ud800 buffer"); 81 } 82 83 CharBuffer getUnmapCharBuffer() { 84 return null; 85 } 86 87 CharBuffer getExceptionCharBuffer() { 88 return null; 89 } 90 91 protected byte[] getIllegalByteArray() { 92 return new byte[] { (byte) 0xd8, (byte) 0x00 }; 93 } 94 95 } 96