File: AbstractTestBraillo440Embosser.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 (85 lines) | stat: -rw-r--r-- 3,322 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package com_braillo;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Arrays;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;

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.PageFormat;
import org.daisy.paper.PaperCatalog;
import org.daisy.paper.RollPaperFormat;
import org.daisy.printing.FileDevice;
import org.xml.sax.SAXException;

public abstract class AbstractTestBraillo440Embosser {
	final TableCatalog tc;
	final PaperCatalog pc;
	final PageFormat fa44_2p;
	final PageFormat fa44_4p;
	final Embosser emb;

	public AbstractTestBraillo440Embosser(Embosser emb) {
		this.tc = TableCatalog.newInstance();
		this.pc = PaperCatalog.newInstance();
		this.fa44_2p = new RollPaperFormat(pc.get("org_daisy.RollPaperProvider.PaperSize.W33CM").asRollPaper(), Length.newMillimeterValue(261));
		this.fa44_4p = new RollPaperFormat(pc.get("org_daisy.RollPaperProvider.PaperSize.W33CM").asRollPaper(), Length.newMillimeterValue(522));
		this.emb = emb;

		emb.setFeature(EmbosserFeatures.TABLE, tc.get("com_braillo.BrailloTableProvider.TableType.BRAILLO_6DOT_001_00"));
	}

	public void performTest(String resource, String expPath, String expExt, int fileCount) throws IOException, ParserConfigurationException, SAXException, UnsupportedWidthException, TransformerException {
		File tmp = File.createTempFile("BrailloEmbosserTest", ".tmp");
		assertTrue("Verify that test is correctly set up", tmp.delete());
		File dir = new File(tmp.getParentFile(), tmp.getName());
		assertTrue("Verify that test is correctly set up", dir.mkdir());
		FileDevice fd = new FileDevice(dir);
		try {
			EmbosserWriter ew = emb.newEmbosserWriter(fd);
			PEFHandler.Builder builder = new PEFHandler.Builder(ew);
			builder.align(Alignment.CENTER_INNER);
			PEFConverterFacade.parsePefFile(this.getClass().getResourceAsStream(resource), builder.build());
			assertEquals("Assert that the number of generated files is correct", fileCount, dir.listFiles().length);
			FileCompare fc = new FileCompare();
			File[] res = dir.listFiles();
			Arrays.sort(res);
			int i = 1;
			for (File v : res) {
				boolean equal = fc.compareBinary(new FileInputStream(v), this.getClass().getResourceAsStream(expPath + i + expExt));
				assertTrue("Assert that the contents of the file is as expected.", equal);
				i++;
				// early clean up
				if (!v.delete()) {
					v.deleteOnExit();
				}
			}
		} finally {
			// clean up again, if an exception occurred
			for (File v : dir.listFiles()) {
				if (!v.delete()) {
					v.deleteOnExit();
				}
			}
			// remove dir
			if (!dir.delete()) {
				dir.deleteOnExit();
			}
		}
	}
}