001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.tools.ant.taskdefs;
020:
021: import java.io.ByteArrayOutputStream;
022: import java.io.PrintStream;
023:
024: import org.apache.tools.ant.BuildFileTest;
025: import org.apache.tools.ant.DefaultLogger;
026: import org.apache.tools.ant.Project;
027:
028: /**
029: */
030: public class EchoTest extends BuildFileTest {
031:
032: public EchoTest(String name) {
033: super (name);
034: }
035:
036: public void setUp() {
037: configureProject("src/etc/testcases/taskdefs/echo.xml");
038: }
039:
040: public void tearDown() {
041: executeTarget("clean");
042: }
043:
044: // Output an empty String
045: public void test1() {
046: expectLog("test1", "");
047: }
048:
049: public void testLogBlankEcho() {
050: EchoTestLogger logger = new EchoTestLogger();
051: getProject().addBuildListener(logger);
052: getProject().executeTarget("test1");
053: assertEquals(" [echo] ", logger.lastLoggedMessage);
054: }
055:
056: // Output 'OUTPUT OF ECHO'
057: public void test2() {
058: expectLog("test2", "OUTPUT OF ECHO");
059: }
060:
061: public void test3() {
062: expectLog("test3", "\n" + " This \n" + " is\n"
063: + " a \n" + " multiline\n" + " message\n"
064: + " ");
065: }
066:
067: public void testFile() throws Exception {
068: executeTarget("testFile");
069: }
070:
071: public void testAppend() throws Exception {
072: executeTarget("testAppend");
073: }
074:
075: public void testEmptyEncoding() throws Exception {
076: executeTarget("testEmptyEncoding");
077: }
078:
079: public void testUTF16Encoding() throws Exception {
080: executeTarget("testUTF16Encoding");
081: }
082:
083: public void testUTF8Encoding() throws Exception {
084: executeTarget("testUTF8Encoding");
085: }
086:
087: private class EchoTestLogger extends DefaultLogger {
088: String lastLoggedMessage;
089:
090: /**
091: *
092: */
093: public EchoTestLogger() {
094: super ();
095: this .setMessageOutputLevel(Project.MSG_DEBUG);
096: this .setOutputPrintStream(new PrintStream(
097: new ByteArrayOutputStream(256)));
098: this .setErrorPrintStream(new PrintStream(
099: new ByteArrayOutputStream(256)));
100: }
101:
102: /*
103: * @param message
104: */
105: protected void log(String message) {
106: this.lastLoggedMessage = message;
107: }
108:
109: }
110: }
|