Skip to content

Commit

Permalink
Merge branch '2.19'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 14, 2025
2 parents 5ad4e50 + 697797b commit 4a6a7b4
Show file tree
Hide file tree
Showing 77 changed files with 653 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import java.math.BigInteger;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Stack;
import java.util.*;

import tools.jackson.core.*;
import tools.jackson.core.base.ParserBase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

import java.io.ByteArrayOutputStream;

import org.junit.jupiter.api.Test;

import tools.jackson.core.JsonParser;
import tools.jackson.core.JsonToken;
import tools.jackson.core.exc.StreamReadException;

import tools.jackson.databind.ObjectMapper;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

// Mostly for [dataformats-binary#186]: corrupt encoding indicating humongous payload
public class BrokenLongBinary186Test extends CBORTestBase
{
Expand All @@ -20,12 +25,14 @@ public class BrokenLongBinary186Test extends CBORTestBase
*/

// [dataformats-binary#186]
@Test
public void testCorruptVeryLongBinary() throws Exception {
// Let's do about 2 GB to likely trigger failure
_testCorruptLong(1_999_999_999, 95000);
}

// [dataformats-binary#186]
@Test
public void testCorruptQuiteLongBinary() throws Exception {
// Value below limit for chunked handling
_testCorruptLong(CBORParser.LONGEST_NON_CHUNKED_BINARY >> 1, 37);
Expand All @@ -51,6 +58,7 @@ private void _testCorruptLong(int allegedLength, int actualIncluded)
*/

// [dataformats-binary#186]
@Test
public void testQuiteLongStreaming() throws Exception
{
// Can try bit shorter here, like 500 megs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import java.io.*;

import org.junit.jupiter.api.Test;

import tools.jackson.core.*;

import tools.jackson.databind.ObjectMapper;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.*;

/**
* Miscellaneous tests for {@link CBORFactory}, and for some aspects
Expand All @@ -18,6 +20,7 @@ public class CBORFactoryPropertiesTest extends CBORTestBase

private final static CBORFactory CBOR_F = new CBORFactory();

@Test
public void testCBORFactorySerializable() throws Exception
{
CBORFactory f = new CBORFactory();
Expand All @@ -32,6 +35,7 @@ public void testCBORFactorySerializable() throws Exception
assertArrayEquals(doc, docOut);
}

@Test
public void testCBORFactoryCopy() throws Exception
{
CBORFactory f2 = CBOR_F.copy();
Expand All @@ -52,6 +56,7 @@ private byte[] cborDoc(TokenStreamFactory f, String json) throws IOException
}
}

@Test
public void testVersions() throws Exception
{
ObjectMapper mapper = sharedMapper();
Expand All @@ -69,13 +74,15 @@ public void testVersions() throws Exception
p.close();
}

@Test
public void testCapabilities() throws Exception
{
assertTrue(CBOR_F.canHandleBinaryNatively());
assertEquals(null, CBOR_F.getFormatReadFeatureType());
assertEquals(CBORWriteFeature.class, CBOR_F.getFormatWriteFeatureType());
}

@Test
public void testInabilityToReadChars() throws Exception
{
final String EXP = "Cannot create parser for character-based (not byte-based)";
Expand All @@ -99,6 +106,7 @@ public void testInabilityToReadChars() throws Exception
}
}

@Test
public void testInabilityToWriteChars() throws Exception
{
try {
Expand Down
20 changes: 8 additions & 12 deletions cbor/src/test/java/tools/jackson/dataformat/cbor/CBORTestBase.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
package tools.jackson.dataformat.cbor;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Random;

import org.junit.Assert;

import tools.jackson.core.*;

import tools.jackson.databind.ObjectMapper;
Expand All @@ -18,8 +13,9 @@

import tools.jackson.dataformat.cbor.databind.CBORMapper;

import static org.junit.jupiter.api.Assertions.*;

public abstract class CBORTestBase
extends junit.framework.TestCase
{
// From JSON specification, sample doc...
protected final static int SAMPLE_SPEC_VALUE_WIDTH = 800;
Expand Down Expand Up @@ -228,22 +224,22 @@ protected void verifyException(Throwable e, String... matches)
}

protected void _verifyBytes(byte[] actBytes, byte... expBytes) {
Assert.assertArrayEquals(expBytes, actBytes);
assertArrayEquals(expBytes, actBytes);
}

protected void _verifyBytes(byte[] actBytes, byte exp1, byte[] expRest) {
byte[] expBytes = new byte[expRest.length+1];
System.arraycopy(expRest, 0, expBytes, 1, expRest.length);
expBytes[0] = exp1;
Assert.assertArrayEquals(expBytes, actBytes);
assertArrayEquals(expBytes, actBytes);
}

protected void _verifyBytes(byte[] actBytes, byte exp1, byte exp2, byte[] expRest) {
byte[] expBytes = new byte[expRest.length+2];
System.arraycopy(expRest, 0, expBytes, 2, expRest.length);
expBytes[0] = exp1;
expBytes[1] = exp2;
Assert.assertArrayEquals(expBytes, actBytes);
assertArrayEquals(expBytes, actBytes);
}

protected void _verifyBytes(byte[] actBytes, byte exp1, byte exp2, byte exp3, byte[] expRest) {
Expand All @@ -252,7 +248,7 @@ protected void _verifyBytes(byte[] actBytes, byte exp1, byte exp2, byte exp3, by
expBytes[0] = exp1;
expBytes[1] = exp2;
expBytes[2] = exp3;
Assert.assertArrayEquals(expBytes, actBytes);
assertArrayEquals(expBytes, actBytes);
}

/**
Expand All @@ -271,7 +267,7 @@ protected String getAndVerifyText(JsonParser p) throws IOException
if (str.length() != actLen) {
fail("Internal problem (p.token == "+p.currentToken()+"): p.getText().length() ['"+str+"'] == "+str.length()+"; p.getTextLength() == "+actLen);
}
assertEquals("String access via getText(), getTextXxx() must be the same", str, str2);
assertEquals(str, str2, "String access via getText(), getTextXxx() must be the same");

return str;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import java.io.ByteArrayOutputStream;
import java.math.BigDecimal;

import static org.junit.Assert.assertArrayEquals;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;

// for [jackson-core#730]
public class FloatPrecisionTest extends CBORTestBase
{
// for [jackson-core#730]
@Test
public void testFloatRoundtrips() throws Exception
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package tools.jackson.dataformat.cbor;

import org.junit.jupiter.api.Test;

import tools.jackson.core.JsonParser;
import tools.jackson.core.StreamReadCapability;
import tools.jackson.databind.ObjectMapper;

import static org.junit.jupiter.api.Assertions.assertTrue;

public class FormatDefaultsTest extends CBORTestBase
{
private final ObjectMapper MAPPER = cborMapper();

@Test
public void testParserDefaults() throws Exception
{
try (JsonParser p = MAPPER.createParser(new byte[4])) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
package tools.jackson.dataformat.cbor;

import java.io.ByteArrayOutputStream;
import java.util.*;
import java.util.List;
import java.util.Map;

import org.junit.jupiter.api.Test;

import tools.jackson.core.JsonGenerator;

import tools.jackson.databind.ObjectMapper;

import tools.jackson.dataformat.cbor.databind.CBORMapper;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class GeneratorDeepNestingTest extends CBORTestBase
{
private final ObjectMapper MAPPER = CBORMapper.shared();

// for [dataformats-binary#62]
@SuppressWarnings("unchecked")
@Test
public void testDeeplyNestedMap() throws Exception
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
Expand Down Expand Up @@ -62,6 +68,7 @@ private void _verifyNestedMap(Map<String,?> map, int level) {
}
}

@Test
public void testDeeplyNestedArray() throws Exception
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package tools.jackson.dataformat.cbor;

import java.io.*;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import org.junit.jupiter.api.Test;

import tools.jackson.core.*;
import tools.jackson.core.exc.StreamWriteException;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.fail;

public class GeneratorDupHandlingTest extends CBORTestBase
{
@Test
public void testSimpleDupsEagerlyBytes() throws Exception {
_testSimpleDups(false, new CBORFactory());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import java.io.ByteArrayOutputStream;

import org.junit.jupiter.api.Test;

import tools.jackson.core.ObjectWriteContext;

import static org.junit.jupiter.api.Assertions.assertFalse;

/**
* Unit tests geared at testing issues that were raised due to
* inter-operability with other CBOR codec implementations
Expand All @@ -18,6 +22,7 @@ public class GeneratorInteropTest extends CBORTestBase
};

// Test for [Issue#6], for optional writing of CBOR Type Description Tag
@Test
public void testTypeDescriptionTag() throws Exception
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
Expand All @@ -30,6 +35,7 @@ public void testTypeDescriptionTag() throws Exception
_verifyBytes(out.toByteArray(), TYPE_DESC_AND_TRUE);
}

@Test
public void testAutoTypeDescription() throws Exception
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import tools.jackson.core.exc.StreamWriteException;

import static org.junit.jupiter.api.Assertions.fail;

public class GeneratorInvalidCallsTest extends CBORTestBase
{
public void testInvalidFieldNameInRoot()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package tools.jackson.dataformat.cbor;

import java.io.*;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.*;

import org.junit.jupiter.api.Test;

import tools.jackson.core.*;
import tools.jackson.core.io.SerializedString;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class GeneratorLongStringTest extends CBORTestBase
{
final static int DOC_LEN = 2000000; // 2 meg test doc

@Test
public void testLongWithMultiBytes() throws Exception
{
ArrayList<String> strings = new ArrayList<String>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

import java.io.ByteArrayOutputStream;

import org.junit.jupiter.api.Test;

import tools.jackson.core.JsonParser;
import tools.jackson.core.JsonToken;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

public class GeneratorShortStringTest extends CBORTestBase
{
@Test
public void testEmptyString() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (CBORGenerator gen = cborGenerator(out)) {
Expand All @@ -25,6 +31,7 @@ public void testEmptyString() throws Exception {
_verifyBytes(out.toByteArray(), CBORConstants.BYTE_EMPTY_STRING);
}

@Test
public void testShortTextAsString() throws Exception {
for (int len = 1; len <= 23; ++len) {
final String value = generateAsciiString(len);
Expand All @@ -40,6 +47,7 @@ public void testShortTextAsString() throws Exception {
}
}

@Test
public void testShortTextAsCharArray() throws Exception {
for (int len = 1; len <= 23; ++len) {
final String value = generateAsciiString(len);
Expand All @@ -55,6 +63,7 @@ public void testShortTextAsCharArray() throws Exception {
}
}

@Test
public void testMediumTextAsString() throws Exception {
for (int len = 24; len <= 255; ++len) {
final String value = generateAsciiString(len);
Expand All @@ -71,6 +80,7 @@ public void testMediumTextAsString() throws Exception {
}
}

@Test
public void testMediumTextAsCharArray() throws Exception {
for (int len = 24; len <= 255; ++len) {
final String value = generateAsciiString(len);
Expand Down
Loading

0 comments on commit 4a6a7b4

Please sign in to comment.