From 946d9a0b59d1a615278ad52518fa588407dfebd2 Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Wed, 7 Jan 2015 14:59:04 -0800 Subject: 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 --- .../test/java/libcore/javax/net/ssl/TestSSLEnginePair.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'support/src/test/java') 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; } -- cgit v1.1