Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negative tests #65

Merged
merged 15 commits into from Apr 14, 2022
Merged
10 changes: 10 additions & 0 deletions examples/counterexamples/annotationtarget1.xml
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" xmlns="http://docs.oasis-open.org/odata/ns/edm" Version="4.01">
<edmx:DataServices>
<Schema Namespace="org.example">
<Annotations Target="org.example.Function1(org.example.Type1,)">
<Annotation Term="Core.Description" />
</Annotations>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
6 changes: 6 additions & 0 deletions examples/counterexamples/test.properties
@@ -0,0 +1,6 @@
test1.xml.line=9
test1.xml.col=14
test1.xml.rule=cvc-complex-type.2.4.a
HeikoTheissen marked this conversation as resolved.
Show resolved Hide resolved
annotationtarget1.xml.line=5
annotationtarget1.xml.col=71
annotationtarget1.xml.rule=cvc-pattern-valid
19 changes: 19 additions & 0 deletions examples/counterexamples/test1.xml
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" xmlns="http://docs.oasis-open.org/odata/ns/edm" Version="4.01">
<edmx:DataServices>
<Schema Namespace="org.example">
<EntityType Name="DoubleKey">
<Key>
<PropertyRef Name="ID" />
</Key>
<Key>
<PropertyRef Name="FirstName" />
<PropertyRef Name="LastName" />
</Key>
<Property Name="ID" Type="Edm.String" Nullable="false" />
<Property Name="FirstName" Type="Edm.String" Nullable="false" />
<Property Name="LastName" Type="Edm.String" Nullable="false" />
</EntityType>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
55 changes: 50 additions & 5 deletions examples/miscellaneous2.json
Expand Up @@ -7,6 +7,14 @@
"$Namespace": "Some.Other.Schema"
}
]
},
"https://oasis-tcs.github.io/odata-vocabularies/vocabularies/Org.OData.Core.V1.json": {
"$Include": [
{
"$Namespace": "Org.OData.Core.V1",
"$Alias": "Core"
}
]
}
},
"org.example2": {
Expand Down Expand Up @@ -51,6 +59,22 @@
}
],
"OddWaldos": [
{
"$Kind": "Function",
"$EntitySetPath": "waldos",
"$IsBound": true,
"$Parameter": [
{
"$Name": "waldos",
"$Collection": true,
"$Type": "One.Waldo"
}
],
"$ReturnType": {
"$Collection": true,
"$Type": "One.Waldo"
}
},
{
"$Kind": "Function",
"$EntitySetPath": "waldos",
Expand All @@ -77,8 +101,11 @@
"$IsBound": true,
"$Parameter": [
{
"$Name": "foo",
"$Name": "bar",
"$Type": "One.Waldo"
},
{
"$Name": "Reason"
}
]
},
Expand All @@ -87,11 +114,9 @@
"$IsBound": true,
"$Parameter": [
{
"$Name": "bar",
"$Name": "foo",
"$Collection": true,
"$Type": "One.Waldo"
},
{
"$Name": "Reason"
}
]
}
Expand All @@ -102,6 +127,26 @@
"ID"
],
"ID": {}
},
"$Annotations": {
"One.Foo()": {
"@Core.Description": "Unbound function"
},
"One.OddWaldos(Collection(One.Waldo),One.Waldo)": {
"@Core.Description": "Function bound to a collection of Waldos with an additional parameter"
},
"One.OddWaldos(Collection(One.Waldo))": {
"@Core.Description": "Function bound to a collection of Waldos"
},
"One.Rejection()": {
"@Core.Description": "Unbound action"
},
"One.Rejection(One.Waldo)": {
"@Core.Description": "Action bound to a single Waldo"
},
"One.Rejection(Collection(One.Waldo))": {
"@Core.Description": "Action bound to a collection of Waldos"
}
}
},
"Schema.Two": {
Expand Down
37 changes: 34 additions & 3 deletions examples/miscellaneous2.xml
Expand Up @@ -3,6 +3,9 @@
<edmx:Reference Uri="SomeOther.xml">
<edmx:Include Namespace="Some.Other.Schema" />
</edmx:Reference>
<edmx:Reference Uri="https://oasis-tcs.github.io/odata-vocabularies/vocabularies/Org.OData.Core.V1.xml">
<edmx:Include Alias="Core" Namespace="Org.OData.Core.V1" />
</edmx:Reference>

<edmx:DataServices>
<Schema Namespace="org.example2">
Expand All @@ -26,24 +29,52 @@
<Function Name="Foo">
<ReturnType Type="Edm.String" MaxLength="42" />
</Function>

<Function Name="OddWaldos" IsBound="true" EntitySetPath="waldos">
<Parameter Name="waldos" Type="Collection(One.Waldo)" />
<ReturnType Type="Collection(One.Waldo)" />
</Function>
HeikoTheissen marked this conversation as resolved.
Show resolved Hide resolved
<Function Name="OddWaldos" IsBound="true" EntitySetPath="waldos">
<Parameter Name="waldos" Type="Collection(One.Waldo)" />
<ReturnType Type="Collection(One.Waldo)" />
</Function>

<Action Name="Rejection" />
<Action Name="Rejection" IsBound="true">
<Parameter Name="foo" Type="One.Waldo" Nullable="false" />
</Action>
<Action Name="Rejection" IsBound="true">
<Parameter Name="bar" Type="One.Waldo" Nullable="false" />
<Parameter Name="Reason" Type="Edm.String" MaxLength="max" Nullable="false" />
</Action>
<Action Name="Rejection" IsBound="true">
<Parameter Name="foo" Type="Collection(One.Waldo)" Nullable="false" />
</Action>

<EntityType Name="Waldo">
<Key>
<PropertyRef Name="ID" />
</Key>
<Property Name="ID" Type="Edm.String" Nullable="false" />
</EntityType>

<Annotations Target="One.Foo()">
<Annotation Term="Core.Description" String="Unbound function" />
</Annotations>

<Annotations Target="One.OddWaldos(Collection(One.Waldo),One.Waldo)">
<Annotation Term="Core.Description" String="Function bound to a collection of Waldos with an additional parameter" />
</Annotations>
<Annotations Target="One.OddWaldos(Collection(One.Waldo))">
<Annotation Term="Core.Description" String="Function bound to a collection of Waldos" />
</Annotations>

<Annotations Target="One.Rejection()">
<Annotation Term="Core.Description" String="Unbound action" />
</Annotations>
<Annotations Target="One.Rejection(One.Waldo)">
<Annotation Term="Core.Description" String="Action bound to a single Waldo" />
</Annotations>
<Annotations Target="One.Rejection(Collection(One.Waldo))">
<Annotation Term="Core.Description" String="Action bound to a collection of Waldos" />
</Annotations>
</Schema>

<Schema Namespace="Schema.Two" Alias="Two">
Expand Down
31 changes: 31 additions & 0 deletions java/Validator.java
Expand Up @@ -2,9 +2,12 @@
import javax.xml.validation.SchemaFactory;
import javax.xml.XMLConstants;
import java.io.File;
import java.io.FileInputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.Properties;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

class XMLFiles implements FilenameFilter {
public boolean accept(File dir, String name) {
Expand All @@ -20,5 +23,33 @@ public static void main(String[] args) throws IOException, SAXException {
System.out.println(file.getName());
validator.validate(new StreamSource(file));
}
var test = new Properties();
test.load(new FileInputStream("examples/counterexamples/test.properties"));
for (var file : new File("examples/counterexamples").listFiles(new XMLFiles())) {
int line = Integer.parseInt(test.getProperty(file.getName() + ".line"));
int col = Integer.parseInt(test.getProperty(file.getName() + ".col"));
String rule = test.getProperty(file.getName() + ".rule");
try {
validator.validate(new StreamSource(file));
System.err.println(file.getName() + " does not fail at line " +
line + ", column " +
col + ", rule " + rule);
System.exit(1);
} catch(SAXParseException e) {
if (e.getColumnNumber() == col &&
e.getLineNumber() == line &&
e.getMessage().startsWith(rule + ":"))
System.out.println("Negative test " + file.getName());
else {
System.err.println(file.getName() + " fails at line " +
e.getLineNumber() + ", column " +
e.getColumnNumber() + ", rule " + e.getMessage());
System.err.println("instead of line " +
line + ", column " +
col + ", rule " + rule);
System.exit(1);
}
}
}
}
}
26 changes: 9 additions & 17 deletions schemas/edm.xsd
Expand Up @@ -54,9 +54,7 @@
prose specification document take precedence.

-->
<xs:schema elementFormDefault="qualified" attributeFormDefault="unqualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:edm="http://docs.oasis-open.org/odata/ns/edm" targetNamespace="http://docs.oasis-open.org/odata/ns/edm"
>
<xs:schema elementFormDefault="qualified" attributeFormDefault="unqualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:edm="http://docs.oasis-open.org/odata/ns/edm" targetNamespace="http://docs.oasis-open.org/odata/ns/edm">
<xs:annotation>
<xs:documentation xml:lang="en">
Entity Data Model part of the Common Schema Definition Language
Expand Down Expand Up @@ -604,15 +602,13 @@
<xs:restriction base="xs:NCName">
<xs:maxLength value="511" />
<!-- one or more SimpleIdentifiers separated by dots -->
<xs:pattern
value="[\p{L}\p{Nl}_][\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Pc}\p{Cf}]{0,}(\.[\p{L}\p{Nl}_][\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Pc}\p{Cf}]{0,}){0,}" />
<xs:pattern value="[\p{L}\p{Nl}_][\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Pc}\p{Cf}]{0,}(\.[\p{L}\p{Nl}_][\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Pc}\p{Cf}]{0,}){0,}" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="TQualifiedName">
<xs:restriction base="xs:NCName">
<!-- a NamespaceName followed by a dot and a SimpleIdentifier -->
<xs:pattern
value="[\p{L}\p{Nl}_][\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Pc}\p{Cf}]{0,}(\.[\p{L}\p{Nl}_][\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Pc}\p{Cf}]{0,}){1,}" />
<xs:pattern value="[\p{L}\p{Nl}_][\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Pc}\p{Cf}]{0,}(\.[\p{L}\p{Nl}_][\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Pc}\p{Cf}]{0,}){1,}" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="TEnumMemberList">
Expand All @@ -624,8 +620,7 @@
<xs:restriction base="xs:token">
<!-- The below pattern represents the allowed identifiers in the ECMAScript specification plus the '.' for namespace qualification
and the Collection() wrapper -->
<xs:pattern
value="Collection\([\p{L}\p{Nl}_][\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Pc}\p{Cf}]{0,}(\.[\p{L}\p{Nl}_][\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Pc}\p{Cf}]{0,}){1,}\)" />
<xs:pattern value="Collection\([\p{L}\p{Nl}_][\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Pc}\p{Cf}]{0,}(\.[\p{L}\p{Nl}_][\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Pc}\p{Cf}]{0,}){1,}\)" />
</xs:restriction>
</xs:simpleType>
</xs:union>
Expand All @@ -634,8 +629,7 @@
<xs:restriction base="xs:string">
<!-- The below pattern represents the allowed identifiers in the ECMAScript specification plus the '.' for namespace qualification
and the '/' for path segment separation -->
<xs:pattern
value="[\p{L}\p{Nl}_][\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Pc}\p{Cf}]{0,}([\./][\p{L}\p{Nl}_][\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Pc}\p{Cf}]{0,}){0,}" />
<xs:pattern value="[\p{L}\p{Nl}_][\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Pc}\p{Cf}]{0,}([\./][\p{L}\p{Nl}_][\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Pc}\p{Cf}]{0,}){0,}" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="TInstancePath">
Expand All @@ -648,16 +642,15 @@
<!-- The below pattern represents the allowed identifiers in the ECMAScript specification plus the '/' for path segment separation
and
the '.' for namespace qualification inside the segments. -->
<xs:pattern
value="(/?@?[\p{L}\p{Nl}_][\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Pc}\p{Cf}]{0,}(([\./#@]|/@)[\p{L}\p{Nl}_][\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Pc}\p{Cf}]{0,}){0,}(/$count)?)?" />
<xs:pattern value="(/?@?[\p{L}\p{Nl}_][\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Pc}\p{Cf}]{0,}(([\./#@]|/@)[\p{L}\p{Nl}_][\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Pc}\p{Cf}]{0,}){0,}(/$count)?)?" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="TTarget">
<xs:restriction base="xs:string">
<!-- The below pattern represents the allowed identifiers in the ECMAScript specification plus the '.' for namespace qualification,
the '/' for path segment separation, and parentheses and comma for overload targeting -->
<xs:pattern
value="[\p{L}\p{Nl}_][\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Pc}\p{Cf}]{0,}(([\.\(,#]|/@?)(\)|[\p{L}\p{Nl}_][\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Pc}\p{Cf}]{0,}\)?)){0,}(/$ReturnType)?" />
value="[\p{L}\p{Nl}_][\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Pc}\p{Cf}]{0,}(([.,#(]|/@?|\(?\){1,}((,|/@?))?)[\p{L}\p{Nl}_][\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Pc}\p{Cf}]{0,}){0,}\(?\){0,}(/$ReturnType)?" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="TClientFunction">
Expand Down Expand Up @@ -889,8 +882,7 @@
<!-- binary data in base64url encoding -->
<xs:simpleType name="binary">
<xs:restriction base="xs:string">
<xs:pattern
value="([A-Za-z0-9_\-]{4})*([A-Za-z0-9_\-]{3}[A-Za-z0-9_\-]|[A-Za-z0-9_\-]{2}[AEIMQUYcgkosw048]=?|[A-Za-z0-9_\-][AQgw](==)?)?" />
<xs:pattern value="([A-Za-z0-9_\-]{4})*([A-Za-z0-9_\-]{3}[A-Za-z0-9_\-]|[A-Za-z0-9_\-]{2}[AEIMQUYcgkosw048]=?|[A-Za-z0-9_\-][AQgw](==)?)?" />
</xs:restriction>
</xs:simpleType>
<!--boolean without 0 and 1 -->
Expand Down Expand Up @@ -922,4 +914,4 @@
<xs:pattern value="[^YM]*[DT].*" />
</xs:restriction>
</xs:simpleType>
</xs:schema>
</xs:schema>