diff options
author | Kenny Root <kroot@google.com> | 2015-01-07 14:59:04 -0800 |
---|---|---|
committer | Kenny Root <kroot@google.com> | 2015-01-07 14:59:08 -0800 |
commit | 946d9a0b59d1a615278ad52518fa588407dfebd2 (patch) | |
tree | 56e9f66fb2ce62a3465e211c87ea7fbe34f74fab | |
parent | ecd42914677fde7762bd47e33d5a0dd81989c9e9 (diff) | |
download | libcore-946d9a0b59d1a615278ad52518fa588407dfebd2.zip libcore-946d9a0b59d1a615278ad52518fa588407dfebd2.tar.gz libcore-946d9a0b59d1a615278ad52518fa588407dfebd2.tar.bz2 |
SSLEngineTest: position should be same as produced/consumed
The position of the buffer should match the number of bytes produced or
consumed. Make sure all the tests have this condition on the handshake.
Bug: 18921387
Change-Id: I8d248b2ac189d801586510fb5aca2e3bd6701ffe
-rw-r--r-- | support/src/test/java/libcore/javax/net/ssl/TestSSLEnginePair.java | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/support/src/test/java/libcore/javax/net/ssl/TestSSLEnginePair.java b/support/src/test/java/libcore/javax/net/ssl/TestSSLEnginePair.java index 709f568..6c2c943 100644 --- a/support/src/test/java/libcore/javax/net/ssl/TestSSLEnginePair.java +++ b/support/src/test/java/libcore/javax/net/ssl/TestSSLEnginePair.java @@ -134,8 +134,6 @@ public final class TestSSLEnginePair extends Assert { void beforeBeginHandshake(SSLEngine client, SSLEngine server) {} } - private static final ByteBuffer EMPTY_BYTE_BUFFER = ByteBuffer.allocate(0); - private static boolean handshakeCompleted(SSLEngine engine, ByteBuffer output, ByteBuffer input, @@ -165,9 +163,12 @@ public final class TestSSLEnginePair extends Assert { if (input.remaining() == 0) { return false; } + int inputPositionBefore = input.position(); SSLEngineResult unwrapResult = engine.unwrap(input, scratch); assertEquals(SSLEngineResult.Status.OK, unwrapResult.getStatus()); assertEquals(0, scratch.position()); + assertEquals(0, unwrapResult.bytesProduced()); + assertEquals(input.position() - inputPositionBefore, unwrapResult.bytesConsumed()); assertFinishedOnce(finished, unwrapResult); return true; } @@ -177,8 +178,15 @@ public final class TestSSLEnginePair extends Assert { if (output.remaining() != output.capacity()) { return false; } - SSLEngineResult wrapResult = engine.wrap(EMPTY_BYTE_BUFFER, output); + ByteBuffer emptyByteBuffer = ByteBuffer.allocate(0); + int inputPositionBefore = emptyByteBuffer.position(); + int outputPositionBefore = output.position(); + SSLEngineResult wrapResult = engine.wrap(emptyByteBuffer, output); assertEquals(SSLEngineResult.Status.OK, wrapResult.getStatus()); + assertEquals(0, wrapResult.bytesConsumed()); + assertEquals(inputPositionBefore, emptyByteBuffer.position()); + assertEquals(output.position() - outputPositionBefore, + wrapResult.bytesProduced()); assertFinishedOnce(finished, wrapResult); return true; } |