/*******************************************************************************
 * 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.model.script;

import org.eclipse.birt.report.model.api.ColorHandle;
import org.eclipse.birt.report.model.api.StyleHandle;
import org.eclipse.birt.report.model.api.util.ColorUtil;

/**
 * Tests the native color script: transparent, value, rgb, cssValue.
 */

public class NativeColorTest extends ScriptTestCase
{

	/*
	 * (non-Javadoc)
	 * 
	 * @see junit.framework.TestCase#setUp()
	 */
	protected void setUp( ) throws Exception
	{
		super.setUp( );

		StyleHandle styleHandle = designHandle.getElementFactory( ).newStyle(
				"style1" ); //$NON-NLS-1$
		designHandle.getStyles( ).add( styleHandle );
		ColorHandle colorHandle = styleHandle.getBackgroundColor( );
		colorHandle.setValue( "red" ); //$NON-NLS-1$

		context.registerBean( "color", //$NON-NLS-1$
				new Color( colorHandle ) );
	}

	/**
	 * Tests to read color values.
	 * 
	 * @throws Exception
	 */

	public void testAllValues( ) throws Exception
	{
		String script1 = "color.transparent "; //$NON-NLS-1$
		Object value1 = eval( script1 );
		assertFalse( Boolean.getBoolean( value1.toString( ) ) ); //$NON-NLS-1$

		script1 = "color.rgb "; //$NON-NLS-1$
		value1 = eval( script1 );
		assertEquals(
				( ColorUtil.parsePredefinedColor( "red" ) ), ( (Number) value1 ).intValue( ) ); //$NON-NLS-1$

		script1 = "color.value "; //$NON-NLS-1$
		value1 = eval( script1 );
		assertEquals( "red", value1 ); //$NON-NLS-1$

		script1 = "color.cssValue "; //$NON-NLS-1$
		value1 = eval( script1 );
		assertEquals( "red", value1 ); //$NON-NLS-1$
	}
}