/*******************************************************************************
 * Copyright (c) 2004 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/

package org.eclipse.birt.report.engine.emitter.html;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import junit.framework.TestCase;

/**
 * Unit test for Class HTMLWriter.
 * 
 */
public class HTMLWriterTest extends TestCase
{

	/*
	 * @see TestCase#setUp()
	 */
	protected void setUp( ) throws Exception
	{
		super.setUp( );
	}

	/**
	 * Test HTMLWriter getEscapedStr()
	 * <p>
	 * Test Case:
	 * <ul>
	 * <li>getEscapedStr</li>
	 * </ul>
	 * Excepted:
	 * <ul>
	 * <li>all the corresponding characters are transformed</li>
	 * </ul>
	 * 
	 * @throws IOException
	 */
	public void testGetEscapeStr( ) throws IOException
	{
		ByteArrayOutputStream stream = new ByteArrayOutputStream( );
		HTMLWriter writer = new HTMLWriter( );

		writer.open( stream );

		writer.text( "&<>\"1 2  3   4    " ); //$NON-NLS-1$
		// flush the buffer
		writer.endWriter( );

		assertEquals(
				"&amp;&lt;&gt;\"1 2 &nbsp;3 &nbsp; 4 &nbsp; &nbsp;", //$NON-NLS-1$
				stream.toString( ).replaceAll( "[\\r|\\t|\\n]*", "" ) ); //$NON-NLS-1$ //$NON-NLS-2$

		stream.close( );
	}
	
	
	public void testWhiteSpace( ) throws IOException
	{
		ByteArrayOutputStream stream = new ByteArrayOutputStream( );
		HTMLWriter writer = new HTMLWriter( );

		writer.open( stream );

		writer.text( " a  b \n  abc  \r\n   abc cde" ); //$NON-NLS-1$
		// flush the buffer
		writer.endWriter( );

		assertEquals(
				"&nbsp;a &nbsp;b&nbsp;<br>&nbsp;&nbsp;abc &nbsp;<br>&nbsp;&nbsp; abc cde", //$NON-NLS-1$
				stream.toString( ).replaceAll( "[\\r|\\t|\\n]*", "" ) ); //$NON-NLS-1$ //$NON-NLS-2$

		stream.close( );
	}
}
