From 3677515b0f5cb32e9bc0b87f614481317dc1221c Mon Sep 17 00:00:00 2001 From: Shubham Verma Date: Tue, 9 Jan 2024 22:52:16 -0500 Subject: [PATCH 1/2] Add test cases for checkExternalDecimal() Signed-off-by: Shubham Verma --- .../arithmetics/TestValidityChecking.java | 495 +++++++++++++++++- 1 file changed, 490 insertions(+), 5 deletions(-) diff --git a/openj9.test.daa/src/test.daa/net/openj9/test/arithmetics/TestValidityChecking.java b/openj9.test.daa/src/test.daa/net/openj9/test/arithmetics/TestValidityChecking.java index 112d704..623261a 100644 --- a/openj9.test.daa/src/test.daa/net/openj9/test/arithmetics/TestValidityChecking.java +++ b/openj9.test.daa/src/test.daa/net/openj9/test/arithmetics/TestValidityChecking.java @@ -3,16 +3,16 @@ * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which accompanies this distribution -* and is available at http://eclipse.org/legal/epl-2.0 or the Apache License, -* Version 2.0 which accompanies this distribution and is available at +* and is available at http://eclipse.org/legal/epl-2.0 or the Apache License, +* Version 2.0 which accompanies this distribution and is available at * https://www.apache.org/licenses/LICENSE-2.0. -* +* * This Source Code may also be made available under the following Secondary -* Licenses when the conditions for such availability set forth in the +* Licenses when the conditions for such availability set forth in the * Eclipse Public License, v. 2.0 are satisfied: GNU General Public License, * version 2 with the GNU Classpath Exception [1] and GNU General Public License, * version 2 with the OpenJDK Assembly Exception [2]. -* +* * [1] https://www.gnu.org/software/classpath/license.html * [2] https://openjdk.org/legal/assembly-exception.html * @@ -29,6 +29,7 @@ import com.ibm.dataaccess.DecimalData; import com.ibm.dataaccess.PackedDecimal; +import com.ibm.dataaccess.ExternalDecimal; import org.junit.Test; import org.junit.Assert; @@ -748,6 +749,490 @@ public void testEmptyArrayForCheckPacked() } + @Test + public void testFailingArguments() + { + final byte[] a = new byte[] {(byte) 0x40, (byte) 0xF9, (byte) 0xF1, (byte) 0xF2, (byte) 0xC3}; + int result = ExternalDecimal.checkExternalDecimal(a, 0, 5, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 5); + Assert.assertEquals("Precision == bytesWithSpaces should result in return code of 3", 3, result); + + result = ExternalDecimal.checkExternalDecimal(a, 0, 5, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, -5); + Assert.assertEquals("bytesWithSpaces < 0 should result in return code of 3", 3, result); + + result = ExternalDecimal.checkExternalDecimal(a, 2, 5, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 1); + Assert.assertEquals("bytesWithSpaces < 0 should result in return code of 3", 2, result); + + try { + ExternalDecimal.checkExternalDecimal(a, 0, -5, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 5); + } + catch (IllegalArgumentException e) { + e.getMessage().contains("Precision must be greater than 0"); + } + + try { + ExternalDecimal.checkExternalDecimal(a, 0, 0, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 5); + } + catch (IllegalArgumentException e) { + e.getMessage().contains("Precision must be greater than 0"); + } + + try { + ExternalDecimal.checkExternalDecimal(a, -1, 3, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 5); + } + catch (IllegalArgumentException e) { + e.getMessage().contains("Offset must be non-negative integer"); + } + + try { + ExternalDecimal.checkExternalDecimal(a, 0, 3, 23, 5); + } + catch (IllegalArgumentException e) { + e.getMessage().contains("Invalid decimalType"); + } + + try { + ExternalDecimal.checkExternalDecimal(a, 0, 9, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 5); + } + catch (ArrayIndexOutOfBoundsException e) { + e.getMessage().contains("Array access index out of bounds"); + } + } + + @Test + public void testExternalDecimalWithSpace() + { + final byte[] a = new byte[] {(byte) 0x40, (byte) 0xF9, (byte) 0xF1, (byte) 0xF2, (byte) 0xC3}; + int result = ExternalDecimal.checkExternalDecimal(a, 0, 5, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 1); // rc = 2 + Assert.assertEquals("Result code for signEmbeddedTrailingPrefered(a) should have been 0", 0, result); // hardware returns 2 + + // Debugging - Start + result = ExternalDecimal.checkExternalDecimal(a, 0, 5, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 2); // rc = 0 + // it honors DSC < DC but maybe it needs it to be +1 than actual value? + // bytes with spaces set to 2 instead of 1 is considered valid external decimal + Assert.assertEquals("Result code for signEmbeddedTrailingPrefered(a) should have been 0", 0, result); // hardware returns 2 + + final byte[] a1 = new byte[] {(byte) 0xF1, (byte) 0xF9, (byte) 0xF1, (byte) 0xF2, (byte) 0xC3}; + result = ExternalDecimal.checkExternalDecimal(a, 0, 5, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 1); // rc = ? + Assert.assertEquals("Result code for signEmbeddedTrailingPrefered(a) should have been 0", 0, result); + + final byte[] a2 = new byte[] {(byte) 0x40, (byte) 0x40, (byte) 0xF1, (byte) 0xF2, (byte) 0xC3}; + result = ExternalDecimal.checkExternalDecimal(a, 0, 5, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 2); // rc = ? + Assert.assertEquals("Result code for signEmbeddedTrailingPrefered(a) should have been 0", 0, result); + // Debugging - End + + final byte[] b = new byte[] {(byte) 0x40, (byte) 0x40, (byte) 0x40, (byte) 0x40, (byte) 0x40, + (byte) 0x40, (byte) 0x40, (byte) 0xF9, (byte) 0xF1, (byte) 0xF2, + (byte) 0xC3}; + result = ExternalDecimal.checkExternalDecimal(b, 0, 11, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 7); + Assert.assertEquals("Result code for signEmbeddedTrailingPrefered(b) should have been 0", 0, result); // hardware returns 2 + + result = ExternalDecimal.checkExternalDecimal(b, 0, 11, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 5); + Assert.assertEquals("Result code for signEmbeddedTrailingPrefered(b) should have been 2", 2, result); + + final byte[] c = new byte[] {(byte) 0x40, (byte) 0xC9, (byte) 0xF1, (byte) 0xF2, (byte) 0xF3}; + result = ExternalDecimal.checkExternalDecimal(c, 0, 5, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 1); + Assert.assertEquals("Result code for signEmbeddedTrailingPrefered(c) should have been 2", 2, result); + + result = ExternalDecimal.checkExternalDecimal(c, 0, 5, DecimalData.EBCDIC_SIGN_EMBEDDED_LEADING, 0); + Assert.assertEquals("Result code for signEmbeddedTrailingPrefered(c) should have been 3", 3, result); + + final byte[] d = new byte[] {(byte) 0x40, (byte) 0x40, (byte) 0x40, (byte) 0x40, (byte) 0x40, + (byte) 0x40, (byte) 0x40, (byte) 0xC9, (byte) 0xF1, (byte) 0xF2, + (byte) 0xF3}; + result = ExternalDecimal.checkExternalDecimal(d, 0, 11, DecimalData.EBCDIC_SIGN_EMBEDDED_LEADING, 7); + Assert.assertEquals("Result code for signEmbeddedTrailingPrefered(d) should have been 3", 3, result); + + result = ExternalDecimal.checkExternalDecimal(d, 0, 11, DecimalData.EBCDIC_SIGN_EMBEDDED_LEADING, 5); + // hardware returned 2, so need to double check what is expected here + Assert.assertEquals("Result code for signEmbeddedTrailingPrefered(d) should have been 3", 3, result); + + result = ExternalDecimal.checkExternalDecimal(d, 0, 9, DecimalData.EBCDIC_SIGN_EMBEDDED_LEADING, 10); + Assert.assertEquals("Result code for signEmbeddedTrailingPrefered(d) should have been 3", 3, result); + + final byte[] e = new byte[] {(byte) 0x40, (byte) 0xF9, (byte) 0xF1, (byte) 0xF2, (byte) 0xF2, (byte) 0xF2, (byte) 0xC3}; + result = ExternalDecimal.checkExternalDecimal(e, 2, 5, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 1); + Assert.assertEquals("Result code for valid external decimal with offset > bytesWithSpaces", 0, result); + } + + @Test + public void testCheckExternalDecimalPreferredPlusSign() + { + // Preferred Plus Sign: C + final byte[] signEmbeddedTrailingPreferedPlus = new byte[] {(byte) 0xF9, (byte) 0xF1, (byte) 0xF2, (byte) 0xC3}; + int result = ExternalDecimal.checkExternalDecimal(signEmbeddedTrailingPreferedPlus, 0, 4, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 0); + Assert.assertEquals("Result code for signEmbeddedTrailingPreferedPlus should have been 0", 0, result); + + final byte[] signEmbeddedLeadingPreferedPlus = new byte[] {(byte) 0xC9, (byte) 0xF1, (byte) 0xF2, (byte) 0xF3}; + result = ExternalDecimal.checkExternalDecimal(signEmbeddedLeadingPreferedPlus, 0, 4, DecimalData.EBCDIC_SIGN_EMBEDDED_LEADING, 0); + Assert.assertEquals("Result code for signEmbeddedLeadingPreferedPlus should have been 0", 0, result); + + final byte[] signSeparateTrailingPreferedPlus = new byte[] {(byte) 0xF1, (byte) 0xF2, (byte) 0xF3, (byte) 0x4e}; + result = ExternalDecimal.checkExternalDecimal(signSeparateTrailingPreferedPlus, 0, 3, DecimalData.EBCDIC_SIGN_SEPARATE_TRAILING, 0); + Assert.assertEquals("Result code for signSeparateTrailingPreferedPlus should have been 0", 0, result); + + final byte[] signSeparateLeadingPreferedPlus = new byte[] {(byte) 0x4e, (byte) 0xF9, (byte) 0xF1, (byte) 0xF2}; + result = ExternalDecimal.checkExternalDecimal(signSeparateLeadingPreferedPlus, 0, 3, DecimalData.EBCDIC_SIGN_SEPARATE_LEADING, 0); + Assert.assertEquals("Result code for signSeparateLeadingPreferedPlus should have been 0", 0, result); + } + + @Test + public void testCheckExternalDecimal16Digits() + { + // Test max digits a vector register can hold (16) + final byte[] signEmbeddedTrailing = new byte[] {(byte) 0xF6, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, + (byte) 0xF8, (byte) 0xF1, (byte) 0xF2, (byte) 0xF9, (byte) 0xF1, + (byte) 0xF3, (byte) 0xF8, (byte) 0xF1, (byte) 0xF2, (byte) 0xF2, (byte) 0xC3}; + int result = ExternalDecimal.checkExternalDecimal(signEmbeddedTrailing, 0, 16, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 0); + Assert.assertEquals("Result code for signEmbeddedTrailing should have been 0", 0, result); + + final byte[] signEmbeddedLeading = new byte[] {(byte) 0xC6, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, + (byte) 0xF8, (byte) 0xF1, (byte) 0xF2, (byte) 0xF9, (byte) 0xF1, + (byte) 0xF3, (byte) 0xF8, (byte) 0xF1, (byte) 0xF2, (byte) 0xF2, (byte) 0xF3}; + result = ExternalDecimal.checkExternalDecimal(signEmbeddedLeading, 0, 16, DecimalData.EBCDIC_SIGN_EMBEDDED_LEADING, 0); + Assert.assertEquals("Result code for signEmbeddedLeading should have been 0", 0, result); + + final byte[] signSeparateTrailing = new byte[] {(byte) 0xF6, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, + (byte) 0xF8, (byte) 0xF1, (byte) 0xF2, (byte) 0xF9, (byte) 0xF1, + (byte) 0xF3, (byte) 0xF8, (byte) 0xF1, (byte) 0xF2, (byte) 0xF2, (byte) 0x4E}; + result = ExternalDecimal.checkExternalDecimal(signSeparateTrailing, 0, 15, DecimalData.EBCDIC_SIGN_SEPARATE_TRAILING, 0); + Assert.assertEquals("Result code for signSeparateTrailing should have been 0", 0, result); + + final byte[] signSeparateLeading = new byte[] {(byte) 0x4E, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, + (byte) 0xF8, (byte) 0xF1, (byte) 0xF2, (byte) 0xF9, (byte) 0xF1, + (byte) 0xF3, (byte) 0xF8, (byte) 0xF1, (byte) 0xF2, (byte) 0xF2, (byte) 0xF4}; + result = ExternalDecimal.checkExternalDecimal(signSeparateLeading, 0, 15, DecimalData.EBCDIC_SIGN_SEPARATE_LEADING, 0); + Assert.assertEquals("Result code for signSeparateLeading should have been 0", 0, result); + } + + @Test + public void testCheckExternalDecimal25Digits() + { + // Test low and high vector register + final byte[] signEmbeddedTrailing = new byte[] {(byte) 0xF6, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, + (byte) 0xF7, (byte) 0xF3, (byte) 0xF2, (byte) 0xF1, (byte) 0xF4, + (byte) 0xF6, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, + (byte) 0xF8, (byte) 0xF1, (byte) 0xF2, (byte) 0xF9, (byte) 0xF1, + (byte) 0xF3, (byte) 0xF8, (byte) 0xF1, (byte) 0xF2, (byte) 0xC3}; + int result = ExternalDecimal.checkExternalDecimal(signEmbeddedTrailing, 0, 25, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 0); + Assert.assertEquals("Result code for signEmbeddedTrailing should have been 0", 0, result); + + final byte[] signEmbeddedLeading = new byte[] {(byte) 0xC6, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, + (byte) 0xF7, (byte) 0xF3, (byte) 0xF2, (byte) 0xF1, (byte) 0xF4, + (byte) 0xF6, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, + (byte) 0xF8, (byte) 0xF1, (byte) 0xF2, (byte) 0xF9, (byte) 0xF1, + (byte) 0xF3, (byte) 0xF8, (byte) 0xF1, (byte) 0xF2, (byte) 0xF3}; + result = ExternalDecimal.checkExternalDecimal(signEmbeddedLeading, 0, 25, DecimalData.EBCDIC_SIGN_EMBEDDED_LEADING, 0); + Assert.assertEquals("Result code for signEmbeddedLeading should have been 0", 0, result); + + final byte[] signSeparateTrailing = new byte[] {(byte) 0xF6, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, + (byte) 0xF7, (byte) 0xF3, (byte) 0xF2, (byte) 0xF1, (byte) 0xF4, + (byte) 0xF6, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, + (byte) 0xF8, (byte) 0xF1, (byte) 0xF2, (byte) 0xF9, (byte) 0xF1, + (byte) 0xF3, (byte) 0xF8, (byte) 0xF1, (byte) 0xF2, (byte) 0x4E}; + result = ExternalDecimal.checkExternalDecimal(signSeparateTrailing, 0, 24, DecimalData.EBCDIC_SIGN_SEPARATE_TRAILING, 0); + Assert.assertEquals("Result code for signSeparateTrailing should have been 0", 0, result); + + final byte[] signSeparateLeading = new byte[] {(byte) 0x4E, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, + (byte) 0xF7, (byte) 0xF3, (byte) 0xF2, (byte) 0xF1, (byte) 0xF4, + (byte) 0xF6, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, + (byte) 0xF8, (byte) 0xF1, (byte) 0xF2, (byte) 0xF9, (byte) 0xF1, + (byte) 0xF3, (byte) 0xF8, (byte) 0xF1, (byte) 0xF2, (byte) 0xF4}; + result = ExternalDecimal.checkExternalDecimal(signSeparateLeading, 0, 24, DecimalData.EBCDIC_SIGN_SEPARATE_LEADING, 0); + Assert.assertEquals("Result code for signSeparateLeading should have been 0", 0, result); + } + + @Test + public void testCheckExternalDecimal32Digits() + { + // Test max both vector registers maxed out + final byte[] signEmbeddedTrailing = new byte[] {(byte) 0xF6, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, + (byte) 0xF5, (byte) 0xF1, (byte) 0xF8, (byte) 0xF2, (byte) 0xF4, + (byte) 0xF7, (byte) 0xF3, (byte) 0xF2, (byte) 0xF1, (byte) 0xF4, + (byte) 0xF6, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, + (byte) 0xF8, (byte) 0xF1, (byte) 0xF2, (byte) 0xF9, (byte) 0xF1, + (byte) 0xF3, (byte) 0xF8, (byte) 0xF1, (byte) 0xF3, (byte) 0xF4, + (byte) 0xC3}; + int result = ExternalDecimal.checkExternalDecimal(signEmbeddedTrailing, 0, 31, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 0); + Assert.assertEquals("Result code for signEmbeddedTrailing should have been 0", 0, result); + + final byte[] signEmbeddedLeading = new byte[] {(byte) 0xC6, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, + (byte) 0xF5, (byte) 0xF1, (byte) 0xF8, (byte) 0xF2, (byte) 0xF4, + (byte) 0xF7, (byte) 0xF3, (byte) 0xF2, (byte) 0xF1, (byte) 0xF4, + (byte) 0xF6, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, + (byte) 0xF8, (byte) 0xF1, (byte) 0xF2, (byte) 0xF9, (byte) 0xF1, + (byte) 0xF3, (byte) 0xF8, (byte) 0xF1, (byte) 0xF3, (byte) 0xF4, + (byte) 0xF3}; + result = ExternalDecimal.checkExternalDecimal(signEmbeddedLeading, 0, 31, DecimalData.EBCDIC_SIGN_EMBEDDED_LEADING, 0); + Assert.assertEquals("Result code for signEmbeddedLeading should have been 0", 0, result); + + final byte[] signSeparateTrailing = new byte[] {(byte) 0xF6, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, + (byte) 0xF5, (byte) 0xF1, (byte) 0xF8, (byte) 0xF2, (byte) 0xF4, + (byte) 0xF7, (byte) 0xF3, (byte) 0xF2, (byte) 0xF1, (byte) 0xF4, + (byte) 0xF6, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, + (byte) 0xF8, (byte) 0xF1, (byte) 0xF2, (byte) 0xF9, (byte) 0xF1, + (byte) 0xF3, (byte) 0xF8, (byte) 0xF1, (byte) 0xF3, (byte) 0xF4, + (byte) 0xF2, (byte) 0x4E}; + result = ExternalDecimal.checkExternalDecimal(signSeparateTrailing, 0,31, DecimalData.EBCDIC_SIGN_SEPARATE_TRAILING, 0); + Assert.assertEquals("Result code for signSeparateTrailing should have been 0", 0, result); + + final byte[] signSeparateLeading = new byte[] {(byte) 0x4E, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, + (byte) 0xF5, (byte) 0xF1, (byte) 0xF8, (byte) 0xF2, (byte) 0xF4, + (byte) 0xF7, (byte) 0xF3, (byte) 0xF2, (byte) 0xF1, (byte) 0xF4, + (byte) 0xF6, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, + (byte) 0xF8, (byte) 0xF1, (byte) 0xF2, (byte) 0xF9, (byte) 0xF1, + (byte) 0xF3, (byte) 0xF8, (byte) 0xF1, (byte) 0xF3, (byte) 0xF4, + (byte) 0xF2, (byte) 0xF4}; + result = ExternalDecimal.checkExternalDecimal(signSeparateLeading, 0, 31, DecimalData.EBCDIC_SIGN_SEPARATE_LEADING, 0); + Assert.assertEquals("Result code for signSeparateLeading should have been 0", 0, result); + } + + @Test + public void testCheckExternalDecimalPreferredMinusSign() + { + // Preferred Minus Sign: D + final byte[] signEmbeddedTrailingPreferedMinus = new byte[] {(byte) 0xF9, (byte) 0xF1, (byte) 0xF2, (byte) 0xD3}; + int result = ExternalDecimal.checkExternalDecimal(signEmbeddedTrailingPreferedMinus, 0, 4, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 0); + Assert.assertEquals("Result code for signEmbeddedTrailingPreferedMinus should have been 0", 0, result); + + final byte[] signEmbeddedLeadingPreferedMinus = new byte[] {(byte) 0xD9, (byte) 0xF1, (byte) 0xF2, (byte) 0xF3}; + result = ExternalDecimal.checkExternalDecimal(signEmbeddedLeadingPreferedMinus, 0, 4, DecimalData.EBCDIC_SIGN_EMBEDDED_LEADING, 0); + Assert.assertEquals("Result code for signEmbeddedLeadingPreferedMinus should have been 0", 0, result); + + final byte[] signSeparateTrailingPreferedMinus = new byte[] {(byte) 0xF1, (byte) 0xF2, (byte) 0xF3, (byte) 0x60}; + result = ExternalDecimal.checkExternalDecimal(signSeparateTrailingPreferedMinus, 0, 3, DecimalData.EBCDIC_SIGN_SEPARATE_TRAILING, 0); + Assert.assertEquals("Result code for signSeparateTrailingPreferedMinus should have been 0", 0, result); + + final byte[] signSeparateLeadingPreferedMinus = new byte[] {(byte) 0x60, (byte) 0xF9, (byte) 0xF1, (byte) 0xF2}; + result = ExternalDecimal.checkExternalDecimal(signSeparateLeadingPreferedMinus, 0, 3, DecimalData.EBCDIC_SIGN_SEPARATE_LEADING, 0); + Assert.assertEquals("Result code for signSeparateLeadingPreferedMinus should have been 0", 0, result); + + // Preferred Minus Sign: B + final byte[] signEmbeddedTrailingAlternatePlusB = new byte[] {(byte) 0xF9, (byte) 0xF1, (byte) 0xF2, (byte) 0xB3}; + result = ExternalDecimal.checkExternalDecimal(signEmbeddedTrailingAlternatePlusB, 0, 4, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 0); + Assert.assertEquals("Result code for signEmbeddedTrailingAlternatePlusB should have been 0", 0, result); + + final byte[] signEmbeddedLeadingAlternatePlusB = new byte[] {(byte) 0xB9, (byte) 0xF1, (byte) 0xF2, (byte) 0xF3}; + result = ExternalDecimal.checkExternalDecimal(signEmbeddedLeadingAlternatePlusB, 0, 4, DecimalData.EBCDIC_SIGN_EMBEDDED_LEADING, 0); + Assert.assertEquals("Result code for signEmbeddedLeadingAlternatePlusB should have been 0", 0, result); + } + + @Test + public void testCheckExternalDecimalAlternatePlusSign() + { + // Alternate Plus Sign: A + final byte[] signEmbeddedTrailingAlternatePlusA = new byte[] {(byte) 0xF9, (byte) 0xF1, (byte) 0xF2, (byte) 0xA3}; + int result = ExternalDecimal.checkExternalDecimal(signEmbeddedTrailingAlternatePlusA, 0, 4, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 0); + Assert.assertEquals("Result code for signEmbeddedTrailingAlternatePlusA should have been 0", 0, result); + + final byte[] signEmbeddedLeadingAlternatePlusA = new byte[] {(byte) 0xA9, (byte) 0xF1, (byte) 0xF2, (byte) 0xF3}; + result = ExternalDecimal.checkExternalDecimal(signEmbeddedLeadingAlternatePlusA, 0, 4, DecimalData.EBCDIC_SIGN_EMBEDDED_LEADING, 0); + Assert.assertEquals("Result code for signEmbeddedLeadingAlternatePlusA should have been 0", 0, result); + + // Alternate Plus Sign: E + final byte[] signEmbeddedTrailingAlternatePlusE = new byte[] {(byte) 0xF9, (byte) 0xF1, (byte) 0xF2, (byte) 0xE3}; + result = ExternalDecimal.checkExternalDecimal(signEmbeddedTrailingAlternatePlusE, 0, 4, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 0); + Assert.assertEquals("Result code for signEmbeddedTrailingAlternatePlusE should have been 0", 0, result); + + final byte[] signEmbeddedLeadingAlternatePlusE = new byte[] {(byte) 0xE9, (byte) 0xF1, (byte) 0xF2, (byte) 0xF3}; + result = ExternalDecimal.checkExternalDecimal(signEmbeddedLeadingAlternatePlusE, 0, 4, DecimalData.EBCDIC_SIGN_EMBEDDED_LEADING, 0); + Assert.assertEquals("Result code for signEmbeddedLeadingAlternatePlusE should have been 0", 0, result); + + // Alternate Plus Sign: F + final byte[] signEmbeddedTrailingAlternatePlusF = new byte[] {(byte) 0xF9, (byte) 0xF1, (byte) 0xF2, (byte) 0xF3}; + result = ExternalDecimal.checkExternalDecimal(signEmbeddedTrailingAlternatePlusF, 0, 4, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 0); + Assert.assertEquals("Result code for signEmbeddedTrailingAlternatePlusF should have been 0", 0, result); + + final byte[] signEmbeddedLeadingAlternatePlusF = new byte[] {(byte) 0xF9, (byte) 0xF1, (byte) 0xF2, (byte) 0xF3}; + result = ExternalDecimal.checkExternalDecimal(signEmbeddedLeadingAlternatePlusF, 0, 4, DecimalData.EBCDIC_SIGN_EMBEDDED_LEADING, 0); + Assert.assertEquals("Result code for signEmbeddedLeadingAlternatePlusF should have been 0", 0, result); + } + + @Test + public void testCheckExternalDecimalInvalidDigits() + { + // Sign embedded trailing + final byte[] signEmbeddedTrailingInvalidDigitZone = new byte[] {(byte) 0xA9, (byte) 0xF1, (byte) 0xF2, (byte) 0xB3}; + int result = ExternalDecimal.checkExternalDecimal(signEmbeddedTrailingInvalidDigitZone, 0, 4, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 0); + Assert.assertEquals("Result code for signEmbeddedTrailingInvalidDigitZone should have been 2", 2, result); + + final byte[] signEmbeddedTrailingInvalidDigitValue = new byte[] {(byte) 0xF9, (byte) 0xFD, (byte) 0xF2, (byte) 0xB3}; + result = ExternalDecimal.checkExternalDecimal(signEmbeddedTrailingInvalidDigitValue, 0, 4, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 0); + Assert.assertEquals("Result code for signEmbeddedTrailingInvalidDigitValue should have been 2", 2, result); + + // Sign embedded leading + final byte[] signEmbeddedLeadingInvalidDigitZone = new byte[] {(byte) 0xB9, (byte) 0xA1, (byte) 0xF2, (byte) 0xF3}; + result = ExternalDecimal.checkExternalDecimal(signEmbeddedLeadingInvalidDigitZone, 0, 4, DecimalData.EBCDIC_SIGN_EMBEDDED_LEADING, 0); + Assert.assertEquals("Result code for signEmbeddedLeadingInvalidDigitZone should have been 2", 2, result); + + final byte[] signEmbeddedLeadingInvalidDigitValue = new byte[] {(byte) 0xB9, (byte) 0xFD, (byte) 0xF2, (byte) 0xF3}; + result = ExternalDecimal.checkExternalDecimal(signEmbeddedLeadingInvalidDigitValue, 0, 4, DecimalData.EBCDIC_SIGN_EMBEDDED_LEADING, 0); + Assert.assertEquals("Result code for signEmbeddedLeadingInvalidDigitValue should have been 2", 2, result); + + // Sign separate trailing + final byte[] signSeparateTrailingInvalidDigitZone = new byte[] {(byte) 0xF9, (byte) 0xF1, (byte) 0xA2, (byte) 0xF3, (byte) 0x4E}; + result = ExternalDecimal.checkExternalDecimal(signSeparateTrailingInvalidDigitZone, 0, 4, DecimalData.EBCDIC_SIGN_SEPARATE_TRAILING, 0); + Assert.assertEquals("Result code for signSeparateTrailingInvalidDigitZone should have been 2", 2, result); + + final byte[] signSeparateTrailingInvalidDigitValue = new byte[] {(byte) 0xF9, (byte) 0xF1, (byte) 0xF2, (byte) 0xFD, (byte) 0x4E}; + result = ExternalDecimal.checkExternalDecimal(signSeparateTrailingInvalidDigitValue, 0, 4, DecimalData.EBCDIC_SIGN_SEPARATE_TRAILING, 0); + Assert.assertEquals("Result code for signSeparateTrailingInvalidDigitValue should have been 2", 2, result); + + // Sign separate leading + final byte[] signSeparateLeadingInvalidDigitZone = new byte[] {(byte) 0x4E, (byte) 0xF9, (byte) 0xF1, (byte) 0xA2, (byte) 0xF3}; + result = ExternalDecimal.checkExternalDecimal(signSeparateLeadingInvalidDigitZone, 0, 4, DecimalData.EBCDIC_SIGN_SEPARATE_LEADING, 0); + Assert.assertEquals("Result code for signSeparateLeadingInvalidDigitZone should have been 2", 2, result); + + final byte[] signSeparateLeadingInvalidDigitValue = new byte[] {(byte) 0x4e, (byte) 0xF9, (byte) 0xF1, (byte) 0xFD, (byte) 0xF3}; + result = ExternalDecimal.checkExternalDecimal(signSeparateLeadingInvalidDigitValue, 0, 4, DecimalData.EBCDIC_SIGN_SEPARATE_LEADING, 0); + Assert.assertEquals("Result code for signSeparateLeadingInvalidDigitValue should have been 2", 2, result); + } + + @Test + public void testCheckExternalDecimalInvalidSignDigits() + { + final byte[] signEmbeddedTrailingInvalidSignDigit = new byte[] {(byte) 0xF9, (byte) 0xF1, (byte) 0xF2, (byte) 0x23}; + int result = ExternalDecimal.checkExternalDecimal(signEmbeddedTrailingInvalidSignDigit, 0, 4, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 0); + Assert.assertEquals("Result code for signEmbeddedTrailingInvalidSignDigit should have been 1", 1, result); + + final byte[] signEmbeddedLeadingInvalidSignDigit = new byte[] {(byte) 0x49, (byte) 0xF2, (byte) 0xF2, (byte) 0xF3}; + result = ExternalDecimal.checkExternalDecimal(signEmbeddedLeadingInvalidSignDigit, 0, 4, DecimalData.EBCDIC_SIGN_EMBEDDED_LEADING, 0); + Assert.assertEquals("Result code for signEmbeddedLeadingInvalidSignDigit should have been 1", 1, result); + + final byte[] signSeparateTrailingInvalidSignDigit = new byte[] {(byte) 0xF9, (byte) 0xF1, (byte) 0xF2, (byte) 0xF1, (byte) 0x43}; + result = ExternalDecimal.checkExternalDecimal(signSeparateTrailingInvalidSignDigit, 0, 4, DecimalData.EBCDIC_SIGN_SEPARATE_TRAILING, 0); + Assert.assertEquals("Result code for signSeparateTrailingInvalidSignDigit should have been 1", 1, result); + + final byte[] signSeparateLeadingInvalidSignDigit = new byte[] {(byte) 0x43, (byte) 0xF9, (byte) 0xF1, (byte) 0xF1, (byte) 0xF3}; + result = ExternalDecimal.checkExternalDecimal(signSeparateLeadingInvalidSignDigit, 0, 4, DecimalData.EBCDIC_SIGN_SEPARATE_LEADING, 0); + Assert.assertEquals("Result code for signSeparateLeadingInvalidSignDigit should have been 1", 1, result); + } + + @Test + public void testCheckExternalDecimalInvalidDigitsAndSignDigit() + { + final byte[] signEmbeddedTrailingInvalidDigitAndSignDigit = new byte[] {(byte) 0xF9, (byte) 0xFD, (byte) 0xF2, (byte) 0x23}; + int result = ExternalDecimal.checkExternalDecimal(signEmbeddedTrailingInvalidDigitAndSignDigit, 0, 4, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 0); + Assert.assertEquals("Result code for signEmbeddedTrailingInvalidDigitAndSignDigit should have been 3", 3, result); + + final byte[] signEmbeddedLeadingInvalidDigitAndSignDigit = new byte[] {(byte) 0x49, (byte) 0xFD, (byte) 0xF2, (byte) 0xF3}; + result = ExternalDecimal.checkExternalDecimal(signEmbeddedLeadingInvalidDigitAndSignDigit, 0, 4, DecimalData.EBCDIC_SIGN_EMBEDDED_LEADING, 0); + Assert.assertEquals("Result code for signEmbeddedLeadingInvalidDigitAndSignDigit should have been 3", 3, result); + + final byte[] signSeparateTrailingInvalidDigitAndSignDigit = new byte[] {(byte) 0xF9, (byte) 0xF1, (byte) 0xF2, (byte) 0xFD, (byte) 0x4F}; + result = ExternalDecimal.checkExternalDecimal(signSeparateTrailingInvalidDigitAndSignDigit, 0, 4, DecimalData.EBCDIC_SIGN_SEPARATE_TRAILING, 0); + Assert.assertEquals("Result code for signSeparateTrailingInvalidDigitAndSignDigit should have been 3", 3, result); + + final byte[] signSeparateLeadingInvalidDigitAndSignDigit = new byte[] {(byte) 0x4A, (byte) 0xF9, (byte) 0xF1, (byte) 0xFD, (byte) 0xF3}; + result = ExternalDecimal.checkExternalDecimal(signSeparateLeadingInvalidDigitAndSignDigit, 0, 4, DecimalData.EBCDIC_SIGN_SEPARATE_LEADING, 0); + Assert.assertEquals("Result code for signSeparateLeadingInvalidDigitAndSignDigit should have been 3", 3, result); + } + + @Test + public void testCheckExternalDecimalWithOffset() + { + final byte[] signEmbeddedTrailingInvalidDigitAndSignDigit = new byte[] {(byte) 0xF9, (byte) 0xFD, (byte) 0xF2, (byte) 0x23}; + int result = ExternalDecimal.checkExternalDecimal(signEmbeddedTrailingInvalidDigitAndSignDigit, 1, 3, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 0); + Assert.assertEquals("Result code for signEmbeddedTrailingInvalidDigitAndSignDigit should have been 3", 3, result); + + final byte[] signEmbeddedLeadingInvalidDigitAndSignDigit = new byte[] {(byte) 0x49, (byte) 0xFD, (byte) 0x42, (byte) 0xFD}; + result = ExternalDecimal.checkExternalDecimal(signEmbeddedLeadingInvalidDigitAndSignDigit, 2, 2, DecimalData.EBCDIC_SIGN_EMBEDDED_LEADING, 0); + Assert.assertEquals("Result code for signEmbeddedLeadingInvalidDigitAndSignDigit should have been 3", 3, result); + + final byte[] signSeparateTrailingInvalidDigitAndSignDigit = new byte[] {(byte) 0xF9, (byte) 0xF1, (byte) 0xF2, (byte) 0xFD, (byte) 0x4F}; + result = ExternalDecimal.checkExternalDecimal(signSeparateTrailingInvalidDigitAndSignDigit, 1, 3, DecimalData.EBCDIC_SIGN_SEPARATE_TRAILING, 0); + Assert.assertEquals("Result code for signSeparateTrailingInvalidDigitAndSignDigit should have been 3", 3, result); + + final byte[] signSeparateLeadingInvalidDigitAndSignDigit = new byte[] {(byte) 0x4A, (byte) 0xF9, (byte) 0xF1, (byte) 0xFD, (byte) 0xF3}; + result = ExternalDecimal.checkExternalDecimal(signSeparateLeadingInvalidDigitAndSignDigit, 1, 3, DecimalData.EBCDIC_SIGN_SEPARATE_LEADING, 0); + Assert.assertEquals("Result code for signSeparateLeadingInvalidDigitAndSignDigit should have been 3", 3, result); + } + + @Test + public void testCheckExternalDecimal16DigitsWithOffset() + { + // Test low and high vector register + final byte[] signEmbeddedTrailing = new byte[] {(byte) 0xF6, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, + (byte) 0xF7, (byte) 0xF3, (byte) 0xF2, (byte) 0xFD, (byte) 0xF4, + (byte) 0xF6, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, + (byte) 0xF8, (byte) 0xF1, (byte) 0xF2, (byte) 0xF9, (byte) 0xF1, + (byte) 0xF3, (byte) 0xF8, (byte) 0xF1, (byte) 0xF2, (byte) 0xC3}; + int result = ExternalDecimal.checkExternalDecimal(signEmbeddedTrailing, 9, 16, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 0); + Assert.assertEquals("Result code for signEmbeddedTrailing should have been 0", 0, result); + + final byte[] signEmbeddedLeading = new byte[] {(byte) 0xF6, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, + (byte) 0xF7, (byte) 0xF3, (byte) 0xFB, (byte) 0xC1, (byte) 0xF4, + (byte) 0xF6, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, + (byte) 0xF8, (byte) 0xF1, (byte) 0xF2, (byte) 0xF9, (byte) 0xF1, + (byte) 0xF3, (byte) 0xF8, (byte) 0xF1, (byte) 0xF2, (byte) 0xF3}; + result = ExternalDecimal.checkExternalDecimal(signEmbeddedLeading, 9, 16, DecimalData.EBCDIC_SIGN_EMBEDDED_LEADING, 0); + Assert.assertEquals("Result code for signEmbeddedLeading should have been 0", 0, result); + + final byte[] signSeparateTrailing = new byte[] {(byte) 0xF6, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, + (byte) 0xF7, (byte) 0xF3, (byte) 0xF2, (byte) 0xF4, (byte) 0xF2, + (byte) 0xF6, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, + (byte) 0xF8, (byte) 0xF1, (byte) 0xF2, (byte) 0xF9, (byte) 0xF1, + (byte) 0xF3, (byte) 0xF8, (byte) 0xF1, (byte) 0xF2, (byte) 0x4E}; + result = ExternalDecimal.checkExternalDecimal(signSeparateTrailing, 9, 15, DecimalData.EBCDIC_SIGN_SEPARATE_TRAILING, 0); + Assert.assertEquals("Result code for signSeparateTrailing should have been 0", 0, result); + + final byte[] signSeparateLeading = new byte[] {(byte) 0xF4, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, + (byte) 0xFD, (byte) 0xFA, (byte) 0xF2, (byte) 0x4E, (byte) 0x4E, + (byte) 0xF6, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, + (byte) 0xF8, (byte) 0xF1, (byte) 0xF2, (byte) 0xF9, (byte) 0xF1, + (byte) 0xF3, (byte) 0xF8, (byte) 0xF1, (byte) 0xF2, (byte) 0xF4}; + result = ExternalDecimal.checkExternalDecimal(signSeparateLeading, 9, 15, DecimalData.EBCDIC_SIGN_SEPARATE_LEADING, 0); + Assert.assertEquals("Result code for signSeparateLeading should have been 0", 0, result); + } + + @Test + public void testCheckExternalDecimal32DigitsWithOffset() + { + // Test max both vector registers maxed out + final byte[] signEmbeddedTrailing = new byte[] {(byte) 0xF6, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, + (byte) 0xF4, (byte) 0xF5, (byte) 0xF6, (byte) 0xF8, (byte) 0xF2, + (byte) 0xF5, (byte) 0xF1, (byte) 0xF8, (byte) 0xF2, (byte) 0xF4, + (byte) 0xF7, (byte) 0xF3, (byte) 0xF2, (byte) 0xF1, (byte) 0xF4, + (byte) 0xF6, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, + (byte) 0xF8, (byte) 0xF1, (byte) 0xF2, (byte) 0xF9, (byte) 0xF1, + (byte) 0xF3, (byte) 0xF8, (byte) 0xF1, (byte) 0xF3, (byte) 0xF4, + (byte) 0xC3}; + int result = ExternalDecimal.checkExternalDecimal(signEmbeddedTrailing, 5, 31, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 0); + Assert.assertEquals("Result code for signEmbeddedTrailing should have been 0", 0, result); + + final byte[] signEmbeddedLeading = new byte[] {(byte) 0xCF, (byte) 0xF3, (byte) 0xF9, (byte) 0xA1, (byte) 0xC4, + (byte) 0xF4, (byte) 0xF5, (byte) 0xF6, (byte) 0xF8, (byte) 0xF6, + (byte) 0xF5, (byte) 0xF1, (byte) 0xF8, (byte) 0xF2, (byte) 0xF4, + (byte) 0xF7, (byte) 0xF3, (byte) 0xF2, (byte) 0xF1, (byte) 0xF4, + (byte) 0xF6, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, + (byte) 0xF8, (byte) 0xF1, (byte) 0xF2, (byte) 0xF9, (byte) 0xF1, + (byte) 0xF3, (byte) 0xF8, (byte) 0xF1, (byte) 0xF3, (byte) 0xF4, + (byte) 0xF4}; + result = ExternalDecimal.checkExternalDecimal(signEmbeddedLeading, 5, 31, DecimalData.EBCDIC_SIGN_EMBEDDED_LEADING, 0); + Assert.assertEquals("Result code for signEmbeddedLeading should have been 0", 0, result); + + final byte[] signSeparateTrailing = new byte[] {(byte) 0xFA, (byte) 0xF3, (byte) 0xF9, (byte) 0xFA, (byte) 0xFD, + (byte) 0xF4, (byte) 0xF5, (byte) 0xF6, (byte) 0xF8, (byte) 0xF2, + (byte) 0xF5, (byte) 0xF1, (byte) 0xF8, (byte) 0xF2, (byte) 0xF4, + (byte) 0xF7, (byte) 0xF3, (byte) 0xF2, (byte) 0xF1, (byte) 0xF4, + (byte) 0xF6, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, + (byte) 0xF8, (byte) 0xF1, (byte) 0xF2, (byte) 0xF9, (byte) 0xF1, + (byte) 0xF3, (byte) 0xF8, (byte) 0xF1, (byte) 0xF3, (byte) 0xF4, + (byte) 0xF2, (byte) 0x4E}; + result = ExternalDecimal.checkExternalDecimal(signSeparateTrailing, 5,31, DecimalData.EBCDIC_SIGN_SEPARATE_TRAILING, 0); + Assert.assertEquals("Result code for signSeparateTrailing should have been 0", 0, result); + + final byte[] signSeparateLeading = new byte[] {(byte) 0xFA, (byte) 0xF3, (byte) 0xF9, (byte) 0xFA, (byte) 0xFD, + (byte) 0x4E, (byte) 0xF5, (byte) 0xF6, (byte) 0xF8, (byte) 0xF2, + (byte) 0xF5, (byte) 0xF1, (byte) 0xF8, (byte) 0xF2, (byte) 0xF4, + (byte) 0xF7, (byte) 0xF3, (byte) 0xF2, (byte) 0xF1, (byte) 0xF4, + (byte) 0xF6, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, + (byte) 0xF8, (byte) 0xF1, (byte) 0xF2, (byte) 0xF9, (byte) 0xF1, + (byte) 0xF3, (byte) 0xF8, (byte) 0xF1, (byte) 0xF3, (byte) 0xF4, + (byte) 0xF2, (byte) 0xF4}; + result = ExternalDecimal.checkExternalDecimal(signSeparateLeading, 5, 31, DecimalData.EBCDIC_SIGN_SEPARATE_LEADING, 0); + Assert.assertEquals("Result code for signSeparateLeading should have been 0", 0, result); + } + public static void main(String[] args) { Result result = new Result(); From 45bd5f522f4a2e36fbb82c40d2506c0bdad56263 Mon Sep 17 00:00:00 2001 From: Shubham Verma Date: Wed, 3 Apr 2024 13:34:47 -0400 Subject: [PATCH 2/2] Changes based on PR suggestions Signed-off-by: Shubham Verma --- .../arithmetics/TestValidityChecking.java | 62 ++++++++----------- 1 file changed, 26 insertions(+), 36 deletions(-) diff --git a/openj9.test.daa/src/test.daa/net/openj9/test/arithmetics/TestValidityChecking.java b/openj9.test.daa/src/test.daa/net/openj9/test/arithmetics/TestValidityChecking.java index 623261a..e506540 100644 --- a/openj9.test.daa/src/test.daa/net/openj9/test/arithmetics/TestValidityChecking.java +++ b/openj9.test.daa/src/test.daa/net/openj9/test/arithmetics/TestValidityChecking.java @@ -759,42 +759,39 @@ public void testFailingArguments() result = ExternalDecimal.checkExternalDecimal(a, 0, 5, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, -5); Assert.assertEquals("bytesWithSpaces < 0 should result in return code of 3", 3, result); - result = ExternalDecimal.checkExternalDecimal(a, 2, 5, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 1); - Assert.assertEquals("bytesWithSpaces < 0 should result in return code of 3", 2, result); - try { ExternalDecimal.checkExternalDecimal(a, 0, -5, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 5); } catch (IllegalArgumentException e) { - e.getMessage().contains("Precision must be greater than 0"); + Assert.assertTrue(e.getMessage().contains("Precision must be greater than 0")); } try { ExternalDecimal.checkExternalDecimal(a, 0, 0, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 5); } catch (IllegalArgumentException e) { - e.getMessage().contains("Precision must be greater than 0"); + Assert.assertTrue(e.getMessage().contains("Precision must be greater than 0")); } try { ExternalDecimal.checkExternalDecimal(a, -1, 3, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 5); } catch (IllegalArgumentException e) { - e.getMessage().contains("Offset must be non-negative integer"); + Assert.assertTrue(e.getMessage().contains("Offset must be non-negative integer")); } try { ExternalDecimal.checkExternalDecimal(a, 0, 3, 23, 5); } catch (IllegalArgumentException e) { - e.getMessage().contains("Invalid decimalType"); + Assert.assertTrue(e.getMessage().contains("Invalid decimalType")); } try { ExternalDecimal.checkExternalDecimal(a, 0, 9, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 5); } catch (ArrayIndexOutOfBoundsException e) { - e.getMessage().contains("Array access index out of bounds"); + Assert.assertTrue(e.getMessage().contains("Array access index out of bounds")); } } @@ -802,56 +799,49 @@ public void testFailingArguments() public void testExternalDecimalWithSpace() { final byte[] a = new byte[] {(byte) 0x40, (byte) 0xF9, (byte) 0xF1, (byte) 0xF2, (byte) 0xC3}; - int result = ExternalDecimal.checkExternalDecimal(a, 0, 5, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 1); // rc = 2 - Assert.assertEquals("Result code for signEmbeddedTrailingPrefered(a) should have been 0", 0, result); // hardware returns 2 - - // Debugging - Start - result = ExternalDecimal.checkExternalDecimal(a, 0, 5, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 2); // rc = 0 - // it honors DSC < DC but maybe it needs it to be +1 than actual value? - // bytes with spaces set to 2 instead of 1 is considered valid external decimal - Assert.assertEquals("Result code for signEmbeddedTrailingPrefered(a) should have been 0", 0, result); // hardware returns 2 - - final byte[] a1 = new byte[] {(byte) 0xF1, (byte) 0xF9, (byte) 0xF1, (byte) 0xF2, (byte) 0xC3}; - result = ExternalDecimal.checkExternalDecimal(a, 0, 5, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 1); // rc = ? - Assert.assertEquals("Result code for signEmbeddedTrailingPrefered(a) should have been 0", 0, result); - - final byte[] a2 = new byte[] {(byte) 0x40, (byte) 0x40, (byte) 0xF1, (byte) 0xF2, (byte) 0xC3}; - result = ExternalDecimal.checkExternalDecimal(a, 0, 5, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 2); // rc = ? - Assert.assertEquals("Result code for signEmbeddedTrailingPrefered(a) should have been 0", 0, result); - // Debugging - End + int result = ExternalDecimal.checkExternalDecimal(a, 0, 5, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 1); + // Test valid external decimal sign embedded trailing with single space + Assert.assertEquals("Expected a valid external decimal with single leading space", 0, result); final byte[] b = new byte[] {(byte) 0x40, (byte) 0x40, (byte) 0x40, (byte) 0x40, (byte) 0x40, (byte) 0x40, (byte) 0x40, (byte) 0xF9, (byte) 0xF1, (byte) 0xF2, (byte) 0xC3}; result = ExternalDecimal.checkExternalDecimal(b, 0, 11, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 7); - Assert.assertEquals("Result code for signEmbeddedTrailingPrefered(b) should have been 0", 0, result); // hardware returns 2 + // Test valid external decimal sign embedded trailing with multiple leading spaces + Assert.assertEquals("Expected a valid external decimal with multiple leading spaces", 0, result); result = ExternalDecimal.checkExternalDecimal(b, 0, 11, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 5); - Assert.assertEquals("Result code for signEmbeddedTrailingPrefered(b) should have been 2", 2, result); + // Test invalid external decimal sign embedded with space byte in place of a numeric byte (F[0-9]) + Assert.assertEquals("Expected invalid digit with space byte instead of a numeric byte (F[0-9])", 2, result); final byte[] c = new byte[] {(byte) 0x40, (byte) 0xC9, (byte) 0xF1, (byte) 0xF2, (byte) 0xF3}; result = ExternalDecimal.checkExternalDecimal(c, 0, 5, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 1); - Assert.assertEquals("Result code for signEmbeddedTrailingPrefered(c) should have been 2", 2, result); + Assert.assertEquals("Expected invalid zone code", 2, result); + // Fails with 3 because space byte was present in place of the sign byte result = ExternalDecimal.checkExternalDecimal(c, 0, 5, DecimalData.EBCDIC_SIGN_EMBEDDED_LEADING, 0); - Assert.assertEquals("Result code for signEmbeddedTrailingPrefered(c) should have been 3", 3, result); + Assert.assertEquals("Expected invalid sign code for external decimal with leading embedded sign", 3, result); final byte[] d = new byte[] {(byte) 0x40, (byte) 0x40, (byte) 0x40, (byte) 0x40, (byte) 0x40, (byte) 0x40, (byte) 0x40, (byte) 0xC9, (byte) 0xF1, (byte) 0xF2, (byte) 0xF3}; + + // Fails because spaces are valid only if sign is embedded and trailing result = ExternalDecimal.checkExternalDecimal(d, 0, 11, DecimalData.EBCDIC_SIGN_EMBEDDED_LEADING, 7); - Assert.assertEquals("Result code for signEmbeddedTrailingPrefered(d) should have been 3", 3, result); + Assert.assertEquals("Expected invalid external decimal as spaces are valid only if sign is embedded and trailing", 3, result); + // Fails with 3 because space byte was present in place of a sign byte result = ExternalDecimal.checkExternalDecimal(d, 0, 11, DecimalData.EBCDIC_SIGN_EMBEDDED_LEADING, 5); - // hardware returned 2, so need to double check what is expected here - Assert.assertEquals("Result code for signEmbeddedTrailingPrefered(d) should have been 3", 3, result); + Assert.assertEquals("Expected invalid sign code", 3, result); + // Fails with 3 because number of spaces is greater than precision result = ExternalDecimal.checkExternalDecimal(d, 0, 9, DecimalData.EBCDIC_SIGN_EMBEDDED_LEADING, 10); - Assert.assertEquals("Result code for signEmbeddedTrailingPrefered(d) should have been 3", 3, result); + Assert.assertEquals("Expected invalid digit as space digit count is greater than precision", 3, result); final byte[] e = new byte[] {(byte) 0x40, (byte) 0xF9, (byte) 0xF1, (byte) 0xF2, (byte) 0xF2, (byte) 0xF2, (byte) 0xC3}; + // Test offset greater than number of spaces result = ExternalDecimal.checkExternalDecimal(e, 2, 5, DecimalData.EBCDIC_SIGN_EMBEDDED_TRAILING, 1); - Assert.assertEquals("Result code for valid external decimal with offset > bytesWithSpaces", 0, result); + Assert.assertEquals("Expected valid digit", 0, result); } @Test @@ -942,7 +932,7 @@ public void testCheckExternalDecimal25Digits() } @Test - public void testCheckExternalDecimal32Digits() + public void testCheckExternalDecimal31Digits() { // Test max both vector registers maxed out final byte[] signEmbeddedTrailing = new byte[] {(byte) 0xF6, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3, @@ -1185,7 +1175,7 @@ public void testCheckExternalDecimal16DigitsWithOffset() } @Test - public void testCheckExternalDecimal32DigitsWithOffset() + public void testCheckExternalDecimal31DigitsWithOffset() { // Test max both vector registers maxed out final byte[] signEmbeddedTrailing = new byte[] {(byte) 0xF6, (byte) 0xF3, (byte) 0xF9, (byte) 0xF1, (byte) 0xF3,