1/* 2 * Copyright (C) 2008 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.java.io; 18 19import java.io.PrintWriter; 20import java.io.StringWriter; 21import junit.framework.TestCase; 22 23public class OldAndroidPrintWriterTest extends TestCase { 24 25 public void testPrintWriter() throws Exception { 26 String str = "AbCdEfGhIjKlMnOpQrStUvWxYz"; 27 StringWriter aa = new StringWriter(); 28 PrintWriter a = new PrintWriter(aa); 29 30 try { 31 a.write(str, 0, 26); 32 a.write('X'); 33 34 assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzX", aa.toString()); 35 36 a.write("alphabravodelta", 5, 5); 37 a.append('X'); 38 assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzXbravoX", aa.toString()); 39 a.append("omega"); 40 assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzXbravoXomega", aa.toString()); 41 a.print("ZZZ"); 42 assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzXbravoXomegaZZZ", aa.toString()); 43 } finally { 44 a.close(); 45 } 46 47 StringWriter ba = new StringWriter(); 48 PrintWriter b = new PrintWriter(ba); 49 try { 50 b.print(true); 51 b.print((char) 'A'); 52 b.print("BCD".toCharArray()); 53 b.print((double) 1.2); 54 b.print((float) 3); 55 b.print((int) 4); 56 b.print((long) 5); 57 assertEquals("trueABCD1.23.045", ba.toString()); 58 b.println(); 59 b.println(true); 60 b.println((char) 'A'); 61 b.println("BCD".toCharArray()); 62 b.println((double) 1.2); 63 b.println((float) 3); 64 b.println((int) 4); 65 b.println((long) 5); 66 b.print("THE END"); 67 assertEquals("trueABCD1.23.045\ntrue\nA\nBCD\n1.2\n3.0\n4\n5\nTHE END", ba.toString()); 68 } finally { 69 b.close(); 70 } 71 } 72} 73