Enhance Parser decode

* Avoid using expected IndexOutOfBound exception
* Add few more error checks
* Add few malformated message error test cases
This commit is contained in:
Nicolas Milliard
2015-03-16 15:13:40 -07:00
parent 148608b252
commit 296aef8799
3 changed files with 62 additions and 29 deletions

View File

@@ -11,7 +11,6 @@ public class ParserTest {
private static Parser.Encoder encoder = new Parser.Encoder();
@Test
public void encodeConnection() {
Packet packet = new Packet(Parser.CONNECT);
@@ -47,4 +46,22 @@ public class ParserTest {
packet.nsp = "/";
Helpers.test(packet);
}
@Test
public void decodeInError() throws JSONException {
// Random string
Helpers.testDecodeError("asdf");
// Unknown type
Helpers.testDecodeError(Parser.types.length + "asdf");
// Binary event with no `-`
Helpers.testDecodeError(Parser.BINARY_EVENT + "asdf");
// Binary ack with no `-`
Helpers.testDecodeError(Parser.BINARY_ACK + "asdf");
// Binary event with no attachment
Helpers.testDecodeError(String.valueOf(Parser.BINARY_EVENT));
// event non numeric id
Helpers.testDecodeError(Parser.EVENT + "2sd");
// event with invalid json data
Helpers.testDecodeError(Parser.EVENT + "2[\"a\",1,{asdf}]");
}
}