
package org.eclipse.birt.report.engine.ir;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;

import org.eclipse.birt.report.engine.EngineCase;
import org.eclipse.birt.report.engine.parser.ReportDesignWriter;
import org.eclipse.birt.report.engine.parser.ReportParser;

public class EngineIRIOTest extends EngineCase
{

	// static final String DESIGN_STREAM =
	// "org/eclipse/birt/report/engine/ir/ir_io_test.rptdesign";

	
	public void testIO() throws Exception
	{
		String[] designStreams = new String[]{"ir_io_test.rptdesign",
				"../parser/action_test.rptdesign",
				"../parser/bookmark_test.rptdesign",
				"../parser/cell_test.rptdesign",
				"../parser/highlight_test.rptdesign",
				"../parser/image_test.rptdesign",
				"../parser/map_test.rptdesign",
				"../parser/report_item_test.rptdesign",
				"../parser/text_test.rptdesign",
				"../parser/toc_test.rptdesign",
				"../parser/user_property_test.rptdesign",
				"../parser/visibility_test.rptdesign",
				"../parser/user_property_test.rptdesign"};
		
		for (int i = 0; i < designStreams.length; i++)
		{
			doTestIO(designStreams[i]);
		}
	}

	public void doTestIO( String designName ) throws Exception
	{
		// load the report design
		Report report = new ReportParser( ).parse( ".", this.getClass( )
				.getResourceAsStream( designName ) );
		assertTrue( report != null );

		// write it into the stream
		ByteArrayOutputStream out = new ByteArrayOutputStream( );
		new EngineIRWriter( ).write( out, report );
		out.close( );

		// load it from the stream
		InputStream in = new ByteArrayInputStream( out.toByteArray( ) );
		EngineIRReader reader = new EngineIRReader( );
		Report report2 = reader.read( in );
		reader.link( report2, report.getReportDesign( ) );
		// check if the report 2 equals the report 1
		ByteArrayOutputStream out1 = new ByteArrayOutputStream( );
		ByteArrayOutputStream out2 = new ByteArrayOutputStream( );

		ReportDesignWriter writer = new ReportDesignWriter( );

		writer.write( out1, report );
		writer.write( out2, report2 );

		String golden = new String( out1.toByteArray( ) );
		String value = new String( out2.toByteArray( ) );

		assertEquals( golden, value );
	}

}

@@ -492,16 +492,17 @@
  testIO(
+ 
 ) throws
@@ -555,16 +555,21 @@
 tring%5B%5D%7B
+%0A%09%09%09%09
 %22ir_io_t
@@ -589,26 +589,16 @@
 %22,%0A%09%09%09%09%22
-../parser/
 action_t
@@ -618,26 +618,16 @@
 %22,%0A%09%09%09%09%22
-../parser/
 bookmark
@@ -649,26 +649,16 @@
 %22,%0A%09%09%09%09%22
-../parser/
 cell_tes
@@ -676,26 +676,16 @@
 %22,%0A%09%09%09%09%22
-../parser/
 highligh
@@ -708,26 +708,16 @@
 %22,%0A%09%09%09%09%22
-../parser/
 image_te
@@ -736,26 +736,16 @@
 %22,%0A%09%09%09%09%22
-../parser/
 map_test
@@ -762,26 +762,16 @@
 %22,%0A%09%09%09%09%22
-../parser/
 report_i
@@ -796,26 +796,16 @@
 %22,%0A%09%09%09%09%22
-../parser/
 text_tes
@@ -823,26 +823,16 @@
 %22,%0A%09%09%09%09%22
-../parser/
 toc_test
@@ -845,34 +845,24 @@
 sign%22,%0A%09%09%09%09%22
-../parser/
 user_propert
@@ -885,26 +885,16 @@
 %22,%0A%09%09%09%09%22
-../parser/
 visibili
@@ -915,54 +915,11 @@
 ign%22
-,%0A%09%09%09%09%22../parser/user_property_test.rptdesign%22
+%0A%09%09
 %7D;%0A%09
@@ -985,16 +985,17 @@
 oTestIO(
+ 
 designSt
@@ -1002,16 +1002,20 @@
 reams%5Bi%5D
+, i 
 );%0A%09%09%7D%0A%09
@@ -1057,16 +1057,23 @@
 signName
+, int i
  ) throw
@@ -1121,111 +1121,239 @@
 n%0A%09%09
-Report report = new ReportParser( ).parse( %22.%22, this.getClass( )%0A%09%09%09%09.getResourceAsStream( designName )
+Class%3C?%3E clz = i == 0%0A%09%09%09%09? this.getClass( )%0A%09%09%09%09: org.eclipse.birt.report.engine.parser.EngineIRParserTest.class;%0A%09%09InputStream input = clz.getResourceAsStream( designName );%0A%09%09Report report = new ReportParser( ).parse( %22.%22, input
  );%0A

Fix bugzilla bug 292724 -- Errors occurs in Junit test of org.eclipse.birt.report.engine.tests in 2.5.2 daily build v20091020-0630