4 new revisions: Revision: d42e92ac95bf Branch: default Author: Michael Whapples Date: Thu Jul 24 11:09:58 2014 UTCLog: Change the test definition file as we will put all tests in the one fi...
http://code.google.com/p/liblouisutdml/source/detail?r=d42e92ac95bf Revision: 31e24a89f2f2 Branch: default Author: Michael Whapples Date: Fri Jul 25 18:09:51 2014 UTC Log: Some more work on translateString test http://code.google.com/p/liblouisutdml/source/detail?r=31e24a89f2f2 Revision: aa800810235d Branch: default Author: Michael Whapples Date: Fri Jul 25 18:10:29 2014 UTC Log: Merge of boxline fix http://code.google.com/p/liblouisutdml/source/detail?r=aa800810235d Revision: 7b4a270c52a0 Branch: default Author: Michael Whapples Date: Mon Jul 28 13:14:02 2014 UTC Log: completed test function for translateString http://code.google.com/p/liblouisutdml/source/detail?r=7b4a270c52a0 ============================================================================== Revision: d42e92ac95bf Branch: default Author: Michael Whapples Date: Thu Jul 24 11:09:58 2014 UTCLog: Change the test definition file as we will put all tests in the one file
http://code.google.com/p/liblouisutdml/source/detail?r=d42e92ac95bf Added: /java/testdata/tests.xml Deleted: /java/testdata/translateFileTests.xml Modified: /java/testdata/Makefile.am /java/tests/org/liblouis/SimpleTest.java ======================================= --- /dev/null +++ /java/testdata/tests.xml Thu Jul 24 11:09:58 2014 UTC @@ -0,0 +1,9 @@ +<?xml version="1.0"?> +<tests> + <translateFileTest> + <configList>nimas.cfg</configList> + <inFile>testdata/list-test.xml</inFile> + <expectedOutFile>testdata/output.utd</expectedOutFile> + <mode>0</mode> + </translateFileTest> +</tests> ======================================= --- /java/testdata/translateFileTests.xml Tue Jul 15 09:50:50 2014 UTC +++ /dev/null @@ -1,9 +0,0 @@ -<?xml version="1.0"?> -<tests> - <translateFileTest> - <configList>nimas.cfg</configList> - <inFile>testdata/list-test.xml</inFile> - <expectedOutFile>testdata/output.utd</expectedOutFile> - <mode>0</mode> - </translateFileTest> -</tests> ======================================= --- /java/testdata/Makefile.am Tue Jul 15 09:50:50 2014 UTC +++ /java/testdata/Makefile.am Thu Jul 24 11:09:58 2014 UTC @@ -1,7 +1,7 @@ SUBDIRS = liblouis \ liblouisutdml -EXTRA_DIST = translateFileTests.xml \ +EXTRA_DIST = tests.xml \ list-test.xml \ output.utd ======================================= --- /java/tests/org/liblouis/SimpleTest.java Tue Jul 15 09:22:37 2014 UTC +++ /java/tests/org/liblouis/SimpleTest.java Thu Jul 24 11:09:58 2014 UTC @@ -40,7 +40,7 @@DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
domFactory.setNamespaceAware(true); DocumentBuilder builder = domFactory.newDocumentBuilder();- Document doc = builder.parse(new File("testdata", "translateFileTests.xml").getAbsolutePath()); + Document doc = builder.parse(new File("testdata", "tests.xml").getAbsolutePath());
XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); XPathExpression testsExpr = xpath.compile("/tests/translateFileTest"); ============================================================================== Revision: 31e24a89f2f2 Branch: default Author: Michael Whapples Date: Fri Jul 25 18:09:51 2014 UTC Log: Some more work on translateString test http://code.google.com/p/liblouisutdml/source/detail?r=31e24a89f2f2 Modified: /java/src/org/liblouis/LibLouisUTDML.java /java/tests/org/liblouis/SimpleTest.java ======================================= --- /java/src/org/liblouis/LibLouisUTDML.java Tue Jul 15 09:13:24 2014 UTC +++ /java/src/org/liblouis/LibLouisUTDML.java Fri Jul 25 18:09:51 2014 UTC @@ -121,7 +121,7 @@ byte[]inbuf, byte[]outbuf, int[]outlen, String logFilename, - String settingsSrting, int mode); + String settingsString, int mode); /** the brf characters in inbuf are translated to print characters in outbuf according to the settings in the configuration files and ======================================= --- /java/tests/org/liblouis/SimpleTest.java Thu Jul 24 11:09:58 2014 UTC +++ /java/tests/org/liblouis/SimpleTest.java Fri Jul 25 18:09:51 2014 UTC @@ -13,7 +13,10 @@ import org.w3c.dom.*; import org.xml.sax.SAXException; -import org.testng.annotations.*; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; import org.testng.Assert; import org.liblouis.LibLouisUTDML; @@ -28,6 +31,10 @@ lbu.setDataPath(new File("testdata").getAbsolutePath()); lbu.setLogLevel(LogLevel.FATAL); } + @AfterMethod + public void freeLibLouisUTDML() { + lbu.free(); + }private String getTextFromNode(XPathExpression expr, Node searchNode) throws XPathExpressionException { NodeList resultList = (NodeList)expr.evaluate(searchNode, XPathConstants.NODESET);
if (resultList.getLength() == 0) { @@ -35,6 +42,18 @@ } return resultList.item(0).getNodeValue(); }+ private int getIntFromNode(XPathExpression expr, Node searchNode, int defaultValue) throws XPathExpressionException {
+ int result = defaultValue; + String resultStr = ""; + try { + if ((resultStr = getTextFromNode(expr, searchNode)) != null) { + result = Integer.parseInt(resultStr); + } + } catch (NumberFormatException e) { + result = defaultValue; + } + return result; + } @DataProvider(name="translateFileTest")public Object[][] translateFileData() throws ParserConfigurationException, SAXException, XPathExpressionException, IOException { DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
@@ -53,7 +72,6 @@NodeList testNodes = (NodeList)testsExpr.evaluate(doc, XPathConstants.NODESET);
List<Object[]> tests = new ArrayList<Object[]>(); Object[] testCase; - String modeStr; for (int i = 0; i < testNodes.getLength(); i++) { testCase = new Object[6];if ((testCase[0] = getTextFromNode(configListExpr, testNodes.item(i))) == null) {
@@ -70,14 +88,7 @@ } testCase[3] = getTextFromNode(logFileExpr, testNodes.item(i)); testCase[4] = getTextFromNode(settingsExpr, testNodes.item(i)); - testCase[5] = 0; - try {- if ((modeStr = getTextFromNode(modeExpr, testNodes.item(i))) != null) {
- testCase[5] = Integer.parseInt(modeStr); - } - } catch(Exception e) { - testCase[5] = 0; - } + testCase[5] = getIntFromNode(modeExpr, testNodes.item(i), 0); tests.add(testCase); } return tests.toArray(new Object[tests.size()][6]); @@ -111,4 +122,43 @@ Assert.fail("The actual file does not match the expected file"); } } + @Test(enabled=false) + public void testBackTranslateFile() { + Assert.fail("Not implemented yet"); + } + @DataProvider(name="translateStringTest")+ public Object[][] translateStringData() throws IOException, ParserConfigurationException, SAXException, XPathExpressionException { + DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
+ domFactory.setNamespaceAware(true); + DocumentBuilder builder = domFactory.newDocumentBuilder();+ Document doc = builder.parse(new File("testdata", "tests.xml").getAbsolutePath());
+ XPathFactory factory = XPathFactory.newInstance(); + XPath xpath = factory.newXPath();+ XPathExpression testsExpr = xpath.compile("/tests/translateStringTest");
+ XPathExpression configListExpr = xpath.compile("configList"); + XPathExpression inbufExpr = xpath.compile("inbuf"); + XPathExpression outbufExpr = xpath.compile("outbuf"); + XPathExpression logFileNameExpr = xpath.compile("logFileName"); + XPathExpression settingsExpr = xpath.compile("settings"); + XPathExpression modeExpr = xpath.compile("mode"); + List<Object[]> tests = new ArrayList<Object[]>(); + Object[] testCase;+ NodeList testNodes = (NodeList)testsExpr.evaluate(doc, XPathConstants.NODESET);
+ for (int i = 0; i < testNodes.getLength(); i++) { + testCase = new Object[7];+ if ((testCase[0] = getTextFromNode(configListExpr, testNodes.item(i))) == null) {
+ System.out.println("No configList so skipping test"); + continue; + } + testCase[4] = getTextFromNode(logFileNameExpr, testNodes.item(i)); + testCase[5] = getTextFromNode(settingsExpr, testNodes.item(i)); + testCase[6] = getIntFromNode(modeExpr, testNodes.item(i), 0); + tests.add(testCase); + } + return tests.toArray(new Object[testNodes.getLength()][7]); + } + @Test(dataProvider="translateStringTest")+ public void testTranslateString(String configList, String inbuf, String outbuf, int outlen, String logFilename, String settingsString, int mode) {
+ Assert.fail("Not implemented"); + } } ============================================================================== Revision: aa800810235d Branch: default Author: Michael Whapples Date: Fri Jul 25 18:10:29 2014 UTC Log: Merge of boxline fix http://code.google.com/p/liblouisutdml/source/detail?r=aa800810235d ============================================================================== Revision: 7b4a270c52a0 Branch: default Author: Michael Whapples Date: Mon Jul 28 13:14:02 2014 UTC Log: completed test function for translateString http://code.google.com/p/liblouisutdml/source/detail?r=7b4a270c52a0 Modified: /java/testdata/tests.xml /java/tests/org/liblouis/SimpleTest.java ======================================= --- /java/testdata/tests.xml Thu Jul 24 11:09:58 2014 UTC +++ /java/testdata/tests.xml Mon Jul 28 13:14:02 2014 UTC @@ -6,4 +6,9 @@ <expectedOutFile>testdata/output.utd</expectedOutFile> <mode>0</mode> </translateFileTest> + <translateStringTest> + <configList>nimas.cfg</configList> + <inbuf>testdata/list-test.xml</inbuf> + <outbuf>testdata/output.utd</outbuf> + </translateStringTest> </tests> ======================================= --- /java/tests/org/liblouis/SimpleTest.java Fri Jul 25 18:09:51 2014 UTC +++ /java/tests/org/liblouis/SimpleTest.java Mon Jul 28 13:14:02 2014 UTC @@ -2,8 +2,11 @@ import java.io.IOException; import java.io.File; +import java.io.FileInputStream; import java.io.FileReader; +import java.io.InputStream; import java.io.BufferedReader; +import java.io.InputStreamReader; import java.util.List; import java.util.ArrayList; @@ -17,7 +20,8 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; -import org.testng.Assert; +import static org.testng.Assert.fail; +import static org.testng.Assert.assertEquals; import org.liblouis.LibLouisUTDML; import org.liblouis.LogLevel; @@ -54,6 +58,34 @@ } return result; } + private void closeStream(InputStream s) { + try { + s.close(); + } catch (IOException e) { + // No action needed + } + } + private String readFileToString(String filename, String encoding) { + FileInputStream in = null; + BufferedReader br = null; + StringBuilder builder = new StringBuilder(); + try { + in = new FileInputStream(filename); + br = new BufferedReader(new InputStreamReader(in, encoding)); + int read, n = 1024 * 1024; + char[] buf = new char[n]; + while ((read = br.read(buf, 0, n)) != -1) { + builder.append(buf, 0, read); + } + } catch (IOException e) { + System.out.println("Problem reading data file"); + } finally { + if (in != null) { + closeStream(in); + } + } + return builder.toString(); + } @DataProvider(name="translateFileTest")public Object[][] translateFileData() throws ParserConfigurationException, SAXException, XPathExpressionException, IOException { DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
@@ -119,12 +151,12 @@ }// Check for failure, only one of actualLine or expectedLine will be null
if ((actualLine == null) ^ (expectedLine == null)) { - Assert.fail("The actual file does not match the expected file"); + fail("The actual file does not match the expected file"); } } @Test(enabled=false) public void testBackTranslateFile() { - Assert.fail("Not implemented yet"); + fail("Not implemented yet"); } @DataProvider(name="translateStringTest")public Object[][] translateStringData() throws IOException, ParserConfigurationException, SAXException, XPathExpressionException {
@@ -135,30 +167,51 @@ XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath();XPathExpression testsExpr = xpath.compile("/tests/translateStringTest");
- XPathExpression configListExpr = xpath.compile("configList"); - XPathExpression inbufExpr = xpath.compile("inbuf"); - XPathExpression outbufExpr = xpath.compile("outbuf"); - XPathExpression logFileNameExpr = xpath.compile("logFileName"); - XPathExpression settingsExpr = xpath.compile("settings"); - XPathExpression modeExpr = xpath.compile("mode"); + XPathExpression configListExpr = xpath.compile("configList/text()"); + XPathExpression inbufExpr = xpath.compile("inbuf/text()"); + XPathExpression outbufExpr = xpath.compile("outbuf/text()"); + XPathExpression logFileNameExpr = xpath.compile("logFileName/text()"); + XPathExpression settingsExpr = xpath.compile("settings/text()"); + XPathExpression modeExpr = xpath.compile("mode/text()"); List<Object[]> tests = new ArrayList<Object[]>(); Object[] testCase;NodeList testNodes = (NodeList)testsExpr.evaluate(doc, XPathConstants.NODESET);
+ String tmpStr = null; for (int i = 0; i < testNodes.getLength(); i++) { testCase = new Object[7];if ((testCase[0] = getTextFromNode(configListExpr, testNodes.item(i))) == null) {
System.out.println("No configList so skipping test"); continue; }+ if ((tmpStr = getTextFromNode(inbufExpr, testNodes.item(i))) != null) {
+ testCase[1] = readFileToString(tmpStr, "UTF8"); + } else { + System.out.println("No inbuf defined"); + continue; + }+ if ((tmpStr = getTextFromNode(outbufExpr, testNodes.item(i))) != null) {
+ testCase[2] = readFileToString(tmpStr, "UTF8"); + } else { + System.out.println("No outbuf defined"); + continue; + } + testCase[3] = ((String)testCase[2]).length() + 1; testCase[4] = getTextFromNode(logFileNameExpr, testNodes.item(i)); testCase[5] = getTextFromNode(settingsExpr, testNodes.item(i)); testCase[6] = getIntFromNode(modeExpr, testNodes.item(i), 0); tests.add(testCase); } - return tests.toArray(new Object[testNodes.getLength()][7]); + return tests.toArray(new Object[tests.size()][7]); } @Test(dataProvider="translateStringTest")- public void testTranslateString(String configList, String inbuf, String outbuf, int outlen, String logFilename, String settingsString, int mode) {
- Assert.fail("Not implemented");+ public void testTranslateString(String configList, String inbuf, String outbuf, int outlen, String logFilename, String settingsString, int mode) throws Exception {
+ byte[] actualOutbuf = new byte[outlen*4];+ byte[] inbufBytes = java.util.Arrays.copyOf(inbuf.getBytes("UTF-8"), inbuf.length()+1);
+ int[] outlenArray = new int[] { outlen };+ if (!lbu.translateString(configList, inbufBytes, actualOutbuf, outlenArray, logFilename, settingsString, mode)) { + throw new Exception("LibLouisUTDML was unable to perform the translation");
+ }+ String actualResult = new String(actualOutbuf, 0, outlenArray[0], "UTF-8");
+ assertEquals(outbuf, actualResult); } } For a description of the software, to download it and links to project pages go to http://www.abilitiessoft.com