1af74d493c2c90d9394ec75be6a9d2b9f62cb5e5fElliott Hughes/* 2af74d493c2c90d9394ec75be6a9d2b9f62cb5e5fElliott Hughes * Copyright (C) 2009 The Android Open Source Project 3f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 4af74d493c2c90d9394ec75be6a9d2b9f62cb5e5fElliott Hughes * Licensed under the Apache License, Version 2.0 (the "License"); 5af74d493c2c90d9394ec75be6a9d2b9f62cb5e5fElliott Hughes * you may not use this file except in compliance with the License. 6af74d493c2c90d9394ec75be6a9d2b9f62cb5e5fElliott Hughes * You may obtain a copy of the License at 7f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 8af74d493c2c90d9394ec75be6a9d2b9f62cb5e5fElliott Hughes * http://www.apache.org/licenses/LICENSE-2.0 9f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes * 10af74d493c2c90d9394ec75be6a9d2b9f62cb5e5fElliott Hughes * Unless required by applicable law or agreed to in writing, software 11af74d493c2c90d9394ec75be6a9d2b9f62cb5e5fElliott Hughes * distributed under the License is distributed on an "AS IS" BASIS, 12af74d493c2c90d9394ec75be6a9d2b9f62cb5e5fElliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13af74d493c2c90d9394ec75be6a9d2b9f62cb5e5fElliott Hughes * See the License for the specific language governing permissions and 14af74d493c2c90d9394ec75be6a9d2b9f62cb5e5fElliott Hughes * limitations under the License. 15af74d493c2c90d9394ec75be6a9d2b9f62cb5e5fElliott Hughes */ 16af74d493c2c90d9394ec75be6a9d2b9f62cb5e5fElliott Hughes 174557728efb66c455a52b7669a8eefef7a9e54854Jesse Wilsonpackage libcore.javax.xml.parsers; 18af74d493c2c90d9394ec75be6a9d2b9f62cb5e5fElliott Hughes 19ff42219e3ea3d712f931ae7f26af236339b5cf23Elliott Hughesimport static tests.support.Support_Xml.*; 20ff42219e3ea3d712f931ae7f26af236339b5cf23Elliott Hughes 21af74d493c2c90d9394ec75be6a9d2b9f62cb5e5fElliott Hughespublic class DocumentBuilderTest extends junit.framework.TestCase { 22af74d493c2c90d9394ec75be6a9d2b9f62cb5e5fElliott Hughes // http://code.google.com/p/android/issues/detail?id=2607 23af74d493c2c90d9394ec75be6a9d2b9f62cb5e5fElliott Hughes public void test_characterReferences() throws Exception { 246bcf32ab404c39b85d25430f6df16503ef3526cfElliott Hughes assertEquals("aAb", firstChildTextOf(domOf("<p>aAb</p>"))); 256bcf32ab404c39b85d25430f6df16503ef3526cfElliott Hughes assertEquals("aAb", firstChildTextOf(domOf("<p>aAb</p>"))); 26ee0acd736401acd37e5a3f491191a173736bcaadElliott Hughes assertEquals("a\u00fcb", firstChildTextOf(domOf("<p>aüb</p>"))); 27ee0acd736401acd37e5a3f491191a173736bcaadElliott Hughes assertEquals("a\u00fcb", firstChildTextOf(domOf("<p>aüb</p>"))); 28af74d493c2c90d9394ec75be6a9d2b9f62cb5e5fElliott Hughes } 29af74d493c2c90d9394ec75be6a9d2b9f62cb5e5fElliott Hughes 30af74d493c2c90d9394ec75be6a9d2b9f62cb5e5fElliott Hughes // http://code.google.com/p/android/issues/detail?id=2607 31af74d493c2c90d9394ec75be6a9d2b9f62cb5e5fElliott Hughes public void test_predefinedEntities() throws Exception { 326bcf32ab404c39b85d25430f6df16503ef3526cfElliott Hughes assertEquals("a<b", firstChildTextOf(domOf("<p>a<b</p>"))); 336bcf32ab404c39b85d25430f6df16503ef3526cfElliott Hughes assertEquals("a>b", firstChildTextOf(domOf("<p>a>b</p>"))); 346bcf32ab404c39b85d25430f6df16503ef3526cfElliott Hughes assertEquals("a&b", firstChildTextOf(domOf("<p>a&b</p>"))); 356bcf32ab404c39b85d25430f6df16503ef3526cfElliott Hughes assertEquals("a'b", firstChildTextOf(domOf("<p>a'b</p>"))); 366bcf32ab404c39b85d25430f6df16503ef3526cfElliott Hughes assertEquals("a\"b", firstChildTextOf(domOf("<p>a"b</p>"))); 376bcf32ab404c39b85d25430f6df16503ef3526cfElliott Hughes } 38f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes 396bcf32ab404c39b85d25430f6df16503ef3526cfElliott Hughes // http://code.google.com/p/android/issues/detail?id=2487 406bcf32ab404c39b85d25430f6df16503ef3526cfElliott Hughes public void test_cdata_attributes() throws Exception { 416bcf32ab404c39b85d25430f6df16503ef3526cfElliott Hughes assertEquals("hello & world", attrOf(firstElementOf(domOf("<?xml version=\"1.0\"?><root attr=\"hello & world\" />")))); 426bcf32ab404c39b85d25430f6df16503ef3526cfElliott Hughes try { 436bcf32ab404c39b85d25430f6df16503ef3526cfElliott Hughes domOf("<?xml version=\"1.0\"?><root attr=\"hello <![CDATA[ some-cdata ]]> world\" />"); 446bcf32ab404c39b85d25430f6df16503ef3526cfElliott Hughes fail("SAXParseException not thrown"); 456bcf32ab404c39b85d25430f6df16503ef3526cfElliott Hughes } catch (org.xml.sax.SAXParseException ex) { 466bcf32ab404c39b85d25430f6df16503ef3526cfElliott Hughes // Expected. 476bcf32ab404c39b85d25430f6df16503ef3526cfElliott Hughes } 486bcf32ab404c39b85d25430f6df16503ef3526cfElliott Hughes assertEquals("hello <![CDATA[ some-cdata ]]> world", attrOf(firstElementOf(domOf("<?xml version=\"1.0\"?><root attr=\"hello <![CDATA[ some-cdata ]]> world\" />")))); 496bcf32ab404c39b85d25430f6df16503ef3526cfElliott Hughes assertEquals("hello <![CDATA[ some-cdata ]]> world", attrOf(firstElementOf(domOf("<?xml version=\"1.0\"?><root attr=\"hello <![CDATA[ some-cdata ]]> world\" />")))); 506bcf32ab404c39b85d25430f6df16503ef3526cfElliott Hughes } 51f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes 526bcf32ab404c39b85d25430f6df16503ef3526cfElliott Hughes // http://code.google.com/p/android/issues/detail?id=2487 536bcf32ab404c39b85d25430f6df16503ef3526cfElliott Hughes public void test_cdata_body() throws Exception { 546bcf32ab404c39b85d25430f6df16503ef3526cfElliott Hughes assertEquals("hello & world", firstChildTextOf(domOf("<?xml version=\"1.0\"?><root>hello & world</root>"))); 556bcf32ab404c39b85d25430f6df16503ef3526cfElliott Hughes assertEquals("hello some-cdata world", firstChildTextOf(domOf("<?xml version=\"1.0\"?><root>hello <![CDATA[ some-cdata ]]> world</root>"))); 566bcf32ab404c39b85d25430f6df16503ef3526cfElliott Hughes assertEquals("hello <![CDATA[ some-cdata ]]> world", firstChildTextOf(domOf("<?xml version=\"1.0\"?><root>hello <![CDATA[ some-cdata ]]> world</root>"))); 576bcf32ab404c39b85d25430f6df16503ef3526cfElliott Hughes try { 586bcf32ab404c39b85d25430f6df16503ef3526cfElliott Hughes domOf("<?xml version=\"1.0\"?><root>hello <![CDATA[ some-cdata ]]> world</root>"); 596bcf32ab404c39b85d25430f6df16503ef3526cfElliott Hughes fail("SAXParseException not thrown"); 606bcf32ab404c39b85d25430f6df16503ef3526cfElliott Hughes } catch (org.xml.sax.SAXParseException ex) { 616bcf32ab404c39b85d25430f6df16503ef3526cfElliott Hughes // Expected. 626bcf32ab404c39b85d25430f6df16503ef3526cfElliott Hughes } 63af74d493c2c90d9394ec75be6a9d2b9f62cb5e5fElliott Hughes } 64af74d493c2c90d9394ec75be6a9d2b9f62cb5e5fElliott Hughes} 65