[
https://issues.apache.org/jira/browse/DAFFODIL-2473?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17338479#comment-17338479
]
Mike Beckerle commented on DAFFODIL-2473:
-----------------------------------------
For testing, you will want to create a set of TDML tests that exercise the
shifts for each type etc.
Find the file Functions.tdml in
daffodil-test/src/test/resources/.../section23/.../Functions.tdml
This is a giant file (much too big at 13K lines), we want to strip it down to
just 1 test that you will then adapt into each of your tests.
Copy Functions.tdml, and name the copy BitFunctions.tdml, then
* delete lines 29 to 4167. The next thing in the file should be
<tdml:defineSchema name="XPathFunctions"...>
* change the name of that defineSchema from XPathFunctions to "BitFunctions"
* add the attribute elementFormDefault="unqualified" to the tdml:defineSchema
start tag.
* delete all from line 4172 to 4459. Next should be xs:element
name="round-hte".
* delete all from line 4470 to 5054.
* delete all from line 5056 to 6085 Next shoudl be a test case
xPathFunc_round_hte_01.
* delete all from line 6103 to 13922. The last line should be </tdml:testSuite>
You have a nice small TDML file now. It has a defineSchema with 1 element in
it, and one parserTestCase in it.
* add xmlns:dfdlx="http://www.ogf.org/dfdl/dfdl-1.0/extensions" namespace
prefix definition to the testSuite element near top of file around line 26.
* Rename the element "round-hte" (in the defineSchema) to "leftInt"
* Change the type of the num child element from xs:float to xs:int, and delete
the dfdl:textNumberPattern property
* Rename the precision child element to "count"
* Rename the child element named "roundval" to "value" and its type to xs:int
* Change the inputValueCalc property to call your leftShift function like
** dfdl:inputValueCalc="\{ dfdlx:leftShift( ../ex:num, ../ex:count ) }"
* Remove the "ex:" prefixes. Those are no longer needed (because we did
elementFormDefault="unqualified" above)
You now have a DFDL schema defined in the TDML file that will let you test your
leftShift for type xs:int, using little triplets of comma separated integers.
Eventually you'll go back here and add elements for unsignedLong, unsignedInt,
unsignedShort, unsignedByte, long, short, byte. But for now don't do that yet.
Next look at the one parserTestCase in the file.
* change the test name{color:#172b4d} from
{color}{color:#067d17}xPathFunc_round_hte_01 to leftShift_int_01
{color}
* change the model attribute from "XPathFunctions" to "BitFunctions"
* delete the description attribute
* change the root attribute to "leftInt
* Remove the <tdml:documentPart.. element entirely
* Change the <tdml:document> tag and its close to
<tdml:document>1,2</tdml:document>
* Change the infoset elements inside the tdml:dfdlInfoset element to:
**
{code:java}
<ex:leftShift>
<num>1</num>
<count>2</count>
<value>4</value>
</ex:leftShift>{code}
You now have a single parser test case which can be run to test left-shifting
of int.
Now we just need a Scala JUnit driver, and then we can run the tests like Junit.
Find the file TestDFDLExpressions.scala in
daffodil-test/src/test/resources/....section23/dfdl_expressions/TestDFDLExpressions.scala
Copy this file, renaming it to TestBitFunctions.scala
Edit your new TestBitFunctions.scala
* Rename the object, class, and import to TestBitFunctions
* delete all testDir definitions except testDir2
* delete all runner definitions except runner2
* in the shutdown method, delete all except the reset of runner2
* inside the class, delete all tests except the @Test def
test_xPathFunc_round_hte_01 (line 430)
* rename that test to test_leftShift_int_01, and change the string argument to
"leftShift_int_01"
You now have a scala test driver that will run your TDML test case as a Junit
test.
You can invoke this from an IDE like IntelliJ IDEA or ScalaIDE as a junit test
in the usual manner, if you have one of those setup (highly recommended. I use
IntelliJ IDEA.)
Or you can build the new daffodil with 'sbt stage' which creates a build of
daffodil you can run for testing. The daffodil command that is builds lives
under daffodil/target somewhere.
The daffodil or daffodil.bat (on windows) scripts are in
daffodil-cli/target/universal/stage/bin.
So if you run
daffodil-cli/target/universal/stage/bin/daffodil test
daffodil-test/src/test/resources/org/apache/daffodil/section23/dfdl_expressions/BitFunctions.tdml
That should run your TDML test.
You can then add new parserTestCases to cover the other integer types, shifts
by greater than the width in bits, and error situations like shifting by a
negative count.
'sbt test' will test all of daffodil, including running all your tests via
their scala JUnit test driver lines in TestBitFunctions.scala.
> Need bit-wise AND, OR, NOT, and shift operations
> ------------------------------------------------
>
> Key: DAFFODIL-2473
> URL: https://issues.apache.org/jira/browse/DAFFODIL-2473
> Project: Daffodil
> Issue Type: New Feature
> Components: Back End, Front End
> Affects Versions: 3.0.0
> Reporter: Mike Beckerle
> Priority: Critical
>
> There are a number of data representations DFDL cannot handle because it
> cannot manipulate numbers with sufficient flexibility in expressions.
> We need AND, OR, NOT, maybe XOR, and shift left, shift right, and probably
> arithmetic shift right (which does sign-extension of signed numbers). We
> should add functions for the whole set of them.
> On signed numbers with specific sizes (long, int, short, byte) these should
> behave as if the data was binary in 2s complement representation, i.e., as if
> the most-significant-bit was playing the role of 2s complement sign.
> These operations should all be undefined (Schema Def Error) on decimal,
> integer, and non-negative integer values, as well as float and double.
> Specifically, these operations are defined on long and its subtypes, and
> unsignedLong and its subtypes only.
>
>
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)