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 17package tests.api.java.nio.charset; 18 19import dalvik.annotation.TestTargetClass; 20import dalvik.annotation.TestTargets; 21import dalvik.annotation.TestTargetNew; 22import dalvik.annotation.TestLevel; 23 24import java.nio.CharBuffer; 25import java.nio.charset.CharacterCodingException; 26import java.nio.charset.Charset; 27 28@TestTargetClass(java.nio.charset.CharsetEncoder.class) 29/** 30 * test case specific activity of gb18030 charset encoder 31 */ 32public class GBCharsetEncoderTest extends AbstractCharsetEncoderTestCase { 33 34 /* 35 * @see CharsetEncoderTest#setUp() 36 */ 37 protected void setUp() throws Exception { 38 // charset for gb180303 39 cs = Charset.forName("gb18030");; 40 super.setUp(); 41 } 42 43 /* 44 * @see CharsetEncoderTest#tearDown() 45 */ 46 protected void tearDown() throws Exception { 47 super.tearDown(); 48 } 49 50 @TestTargetNew( 51 level = TestLevel.PARTIAL, 52 notes = "IllegalStateException checking missed.", 53 method = "canEncode", 54 args = {char.class} 55 ) 56 public void testCanEncodechar() throws CharacterCodingException { 57 // normal case for utfCS 58 assertTrue(encoder.canEncode('\u0077')); 59 assertTrue(encoder.canEncode('\uc2a3')); 60 61 // for non-mapped char 62 assertTrue(encoder.canEncode('\uc2c0')); 63 } 64 65 /* 66 * Class under test for boolean canEncode(CharSequence) 67 */ 68 @TestTargetNew( 69 level = TestLevel.PARTIAL, 70 notes = "IllegalStateException checking missed.", 71 method = "canEncode", 72 args = {java.lang.CharSequence.class} 73 ) 74 public void testCanEncodeCharSequence() { 75 assertTrue(encoder.canEncode("")); 76 // surrogate char 77 78 // valid surrogate pair 79 assertTrue(encoder.canEncode("\ud800\udc00")); 80 // invalid surrogate pair 81 assertFalse(encoder.canEncode("\ud800\udb00")); 82 assertFalse(encoder.canEncode("\ud800")); 83 } 84 85 @TestTargets({ 86 @TestTargetNew( 87 level = TestLevel.COMPLETE, 88 notes = "", 89 method = "averageBytesPerChar", 90 args = {} 91 ), 92 @TestTargetNew( 93 level = TestLevel.COMPLETE, 94 notes = "", 95 method = "maxBytesPerChar", 96 args = {} 97 ) 98 }) 99 public void testSpecificDefaultValue() { 100 // FIXME: different here! 101 assertEquals(4.0, encoder.maxBytesPerChar(), 0.0); 102 assertEquals(2.5, encoder.averageBytesPerChar(), 0.0); 103 104 // assertTrue(encoder.averageBytesPerChar() == 3); 105 // assertTrue(encoder.maxBytesPerChar() == 2); 106 107 } 108 109 CharBuffer getMalformedCharBuffer() { 110 return CharBuffer.wrap("\ud800 buffer"); 111 } 112 113 CharBuffer getUnmapCharBuffer() { 114 return null; 115 } 116 117 CharBuffer getExceptionCharBuffer() { 118 return null; 119 } 120 121 protected byte[] getIllegalByteArray() { 122 return new byte[] { (byte) 0xd8, (byte) 0x00 }; 123 } 124 125} 126