< prev index next >
test/jdk/java/net/httpclient/http2/jdk.incubator.httpclient/jdk/incubator/http/internal/hpack/DecoderTest.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
@@ -22,12 +22,12 @@
*/
package jdk.incubator.http.internal.hpack;
import org.testng.annotations.Test;
+import java.io.IOException;
import java.io.UncheckedIOException;
-import java.net.ProtocolException;
import java.nio.ByteBuffer;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Supplier;
@@ -398,11 +398,11 @@
//
// This test is missing in the spec
//
@Test
- public void sizeUpdate() {
+ public void sizeUpdate() throws IOException {
Decoder d = new Decoder(4096);
assertEquals(d.getTable().maxSize(), 4096);
d.decode(ByteBuffer.wrap(new byte[]{0b00111110}), true, nopCallback()); // newSize = 30
assertEquals(d.getTable().maxSize(), 30);
}
@@ -419,38 +419,30 @@
e.header("a", "b");
e.encode(b);
b.flip();
{
Decoder d = new Decoder(4096);
- UncheckedIOException ex = assertVoidThrows(UncheckedIOException.class,
+ assertVoidThrows(IOException.class,
() -> d.decode(b, true, (name, value) -> { }));
-
- assertNotNull(ex.getCause());
- assertEquals(ex.getCause().getClass(), ProtocolException.class);
}
b.flip();
{
Decoder d = new Decoder(4096);
- UncheckedIOException ex = assertVoidThrows(UncheckedIOException.class,
+ assertVoidThrows(IOException.class,
() -> d.decode(b, false, (name, value) -> { }));
-
- assertNotNull(ex.getCause());
- assertEquals(ex.getCause().getClass(), ProtocolException.class);
}
}
@Test
public void corruptedHeaderBlockInteger() {
Decoder d = new Decoder(4096);
ByteBuffer data = ByteBuffer.wrap(new byte[]{
(byte) 0b11111111, // indexed
(byte) 0b10011010 // 25 + ...
});
- UncheckedIOException e = assertVoidThrows(UncheckedIOException.class,
+ IOException e = assertVoidThrows(IOException.class,
() -> d.decode(data, true, nopCallback()));
- assertNotNull(e.getCause());
- assertEquals(e.getCause().getClass(), ProtocolException.class);
assertExceptionMessageContains(e, "Unexpected end of header block");
}
// 5.1. Integer Representation
// ...
@@ -469,14 +461,14 @@
(byte) 0b11111111,
(byte) 0b11111111,
(byte) 0b00000111
});
- IllegalArgumentException e = assertVoidThrows(IllegalArgumentException.class,
+ IOException e = assertVoidThrows(IOException.class,
() -> d.decode(data, true, nopCallback()));
- assertExceptionMessageContains(e, "index=2147483647");
+ assertExceptionMessageContains(e.getCause(), "index=2147483647");
}
@Test
public void headerBlockIntegerOverflow() {
Decoder d = new Decoder(4096);
@@ -488,11 +480,11 @@
(byte) 0b11111111,
(byte) 0b11111111,
(byte) 0b00000111
});
- IllegalArgumentException e = assertVoidThrows(IllegalArgumentException.class,
+ IOException e = assertVoidThrows(IOException.class,
() -> d.decode(data, true, nopCallback()));
assertExceptionMessageContains(e, "Integer overflow");
}
@@ -505,14 +497,12 @@
0b00001000, // huffman=false, length=8
0b00000000, // \
0b00000000, // but only 3 octets available...
0b00000000 // /
});
- UncheckedIOException e = assertVoidThrows(UncheckedIOException.class,
+ IOException e = assertVoidThrows(IOException.class,
() -> d.decode(data, true, nopCallback()));
- assertNotNull(e.getCause());
- assertEquals(e.getCause().getClass(), ProtocolException.class);
assertExceptionMessageContains(e, "Unexpected end of header block");
}
@Test
public void corruptedHeaderBlockString2() {
@@ -525,14 +515,12 @@
0b00000000, // \
0b00000000, // but only 5 octets available...
0b00000000, // /
0b00000000 // /
});
- UncheckedIOException e = assertVoidThrows(UncheckedIOException.class,
+ IOException e = assertVoidThrows(IOException.class,
() -> d.decode(data, true, nopCallback()));
- assertNotNull(e.getCause());
- assertEquals(e.getCause().getClass(), ProtocolException.class);
assertExceptionMessageContains(e, "Unexpected end of header block");
}
// 5.2. String Literal Representation
// ...A Huffman-encoded string literal containing the EOS symbol MUST be
@@ -545,11 +533,11 @@
0b00000000,
(byte) 0b10000110, // huffman=true, length=6
0b00011001, 0b01001101, (byte) 0b11111111,
(byte) 0b11111111, (byte) 0b11111111, (byte) 0b11111100
});
- IllegalArgumentException e = assertVoidThrows(IllegalArgumentException.class,
+ IOException e = assertVoidThrows(IOException.class,
() -> d.decode(data, true, nopCallback()));
assertExceptionMessageContains(e, "Encountered EOS");
}
@@ -564,11 +552,11 @@
0b00000000,
(byte) 0b10000011, // huffman=true, length=3
0b00011001, 0b01001101, (byte) 0b11111111
// len("aei") + len(padding) = (5 + 5 + 5) + (9)
});
- IllegalArgumentException e = assertVoidThrows(IllegalArgumentException.class,
+ IOException e = assertVoidThrows(IOException.class,
() -> d.decode(data, true, nopCallback()));
assertExceptionMessageContains(e, "Padding is too long", "len=9");
}
@@ -595,11 +583,11 @@
0b00001111, // literal, index=15
0b00000000,
(byte) 0b10000011, // huffman=true, length=3
0b00011001, 0b01111010, (byte) 0b11111110
});
- IllegalArgumentException e = assertVoidThrows(IllegalArgumentException.class,
+ IOException e = assertVoidThrows(IOException.class,
() -> d.decode(data, true, nopCallback()));
assertExceptionMessageContains(e, "Not a EOS prefix");
}
@@ -646,17 +634,21 @@
return;
}
Decoder d = supplier.get();
do {
ByteBuffer n = i.next();
+ try {
d.decode(n, !i.hasNext(), (name, value) -> {
if (value == null) {
actual.add(name.toString());
} else {
actual.add(name + ": " + value);
}
});
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
} while (i.hasNext());
assertEquals(d.getTable().getStateString(), expectedHeaderTable);
assertEquals(actual.stream().collect(Collectors.joining("\n")), expectedHeaderList);
});
}
@@ -669,17 +661,21 @@
String expectedHeaderTable, String expectedHeaderList) {
ByteBuffer source = SpecHelper.toBytes(hexdump);
List<String> actual = new LinkedList<>();
+ try {
d.decode(source, true, (name, value) -> {
if (value == null) {
actual.add(name.toString());
} else {
actual.add(name + ": " + value);
}
});
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
assertEquals(d.getTable().getStateString(), expectedHeaderTable);
assertEquals(actual.stream().collect(Collectors.joining("\n")), expectedHeaderList);
}
< prev index next >