/*******************************************************************************
 * 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.tests.data.engine.regression;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import utility.EngineCase;

/**
 * <b>Bug description</b>
 * <p>
 * Visibility control over element with evaluate expressions dosen't work
 * <p>
 * <b>Test description</b>
 * <p>
 * This test cover the visibility with evaluate expressions
 * Total.count(row["ID"])==0 and Total.count(row["ID"])>0 in two text elements
 * <P>
 * Excepted result:Only one text should be displayed.
 * 
 */

public class Regression_141600 extends EngineCase {

	private final static String INPUTXML = "Client_City.xml";

	private final static String INPUT = "Regression_141600.xml"; //$NON-NLS-1$

	private final static String GOLDEN = "Regression_141600.html"; //$NON-NLS-1$

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

	protected void setUp() throws Exception {
		super.setUp();
	}

	/**
	 * @throws Exception
	 */

	public void testRegression_141600() throws Exception {
		DataInputStream instr;
		DataOutputStream outstr;

		String outputFileName = "C:\\" + INPUTXML;
		String inputFileName = getClassFolder() + "/" + INPUT_FOLDER + "/"
				+ INPUTXML;

		File inFile = new File(inputFileName);
		File outFile = new File(outputFileName);

		if (outFile.exists()) {
			System.out.println(" already exists");

		}

		if (!inFile.exists()) {
			System.out.println(" does not exist");

		}

		try {
			instr = new DataInputStream(new BufferedInputStream(
					new FileInputStream(inFile)));
			outstr = new DataOutputStream(new BufferedOutputStream(
					new FileOutputStream(outFile)));
			try {
				int data;
				while (true) {
					data = instr.readUnsignedByte();
					outstr.writeByte(data);
				}
			} catch (EOFException eof) {
				outstr.close();
				instr.close();
			}
		} catch (FileNotFoundException nfx) {
			System.out.println("Problem opening files");
		} catch (IOException iox) {
			System.out.println("IO Problems");
		}

		runAndRender_HTML(INPUT, OUTPUT);
		assertTrue(compareHTML(GOLDEN, OUTPUT));
		outFile.delete();
		assertFalse("The temp file hasn't been cleared", outFile.exists());

	}
}
