
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>
 * Background image of Master Page is not show
 * <p>
 * <b>Test description</b>
 * <p>
 * This test make sure that the background image is saved in image folder when generate HTML 
 * 
 */

public class Regression_142894 extends EngineCase
{
	private final static String INPUT = "regression_142894.rptdesign";
	private final static String OUTPUT = "regression_142894.html";
	
	public void test_Regression_142894( ) throws Exception
	{
		runAndRender_HTML( INPUT, OUTPUT );
		testCompare( OUTPUT );
	}
	
	protected void testCompare(String fileHTML) throws IOException
	{

		String fileHTMLFile = getClassFolder() + "/" + OUTPUT_FOLDER + "/" + fileHTML;
		BufferedReader reader = new BufferedReader( new FileReader( new File( fileHTMLFile ) ) );
		String line = null;
		String imageName = null;
		int startNumber = 0;
		int endNumber = 0;
		while ((line = reader.readLine()) != null) 
		{
			if (line.indexOf( "style=\" background-image" ) > 0 ) 
			{
				startNumber = line.trim().indexOf("url") + 13;
				endNumber = line.trim().lastIndexOf("\')");
				imageName = line.trim().substring(startNumber, endNumber);
				break;
			}
		}
		if (imageName == null)
			fail("Can not find the image name, test fail!");

		String goldenImageFile = getClassFolder() + "/" + OUTPUT_FOLDER + "/"
				+ "image" + "/" + imageName;
		File inputFile = new File(goldenImageFile);
		if (inputFile.isFile()) 
		{
			long len = inputFile.length();
			assertTrue(imageName + " is not empty and test pass.", len > 0);
			assertEquals(imageName + " file is incorrect!", 17334, len);
		} 
		else
			fail(imageName + " file is not exist, test fail!");

	}

}
