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

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import org.eclipse.birt.report.tests.engine.EngineCase;

/**
 * <b>Bug description</b>
 * <p>
 * TOC in data with hyperlink failed in firefox.
 * 
 * <p>
 * <b>Test description</b>
 * <p>
 * This test make sure that the hyperlink and toc is add in HTML.
 * 
 */

public class Regression_140968 extends EngineCase
{

	private final String INPUT = "regression_140968.rptdesign";
	private final String OUTPUT = "regression_140968.html";

	public void test_Regression_140968( ) throws Exception
	{
		runAndRender_HTML( INPUT, OUTPUT );
		testCompare( OUTPUT );
	}

	protected void testCompare( String fileHTMLName ) throws IOException
	{
		String fileHTMLFile = getClassFolder( ) + "/" + OUTPUT_FOLDER + "/"
				+ fileHTMLName;
		BufferedReader reader = new BufferedReader( new FileReader( new File(
				fileHTMLFile ) ) );
		String line = null;

		String hyperlinkContent = null;
		int startHyperlink = 0;
		int endHyperlink = 0;

		String tocContent = null;
		int startTOC = 0;
		int endTOC = 0;

		while ( ( line = reader.readLine( ) ) != null )
		{
			if ( line.indexOf( "<a href=" ) > 0 )
			{
				startHyperlink = line.trim( ).indexOf( "href" ) + 6;
				String hpcount = "http://www.actuate.com";
				int hyperlinkCount = hpcount.length( );
				endHyperlink = startHyperlink + hyperlinkCount;
				hyperlinkContent = line.trim( ).substring( startHyperlink,
						endHyperlink );

				assertEquals( "http://www.actuate.com", hyperlinkContent );

				if ( line.indexOf( "id=\"" ) > 0 )
				{
					startTOC = line.trim( ).indexOf( "id" ) + 4;
					String count = "__TOC_";
					int tocCount = count.length( );
					endTOC = startTOC + tocCount;
					tocContent = line.trim( ).substring( startTOC, endTOC );

					assertEquals( "__TOC_", tocContent );

				}
				else
				{
					fail( "No id, test fail." );
				}

			}
		}

	}
}
