Change how documentParts type="file" are located
Rather than using getRequiredResource, find type="file"s the same way
models/schemas are found. This makes is so the full path to a TDML
resource isn't needed (i.e. edu/illinois/ncsa/daffodil/ is not required)
This makes it much easier to pass around TDML files that contain
type="file". This is exactly what we want to do with the pcap examples.
Unit tests needed to be updated because now a documentPart type="file"
uses the test suite to figure out where to look for files.
DFDL-597
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/tdml/TDMLRunner.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/tdml/TDMLRunner.scala
index 3e58040..d3d9747 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/tdml/TDMLRunner.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/tdml/TDMLRunner.scala
@@ -212,13 +212,13 @@
}
/**
- * Try a few possibilities to find the model/schema file.
+ * Try a few possibilities to find the model/schema/tdml resources
*
* IBM's suites have funny model paths in them. We don't have that file structure,
- * so we look for the schema/model files in the working directory, and in the same
+ * so we look for the schema/model/tdml resources in the working directory, and in the same
* directory as the tdml file, and some other variations.
*/
- def findModelFile(fileName: String): File = {
+ def findTDMLResource(fileName: String): File = {
val firstTry = new File(fileName)
if (firstTry.exists()) return firstTry
// see if it can be found relative to the tdml test file, like next to it.
@@ -228,20 +228,20 @@
if (sysFile.exists()) {
// the system Id of the tdml file was a file.
val sysPath = sysFile.getParent()
- val modelFileName = sysPath + File.separator + fileName
- log(LogLevel.Debug, "Model file name is: %s", modelFileName)
- val modelFile = new File(modelFileName)
- if (modelFile.exists()) return modelFile
+ val resourceFileName = sysPath + File.separator + fileName
+ log(LogLevel.Debug, "TDML resource name is: %s", resourceFileName)
+ val resourceFile = new File(resourceFileName)
+ if (resourceFile.exists()) return resourceFile
}
}
// try ignoring the directory part
val parts = fileName.split("/")
if (parts.length > 1) {
val filePart = parts.last
- val secondTry = findModelFile(filePart) // recursively
+ val secondTry = findTDMLResource(filePart) // recursively
if (secondTry.exists()) return secondTry;
}
- throw new FileNotFoundException("Unable to find model file " + fileName + ".")
+ throw new FileNotFoundException("Unable to find tdml resource " + fileName + ".")
}
def findModel(modelName: String): Node = {
@@ -250,7 +250,7 @@
es match {
case Some(defschema) => defschema.xsdSchema
case None => {
- val file = findModelFile(modelName)
+ val file = findTDMLResource(modelName)
val schema = {
val res = (new DaffodilXMLLoader(errorHandler)).loadFile(file)
res
@@ -927,7 +927,7 @@
}
lazy val fileDataInput = {
- val file = new File(Misc.getRequiredResource(partRawContent).toURI)
+ val file = parent.parent.parent.findTDMLResource(partRawContent)
val fis = new FileInputStream(file)
// val fileBytes = Stream.continually(fis.read()).takeWhile(_ != -1).map(_.toByte).toArray
// bytes2Bits(fileBytes)
diff --git a/daffodil-core/src/test/scala/edu/illinois/ncsa/daffodil/tdml/TestTDMLRunner.scala b/daffodil-core/src/test/scala/edu/illinois/ncsa/daffodil/tdml/TestTDMLRunner.scala
index 422ecc4..a75c53a 100644
--- a/daffodil-core/src/test/scala/edu/illinois/ncsa/daffodil/tdml/TestTDMLRunner.scala
+++ b/daffodil-core/src/test/scala/edu/illinois/ncsa/daffodil/tdml/TestTDMLRunner.scala
@@ -134,10 +134,21 @@
}
@Test def testDocWithTextFile() {
- val xml = <document>
- <documentPart type="file">/test/tdml/test.txt</documentPart>
- </document>
- val doc = new Document(xml, null)
+ val xml = <testSuite xmlns={ tdml } ID="suite identifier" suiteName="theSuiteName" description="Some Test Suite Description">
+ <parserTestCase name="test1" root="byte1" model="test-suite/ibm-contributed/dpanum.dfdl.xsd" description="Some test case description.">
+ <document>
+ <documentPart type="file">daffodil-core/src/test/resources/test/tdml/test.txt</documentPart>
+ </document>
+ <infoset>
+ <dfdlInfoset xmlns:xs={ xsd } xmlns:xsi={ xsi }>
+ <byte1 xsi:type="xs:byte">123</byte1>
+ </dfdlInfoset>
+ </infoset>
+ </parserTestCase>
+ </testSuite>
+ val ts = new DFDLTestSuite(xml)
+ val ptc = ts.parserTestCases(0)
+ val doc = ptc.document.get
val docPart = doc.documentParts(0)
val bb = java.nio.ByteBuffer.allocate(11)
doc.data.read(bb)
@@ -147,10 +158,21 @@
}
@Test def testDocWithBinaryFile() {
- val xml = <document>
- <documentPart type="file">/test/tdml/test.bin</documentPart>
- </document>
- val doc = new Document(xml, null)
+ val xml = <testSuite xmlns={ tdml } ID="suite identifier" suiteName="theSuiteName" description="Some Test Suite Description">
+ <parserTestCase name="test1" root="byte1" model="test-suite/ibm-contributed/dpanum.dfdl.xsd" description="Some test case description.">
+ <document>
+ <documentPart type="file">daffodil-core/src/test/resources/test/tdml/test.bin</documentPart>
+ </document>
+ <infoset>
+ <dfdlInfoset xmlns:xs={ xsd } xmlns:xsi={ xsi }>
+ <byte1 xsi:type="xs:byte">123</byte1>
+ </dfdlInfoset>
+ </infoset>
+ </parserTestCase>
+ </testSuite>
+ val ts = new DFDLTestSuite(xml)
+ val ptc = ts.parserTestCases(0)
+ val doc = ptc.document.get
val docPart = doc.documentParts(0)
val bb = java.nio.ByteBuffer.allocate(4)
doc.data.read(bb)
@@ -413,10 +435,10 @@
}
}
- @Test def testFindModelFile() {
+ @Test def testTDMLResource() {
lazy val res = Misc.getRequiredResource("/test-suite/ibm-contributed/dpaext1.tdml")
lazy val ts = new DFDLTestSuite(new File(res.toURI()))
- val mf = ts.findModelFile("./fvt/ext/dpa/dpaspc121_01.dfdl.xsd")
+ val mf = ts.findTDMLResource("./fvt/ext/dpa/dpaspc121_01.dfdl.xsd")
assertTrue(mf.exists())
}
diff --git a/daffodil-perf/src/test/resources/edu/illinois/ncsa/daffodil/expressions/expressions.tdml b/daffodil-perf/src/test/resources/edu/illinois/ncsa/daffodil/expressions/expressions.tdml
index c10ae54..4b4ada2 100644
--- a/daffodil-perf/src/test/resources/edu/illinois/ncsa/daffodil/expressions/expressions.tdml
+++ b/daffodil-perf/src/test/resources/edu/illinois/ncsa/daffodil/expressions/expressions.tdml
@@ -15,7 +15,7 @@
<tdml:parserTestCase name="indexLimit_29030" model="csv_mod_hidden.dfdl.xsd" root="file_29030"
description="Section 23 - Uses of Expression Language - DFDL-23-003R">
<tdml:document>
- <tdml:documentPart type="file">edu/illinois/ncsa/daffodil/expressions/csv_1.6m</tdml:documentPart>
+ <tdml:documentPart type="file">csv_1.6m</tdml:documentPart>
</tdml:document>
<tdml:infoset>
<tdml:dfdlInfoset>
@@ -41,7 +41,7 @@
<tdml:parserTestCase name="indexLimit_100" model="csv_mod_hidden.dfdl.xsd" root="file_100"
description="Section 23 - Uses of Expression Language - DFDL-23-003R">
<tdml:document>
- <tdml:documentPart type="file">edu/illinois/ncsa/daffodil/expressions/csv_1.6m</tdml:documentPart>
+ <tdml:documentPart type="file">csv_1.6m</tdml:documentPart>
</tdml:document>
<tdml:infoset>
<tdml:dfdlInfoset>
diff --git a/daffodil-perf/src/test/resources/edu/illinois/ncsa/daffodil/pcap/pcap.tdml b/daffodil-perf/src/test/resources/edu/illinois/ncsa/daffodil/pcap/pcap.tdml
index eccf651..92ff21b 100644
--- a/daffodil-perf/src/test/resources/edu/illinois/ncsa/daffodil/pcap/pcap.tdml
+++ b/daffodil-perf/src/test/resources/edu/illinois/ncsa/daffodil/pcap/pcap.tdml
@@ -13,7 +13,7 @@
<tdml:parserTestCase name="pcap_test" root="pcap"
model="pcap.dfdl.xsd" description="pcap test">
<tdml:document>
- <tdml:documentPart type="file">edu/illinois/ncsa/daffodil/pcap/dns.cap</tdml:documentPart>
+ <tdml:documentPart type="file">dns.cap</tdml:documentPart>
</tdml:document>
<tdml:infoset>
<tdml:dfdlInfoset>
@@ -32,7 +32,7 @@
<tdml:parserTestCase name="pcap_test2" root="pcap"
model="pcap.dfdl.xsd" description="pcap test">
<tdml:document>
- <tdml:documentPart type="file">edu/illinois/ncsa/daffodil/pcap/lldp.minimal.pcap</tdml:documentPart>
+ <tdml:documentPart type="file">lldp.minimal.pcap</tdml:documentPart>
</tdml:document>
<tdml:infoset>
<tdml:dfdlInfoset>
diff --git a/daffodil-perf/src/test/resources/edu/illinois/ncsa/daffodil/profiling/Profiling.tdml b/daffodil-perf/src/test/resources/edu/illinois/ncsa/daffodil/profiling/Profiling.tdml
index 018b982..4c30168 100644
--- a/daffodil-perf/src/test/resources/edu/illinois/ncsa/daffodil/profiling/Profiling.tdml
+++ b/daffodil-perf/src/test/resources/edu/illinois/ncsa/daffodil/profiling/Profiling.tdml
@@ -7,7 +7,7 @@
description="CSV-style tests">
<document>
- <documentPart type="file">edu/illinois/ncsa/daffodil/profiling/AB007.in</documentPart>
+ <documentPart type="file">AB007.in</documentPart>
</document>
<infoset>
@@ -25,7 +25,7 @@
description="CSV-style tests">
<document>
- <documentPart type="file">edu/illinois/ncsa/daffodil/profiling/AB007Simplified.in</documentPart>
+ <documentPart type="file">AB007Simplified.in</documentPart>
</document>
<infoset>
@@ -43,7 +43,7 @@
description="PCAP profiling">
<document>
- <documentPart type="file">edu/illinois/ncsa/daffodil/profiling/smbtorture.cap</documentPart>
+ <documentPart type="file">smbtorture.cap</documentPart>
</document>
<infoset>
@@ -58,4 +58,4 @@
-</testSuite>
\ No newline at end of file
+</testSuite>
diff --git a/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section00/general/general.tdml b/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section00/general/general.tdml
index 27c08a3..f651185 100644
--- a/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section00/general/general.tdml
+++ b/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section00/general/general.tdml
@@ -78,7 +78,7 @@
model="s1" description="literal nil - DFDL-13-234R">
<tdml:document>
- <tdml:documentPart type="file">edu/illinois/ncsa/daffodil/section00/general/ext_file.txt</tdml:documentPart>
+ <tdml:documentPart type="file">ext_file.txt</tdml:documentPart>
</tdml:document>
<tdml:infoset>
@@ -103,7 +103,7 @@
model="s1" description="literal nil - DFDL-13-234R">
<tdml:document>
- <tdml:documentPart type="file">edu/illinois/ncsa/daffodil/section00/general/ext_file2.txt</tdml:documentPart>
+ <tdml:documentPart type="file">ext_file2.txt</tdml:documentPart>
<tdml:documentPart type="byte">000000002CFFFFFFFF3B</tdml:documentPart>
<tdml:documentPart type="text">,400;</tdml:documentPart>
</tdml:document>
@@ -126,7 +126,7 @@
model="s1" description="literal nil - DFDL-13-234R">
<tdml:document>
- <tdml:documentPart type="file">edu/illinois/ncsa/daffodil/section00/general/file_does_not_exist.txt</tdml:documentPart>
+ <tdml:documentPart type="file">file_does_not_exist.txt</tdml:documentPart>
</tdml:document>
<tdml:errors>
diff --git a/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section23/dfdl_expressions/expressions.tdml b/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section23/dfdl_expressions/expressions.tdml
index 68d5bd5..cb74c71 100644
--- a/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section23/dfdl_expressions/expressions.tdml
+++ b/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section23/dfdl_expressions/expressions.tdml
@@ -1687,7 +1687,7 @@
<tdml:parserTestCase name="indexLimit" model="csv_mod_hidden.dfdl.xsd" root="file"
description="Section 23 - Uses of Expression Language - DFDL-23-003R">
<tdml:document>
- <tdml:documentPart type="file">edu/illinois/ncsa/daffodil/section23/dfdl_expressions/csv_1.6m</tdml:documentPart>
+ <tdml:documentPart type="file">csv_1.6m</tdml:documentPart>
</tdml:document>
<tdml:infoset>
<tdml:dfdlInfoset>