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 java.io.UnsupportedEncodingException;
20
21/**
22 * Test UTF-8 charset.
23 */
24public class UTF8CharsetTest extends AbstractCharsetTestCase {
25
26	/**
27	 * Constructor for UTF8CharsetTest.
28	 *
29	 */
30	public UTF8CharsetTest(String arg0) {
31		super(arg0, "UTF-8", new String[] { "UTF8" }, true, true);
32	}
33
34	/*
35	 * (non-Javadoc)
36	 *
37	 * @see tests.api.java.nio.charset.ConcreteCharsetTest#testDecode_Normal()
38	 */
39	public void testDecode_Normal() {
40		byte[] input = new byte[] { 97, 98, -27, -76, -108, -26, -107, -113 };
41		char[] output = "ab\u5D14\u654F".toCharArray();
42		internalTestDecode(input, output);
43	}
44
45	/*
46	 * (non-Javadoc)
47	 *
48	 * @see tests.api.java.nio.charset.ConcreteCharsetTest#testEncode_Normal()
49	 */
50	public void testEncode_Normal() {
51		String input = "ab\u5D14\u654F";
52		byte[] output = new byte[] { 97, 98, -27, -76, -108, -26, -107, -113 };
53		internalTestEncode(input, output);
54	}
55
56    public void test_surrogate() throws UnsupportedEncodingException {
57        // U+1D11E: MUSICAL SYMBOL G CLEF
58        String s = new StringBuilder().appendCodePoint(0x1D11E).toString();
59        byte utf8[] = s.getBytes("UTF-8");
60        assertEquals(s, new String(utf8, 0, utf8.length, "UTF-8"));
61    }
62}
63