Skip to content

Commit 9b00435

Browse files
committed
Trying to reproduce #30, no luck yet
1 parent a91c259 commit 9b00435

File tree

2 files changed

+108
-49
lines changed

2 files changed

+108
-49
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package com.fasterxml.jackson.dataformat.cbor.mapper;
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import com.fasterxml.jackson.dataformat.cbor.CBORTestBase;
5+
6+
public class NumberArrayBeanTest extends CBORTestBase
7+
{
8+
static class IntsWrapper {
9+
public int[][] values;
10+
11+
protected IntsWrapper() { }
12+
public IntsWrapper(int[][] v) { values = v; }
13+
}
14+
15+
static class LongsWrapper {
16+
public long[][] values;
17+
18+
protected LongsWrapper() { }
19+
public LongsWrapper(long[][] v) { values = v; }
20+
}
21+
22+
static class DoublesWrapper {
23+
public double[][] values;
24+
25+
protected DoublesWrapper() { }
26+
public DoublesWrapper(double[][] v) { values = v; }
27+
}
28+
29+
/*
30+
/**********************************************************
31+
/* Test methods
32+
/**********************************************************
33+
*/
34+
35+
private final ObjectMapper MAPPER = cborMapper();
36+
37+
public void testIntArrayRoundTrip() throws Exception
38+
{
39+
int[][] inputArray = new int[][]{ { -5, 3 } };
40+
byte[] cbor = MAPPER.writeValueAsBytes(new IntsWrapper(inputArray));
41+
IntsWrapper result = MAPPER.readValue(cbor, IntsWrapper.class);
42+
assertNotNull(result);
43+
assertNotNull(result.values);
44+
assertEquals(1, result.values.length);
45+
assertEquals(2, result.values[0].length);
46+
assertEquals(inputArray[0][0], result.values[0][0]);
47+
assertEquals(inputArray[0][1], result.values[0][1]);
48+
}
49+
50+
public void testLongArrayRoundTrip() throws Exception
51+
{
52+
long[][] inputArray = new long[][]{ { 3L + Integer.MAX_VALUE, -3L + Integer.MIN_VALUE } };
53+
byte[] cbor = MAPPER.writeValueAsBytes(new LongsWrapper(inputArray));
54+
LongsWrapper result = MAPPER.readValue(cbor, LongsWrapper.class);
55+
assertNotNull(result);
56+
assertNotNull(result.values);
57+
assertEquals(1, result.values.length);
58+
assertEquals(2, result.values[0].length);
59+
assertEquals(inputArray[0][0], result.values[0][0]);
60+
assertEquals(inputArray[0][1], result.values[0][1]);
61+
}
62+
63+
// for [dataformats-binary#31]
64+
public void testDoubleArrayRoundTrip() throws Exception
65+
{
66+
double[][] inputArray = new double[][]{ { 0.25, -1.5 } };
67+
byte[] cbor = MAPPER.writeValueAsBytes(new DoublesWrapper(inputArray));
68+
DoublesWrapper result = MAPPER.readValue(cbor, DoublesWrapper.class);
69+
assertNotNull(result);
70+
assertNotNull(result.values);
71+
assertEquals(1, result.values.length);
72+
assertEquals(2, result.values[0].length);
73+
assertEquals(inputArray[0][0], result.values[0][0]);
74+
assertEquals(inputArray[0][1], result.values[0][1]);
75+
}
76+
}

cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/NumberBeanTest.java

Lines changed: 32 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,18 @@
55

66
public class NumberBeanTest extends CBORTestBase
77
{
8-
static class IntsWrapper {
9-
public int[][] values;
8+
static class IntBean {
9+
public int value;
1010

11-
protected IntsWrapper() { }
12-
public IntsWrapper(int[][] v) { values = v; }
11+
public IntBean(int v) { value = v; }
12+
protected IntBean() { }
1313
}
1414

15-
static class LongsWrapper {
16-
public long[][] values;
15+
static class LongBean {
16+
public long value;
1717

18-
protected LongsWrapper() { }
19-
public LongsWrapper(long[][] v) { values = v; }
20-
}
21-
22-
static class DoublesWrapper {
23-
public double[][] values;
24-
25-
protected DoublesWrapper() { }
26-
public DoublesWrapper(double[][] v) { values = v; }
18+
public LongBean(long v) { value = v; }
19+
protected LongBean() { }
2720
}
2821

2922
/*
@@ -34,43 +27,33 @@ protected DoublesWrapper() { }
3427

3528
private final ObjectMapper MAPPER = cborMapper();
3629

37-
public void testIntArrayRoundTrip() throws Exception
30+
public void testIntRoundTrip() throws Exception
3831
{
39-
int[][] inputArray = new int[][]{ { -5, 3 } };
40-
byte[] cbor = MAPPER.writeValueAsBytes(new IntsWrapper(inputArray));
41-
IntsWrapper result = MAPPER.readValue(cbor, IntsWrapper.class);
42-
assertNotNull(result);
43-
assertNotNull(result.values);
44-
assertEquals(1, result.values.length);
45-
assertEquals(2, result.values[0].length);
46-
assertEquals(inputArray[0][0], result.values[0][0]);
47-
assertEquals(inputArray[0][1], result.values[0][1]);
32+
for (int i : new int[] { 0, 1, -1,
33+
99, -120,
34+
5500, -9000,
35+
Integer.MIN_VALUE, Integer.MAX_VALUE }) {
36+
IntBean input = new IntBean(i);
37+
byte[] b = MAPPER.writeValueAsBytes(input);
38+
IntBean result = MAPPER.readValue(b, IntBean.class);
39+
assertEquals(input.value, result.value);
40+
}
4841
}
4942

50-
public void testLongArrayRoundTrip() throws Exception
51-
{
52-
long[][] inputArray = new long[][]{ { 3L + Integer.MAX_VALUE, -3L + Integer.MIN_VALUE } };
53-
byte[] cbor = MAPPER.writeValueAsBytes(new LongsWrapper(inputArray));
54-
LongsWrapper result = MAPPER.readValue(cbor, LongsWrapper.class);
55-
assertNotNull(result);
56-
assertNotNull(result.values);
57-
assertEquals(1, result.values.length);
58-
assertEquals(2, result.values[0].length);
59-
assertEquals(inputArray[0][0], result.values[0][0]);
60-
assertEquals(inputArray[0][1], result.values[0][1]);
61-
}
62-
63-
// for [dataformats-binary#31]
64-
public void testDoubleArrayRoundTrip() throws Exception
43+
public void testLongRoundTrip() throws Exception
6544
{
66-
double[][] inputArray = new double[][]{ { 0.25, -1.5 } };
67-
byte[] cbor = MAPPER.writeValueAsBytes(new DoublesWrapper(inputArray));
68-
DoublesWrapper result = MAPPER.readValue(cbor, DoublesWrapper.class);
69-
assertNotNull(result);
70-
assertNotNull(result.values);
71-
assertEquals(1, result.values.length);
72-
assertEquals(2, result.values[0].length);
73-
assertEquals(inputArray[0][0], result.values[0][0]);
74-
assertEquals(inputArray[0][1], result.values[0][1]);
45+
for (long v : new long[] { 0, 1, -1,
46+
100L, -200L,
47+
5000L, -3600L,
48+
Integer.MIN_VALUE, Integer.MAX_VALUE,
49+
1L + Integer.MAX_VALUE, -1L + Integer.MIN_VALUE,
50+
2330462449L, // from [dataformats-binary#30]
51+
Long.MIN_VALUE, Long.MAX_VALUE
52+
}) {
53+
LongBean input = new LongBean(v);
54+
byte[] b = MAPPER.writeValueAsBytes(input);
55+
LongBean result = MAPPER.readValue(b, LongBean.class);
56+
assertEquals(input.value, result.value);
57+
}
7558
}
7659
}

0 commit comments

Comments
 (0)