From 9b00435e864f6d6511cef04f0038809dcc92d37b Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Fri, 14 Oct 2016 20:25:35 -0700 Subject: [PATCH] Trying to reproduce #30, no luck yet --- .../cbor/mapper/NumberArrayBeanTest.java | 76 +++++++++++++++++ .../cbor/mapper/NumberBeanTest.java | 81 ++++++++----------- 2 files changed, 108 insertions(+), 49 deletions(-) create mode 100644 cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/NumberArrayBeanTest.java diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/NumberArrayBeanTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/NumberArrayBeanTest.java new file mode 100644 index 000000000..347a2e584 --- /dev/null +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/NumberArrayBeanTest.java @@ -0,0 +1,76 @@ +package com.fasterxml.jackson.dataformat.cbor.mapper; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.cbor.CBORTestBase; + +public class NumberArrayBeanTest extends CBORTestBase +{ + static class IntsWrapper { + public int[][] values; + + protected IntsWrapper() { } + public IntsWrapper(int[][] v) { values = v; } + } + + static class LongsWrapper { + public long[][] values; + + protected LongsWrapper() { } + public LongsWrapper(long[][] v) { values = v; } + } + + static class DoublesWrapper { + public double[][] values; + + protected DoublesWrapper() { } + public DoublesWrapper(double[][] v) { values = v; } + } + + /* + /********************************************************** + /* Test methods + /********************************************************** + */ + + private final ObjectMapper MAPPER = cborMapper(); + + public void testIntArrayRoundTrip() throws Exception + { + int[][] inputArray = new int[][]{ { -5, 3 } }; + byte[] cbor = MAPPER.writeValueAsBytes(new IntsWrapper(inputArray)); + IntsWrapper result = MAPPER.readValue(cbor, IntsWrapper.class); + assertNotNull(result); + assertNotNull(result.values); + assertEquals(1, result.values.length); + assertEquals(2, result.values[0].length); + assertEquals(inputArray[0][0], result.values[0][0]); + assertEquals(inputArray[0][1], result.values[0][1]); + } + + public void testLongArrayRoundTrip() throws Exception + { + long[][] inputArray = new long[][]{ { 3L + Integer.MAX_VALUE, -3L + Integer.MIN_VALUE } }; + byte[] cbor = MAPPER.writeValueAsBytes(new LongsWrapper(inputArray)); + LongsWrapper result = MAPPER.readValue(cbor, LongsWrapper.class); + assertNotNull(result); + assertNotNull(result.values); + assertEquals(1, result.values.length); + assertEquals(2, result.values[0].length); + assertEquals(inputArray[0][0], result.values[0][0]); + assertEquals(inputArray[0][1], result.values[0][1]); + } + + // for [dataformats-binary#31] + public void testDoubleArrayRoundTrip() throws Exception + { + double[][] inputArray = new double[][]{ { 0.25, -1.5 } }; + byte[] cbor = MAPPER.writeValueAsBytes(new DoublesWrapper(inputArray)); + DoublesWrapper result = MAPPER.readValue(cbor, DoublesWrapper.class); + assertNotNull(result); + assertNotNull(result.values); + assertEquals(1, result.values.length); + assertEquals(2, result.values[0].length); + assertEquals(inputArray[0][0], result.values[0][0]); + assertEquals(inputArray[0][1], result.values[0][1]); + } +} diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/NumberBeanTest.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/NumberBeanTest.java index ffb1c7720..fd104b488 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/NumberBeanTest.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/mapper/NumberBeanTest.java @@ -5,25 +5,18 @@ public class NumberBeanTest extends CBORTestBase { - static class IntsWrapper { - public int[][] values; + static class IntBean { + public int value; - protected IntsWrapper() { } - public IntsWrapper(int[][] v) { values = v; } + public IntBean(int v) { value = v; } + protected IntBean() { } } - static class LongsWrapper { - public long[][] values; + static class LongBean { + public long value; - protected LongsWrapper() { } - public LongsWrapper(long[][] v) { values = v; } - } - - static class DoublesWrapper { - public double[][] values; - - protected DoublesWrapper() { } - public DoublesWrapper(double[][] v) { values = v; } + public LongBean(long v) { value = v; } + protected LongBean() { } } /* @@ -34,43 +27,33 @@ protected DoublesWrapper() { } private final ObjectMapper MAPPER = cborMapper(); - public void testIntArrayRoundTrip() throws Exception + public void testIntRoundTrip() throws Exception { - int[][] inputArray = new int[][]{ { -5, 3 } }; - byte[] cbor = MAPPER.writeValueAsBytes(new IntsWrapper(inputArray)); - IntsWrapper result = MAPPER.readValue(cbor, IntsWrapper.class); - assertNotNull(result); - assertNotNull(result.values); - assertEquals(1, result.values.length); - assertEquals(2, result.values[0].length); - assertEquals(inputArray[0][0], result.values[0][0]); - assertEquals(inputArray[0][1], result.values[0][1]); + for (int i : new int[] { 0, 1, -1, + 99, -120, + 5500, -9000, + Integer.MIN_VALUE, Integer.MAX_VALUE }) { + IntBean input = new IntBean(i); + byte[] b = MAPPER.writeValueAsBytes(input); + IntBean result = MAPPER.readValue(b, IntBean.class); + assertEquals(input.value, result.value); + } } - public void testLongArrayRoundTrip() throws Exception - { - long[][] inputArray = new long[][]{ { 3L + Integer.MAX_VALUE, -3L + Integer.MIN_VALUE } }; - byte[] cbor = MAPPER.writeValueAsBytes(new LongsWrapper(inputArray)); - LongsWrapper result = MAPPER.readValue(cbor, LongsWrapper.class); - assertNotNull(result); - assertNotNull(result.values); - assertEquals(1, result.values.length); - assertEquals(2, result.values[0].length); - assertEquals(inputArray[0][0], result.values[0][0]); - assertEquals(inputArray[0][1], result.values[0][1]); - } - - // for [dataformats-binary#31] - public void testDoubleArrayRoundTrip() throws Exception + public void testLongRoundTrip() throws Exception { - double[][] inputArray = new double[][]{ { 0.25, -1.5 } }; - byte[] cbor = MAPPER.writeValueAsBytes(new DoublesWrapper(inputArray)); - DoublesWrapper result = MAPPER.readValue(cbor, DoublesWrapper.class); - assertNotNull(result); - assertNotNull(result.values); - assertEquals(1, result.values.length); - assertEquals(2, result.values[0].length); - assertEquals(inputArray[0][0], result.values[0][0]); - assertEquals(inputArray[0][1], result.values[0][1]); + for (long v : new long[] { 0, 1, -1, + 100L, -200L, + 5000L, -3600L, + Integer.MIN_VALUE, Integer.MAX_VALUE, + 1L + Integer.MAX_VALUE, -1L + Integer.MIN_VALUE, + 2330462449L, // from [dataformats-binary#30] + Long.MIN_VALUE, Long.MAX_VALUE + }) { + LongBean input = new LongBean(v); + byte[] b = MAPPER.writeValueAsBytes(input); + LongBean result = MAPPER.readValue(b, LongBean.class); + assertEquals(input.value, result.value); + } } }