Skip to content

Commit

Permalink
Added a test for the mark() method
Browse files Browse the repository at this point in the history
  • Loading branch information
elecharny committed Sep 5, 2014
1 parent 760a0f8 commit 53d7fa2
Showing 1 changed file with 50 additions and 30 deletions.
80 changes: 50 additions & 30 deletions codec/src/test/java/org/apache/mina/codec/IoBufferTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ public void testAddMixedOrderBuffers() {
ioBuffer.add(bb1, bb2);
}

//-------------------------------------------------------------------------
// -------------------------------------------------------------------------
// Test the allocate(int) method
// 1) allocation with a negative value
// 2) allocation with a 0 length
// 3) allocation with a 1024 value
//-------------------------------------------------------------------------
// -------------------------------------------------------------------------
/**
* Test the allocation of a new heap IoBuffer with a negative value
*/
Expand Down Expand Up @@ -194,12 +194,12 @@ public void testAllocate1024() {
assertTrue(ioBuffer.hasRemaining());
}

//-------------------------------------------------------------------------
// -------------------------------------------------------------------------
// Test the allocateDirect(int) method. We check :
// 1) allocation with a negative value
// 2) allocation with a 0 length
// 3) allocation with a 1024 value
//-------------------------------------------------------------------------
// -------------------------------------------------------------------------
/**
* Test the allocation of a new heap IoBuffer with a negative value
*/
Expand Down Expand Up @@ -237,7 +237,8 @@ public void testAllocateDirect1024() {
}

/**
* Test the get() method on a IoBuffer containing one ByteBuffer with 3 bytes
* Test the get() method on a IoBuffer containing one ByteBuffer with 3
* bytes
*/
@Test
public void testGetOneBuffer3Bytes() {
Expand Down Expand Up @@ -267,7 +268,8 @@ public void testGetOneBuffer3Bytes() {
}

/**
* Test the get() method on a IoBuffer containing one ByteBuffer with 0 bytes
* Test the get() method on a IoBuffer containing one ByteBuffer with 0
* bytes
*/
@Test
public void testGetOneBuffer0Bytes() {
Expand All @@ -288,7 +290,8 @@ public void testGetOneBuffer0Bytes() {
}

/**
* Test the get() method on a IoBuffer containing two ByteBuffer with 3 bytes
* Test the get() method on a IoBuffer containing two ByteBuffer with 3
* bytes
*/
@Test
public void testGetTwoBuffer3Bytes() {
Expand Down Expand Up @@ -328,13 +331,13 @@ public void testGetTwoBuffer3Bytes() {
}
}

//-------------------------------------------------------------------------
// -------------------------------------------------------------------------
// Test the array() method. We will check those cases :
// 1) array over an empty buffer: we should get an empty byte array
// 2) array over a buffer with one single empty ByteBuffer
// 2) array over a buffer with one single empty ByteBuffer
// 3) array over a buffer with one single ByteBuffer with data
// 4) array over a buffer containing many ByteBuffers
//-------------------------------------------------------------------------
// 4) array over a buffer containing many ByteBuffers
// -------------------------------------------------------------------------
/**
* Test the array method for a IoBuffer containing one empty ByteBuffer
*/
Expand All @@ -349,7 +352,8 @@ public void testArrayEmptyByteBuffer() {
}

/**
* Test the array method for a IoBuffer containing one ByteBuffer (cases 2 and 3)
* Test the array method for a IoBuffer containing one ByteBuffer (cases 2
* and 3)
*/
@Test
public void testArrayOneByteBuffer() {
Expand All @@ -374,7 +378,8 @@ public void testArrayOneByteBuffer() {
}

/**
* Test the array method for a IoBuffer containing one ByteBuffer not initialized
* Test the array method for a IoBuffer containing one ByteBuffer not
* initialized
*/
@Test
public void testArrayByteBufferNotInitialized() {
Expand Down Expand Up @@ -403,7 +408,8 @@ public void testGetInt2IntsOneBB() {
}

/**
* Test the getInt() method, on a buffer containing 2 ints in two ByteBuffers
* Test the getInt() method, on a buffer containing 2 ints in two
* ByteBuffers
*/
@Test
public void testGetInt2Ints2BBs() {
Expand All @@ -422,8 +428,8 @@ public void testGetInt2Ints2BBs() {
}

/**
* Test the getInt() method, on a buffer containing 2 ints in two ByteBuffers
* with LittleInidan order
* Test the getInt() method, on a buffer containing 2 ints in two
* ByteBuffers with LittleInidan order
*/
@Test
public void testGetInt2Ints2BBsLittleIndian() {
Expand All @@ -445,7 +451,8 @@ public void testGetInt2Ints2BBsLittleIndian() {
}

/**
* Test the getInt() method, on a buffer containing 1 int spread in two ByteBuffers
* Test the getInt() method, on a buffer containing 1 int spread in two
* ByteBuffers
*/
@Test
public void testGetInt1Int2BBs() {
Expand All @@ -463,7 +470,8 @@ public void testGetInt1Int2BBs() {
}

/**
* Test the getInt() method, on a buffer containing 1 incomplet int spread in two ByteBuffers
* Test the getInt() method, on a buffer containing 1 incomplet int spread
* in two ByteBuffers
*/
@Test(expected = BufferUnderflowException.class)
public void testGetIntIncompletInt2BBs() {
Expand Down Expand Up @@ -542,14 +550,14 @@ public void testGetIntTwoBuffer() {
}
}

//-------------------------------------------------------------------------
// -------------------------------------------------------------------------
// The the clear method. It will erase all the data in all the inner
// ByteBuffer, thus the buffer size might increase.
// We will check those case :
// 1) clear an empty buffer
// 2) clear a buffer with one ByteBuffer
// 3) clear a buffer with numerous ByteBuffers
//-------------------------------------------------------------------------
// -------------------------------------------------------------------------
/**
* Test the clear() method
*/
Expand Down Expand Up @@ -601,6 +609,18 @@ public void testMark() {
ioBuffer.position(3);
ioBuffer.mark();

// check that we are at the right position
byte b = ioBuffer.get();
assertEquals(b, '3');

b = ioBuffer.get();
assertEquals(b, '4');

// Now reset to the mark
ioBuffer.reset();
b = ioBuffer.get();
assertEquals(b, '3');

ioBuffer.position(6);
ioBuffer.reset();

Expand All @@ -614,7 +634,7 @@ public void testMark() {
ioBuffer.reset();
fail("An InvalidMarkException should have been thrown");
} catch (InvalidMarkException ime) {
//
//
}
}

Expand Down Expand Up @@ -645,13 +665,13 @@ public void testFlip() {
assertEquals(8, ioBuffer.limit());
}

//-------------------------------------------------------------------------
// -------------------------------------------------------------------------
// Test the position() method
// We will test that the position() metho returns the correct result in
// We will test that the position() metho returns the correct result in
// those cases :
// 1) the buffer is empty : must return 0
// 2) must return a value between 0 and limit()
//-------------------------------------------------------------------------
// -------------------------------------------------------------------------
/**
* Test the position method over an emptyIoBuffer
*/
Expand Down Expand Up @@ -716,19 +736,19 @@ public void testSetPositionBuffer() {
}
}

//-------------------------------------------------------------------------
// -------------------------------------------------------------------------
// Test the position(int) method
// We will test many different cases
// 1) a position() in an empty buffer
// 2) a position() with a negative value
// 3) a position() with a value above the limit
// 4) a position() within the current buffer
// 4-1) at the beginning of the current buffer
// 4-2) at the end of the current buffer
// 4-3) in the middle of the current buffer
// 4-1) at the beginning of the current buffer
// 4-2) at the end of the current buffer
// 4-3) in the middle of the current buffer
// 5) a position() before the current buffer
// 6) a position() after the current buffer
//-------------------------------------------------------------------------
// -------------------------------------------------------------------------
/**
* Test the position method over an emptyIoBuffer
*/
Expand Down Expand Up @@ -1043,7 +1063,7 @@ public void testChar() {
ioBuffer.putChar(3, '\u00F1');
fail("Not enough place on the buffer");
} catch (BufferUnderflowException e) {
// Should come here
// Should come here
}

try {
Expand Down

0 comments on commit 53d7fa2

Please sign in to comment.