Skip to content

Commit 2da20fd

Browse files
committed
fix tests
1 parent deb8b15 commit 2da20fd

File tree

4 files changed

+57
-7
lines changed

4 files changed

+57
-7
lines changed

net.lecousin.core/src/test/java/net/lecousin/framework/core/test/io/TestReadable.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,16 +471,16 @@ public void testSkipSyncNegativeValue() throws Exception {
471471
if (skipped != 0)
472472
throw new Exception("Readable is not supposed to be able to skip with a negative value, skipping -10 bytes returned " + skipped + " while 0 was expected.");
473473
}
474+
io.readSync(buffer);
475+
Assert.assertEquals("Invalid byte read after skipSync with negative value", testBuf[testBuf.length / 2 + (int)skipped], b[0]);
474476
skipped = io.skipSync(-2 * testBuf.length);
475477
if (io instanceof IO.Readable.Seekable) {
476-
if (skipped != -((testBuf.length + testBuf.length / 2) - 10))
477-
throw new Exception("Skip beyond beginning of IO on Readable.Seekable is supposed to go to the offset 0. Skipping " + (-2 * testBuf.length) + " returned " + skipped + " but expected was " + (-((testBuf.length + testBuf.length / 2) - 10)));
478+
if (skipped != -((testBuf.length + testBuf.length / 2) - 10 + 1))
479+
throw new Exception("Skip beyond beginning of IO on Readable.Seekable is supposed to go to the offset 0. Skipping " + (-2 * testBuf.length) + " returned " + skipped + " but expected was " + (-((testBuf.length + testBuf.length / 2) - 10 + 1)));
478480
} else {
479481
if (skipped != 0)
480482
throw new Exception("Readable is not supposed to be able to skip with a negative value, skipping -10 bytes returned " + skipped + " while 0 was expected.");
481483
}
482-
io.readSync(buffer);
483-
Assert.assertEquals("Invalid byte read after skipSync with negative value", testBuf[testBuf.length / 2 + (int)skipped], b[0]);
484484
io.close();
485485
}
486486

net.lecousin.core/src/test/java/net/lecousin/framework/core/tests/io/buffered/TestTwoBuffersIODeterminedSizeReadable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public TestTwoBuffersIODeterminedSizeReadable(File testFile, byte[] testBuf, int
2727
@Override
2828
protected TwoBuffersIO createReadableFromFile(FileIO.ReadOnly file, long fileSize) {
2929
if (fileSize <= 40000)
30-
return new TwoBuffersIO.DeterminedSize(file, (int)fileSize, 10);
30+
return new TwoBuffersIO.DeterminedSize(file, (int)fileSize, 0);
3131
return new TwoBuffersIO.DeterminedSize(file, 40000, (int)(fileSize - 40000));
3232
}
3333

net.lecousin.core/src/test/java/net/lecousin/framework/core/tests/io/buffered/TestTwoBuffersIOReadableBuffered.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ public TestTwoBuffersIOReadableBuffered(File testFile, byte[] testBuf, int nbBuf
2626

2727
@Override
2828
protected TwoBuffersIO createReadableBufferedFromFile(FileIO.ReadOnly file, long fileSize) {
29-
return new TwoBuffersIO(file, 40000, (int)(fileSize - 40000));
29+
int second = (int)(fileSize - 39999);
30+
if (second <= 0) second = 10;
31+
return new TwoBuffersIO(file, 39999, second);
3032
}
3133

3234
}

net.lecousin.core/src/test/java/net/lecousin/framework/core/tests/io/encoding/TestBase64.java

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,60 @@ public void testDecoding() throws IOException {
3636
Assert.assertEquals("That is a test!", new String(Base64.decode("VGhhdCBpcyBhIHRlc3Qh=")));
3737

3838
byte[] buf = new byte[100];
39-
Base64.decode4BytesBase64("VGhp".getBytes("US-ASCII"), buf, 10);
39+
Assert.assertEquals(3, Base64.decode4BytesBase64("VGhp".getBytes("US-ASCII"), buf, 10));
4040
Assert.assertEquals((byte)'T', buf[10]);
4141
Assert.assertEquals((byte)'h', buf[11]);
4242
Assert.assertEquals((byte)'i', buf[12]);
4343

4444
Assert.assertArrayEquals("This is a test".getBytes(StandardCharsets.UTF_8), Base64.decode(" VGhpcyBpcyBhIHRlc3Q=".getBytes(StandardCharsets.UTF_8), 3, 20));
45+
46+
Assert.assertEquals(1, Base64.decode4BytesBase64("a0==".getBytes("US-ASCII"), buf, 0));
47+
Assert.assertEquals((byte)'k', buf[0]);
48+
Assert.assertEquals(1, Base64.decode4BytesBase64(ByteBuffer.wrap("a0==".getBytes("US-ASCII")), buf, 3));
49+
Assert.assertEquals((byte)'k', buf[3]);
50+
Assert.assertEquals(1, Base64.decode4BytesBase64(CharBuffer.wrap("a0==".toCharArray()), buf, 5));
51+
Assert.assertEquals((byte)'k', buf[5]);
52+
Assert.assertEquals(1, Base64.decode4BytesBase64(CharBuffer.wrap("a0=".toCharArray()), buf, 6));
53+
Assert.assertEquals((byte)'k', buf[6]);
54+
try {
55+
Base64.decode4BytesBase64(CharBuffer.wrap("a0=x".toCharArray()), buf, 7);
56+
throw new AssertionError("Error expected");
57+
} catch (IOException e) {}
58+
Assert.assertEquals(2, Base64.decode4BytesBase64(CharBuffer.wrap("a01=".toCharArray()), buf, 20));
59+
Assert.assertEquals((byte)'k', buf[20]);
60+
Assert.assertEquals((byte)'M', buf[21]);
61+
try {
62+
Base64.decode4BytesBase64(CharBuffer.wrap("a0}=".toCharArray()), buf, 50);
63+
throw new AssertionError("Error expected");
64+
} catch (IOException e) {}
65+
66+
Assert.assertEquals(0, Base64.decode(new byte[0]).length);
67+
byte[] b2 = Base64.decode("a0==".getBytes("US-ASCII"));
68+
Assert.assertEquals(1, b2.length);
69+
Assert.assertEquals((byte)'k', b2[0]);
70+
71+
Assert.assertEquals(0, Base64.decode(new byte[0], 0, 0).length);
72+
b2 = Base64.decode("a0==".getBytes("US-ASCII"), 0, 4);
73+
Assert.assertEquals(1, b2.length);
74+
Assert.assertEquals((byte)'k', b2[0]);
75+
b2 = Base64.decode("a0=".getBytes("US-ASCII"), 0, 3);
76+
Assert.assertEquals(0, b2.length);
77+
b2 = Base64.decode(ByteBuffer.wrap("a0==".getBytes("US-ASCII")));
78+
Assert.assertEquals(1, b2.length);
79+
Assert.assertEquals((byte)'k', b2[0]);
80+
b2 = Base64.decode(CharBuffer.wrap("a0==".toCharArray()));
81+
Assert.assertEquals(1, b2.length);
82+
Assert.assertEquals((byte)'k', b2[0]);
83+
b2 = Base64.decode(CharBuffer.wrap("a01=".toCharArray()));
84+
Assert.assertEquals(2, b2.length);
85+
Assert.assertEquals((byte)'k', b2[0]);
86+
Assert.assertEquals((byte)'M', b2[1]);
87+
88+
b2 = Base64.decode("VGhp".getBytes("US-ASCII"), 0, 4);
89+
Assert.assertEquals(3, b2.length);
90+
Assert.assertEquals((byte)'T', b2[0]);
91+
Assert.assertEquals((byte)'h', b2[1]);
92+
Assert.assertEquals((byte)'i', b2[2]);
4593
}
4694

4795
@SuppressWarnings("resource")

0 commit comments

Comments
 (0)