1/* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * 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 libcore.javax.xml.parsers; 18 19import static tests.support.Support_Xml.*; 20 21public class DocumentBuilderTest extends junit.framework.TestCase { 22 // http://code.google.com/p/android/issues/detail?id=2607 23 public void test_characterReferences() throws Exception { 24 assertEquals("aAb", firstChildTextOf(domOf("<p>aAb</p>"))); 25 assertEquals("aAb", firstChildTextOf(domOf("<p>aAb</p>"))); 26 assertEquals("a\u00fcb", firstChildTextOf(domOf("<p>aüb</p>"))); 27 assertEquals("a\u00fcb", firstChildTextOf(domOf("<p>aüb</p>"))); 28 } 29 30 // http://code.google.com/p/android/issues/detail?id=2607 31 public void test_predefinedEntities() throws Exception { 32 assertEquals("a<b", firstChildTextOf(domOf("<p>a<b</p>"))); 33 assertEquals("a>b", firstChildTextOf(domOf("<p>a>b</p>"))); 34 assertEquals("a&b", firstChildTextOf(domOf("<p>a&b</p>"))); 35 assertEquals("a'b", firstChildTextOf(domOf("<p>a'b</p>"))); 36 assertEquals("a\"b", firstChildTextOf(domOf("<p>a"b</p>"))); 37 } 38 39 // http://code.google.com/p/android/issues/detail?id=2487 40 public void test_cdata_attributes() throws Exception { 41 assertEquals("hello & world", attrOf(firstElementOf(domOf("<?xml version=\"1.0\"?><root attr=\"hello & world\" />")))); 42 try { 43 domOf("<?xml version=\"1.0\"?><root attr=\"hello <![CDATA[ some-cdata ]]> world\" />"); 44 fail("SAXParseException not thrown"); 45 } catch (org.xml.sax.SAXParseException ex) { 46 // Expected. 47 } 48 assertEquals("hello <![CDATA[ some-cdata ]]> world", attrOf(firstElementOf(domOf("<?xml version=\"1.0\"?><root attr=\"hello <![CDATA[ some-cdata ]]> world\" />")))); 49 assertEquals("hello <![CDATA[ some-cdata ]]> world", attrOf(firstElementOf(domOf("<?xml version=\"1.0\"?><root attr=\"hello <![CDATA[ some-cdata ]]> world\" />")))); 50 } 51 52 // http://code.google.com/p/android/issues/detail?id=2487 53 public void test_cdata_body() throws Exception { 54 assertEquals("hello & world", firstChildTextOf(domOf("<?xml version=\"1.0\"?><root>hello & world</root>"))); 55 assertEquals("hello some-cdata world", firstChildTextOf(domOf("<?xml version=\"1.0\"?><root>hello <![CDATA[ some-cdata ]]> world</root>"))); 56 assertEquals("hello <![CDATA[ some-cdata ]]> world", firstChildTextOf(domOf("<?xml version=\"1.0\"?><root>hello <![CDATA[ some-cdata ]]> world</root>"))); 57 try { 58 domOf("<?xml version=\"1.0\"?><root>hello <![CDATA[ some-cdata ]]> world</root>"); 59 fail("SAXParseException not thrown"); 60 } catch (org.xml.sax.SAXParseException ex) { 61 // Expected. 62 } 63 } 64} 65