<commit_before>/*******************************************************************************
 * 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.engine.api.impl;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.eclipse.birt.core.archive.FileArchiveReader;
import org.eclipse.birt.core.archive.FileArchiveWriter;
import org.eclipse.birt.core.archive.IDocArchiveReader;
import org.eclipse.birt.core.archive.IDocArchiveWriter;
import org.eclipse.birt.core.archive.RAFileInputStream;
import org.eclipse.birt.report.engine.EngineCase;
import org.eclipse.birt.report.engine.api.IReportDocument;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunTask;
import org.eclipse.birt.report.engine.api.ITOCTree;
import org.eclipse.birt.report.engine.api.TOCNode;
import org.eclipse.birt.report.engine.toc.TOCBuilder;
import org.eclipse.birt.report.engine.toc.TOCEntry;
import org.eclipse.birt.report.engine.toc.TOCTree;

/**
 * 
 * 
 */
public class ReportDocumentTest extends EngineCase
{

	static final String REPORT_DESIGN_RESOURCE = "org/eclipse/birt/report/engine/api/impl/test.xml";
	static final String REPORT_DESIGN_RESOURCE_TEMP = "test_temp.xml";
	static final String REPORT_DESIGN = "./test.xml";
	static final String REPORT_DOCUMENT = "./reportdocument";

	protected IReportEngine engine;

	public void setUp( )
	{
		engine = createReportEngine( );

		copyResource( REPORT_DESIGN_RESOURCE, REPORT_DESIGN );
		removeFile( REPORT_DOCUMENT );
	}

	public void tearDown( )
	{
		engine.shutdown( );
		removeFile( REPORT_DESIGN );
		removeFile( REPORT_DOCUMENT );
	}

	public void testDocument( )
	{
		createDocument( );
		checkDocument( );
	}
	
	public void testDesignStream( )
	{
		try
		{
			IReportRunnable runnable = engine
					.openReportDesign( new FileInputStream( new File(
							REPORT_DESIGN ) ) );
			IRunTask runTask = engine.createRunTask( runnable );
			runTask.run( REPORT_DOCUMENT );

			IReportDocument rptDoc = engine
					.openReportDocument( REPORT_DOCUMENT );
			InputStream inputStream = rptDoc.getDesignStream( );
			assertTrue( inputStream != null );
			int streamLength = ( (RAFileInputStream) inputStream ).available( );
			assertTrue( streamLength > 0 );
		}
		catch ( Exception ex )
		{
			ex.printStackTrace( );
			fail( );
		}
	}

	/**
	 * write empty content, the stream shouldn't be created.
	 */
	public void testEmptyDocument( )
	{
		try
		{
			IDocArchiveWriter archive = new FileArchiveWriter( REPORT_DOCUMENT );
			ReportDocumentWriter document = new ReportDocumentWriter( engine,
					archive );

			TOCTree tree = new TOCTree( );
			document.saveTOC( tree );

			HashMap bookmarks = new HashMap( );
			document.saveBookmarks( bookmarks );

			document.close( );

			IDocArchiveReader reader = new FileArchiveReader( REPORT_DOCUMENT );
			ReportDocumentReader docReader = new ReportDocumentReader( engine,
					reader );<commit_msg>fix unit test error cuasing class cast exception<commit_after>/*******************************************************************************
 * 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.engine.api.impl;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.eclipse.birt.core.archive.FileArchiveReader;
import org.eclipse.birt.core.archive.FileArchiveWriter;
import org.eclipse.birt.core.archive.IDocArchiveReader;
import org.eclipse.birt.core.archive.IDocArchiveWriter;
import org.eclipse.birt.core.archive.RAInputStream;
import org.eclipse.birt.report.engine.EngineCase;
import org.eclipse.birt.report.engine.api.IReportDocument;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunTask;
import org.eclipse.birt.report.engine.api.ITOCTree;
import org.eclipse.birt.report.engine.api.TOCNode;
import org.eclipse.birt.report.engine.toc.TOCBuilder;
import org.eclipse.birt.report.engine.toc.TOCEntry;
import org.eclipse.birt.report.engine.toc.TOCTree;

/**
 * 
 * 
 */
public class ReportDocumentTest extends EngineCase
{

	static final String REPORT_DESIGN_RESOURCE = "org/eclipse/birt/report/engine/api/impl/test.xml";
	static final String REPORT_DESIGN_RESOURCE_TEMP = "test_temp.xml";
	static final String REPORT_DESIGN = "./test.xml";
	static final String REPORT_DOCUMENT = "./reportdocument";

	protected IReportEngine engine;

	public void setUp( )
	{
		engine = createReportEngine( );

		copyResource( REPORT_DESIGN_RESOURCE, REPORT_DESIGN );
		removeFile( REPORT_DOCUMENT );
	}

	public void tearDown( )
	{
		engine.shutdown( );
		removeFile( REPORT_DESIGN );
		removeFile( REPORT_DOCUMENT );
	}

	public void testDocument( )
	{
		createDocument( );
		checkDocument( );
	}
	
	public void testDesignStream( )
	{
		try
		{
			IReportRunnable runnable = engine
					.openReportDesign( new FileInputStream( new File(
							REPORT_DESIGN ) ) );
			IRunTask runTask = engine.createRunTask( runnable );
			runTask.run( REPORT_DOCUMENT );

			IReportDocument rptDoc = engine
					.openReportDocument( REPORT_DOCUMENT );
			InputStream inputStream = rptDoc.getDesignStream( );
			assertTrue( inputStream != null );
			int streamLength = ( (RAInputStream) inputStream ).available( );
			assertTrue( streamLength > 0 );
		}
		catch ( Exception ex )
		{
			ex.printStackTrace( );
			fail( );
		}
	}

	/**
	 * write empty content, the stream shouldn't be created.
	 */
	public void testEmptyDocument( )
	{
		try
		{
			IDocArchiveWriter archive = new FileArchiveWriter( REPORT_DOCUMENT );
			ReportDocumentWriter document = new ReportDocumentWriter( engine,
					archive );

			TOCTree tree = new TOCTree( );
			document.saveTOC( tree );

			HashMap bookmarks = new HashMap( );
			document.saveBookmarks( bookmarks );

			document.close( );

			IDocArchiveReader reader = new FileArchiveReader( REPORT_DOCUMENT );
			ReportDocumentReader docReader = new ReportDocumentReader( engine,
					reader );
{'fraction_non_alphanumeric': 0.1421960454354228, 'fraction_numerical': 0.002524190155658393, 'mean_word_length': 4.554517133956386, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1700939', 'n_tokens_mistral': 2363, 'n_tokens_neox': 2120, 'n_words': 467}