/*******************************************************************************
 * 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.DimensionHandle;
import org.eclipse.birt.report.model.api.StyleHandle;


/**
 * Tests the native dimension script: reading values.
 */

public class NativeDimensionTest 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 );
		DimensionHandle dimensionHandle = styleHandle.getBackGroundPositionX( );
		dimensionHandle.setValue( "12 pt" ); //$NON-NLS-1$
		
		context.registerBean( "dimension", //$NON-NLS-1$
				 new Dimension( dimensionHandle ) );
	}

	/**
	 * Tests to read dimension values.
	 * 
	 * @throws Exception
	 */
	
	public void testAllValues( ) throws Exception
	{
		String script1 = "dimension.value"; //$NON-NLS-1$
		Object value1 = eval( script1 );
		assertEquals( "12pt", value1 ); //$NON-NLS-1$

		script1 = "dimension.measure"; //$NON-NLS-1$
		value1 = eval( script1 );
		assertEquals(
				 12, ( (Double) value1 ).doubleValue( ), 2 ); //$NON-NLS-1$
		
		script1 = "dimension.units"; //$NON-NLS-1$
		value1 = eval( script1 );
		assertEquals( "pt", value1 ); //$NON-NLS-1$
	}
}
