Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions xsdlib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
<include>**/*Test.java</include>
<include>**/*TestCase.java</include>
<include>**/*TestCases.java</include>
<include>com/sun/msv/datatype/xsd/conformance/TestDriver.java</include>
</includes>
<excludes>
<exclude>**/*$*</exclude>
Expand Down
23 changes: 13 additions & 10 deletions xsdlib/src/main/java/com/sun/msv/datatype/xsd/Base64BinaryType.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,24 +129,22 @@ private static int calcLength( final char[] buf ) {
int i;

for( i=0; i<len; i++ ) {
if( isXMLSpace(buf[i]) )
continue; // ignore whitespace
if( buf[i]=='=' ) // decodeMap['=']!=-1, so we have to check this first.
break;
if( buf[i]>=256 )
if( buf[i]>=256 || decodeMap[buf[i]] == -1 )
return -1; // incorrect character
if( decodeMap[buf[i]]!=-1 )
base64count++;
base64count++;
}

// once we saw '=', nothing but '=' can be appeared.
for( ; i<len; i++ ) {
if( buf[i]=='=' ) {
paddingCount++;
continue;
}
if( buf[i]>=256 )
if( isXMLSpace(buf[i]) )
continue; // ignore whitespace
if( buf[i]!='=' )
return -1; // incorrect character
if( decodeMap[buf[i]]!=-1 )
return -1;
paddingCount++;
}

// no more than two paddings are allowed.
Expand Down Expand Up @@ -226,6 +224,11 @@ public String convertToLexicalValue( Object value, SerializationContext context
return serializeJavaObject( ((BinaryValueType)value).rawData, context );
}

private static boolean isXMLSpace(char c) {
// Per https://www.w3.org/TR/xml/#NT-S
return c == ' ' || c == '\r' || c == '\n' || c == '\t';
}

// serialization support
private static final long serialVersionUID = 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ public final String convertToLexicalValue( Object value, SerializationContext co

/** converts our DateTimeValueType to a java-friendly Date type. */
public final Object _createJavaObject(String literal, ValidationContext context) {
return CalendarParser.parse(getFormat(),literal);
try {
return CalendarParser.parse(getFormat(),literal);
} catch (IllegalArgumentException e) {
return null;
}
}

public final String serializeJavaObject(Object value, SerializationContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.PrintStream;
import java.util.List;
import org.jdom2.Element;
import org.junit.Assert;
import org.relaxng.datatype.DatatypeException;

/**
Expand Down Expand Up @@ -215,11 +216,15 @@ public void testDataType(
// try round trip conversion.
Object o2 = typeObj.createValue(s,DummyContextProvider.theInstance);
if( o2==null || !o.equals(o2) )
{
System.out.println("equals error: \n\"" + o.toString() + "\"\n\"" + s + "\"\n\"" + o2.toString() + "\"");
roundTripError = true;
}
}
} catch( UnsupportedOperationException uoe ) {
// ignore this exception
} catch( IllegalArgumentException iae ) {
System.out.println("roundtrip IllegalArgumentException");
roundTripError = true;
}

Expand All @@ -240,7 +245,7 @@ public void testDataType(
Object o2 = typeObj.createJavaObject(s,DummyContextProvider.theInstance);
if( o2==null ) {
System.out.println("round-trip conversion failed");
roundTripError = true;
roundTripError = true;
}
}
}
Expand All @@ -266,6 +271,8 @@ public void testDataType(
continue; // do not report error if
// the validator accepts things that
// may not be accepted.
}else if(roundTripError){
Assert.fail("RoundtripError!");
}

// dump error messages
Expand Down Expand Up @@ -293,13 +300,14 @@ public void testDataType(

if( typeObj.createJavaObject(wrongs[i],DummyContextProvider.theInstance)!=null )
err = true;

if( err ) {
if( !this.err.report( new UnexpectedResultException(
typeObj, baseType.getName(),
wrongs[i], false, ti ) ) )
{
out.println("test aborted");
Assert.fail("Test aborted!");
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;
import org.junit.Assert;
import org.junit.Test;
import org.relaxng.datatype.Datatype;
import org.relaxng.datatype.DatatypeException;
Expand All @@ -25,15 +26,15 @@
*
* @author <a href="mailto:kohsuke.kawaguchi@eng.sun.com">Kohsuke KAWAGUCHI</a>
*/
public class TestDriverTest implements ErrorReceiver
public class TestDriver implements ErrorReceiver
{


String parser;

public static void main (String args[]) throws Exception {

TestDriverTest testDriver = new TestDriverTest();
TestDriver testDriver = new TestDriver();
if( args.length>=1 ) testDriver.parser = args[0];
else testDriver.parser = "org.apache.xerces.parsers.SAXParser";
// reads test case file
Expand All @@ -45,7 +46,7 @@ public void runTests() throws Exception {

try {
// reads test case file
Document doc = new SAXBuilder(parser).build(TestDriverTest.class.getResourceAsStream("DataTypeTest.xml") );
Document doc = new SAXBuilder(parser).build(TestDriver.class.getResourceAsStream("DataTypeTest.xml") );

DataTypeTester tester = new DataTypeTester(System.out,this);
// perform test for each "case" item
Expand All @@ -55,6 +56,7 @@ public void runTests() throws Exception {
} catch(JDOMException e) {
e.printStackTrace();
System.err.println(e.getMessage());
Assert.fail(e.getMessage());
}
}

Expand Down Expand Up @@ -86,7 +88,7 @@ public boolean report( UnexpectedResultException exp ) {
try {
System.out.println("serializeJavaObject : "+exp.type.serializeJavaObject(jo,DummyContextProvider.theInstance) );
} catch( Exception e ) {
System.out.println("serializeJavaObject : "+e );
System.out.println("serializeJavaObject : "+e );
}

if(o!=null)
Expand All @@ -111,7 +113,7 @@ public boolean report( UnexpectedResultException exp ) {

// do it again (for trace purpose)
exp.type.isValid(exp.testInstance,DummyContextProvider.theInstance);

Assert.fail("ErrorReported!");
return false;
}

Expand All @@ -128,7 +130,7 @@ public boolean reportTestCaseError( XSDatatype baseType, TypeIncubator incubator
}
catch( Exception ee ) { ; }
*/

Assert.fail("TestCaseErrorReported!");
return false;
}
}
Loading