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: package org.apache.tools.ant.taskdefs.cvslib;
019:
020: import junit.framework.TestCase;
021:
022: import java.util.Date;
023: import java.io.PrintWriter;
024: import java.io.OutputStreamWriter;
025: import java.io.ByteArrayOutputStream;
026: import java.io.ByteArrayInputStream;
027: import java.io.InputStream;
028:
029: import org.apache.tools.ant.util.JAXPUtils;
030: import org.xml.sax.XMLReader;
031: import org.xml.sax.InputSource;
032: import org.xml.sax.ContentHandler;
033: import org.xml.sax.SAXException;
034: import org.xml.sax.Locator;
035: import org.xml.sax.Attributes;
036:
037: /**
038: * Test for the cvslib ChangeLogWriter
039: */
040: public class ChangeLogWriterTest extends TestCase {
041:
042: private ChangeLogWriter writer = new ChangeLogWriter();
043:
044: public void testNonUTF8Characters() throws Exception {
045: CVSEntry entry = new CVSEntry(new Date(), "Se\u00f1orita",
046: "2003 < 2004 && 3 > 5");
047: entry.addFile("Medicare & review.doc", "1.1");
048: entry.addFile("El\u00e8ments de style", "1.2");
049: CVSEntry[] entries = { entry };
050:
051: ByteArrayOutputStream output = new ByteArrayOutputStream();
052: PrintWriter pwriter = new PrintWriter(new OutputStreamWriter(
053: output, "UTF-8"));
054: writer.printChangeLog(pwriter, entries);
055:
056: // make sure that the parsing does not break
057: XMLReader xmlReader = JAXPUtils.getXMLReader();
058: InputStream input = new ByteArrayInputStream(output
059: .toByteArray());
060: xmlReader.setContentHandler(new NullContentHandler());
061: xmlReader.parse(new InputSource(input));
062: }
063:
064: public static class NullContentHandler implements ContentHandler {
065: public void endDocument() throws SAXException {
066: }
067:
068: public void startDocument() throws SAXException {
069: }
070:
071: public void characters(char ch[], int start, int length)
072: throws SAXException {
073: String debug = new String(ch, start, length);
074: }
075:
076: public void ignorableWhitespace(char ch[], int start, int length)
077: throws SAXException {
078: }
079:
080: public void endPrefixMapping(String prefix) throws SAXException {
081: }
082:
083: public void skippedEntity(String name) throws SAXException {
084: }
085:
086: public void setDocumentLocator(Locator locator) {
087: }
088:
089: public void processingInstruction(String target, String data)
090: throws SAXException {
091: }
092:
093: public void startPrefixMapping(String prefix, String uri)
094: throws SAXException {
095: }
096:
097: public void endElement(String namespaceURI, String localName,
098: String qName) throws SAXException {
099: }
100:
101: public void startElement(String namespaceURI, String localName,
102: String qName, Attributes atts) throws SAXException {
103: }
104: }
105: }
|