
package org.eclipse.birt.report.tests.engine.regression;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Locale;

import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.eclipse.birt.report.tests.engine.EngineCase;

/**
 * <b>Bug description</b>
 * <p>
 * Thai3.2: Thai string comparison does not work in BIRT's Map Rule.
 * <p>
 * <b>Test description</b>
 * <p>
 * This test makes sure that map rule works in Thai string comparison.
 * 
 * 
 * 
 */
public class Regression_136365 extends EngineCase
{

	private final static String INPUT = "regression_136365.rptdesign"; //$NON-NLS-1$
	private final static String OUTPUT = "regression_136365.html"; //$NON-NLS-1$

	/**
	 * @throws Exception
	 */

	public void test_Regression_136365( ) throws Exception
	{
		String in_file = getClassFolder( ) + "/" + INPUT_FOLDER + "/" + INPUT, out_file = getClassFolder( )
				+ "/" + OUTPUT_FOLDER + "/" + OUTPUT;
		IRunAndRenderTask task = null;
		IReportRunnable reportRunnable = null;
		HTMLRenderOption options = new HTMLRenderOption( );
		options.setOutputFileName( out_file );
		options.setOutputFormat( "html" );
		reportRunnable = engine.openReportDesign( in_file );
		task = engine.createRunAndRenderTask( reportRunnable );
		task.setAppContext( new HashMap( ) );
		task.setRenderOption( options );
		task.setLocale( new Locale( "th" ) );
		task.run( );
		assertTrue( task.getErrors( ).size( ) <= 0 );
		task.close( );
		checkMap( );
	}

	private void checkMap( ) throws IOException
	{
		BufferedReader reader = new BufferedReader( new FileReader(
				getClassFolder( ) + "/" + OUTPUT_FOLDER + "/" + OUTPUT ) );
		int count = 0;
		String line = null;
		while ( ( line = reader.readLine( ) ) != null )
		{
			if ( line.indexOf( "map" ) != -1 )
				count++;
		}
		assertEquals( 2, count );
	}

}
