import junit.framework.*;

public class testjcanvas extends TestCase{

	public testjcanvas(String name){
		super(name);
	}

	public static Test suite(){
		return new TestSuite(testjcanvas.class);
	}

	public static void main(String[] args){
		junit.textui.TestRunner.run(suite());
	}

	protected void setUp() {

	}

	protected void tearDown() {

	}

	public void testCallback(){
		//check simple callback function
		JCanvas c = new JCanvas("OUT.pdf");
		class P implements Pager{
			public int count = 0;
			public void run(int pageNumber){
				count++;
			}
			public void run(JCanvas canvas){}
		}
		P p = new P();
		c.setPageCallBack(p);
		c.showPage();
		assertTrue(p.count>0);
	}

	public void testFonts(){
		//print available font names
		JCanvas c = new JCanvas("OUT.pdf");
		String[] fonts = c.getAvailableFonts();
		assertTrue(fonts.length>0);
	}

	public void testDrawings(){
		String outFile = "testDrawingsOUT.pdf";
		JCanvas c = new JCanvas(outFile);
		//draw some lines
		int[][] lines = {{10, 20, 30, 40}, {50, 60, 70, 80}};
		c.lines(lines);
		//draw image from a file
		c.drawInlineImage("google.gif", 100, 100);
		//set font
		c.setFont("Helvetica-Bold",24);
		//write string
		c.drawString(10, 700, "Jcanvas at work...");
		c.showPage();
		c.save();
		assertTrue(new java.io.File(outFile).exists());
	}

	public void testCopyPages(){
		String outFile = "testCopyPagesOUT.pdf";
		JCanvas c = new JCanvas(outFile);
		//copy pdf file into current drawing
		c.copyPages("ir684.pdf");
		c.showPage();
		c.setFont("Helvetica-Bold",24);
		c.drawString(10, 700, "did it work?...");
		//save the file
		c.save();
		assertTrue(new java.io.File(outFile).exists());
	}

	public void testAnnotate(){
		String outFile = "testAnnotateOUT.pdf";
		JCanvas c = new JCanvas(outFile);
		c.annotate(outFile, "ir684.pdf", 100, 100, "Helvetica", 24, "Hello World!");
		assertTrue(new java.io.File(outFile).exists());
	}

	public void testRml2Pdf(){
		String outFile = "sampleOUT.pdf";
		JCanvas c = new JCanvas(outFile);
		c.rml_to_pdf("sample.rml");
		assertTrue(new java.io.File(outFile).exists());
	}

}

