File: AbstractTestBraillo200Embosser.java

package info (click to toggle)
brailleutils 1.2.3-8
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 4,088 kB
  • sloc: java: 13,138; xml: 659; makefile: 29; sh: 1
file content (64 lines) | stat: -rw-r--r-- 2,721 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package com_braillo;

import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;

import org.daisy.braille.embosser.Embosser;
import org.daisy.braille.embosser.EmbosserFeatures;
import org.daisy.braille.embosser.EmbosserWriter;
import org.daisy.braille.embosser.UnsupportedWidthException;
import org.daisy.braille.facade.PEFConverterFacade;
import org.daisy.braille.pef.PEFHandler;
import org.daisy.braille.pef.PEFHandler.Alignment;
import org.daisy.braille.table.TableCatalog;
import org.daisy.braille.tools.FileCompare;
import org.daisy.braille.tools.Length;
import org.daisy.paper.PaperCatalog;
import org.daisy.paper.RollPaperFormat;
import org.daisy.paper.TractorPaperFormat;
import org.xml.sax.SAXException;

public abstract class AbstractTestBraillo200Embosser {
	final TableCatalog tc;
	final PaperCatalog pc;
	//final PageFormat a4;
	final TractorPaperFormat tractor_210mm_x_12inch;
	final RollPaperFormat roll_a4;
	final Embosser emb;

	public AbstractTestBraillo200Embosser(Embosser emb) {
		this.tc = TableCatalog.newInstance();
		this.pc = PaperCatalog.newInstance();
		//this.a4 = new SheetPaperFormat(pc.get("org_daisy.ISO216PaperProvider.PaperSize.A4").asSheetPaper(), SheetPaperFormat.Orientation.DEFAULT);
		this.tractor_210mm_x_12inch = new TractorPaperFormat(pc.get("org_daisy.TractorPaperProvider.PaperSize.W210MM_X_H12INCH").asTractorPaper());
		this.roll_a4 = new RollPaperFormat(pc.get("org_daisy.RollPaperProvider.PaperSize.W21CM").asRollPaper(), Length.newMillimeterValue(297));
		this.emb = emb;
		
		//emb.setFeature(EmbosserFeatures.PAGE_FORMAT, a4);
		emb.setFeature(EmbosserFeatures.TABLE, tc.get("com_braillo.BrailloTableProvider.TableType.BRAILLO_6DOT_001_00"));
	}
	
	public void performTest(String resource, String expPath) throws IOException, ParserConfigurationException, SAXException, UnsupportedWidthException {
		File tmp = File.createTempFile("BrailloEmbosserTest", ".tmp");
		try {
			EmbosserWriter ew = emb.newEmbosserWriter(new FileOutputStream(tmp));
			PEFHandler.Builder builder = new PEFHandler.Builder(ew);
			builder.align(Alignment.CENTER_INNER);
			PEFConverterFacade.parsePefFile(this.getClass().getResourceAsStream(resource), builder.build());
			FileCompare fc = new FileCompare();
			assertTrue("Assert that the contents of the file is as expected.",
	                fc.compareBinary(new FileInputStream(tmp), this.getClass().getResourceAsStream(expPath))
	        );
		} finally {
			if (!tmp.delete()) {
				tmp.deleteOnExit();
			}
		}
	}
}