Author: veithen
Date: Sun Sep  5 09:41:25 2010
New Revision: 992747

URL: http://svn.apache.org/viewvc?rev=992747&view=rev
Log:
Added more StAX dialect tests and fixed an issue in the dialect for the BEA 
reference implementation.

Added:
    
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/GetEncodingFromDetectionTestCase.java
   (with props)
Modified:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAInputFactoryWrapper.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/DialectTestCase.java

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAInputFactoryWrapper.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAInputFactoryWrapper.java?rev=992747&r1=992746&r2=992747&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAInputFactoryWrapper.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAInputFactoryWrapper.java
 Sun Sep  5 09:41:25 2010
@@ -74,8 +74,8 @@ class BEAInputFactoryWrapper extends XML
         } catch (IOException ex) {
             throw new XMLStreamException("Unable to read start bytes", ex);
         }
-        int marker = (startBytes[0] & 0xFF) << 24 + (startBytes[1] & 0xFF) << 
16
-                + (startBytes[2] & 0xFF) << 8 + (startBytes[3] & 0xFF);
+        int marker = ((startBytes[0] & 0xFF) << 24) + ((startBytes[1] & 0xFF) 
<< 16)
+                + ((startBytes[2] & 0xFF) << 8) + (startBytes[3] & 0xFF);
         String encoding;
         switch (marker) {
             case 0x0000FEFF:

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java?rev=992747&r1=992746&r2=992747&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java
 Sun Sep  5 09:41:25 2010
@@ -41,6 +41,11 @@ public class DialectTest extends TestSui
         addDialectTest(new DisallowDoctypeDeclWithExternalSubsetTestCase());
         addDialectTest(new DisallowDoctypeDeclWithInternalSubsetTestCase());
         addDialectTest(new GetCharacterEncodingSchemeTestCase());
+        addDialectTest(new GetEncodingFromDetectionTestCase("UTF-8", "UTF-8"));
+        addDialectTest(new GetEncodingFromDetectionTestCase("UnicodeBig", 
"UTF-16BE"));
+        addDialectTest(new GetEncodingFromDetectionTestCase("UnicodeLittle", 
"UTF-16LE"));
+        addDialectTest(new 
GetEncodingFromDetectionTestCase("UnicodeBigUnmarked", "UTF-16BE"));
+        addDialectTest(new 
GetEncodingFromDetectionTestCase("UnicodeLittleUnmarked", "UTF-16LE"));
         addDialectTest(new GetEncodingTestCase());
         addDialectTest(new GetVersionTestCase());
         addDialectTest(new IsCharactersOnCDATASectionTestCase());

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/DialectTestCase.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/DialectTestCase.java?rev=992747&r1=992746&r2=992747&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/DialectTestCase.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/DialectTestCase.java
 Sun Sep  5 09:41:25 2010
@@ -28,7 +28,9 @@ public abstract class DialectTestCase ex
     
     void init(DialectTest test) {
         this.test = test;
-        setName(getClass().getName());
+        if (getName() == null) {
+            setName(getClass().getName());
+        }
     }
     
     protected XMLInputFactory newNormalizedXMLInputFactory() {

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/GetEncodingFromDetectionTestCase.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/GetEncodingFromDetectionTestCase.java?rev=992747&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/GetEncodingFromDetectionTestCase.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/GetEncodingFromDetectionTestCase.java
 Sun Sep  5 09:41:25 2010
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+package org.apache.axiom.util.stax.dialect;
+
+import java.io.ByteArrayInputStream;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+/**
+ * Checks that {...@link XMLStreamReader#getEncoding()} returns accurate 
information for XML documents
+ * without an encoding specified in the XML declaration. For this type of 
document, the parser
+ * should implement the detection algorithm described in Appendix F.1 of the 
XML 1.0 specifications
+ * (Fifth Edition).
+ */
+public class GetEncodingFromDetectionTestCase extends DialectTestCase {
+    private final String javaEncoding;
+    private final String xmlEncoding;
+
+    public GetEncodingFromDetectionTestCase(String javaEncoding, String 
xmlEncoding) {
+        this.javaEncoding = javaEncoding;
+        this.xmlEncoding = xmlEncoding;
+        setName(getClass().getName() + " [" + javaEncoding + "]");
+    }
+
+    protected void runTest() throws Throwable {
+        XMLInputFactory factory = newNormalizedXMLInputFactory();
+        XMLStreamReader reader = factory.createXMLStreamReader(new 
ByteArrayInputStream(
+                "<?xml version=\"1.0\"?><root/>".getBytes(javaEncoding)));
+        assertEquals(xmlEncoding, reader.getEncoding());
+    }
+}

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-staxdialect-tests/src/test/java/org/apache/axiom/util/stax/dialect/GetEncodingFromDetectionTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to