Skip to content

Commit

Permalink
Merge branch '2.19' into joohyukkim/2.19/523-properties-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder authored Jan 12, 2025
2 parents 3981302 + de01c68 commit 1a54d40
Show file tree
Hide file tree
Showing 18 changed files with 449 additions and 453 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
package com.fasterxml.jackson.dataformat.toml;

import java.io.IOException;
import java.io.Reader;
import java.math.BigDecimal;
import java.time.*;
import java.time.temporal.Temporal;

import com.fasterxml.jackson.core.StreamReadFeature;
import com.fasterxml.jackson.core.exc.StreamConstraintsException;
import com.fasterxml.jackson.core.io.IOContext;
import com.fasterxml.jackson.core.io.NumberInput;
import com.fasterxml.jackson.core.util.VersionUtil;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.node.ValueNode;

import java.io.IOException;
import java.io.Reader;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.temporal.Temporal;
import com.fasterxml.jackson.databind.node.*;

class Parser {
private static final JsonNodeFactory factory = new JsonNodeFactoryImpl();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
package com.fasterxml.jackson.dataformat.toml;

import java.io.CharArrayReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;

import com.fasterxml.jackson.core.FormatFeature;
import com.fasterxml.jackson.core.FormatSchema;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.core.StreamReadFeature;
import com.fasterxml.jackson.core.Version;
import java.io.*;

import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.format.InputAccessor;
import com.fasterxml.jackson.core.format.MatchStrength;
import com.fasterxml.jackson.core.io.IOContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.*;
import java.util.Arrays;

import com.fasterxml.jackson.core.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.cfg.CoercionAction;
import com.fasterxml.jackson.databind.cfg.CoercionInputShape;
import com.fasterxml.jackson.databind.cfg.MapperBuilder;
import com.fasterxml.jackson.databind.cfg.*;

public class TomlMapper extends ObjectMapper
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package com.fasterxml.jackson.dataformat.toml;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.ObjectMapper;

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

// Copied from YAML modules "DatabindAdvancedTest"
public class ComplexPojoReadWriteTest extends TomlMapperTestBase
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
package com.fasterxml.jackson.dataformat.toml;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.io.IOException;
import java.nio.file.*;
import java.util.stream.Stream;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.Collections;
import java.util.stream.Collectors;

@RunWith(Parameterized.class)
import static org.junit.jupiter.api.Assertions.assertThrows;

public class ComplianceInvalidTest extends TomlMapperTestBase {
@Parameterized.Parameters
public static Collection<Object[]> data() throws IOException {
Path folder = Paths.get("compliance", "invalid");
if (!Files.exists(folder)) {
return Collections.emptyList();
}
return Files.walk(folder)
.filter(Files::isRegularFile)
.map(p -> new Object[]{p})
.collect(Collectors.toList());
}

private final ObjectMapper MAPPER = newTomlMapper();

Expand All @@ -36,9 +22,29 @@ public ComplianceInvalidTest(Path path) {
this.path = path;
}

@Test(expected = TomlStreamReadException.class)
public void test() throws IOException {
// TODO: verify more details of failure
MAPPER.readTree(path.toFile());
// JUnit 5 throws error when methodSource provides empty `Stream` which
// seems to always be the case....
@Disabled
@MethodSource("data")
@ParameterizedTest
public void test(Path path) throws IOException {
// Test implementation
ObjectMapper MAPPER = newTomlMapper();
assertThrows(
TomlStreamReadException.class,
() -> MAPPER.readTree(path.toFile())
);
}

// This is the static method that provides data for the parameterized test
public static Stream<Object[]> data() throws IOException {
Path folder = Paths.get("compliance", "invalid");
if (!Files.exists(folder)) {
return Stream.empty(); // Ensure this folder exists with files for the test to run
}
return Files.walk(folder)
.filter(Files::isRegularFile)
.map(p -> new Object[]{p});
}

}
Original file line number Diff line number Diff line change
@@ -1,38 +1,30 @@
package com.fasterxml.jackson.dataformat.toml;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.*;
import java.time.*;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Stream;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import com.fasterxml.jackson.core.io.NumberInput;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeCreator;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.UncheckedIOException;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import com.fasterxml.jackson.databind.node.*;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import static org.junit.jupiter.api.Assertions.assertEquals;

@RunWith(Parameterized.class)
public class ComplianceValidTest extends TomlMapperTestBase {
@Parameterized.Parameters
public static Collection<Object[]> data() throws IOException {

public static Stream<Object[]> data() throws IOException {
Path folder = Paths.get("compliance", "valid");
if (!Files.exists(folder)) {
return Collections.emptyList();
return Stream.empty();
}
return Files.walk(folder)
.filter(Files::isRegularFile)
Expand All @@ -57,8 +49,7 @@ public static Collection<Object[]> data() throws IOException {
*/
return null;
})
.filter(Objects::nonNull)
.collect(Collectors.toList());
.filter(Objects::nonNull);
}

private final Path path;
Expand All @@ -69,12 +60,16 @@ public ComplianceValidTest(Path path, ObjectNode expected) {
this.expected = expected;
}

@Test
// JUnit 5 throws error when methodSource provides empty `Stream` which
// seems to always be the case....
@Disabled
@MethodSource("data")
@ParameterizedTest
public void test() throws IOException {
JsonNode actual = TomlMapper.builder()
.enable(TomlReadFeature.PARSE_JAVA_TIME)
.build().readTree(path.toFile());
Assert.assertEquals(mapFromComplianceNode(expected), actual);
assertEquals(mapFromComplianceNode(expected), actual);
}

private static JsonNode mapFromComplianceNode(ObjectNode expected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
import java.io.InputStream;
import java.util.Arrays;

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

import com.fasterxml.jackson.databind.ObjectMapper;

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

/**
* Collection of OSS-Fuzz found issues for TOML format module.
*/
Expand All @@ -24,7 +25,7 @@ public void testArrayCopy57237() throws Exception
"/clusterfuzz-testcase-minimized-TOMLFuzzer-6542204348006400")) {
try {
TOML_MAPPER.readTree(is);
Assert.fail("Should not pass");
fail("Should not pass");
} catch (IOException e) {
// Possibly not what we should get; tweak once working
verifyException(e, "Premature end of file");
Expand All @@ -42,7 +43,7 @@ protected void verifyException(Throwable e, String... matches)
return;
}
}
Assert.fail("Expected an exception with one of substrings ("+Arrays.asList(matches)+"): got one with message \""+msg+"\"");
fail("Expected an exception with one of substrings ("+Arrays.asList(matches)+"): got one with message \""+msg+"\"");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
import java.io.InputStream;
import java.util.Arrays;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.StreamReadConstraints;
import com.fasterxml.jackson.core.StreamWriteConstraints;
import com.fasterxml.jackson.core.exc.StreamConstraintsException;
import org.junit.Assert;
import org.junit.Test;

import com.fasterxml.jackson.core.exc.StreamReadException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import static org.junit.jupiter.api.Assertions.fail;
/**
* Collection of OSS-Fuzz found issues for TOML format module.
*/
Expand All @@ -31,7 +31,7 @@ public void testBigIntegerDecoding50033() throws Exception
;
try {
JsonNode n = TOML_MAPPER.readTree(INPUT);
Assert.fail("Should not pass, got: "+n);
fail("Should not pass, got: "+n);
} catch (StreamReadException e) {
verifyException(e, "Premature end of file");
// NOTE: decoding of token for error message seems wrong, cannot
Expand All @@ -46,7 +46,7 @@ public void testUTF8Decoding50036() throws Exception
byte[] INPUT = new byte[] { 0x20, (byte) 0xCD };
try {
TOML_MAPPER.readTree(INPUT);
Assert.fail("Should not pass");
fail("Should not pass");
// NOTE! This is an actual IOException in Jackson 2.x
} catch (IOException e) {
verifyException(e, "End-of-input after first 1 byte");
Expand All @@ -62,7 +62,7 @@ public void testParseInlineTable50432() throws Exception
"/clusterfuzz-testcase-minimized-TOMLFuzzer-6370486359031808")) {
try {
TOML_MAPPER.readTree(is);
Assert.fail("Should not pass");
fail("Should not pass");
} catch (IOException e) {
String exceptionPrefix = String.format("Document nesting depth (%d) exceeds the maximum allowed",
StreamReadConstraints.DEFAULT_MAX_DEPTH + 1);
Expand All @@ -79,7 +79,7 @@ public void testCodepoint51654() throws Exception
"/clusterfuzz-testcase-minimized-TOMLFuzzer-5068015447703552")) {
try {
TOML_MAPPER.readTree(is);
Assert.fail("Should not pass");
fail("Should not pass");
} catch (IOException e) {
verifyException(e, "EOF in wrong state");
}
Expand All @@ -93,7 +93,7 @@ public void testBigDecimalOverflow() throws Exception
String INPUT = "q=8E8188888888";
try {
TOML_MAPPER.readTree(INPUT);
Assert.fail("Should not pass");
fail("Should not pass");
} catch (StreamReadException e) {
verifyException(e, "Invalid number");
verifyException(e, "8E8188888888");
Expand All @@ -107,7 +107,7 @@ public void testNumberParsingFail50395() throws Exception
String INPUT = "j=427\n-03b-";
try {
TOML_MAPPER.readTree(INPUT);
Assert.fail("Should not pass");
fail("Should not pass");
} catch (StreamReadException e) {
verifyException(e, "Premature end of file");
}
Expand All @@ -122,7 +122,7 @@ public void testStackOverflow50083() throws Exception
}
try {
TOML_MAPPER.readTree(input.toString());
Assert.fail("Should not pass");
fail("Should not pass");
} catch (StreamConstraintsException e) {
String exceptionPrefix = String.format("Document nesting depth (%d) exceeds the maximum allowed",
StreamWriteConstraints.DEFAULT_MAX_DEPTH + 1);
Expand All @@ -140,7 +140,7 @@ protected void verifyException(Throwable e, String... matches)
return;
}
}
Assert.fail("Expected an exception with one of substrings ("+Arrays.asList(matches)+"): got one with message \""+msg+"\"");
fail("Expected an exception with one of substrings ("+Arrays.asList(matches)+"): got one with message \""+msg+"\"");
}

}
Loading

0 comments on commit 1a54d40

Please sign in to comment.