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 17e5fea3d504609d22337a5311d3ce0e72314bceeeNarayan Kamathpackage org.apache.harmony.tests.java.nio.charset; 1856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 1956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughesimport java.io.UnsupportedEncodingException; 2056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 2156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes/** 2256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * Test UTF-8 charset. 2356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes */ 2456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughespublic class UTF8CharsetTest extends AbstractCharsetTestCase { 2556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 2656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes /** 2756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * Constructor for UTF8CharsetTest. 2856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * 2956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes */ 3056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes public UTF8CharsetTest(String arg0) { 3156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes super(arg0, "UTF-8", new String[] { "UTF8" }, true, true); 3256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 3356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 3456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes /* 3556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * (non-Javadoc) 3656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * 3756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * @see tests.api.java.nio.charset.ConcreteCharsetTest#testDecode_Normal() 3856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes */ 3956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes public void testDecode_Normal() { 4056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes byte[] input = new byte[] { 97, 98, -27, -76, -108, -26, -107, -113 }; 4156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes char[] output = "ab\u5D14\u654F".toCharArray(); 4256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes internalTestDecode(input, output); 4356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 4456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 4556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes /* 4656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * (non-Javadoc) 4756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * 4856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes * @see tests.api.java.nio.charset.ConcreteCharsetTest#testEncode_Normal() 4956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes */ 5056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes public void testEncode_Normal() { 5156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes String input = "ab\u5D14\u654F"; 5256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes byte[] output = new byte[] { 97, 98, -27, -76, -108, -26, -107, -113 }; 5356ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes internalTestEncode(input, output); 5456ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 5556ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes 5656ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes public void test_surrogate() throws UnsupportedEncodingException { 5756ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes // U+1D11E: MUSICAL SYMBOL G CLEF 5856ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes String s = new StringBuilder().appendCodePoint(0x1D11E).toString(); 5956ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes byte utf8[] = s.getBytes("UTF-8"); 6056ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes assertEquals(s, new String(utf8, 0, utf8.length, "UTF-8")); 6156ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes } 6256ddb0af9c75dca21f10cd26e73b9f301c58771eElliott Hughes} 63