Skip to content

Commit

Permalink
v2.0, renamed FormatException to BinsonFormatException, v2.0 release,…
Browse files Browse the repository at this point in the history
… a few more tests
  • Loading branch information
franslundberg committed Sep 26, 2017
1 parent 64341ec commit c96a296
Show file tree
Hide file tree
Showing 24 changed files with 179 additions and 126 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ Log

Log entries, latest entry first, format: YYMMDD.

## 170926

Frans: Release 2.0. Renaming: FormatException to BinsonFormatException.
Stable code: No known bugs, 225 successful unit tests, good coverage, no warnings.
There has been zero known bugs since November 2015 and the library has been used
heavily since then. Perhaps fuzz testing could find a few bugs, though? Would be
interesting to try https://github.com/nradov/abnffuzzer.


## 170816

Frans: Release 1.5. The BinsonArray.getXxx() method now throws
Expand Down
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Instructions:
<project name="binson" default="build" basedir=".">

<target name="init" description="Initializes properties and prints version, release, and build.">
<property name="release" value="1.6-dev"/> <!-- CHANGE for release build -->
<property name="release" value="2.0"/> <!-- CHANGE -->

<tstamp>
<format property="dateString" pattern="yyMMdd" />
Expand Down
2 changes: 1 addition & 1 deletion src-test/org/binson/ArrayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void testHas() {
assertFalse(obj.hasBoolean("a"));
}

@Test(expected=FormatException.class)
@Test(expected=BinsonFormatException.class)
public void testNonExistant() {
obj.getArray("b");
}
Expand Down
16 changes: 8 additions & 8 deletions src-test/org/binson/BinsonArrayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public void testSanity() {
Assert.assertEquals(1234, a.getInteger(0));
}

@Test(expected=FormatException.class)
@Test(expected=BinsonFormatException.class)
public void testThatGetIntegerThrowsExceptionWhenFieldHasUnexpectedType() {
BinsonArray a = new BinsonArray().add(12.33);
a.getInteger(0);
Expand All @@ -31,7 +31,7 @@ public void testGetBoolean2() {
Assert.assertEquals(true, a.getBoolean(2));
}

@Test(expected=FormatException.class)
@Test(expected=BinsonFormatException.class)
public void testGetBoolean3() {
BinsonArray a = new BinsonArray().add(false).add(1234);
Assert.assertEquals(false, a.getBoolean(0));
Expand All @@ -44,7 +44,7 @@ public void testGetInteger1() {
Assert.assertEquals(1234, a.getInteger(1));
}

@Test(expected=FormatException.class)
@Test(expected=BinsonFormatException.class)
public void testGetInteger2() {
BinsonArray a = new BinsonArray().add("hello").add(1234);
a.getInteger(0);
Expand All @@ -56,7 +56,7 @@ public void testGetDouble1() {
Assert.assertEquals(12.33, a.getDouble(0), 1e-9);
}

@Test(expected=FormatException.class)
@Test(expected=BinsonFormatException.class)
public void testGetDouble2() {
BinsonArray a = new BinsonArray().add(12.33).add("hello");
a.getDouble(1);
Expand All @@ -68,7 +68,7 @@ public void testGetString1() {
Assert.assertEquals("hello", a.getString(0));
}

@Test(expected=FormatException.class)
@Test(expected=BinsonFormatException.class)
public void testGetString2() {
BinsonArray a = new BinsonArray().add(1234);
a.getString(0);
Expand All @@ -80,7 +80,7 @@ public void testGetBytes1() {
Assert.assertArrayEquals(new byte[]{1, 2, 3}, a.getBytes(1));
}

@Test(expected=FormatException.class)
@Test(expected=BinsonFormatException.class)
public void testGetBytes2() {
BinsonArray a = new BinsonArray().add("hello").add(new byte[]{1, 2, 3});
a.getBytes(0);
Expand All @@ -97,7 +97,7 @@ public void testGetArray1() {
Assert.assertEquals(2, inner.getInteger(1));
}

@Test(expected=FormatException.class)
@Test(expected=BinsonFormatException.class)
public void testGetArray2() {
BinsonArray a = new BinsonArray()
.add("hello")
Expand All @@ -115,7 +115,7 @@ public void testGetObject1() {
Assert.assertEquals(22, inner.getInteger("two"));
}

@Test(expected=FormatException.class)
@Test(expected=BinsonFormatException.class)
public void testGetObject2() {
BinsonArray a = new BinsonArray()
.add("hello")
Expand Down
2 changes: 1 addition & 1 deletion src-test/org/binson/BooleanTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void testHas() {
assertFalse(obj.hasBoolean("a"));
}

@Test(expected=FormatException.class)
@Test(expected=BinsonFormatException.class)
public void testNonExistant() {
Binson obj = new Binson().put("b", false);
obj.getBoolean("a");
Expand Down
2 changes: 1 addition & 1 deletion src-test/org/binson/BytesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void testHas() {
assertFalse(obj.hasBytes("aaa"));
}

@Test(expected=FormatException.class)
@Test(expected=BinsonFormatException.class)
public void testGetNonExistant() {
obj.getBytes("b");
}
Expand Down
2 changes: 1 addition & 1 deletion src-test/org/binson/DoubleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void testHas() {
assertTrue(obj.hasDouble("a"));
}

@Test(expected=FormatException.class)
@Test(expected=BinsonFormatException.class)
public void testNonExistant() {
obj.getDouble("b");
}
Expand Down
4 changes: 2 additions & 2 deletions src-test/org/binson/FromBinsonStringTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.binson.lowlevel.StringFormatException;
import org.binson.lowlevel.StringBinsonFormatException;
import org.junit.Test;

public class FromBinsonStringTest {
Expand Down Expand Up @@ -61,7 +61,7 @@ public void testMaxInteger() {
assertEquals(9223372036854775807L, obj.getInteger("a"));
}

@Test(expected=StringFormatException.class)
@Test(expected=StringBinsonFormatException.class)
public void testToBigInteger() {
String s = "{a:9223372036854775808}"; // 2^63
Binson.fromBinsonString(s);
Expand Down
4 changes: 2 additions & 2 deletions src-test/org/binson/IntegerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public void testHas() {
assertFalse(obj.hasBoolean("a"));
}

@Test(expected=FormatException.class)
@Test(expected=BinsonFormatException.class)
public void testNonExistant1() {
new Binson().getInteger("b");
}

@Test(expected=FormatException.class)
@Test(expected=BinsonFormatException.class)
public void testNonExistant2() {
new Binson().put("bbb", 1).getInteger("b");
}
Expand Down
38 changes: 38 additions & 0 deletions src-test/org/binson/InvalidDataTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.binson;

import org.junit.Test;

/**
* Tests invalid Binson byte arrays.
*
* @author Frans Lundberg
*/
public class InvalidDataTest {

@Test(expected=BinsonFormatException.class)
public void testEmptyByteArray() {
byte[] bytes = new byte[]{};
Binson.fromBytes(bytes);
}

@Test(expected=BinsonFormatException.class)
public void testBadEndByte1() {
byte[] bytes = new Binson().put("a", 1).toBytes();
int last = bytes.length - 1;
bytes[last] = (byte) (bytes[last] - 1);
Binson.fromBytes(bytes);
}

@Test(expected=BinsonFormatException.class)
public void testBadEndByte2() {
byte[] small = new byte[]{0x40, 0x40};
Binson.fromBytes(small);
}

@Test(expected=BinsonFormatException.class)
public void testIntWhereFieldNameExpected() {
// {0x40, 0x14, 1, 'a', 0x44, 0x41} = {"a": true}
byte[] data = new byte[]{0x40, 0x44, 1, 'a', 0x44, 0x41};
Binson.fromBytes(data);
}
}
2 changes: 1 addition & 1 deletion src-test/org/binson/ObjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void testHas() {
assertFalse(obj.hasString("a"));
}

@Test(expected=FormatException.class)
@Test(expected=BinsonFormatException.class)
public void testNonExistant() {
obj.getObject("b");
}
Expand Down
2 changes: 1 addition & 1 deletion src-test/org/binson/StringTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void testHas() {
assertFalse(obj.hasInteger("s"));
}

@Test(expected=FormatException.class)
@Test(expected=BinsonFormatException.class)
public void testNonExistant() {
obj.getString("s2");
}
Expand Down
36 changes: 18 additions & 18 deletions src-test/org/binson/TextParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.io.StringReader;

import org.binson.lowlevel.JsonNull;
import org.binson.lowlevel.StringFormatException;
import org.binson.lowlevel.StringBinsonFormatException;
import org.binson.lowlevel.TextParser;
import org.binson.lowlevel.TextReader;
import org.junit.Assert;
Expand Down Expand Up @@ -76,7 +76,7 @@ public void testOneField() {
assertEquals(true, obj.getBoolean("a"));
}

@Test(expected=StringFormatException.class)
@Test(expected=StringBinsonFormatException.class)
public void testTruE() {
obj("{\"a\":truE}");
assertEquals(true, obj.getBoolean("a"));
Expand All @@ -87,7 +87,7 @@ public void testFalse() {
assertEquals(false, obj.getBoolean("a"));
}

@Test(expected=StringFormatException.class)
@Test(expected=StringBinsonFormatException.class)
public void testFalsE() {
obj("{\"a\":falsE}");
}
Expand All @@ -98,7 +98,7 @@ public void testNull() {
assertEquals(JsonNull.NULL, obj.get("a"));
}

@Test(expected=StringFormatException.class)
@Test(expected=StringBinsonFormatException.class)
public void testNuLL() {
obj("{\"a\":nuLL}");
}
Expand Down Expand Up @@ -225,7 +225,7 @@ public void testInt0() {
assertEquals(0, obj.getInteger("a"));
}

@Test(expected=StringFormatException.class)
@Test(expected=StringBinsonFormatException.class)
public void testIntPlus() {
// This is not valid.
a("+120");
Expand All @@ -238,12 +238,12 @@ public void testIntNeg() {
assertEquals(-123, obj.getInteger("a"));
}

@Test(expected=StringFormatException.class)
@Test(expected=StringBinsonFormatException.class)
public void testIntBad1() {
a("-1222333444555666L");
}

@Test(expected=StringFormatException.class)
@Test(expected=StringBinsonFormatException.class)
public void testIntBad2() {
a("-1222_333_444555666");
}
Expand All @@ -260,12 +260,12 @@ public void testIntSmallest() {
assertEquals(-9223372036854775808L, obj.getInteger("a"));
}

@Test(expected=StringFormatException.class)
@Test(expected=StringBinsonFormatException.class)
public void testIntTooLarge() {
a("9223372036854775808");
}

@Test(expected=StringFormatException.class)
@Test(expected=StringBinsonFormatException.class)
public void testIntTooSmall() {
a("-9223372036854775809");
}
Expand All @@ -282,7 +282,7 @@ public void testFracNeg() {
assertTrue(-1.23 == obj.getDouble("a"));
}

@Test(expected=StringFormatException.class)
@Test(expected=StringBinsonFormatException.class)
public void testFracPlus() {
a("+1.23"); // not valid
assertTrue(+1.23 == obj.getDouble("a"));
Expand All @@ -300,12 +300,12 @@ public void testFracExp2() {
assertTrue(0.00012e+19 == obj.getDouble("a"));
}

@Test(expected=StringFormatException.class)
@Test(expected=StringBinsonFormatException.class)
public void testFracBad1() {
a("01.23");
}

@Test(expected=StringFormatException.class)
@Test(expected=StringBinsonFormatException.class)
public void testFracBad2() {
a(".12");
}
Expand All @@ -322,12 +322,12 @@ public void testFracExp4() {
assertTrue(11234e212 == obj.getDouble("a"));
}

@Test(expected=StringFormatException.class)
@Test(expected=StringBinsonFormatException.class)
public void testFracTooLarge() {
a("1.2e+400");
}

@Test(expected=StringFormatException.class)
@Test(expected=StringBinsonFormatException.class)
public void testFracTooSmall() {
a("-1.2e+400");
}
Expand All @@ -339,7 +339,7 @@ public void testSpecialNaN1() {
assertTrue(Double.isNaN(d));
}

@Test(expected=StringFormatException.class)
@Test(expected=StringBinsonFormatException.class)
public void testSpecialNaN2() {
a("NaN");
}
Expand All @@ -358,12 +358,12 @@ public void testSpecialNegInf() {
assertTrue(d == Double.NEGATIVE_INFINITY);
}

@Test(expected=StringFormatException.class)
@Test(expected=StringBinsonFormatException.class)
public void testSpecialInf2() {
a("inf");
}

@Test(expected=StringFormatException.class)
@Test(expected=StringBinsonFormatException.class)
public void testSpecialInf3() {
a("-inf");
}
Expand Down Expand Up @@ -392,7 +392,7 @@ public void bytesLonger() {
Assert.assertArrayEquals(arr, obj.getBytes("a"));
}

@Test(expected=StringFormatException.class)
@Test(expected=StringBinsonFormatException.class)
public void bytesOddHexCount() {
a("x012");
}
Expand Down
Loading

0 comments on commit c96a296

Please sign in to comment.