Update durations to latest spec.
Added workaraound, to make tests run each time on windows.
git-svn-id: https://svn.apache.org/repos/asf/xmlbeans/trunk@951567 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/build.xml b/build.xml
index aa73835..4da3738 100644
--- a/build.xml
+++ b/build.xml
@@ -1049,6 +1049,9 @@
<ant antfile="${testbuild.file}" target="detailed"/>
</target>
+ <target name="compile.run">
+ <ant antfile="${testbuild.file}" target="compile.run"/>
+ </target>
<path id="test.compile.path">
<pathelement location="build/classes/marshal"/>
diff --git a/src/xmlpublic/org/apache/xmlbeans/GDuration.java b/src/xmlpublic/org/apache/xmlbeans/GDuration.java
index 2fff23d..a7f9a95 100644
--- a/src/xmlpublic/org/apache/xmlbeans/GDuration.java
+++ b/src/xmlpublic/org/apache/xmlbeans/GDuration.java
@@ -67,7 +67,8 @@
public GDuration(CharSequence str)
{
// Form: -PnYnMnDTnHnMnS
- // (where each n may be preceded by a - for us, and the whole may be -)
+ // (where each n may be unsigned integer, i.e., an integer that conforms to the pattern [0-9]+
+ // {was: preceded by a - for us}, and the whole may be -)
// first trim XML whitespace
int len = str.length();
@@ -96,7 +97,6 @@
for (;start < len; start += 1)
{
- boolean negval = false;
char ch = str.charAt(start);
if (ch == 'T')
{
@@ -111,16 +111,8 @@
throw new IllegalArgumentException("illegal duration");
ch = str.charAt(start);
}
- if (ch == '-')
- {
- negval = true;
- if (start == len)
- throw new IllegalArgumentException("illegal duration");
- start += 1;
- ch = str.charAt(start);
- }
if (!GDate.isDigit(ch))
- throw new IllegalArgumentException("illegal duration");
+ throw new IllegalArgumentException("illegal duration at char[" + start + "]: '" + ch + "'");
int value = GDate.digitVal(ch);
for (;;)
{
@@ -140,8 +132,7 @@
throw new IllegalArgumentException("illegal duration");
start = i;
}
- if (negval)
- value = -value;
+
switch (seen)
{
case SEEN_NOTHING:
diff --git a/test/src/xmlobject/schematypes/checkin/GDateTests.java b/test/src/xmlobject/schematypes/checkin/GDateTests.java
index 6d9c11d..a67e347 100755
--- a/test/src/xmlobject/schematypes/checkin/GDateTests.java
+++ b/test/src/xmlobject/schematypes/checkin/GDateTests.java
@@ -54,26 +54,8 @@
"P1Y365D",
"P1Y366D",
"PT0.1S",
- "P1Y-364D",
- "P1Y-365D",
- "P1Y-366D",
- "P1Y-367D",
- "P1Y-12M",
"P1M29D",
- "P1M-27D",
- "P1M-28D",
- "P1M-29D",
- "P1M-31D",
- "P1M-32D",
- "P1MT-660H",
- "P1MT-670H",
- "P1MT-680H",
- "P1MT-690H",
- "P1MT-700H",
- "P1MT-710H",
- "P1MT-720H",
- "P1MT-730H",
- "P1MT-740H",
+
"PT0.1415926S",
"PT5233132S",
"PT142332M",
@@ -104,6 +86,41 @@
};
+ static String[] invalidDurations =
+ {
+ "P1Y-364D",
+ "P1Y-365D",
+ "P1Y-366D",
+ "P1Y-367D",
+ "P1Y-12M",
+ "P1M-27D",
+ "P1M-28D",
+ "P1M-29D",
+ "P1M-31D",
+ "P1M-32D",
+ "P1MT-660H",
+ "P1MT-670H",
+ "P1MT-680H",
+ "P1MT-690H",
+ "P1MT-700H",
+ "P1MT-710H",
+ "P1MT-720H",
+ "P1MT-730H",
+ "P1MT-740H",
+
+ "-PT-0S",
+ "-P-1Y",
+ "-P-1M",
+ "-P-1D",
+ "-PT-1H",
+ "-PT-1M",
+ "-PT-1S",
+ "-P1Y1M-1DT1H1M1S",
+ "-P1Y1M1DT1H-1M1.1S",
+ "-PT-0.1S",
+ "-PT-0.1415926S",
+ };
+
static String[] invalidDates =
{
"+14:01", // tz
@@ -547,6 +564,20 @@
public void testFailure() throws Exception
{
+ for (int i = 0; i < invalidDurations.length; i++)
+ {
+ String str = invalidDurations[i];
+ try
+ {
+ new GDuration(str);
+ }
+ catch (IllegalArgumentException e)
+ {
+ continue;
+ }
+ Assert.fail("Missing exception for GDuration: " + str);
+ }
+
for (int i = 0; i < invalidDates.length; i++)
{
String str = invalidDates[i];
diff --git a/testbuild.xml b/testbuild.xml
index 44cfa04..b602151 100755
--- a/testbuild.xml
+++ b/testbuild.xml
@@ -907,6 +907,7 @@
<!-- This test, for some reason, upon compilation,
affects other tests under Win jdk1.4-->
<target name="-compile.run.excluded" depends="check.asserts">
+ <delete file="${build.dir.test}/output/compile/scomp/j2ee/j2eeconfigxml.jar" description="Workaround failing test."/>
<javac srcdir="${xbeans.test.src}"
destdir="${build.dir.test.src}"
includes="${excludes}"