This is an automated email from the ASF dual-hosted git repository.
mbeckerle pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-daffodil.git
The following commit(s) were added to refs/heads/master by this push:
new 1ac990c Add test that shows DAFFODIL-2456 doesn't happen.
1ac990c is described below
commit 1ac990c8a299a8a5ecc0ae3ead5e3e5e0e25b967
Author: Michael Beckerle <[email protected]>
AuthorDate: Wed Jan 20 10:09:07 2021 -0500
Add test that shows DAFFODIL-2456 doesn't happen.
DAFFODIL-2456
---
.../daffodil/example/ValidatorApiExample.java | 37 +++++++++++++++--
.../resources/test/japi/alwaysInvalid.dfdl.xsd | 46 ++++++++++++++++++++++
2 files changed, 79 insertions(+), 4 deletions(-)
diff --git
a/daffodil-japi/src/test/java/org/apache/daffodil/example/ValidatorApiExample.java
b/daffodil-japi/src/test/java/org/apache/daffodil/example/ValidatorApiExample.java
index 2564c05..8531e17 100644
---
a/daffodil-japi/src/test/java/org/apache/daffodil/example/ValidatorApiExample.java
+++
b/daffodil-japi/src/test/java/org/apache/daffodil/example/ValidatorApiExample.java
@@ -19,14 +19,14 @@ package org.apache.daffodil.example;
import org.apache.daffodil.example.validation.FailingValidator;
import org.apache.daffodil.example.validation.PassingValidator;
-import org.apache.daffodil.japi.Daffodil;
-import org.apache.daffodil.japi.DataProcessor;
-import org.apache.daffodil.japi.ParseResult;
-import org.apache.daffodil.japi.ProcessorFactory;
+import org.apache.daffodil.japi.*;
import org.apache.daffodil.japi.infoset.JDOMInfosetOutputter;
import org.apache.daffodil.japi.io.InputSourceDataInputStream;
+import org.apache.daffodil.util.Misc;
+import org.jdom2.output.XMLOutputter;
import org.junit.Test;
+import java.io.ByteArrayInputStream;
import java.io.IOException;
import static org.junit.Assert.*;
@@ -71,4 +71,33 @@ public class ValidatorApiExample {
assertTrue(res.isValidationError());
}
+
+ @Test // Verifies that Daffodil-2456 is a false report. Not a bug.
+ public void testInvalidNoInfoset() throws IOException,
ClassNotFoundException, InvalidUsageException {
+ org.apache.daffodil.japi.Compiler c = Daffodil.compiler();
+ java.io.File schemaFile =
getResource("/test/japi/alwaysInvalid.dfdl.xsd");
+ ProcessorFactory pf = c.compileFile(schemaFile);
+ for (Diagnostic d: pf.getDiagnostics()) {
+ System.err.println(d.getMessage());
+ }
+ DataProcessor dp =
pf.onPath("/").withValidationMode(ValidationMode.Full);
+
+ java.io.InputStream fis = new ByteArrayInputStream("0".getBytes());
+ InputSourceDataInputStream dis = new InputSourceDataInputStream(fis);
+ JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
+ ParseResult res = dp.parse(dis, outputter);
+
+ assertTrue(res.isValidationError());
+
+ for (Diagnostic d: res.getDiagnostics()) {
+ // doublecheck - all the errors are validation errors.
+ // System.err.println(d.getMessage());
+ assertTrue(d.getMessage().contains("Validation Error"));
+ }
+ assertTrue(res.isError());
+ // XMLOutputter xout = new XMLOutputter();
+ // xout.output(outputter.getResult(), System.out);
+ // Now get the well formed, though invalid result.
+ assertNotNull(outputter.getResult()); // Daffodil-2456 said this
fails. It doesn't. Not reproducible.
+ }
}
diff --git a/daffodil-japi/src/test/resources/test/japi/alwaysInvalid.dfdl.xsd
b/daffodil-japi/src/test/resources/test/japi/alwaysInvalid.dfdl.xsd
new file mode 100644
index 0000000..7610d77
--- /dev/null
+++ b/daffodil-japi/src/test/resources/test/japi/alwaysInvalid.dfdl.xsd
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://example.com"
+ targetNamespace="http://example.com"
+ xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/">
+
+ <xs:include
schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd"/>
+
+ <xs:annotation>
+ <xs:appinfo source="http://www.ogf.org/dfdl/">
+ <dfdl:format ref="GeneralFormat"/>
+ </xs:appinfo>
+ </xs:annotation>
+
+ <xs:element name="root">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="alwaysInvalid" maxOccurs="unbounded">
+ <xs:simpleType dfdl:lengthKind="explicit" dfdl:length="1">
+ <xs:restriction base="xs:unsignedInt">
+ <xs:maxExclusive value="0"/><!-- always fails for unsigned int.
So these are never valid.-->
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+
+
+</xs:schema>