Repository: commons-crypto Updated Branches: refs/heads/master af71a9693 -> 80fa61edf
Skip tests if JNI not loaded Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/80fa61ed Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/80fa61ed Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/80fa61ed Branch: refs/heads/master Commit: 80fa61edf4f7610671bc3ca390109637f58d8296 Parents: af71a96 Author: Sebb <[email protected]> Authored: Wed Jul 6 22:54:18 2016 +0100 Committer: Sebb <[email protected]> Committed: Wed Jul 6 22:54:18 2016 +0100 ---------------------------------------------------------------------- .../crypto/stream/AbstractCipherStreamTest.java | 30 ++++++++++++++++++++ .../stream/PositionedCryptoInputStreamTest.java | 9 +++++- 2 files changed, 38 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/80fa61ed/src/test/java/org/apache/commons/crypto/stream/AbstractCipherStreamTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/crypto/stream/AbstractCipherStreamTest.java b/src/test/java/org/apache/commons/crypto/stream/AbstractCipherStreamTest.java index 79258d1..e587370 100644 --- a/src/test/java/org/apache/commons/crypto/stream/AbstractCipherStreamTest.java +++ b/src/test/java/org/apache/commons/crypto/stream/AbstractCipherStreamTest.java @@ -33,6 +33,7 @@ import java.util.Random; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; +import org.apache.commons.crypto.Crypto; import org.apache.commons.crypto.cipher.AbstractCipherTest; import org.apache.commons.crypto.cipher.CryptoCipher; import org.apache.commons.crypto.utils.ReflectionUtils; @@ -99,6 +100,11 @@ public abstract class AbstractCipherStreamTest { protected void doSkipTest(String cipherClass, boolean withChannel) throws IOException { + if (AbstractCipherTest.OPENSSL_CIPHER_CLASSNAME.equals(cipherClass)) { + if (!Crypto.isNativeCodeLoaded()) { + return; // Skip this test if no JNI + } + } try (InputStream in = getCryptoInputStream( new ByteArrayInputStream(encData), getCipher(cipherClass), defaultBufferSize, iv, withChannel)) { @@ -130,6 +136,11 @@ public abstract class AbstractCipherStreamTest { protected void doByteBufferRead(String cipherClass, boolean withChannel) throws Exception { + if (AbstractCipherTest.OPENSSL_CIPHER_CLASSNAME.equals(cipherClass)) { + if (!Crypto.isNativeCodeLoaded()) { + return; // Skip this test if no JNI + } + } // Default buffer size, initial buffer position is 0 InputStream in = getCryptoInputStream( new ByteArrayInputStream(encData), getCipher(cipherClass), @@ -190,6 +201,11 @@ public abstract class AbstractCipherStreamTest { protected void doByteBufferWrite(String cipherClass, ByteArrayOutputStream baos, boolean withChannel) throws Exception { + if (AbstractCipherTest.OPENSSL_CIPHER_CLASSNAME.equals(cipherClass)) { + if (!Crypto.isNativeCodeLoaded()) { + return; // Skip this test if no JNI + } + } baos.reset(); CryptoOutputStream out = getCryptoOutputStream(baos, getCipher(cipherClass), defaultBufferSize, iv, withChannel); @@ -331,6 +347,13 @@ public abstract class AbstractCipherStreamTest { private void doReadWriteTestForInputStream(int count, String encCipherClass, String decCipherClass, byte[] iv) throws IOException { + if (AbstractCipherTest.OPENSSL_CIPHER_CLASSNAME.equals(encCipherClass) + || + AbstractCipherTest.OPENSSL_CIPHER_CLASSNAME.equals(decCipherClass)) { + if (!Crypto.isNativeCodeLoaded()) { + return; // Skip this test if no JNI + } + } // Created a cipher object of type encCipherClass; CryptoCipher encCipher = getCipher(encCipherClass); @@ -392,6 +415,13 @@ public abstract class AbstractCipherStreamTest { private void doReadWriteTestForReadableByteChannel(int count, String encCipherClass, String decCipherClass, byte[] iv) throws IOException { + if (AbstractCipherTest.OPENSSL_CIPHER_CLASSNAME.equals(encCipherClass) + || + AbstractCipherTest.OPENSSL_CIPHER_CLASSNAME.equals(decCipherClass)) { + if (!Crypto.isNativeCodeLoaded()) { + return; // Skip this test if no JNI + } + } // Creates a cipher object of type encCipherClass; CryptoCipher encCipher = getCipher(encCipherClass); http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/80fa61ed/src/test/java/org/apache/commons/crypto/stream/PositionedCryptoInputStreamTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/crypto/stream/PositionedCryptoInputStreamTest.java b/src/test/java/org/apache/commons/crypto/stream/PositionedCryptoInputStreamTest.java index 5ffef00..f796c0c 100644 --- a/src/test/java/org/apache/commons/crypto/stream/PositionedCryptoInputStreamTest.java +++ b/src/test/java/org/apache/commons/crypto/stream/PositionedCryptoInputStreamTest.java @@ -18,11 +18,13 @@ package org.apache.commons.crypto.stream; +import org.apache.commons.crypto.Crypto; import org.apache.commons.crypto.cipher.AbstractCipherTest; import org.apache.commons.crypto.cipher.CryptoCipher; import org.apache.commons.crypto.stream.input.Input; import org.apache.commons.crypto.utils.ReflectionUtils; import org.junit.Assert; +import org.junit.Assume; import org.junit.Before; import org.junit.Test; @@ -91,8 +93,13 @@ public class PositionedCryptoInputStreamTest { } @Test - public void doTest() throws Exception { + public void doTestJCE() throws Exception { testCipher(AbstractCipherTest.JCE_CIPHER_CLASSNAME); + } + + @Test + public void doTestJNI() throws Exception { + Assume.assumeTrue(Crypto.isNativeCodeLoaded()); testCipher(AbstractCipherTest.OPENSSL_CIPHER_CLASSNAME); }
