13029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey/* 23029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey * Copyright (C) 2013 The Android Open Source Project 33029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey * 43029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey * Licensed under the Apache License, Version 2.0 (the "License"); 53029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey * you may not use this file except in compliance with the License. 63029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey * You may obtain a copy of the License at 73029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey * 83029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey * http://www.apache.org/licenses/LICENSE-2.0 93029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey * 103029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey * Unless required by applicable law or agreed to in writing, software 113029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey * distributed under the License is distributed on an "AS IS" BASIS, 123029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 133029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey * See the License for the specific language governing permissions and 143029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey * limitations under the License. 153029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey */ 163029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey 173029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkeypackage com.android.internal.util; 183029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey 193029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkeyimport junit.framework.TestCase; 203029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey 213029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkeyimport org.xmlpull.v1.XmlSerializer; 223029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey 233029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkeyimport java.io.ByteArrayOutputStream; 243029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey 253029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey/** 263029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey * Tests for {@link FastXmlSerializer} 273029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey */ 283029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkeypublic class FastXmlSerializerTest extends TestCase { 293029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey public void testEmptyText() throws Exception { 303029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey final ByteArrayOutputStream stream = new ByteArrayOutputStream(); 313029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey 323029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey final XmlSerializer out = new FastXmlSerializer(); 333029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey out.setOutput(stream, "utf-8"); 343029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey out.startDocument(null, true); 353029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey out.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); 363029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey 373029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey out.startTag(null, "string"); 383029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey out.attribute(null, "name", "meow"); 393029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey out.text(""); 403029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey out.endTag(null, "string"); 413029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey 423029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey out.endDocument(); 433029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey 443029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey assertEquals("<?xml version='1.0' encoding='utf-8' standalone='yes' ?>\n" 453029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey + "<string name=\"meow\"></string>", stream.toString()); 463029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey } 473029bf225cfa2c4b5b6e76303b0eba0d91c21026Jeff Sharkey} 48