Skip to content

Commit 47bbfeb

Browse files
committed
add tests for xml package
1 parent b8408bb commit 47bbfeb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+80
-7
lines changed

net.lecousin.core/src/test/java/net/lecousin/framework/core/tests/xml/TestXMLStreamEventsAsync.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public void testInnerText() throws Exception {
112112

113113
@Test(timeout=120000)
114114
public void testErrors() {
115-
for (int i = 1; i <= 15; ++i) {
115+
for (int i = TestXMLStreamEventsSync.ERROR_START; i <= TestXMLStreamEventsSync.ERROR_END; ++i) {
116116
String s = Integer.toString(i);
117117
while (s.length() != 3) s = "0" + s;
118118
try {

net.lecousin.core/src/test/java/net/lecousin/framework/core/tests/xml/TestXMLStreamEventsSync.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ public void test1() throws Exception {
2525
Assert.assertTrue(xml.nextStartElement());
2626
Assert.assertEquals("hello", xml.event.text.asString());
2727
Assert.assertEquals("fr", xml.getAttributeValueWithPrefix("language", "code").asString());
28+
Assert.assertNull(xml.getAttributeValueWithPrefix("language2", "code"));
29+
Assert.assertNull(xml.getAttributeValueWithPrefix("language", "code2"));
2830
Assert.assertEquals("fr", xml.getAttributeValueWithNamespaceURI("http://language", "code").asString());
31+
Assert.assertNull(xml.getAttributeValueWithNamespaceURI("http://language2", "code"));
32+
Assert.assertNull(xml.getAttributeValueWithNamespaceURI("http://language", "code2"));
2933
Attribute a = xml.removeAttributeByFullName("language:code");
3034
Assert.assertEquals("fr", a.value.asString());
3135
xml.event.attributes.add(a);
@@ -129,9 +133,12 @@ public void testInnerText() throws Exception {
129133
Assert.assertEquals("Hello World", xml.readInnerText().trim().asString());
130134
}
131135

136+
public static final int ERROR_START = 1;
137+
public static final int ERROR_END = 68;
138+
132139
@Test(timeout=120000)
133140
public void testErrors() {
134-
for (int i = 1; i <= 15; ++i) {
141+
for (int i = ERROR_START; i <= ERROR_END; ++i) {
135142
String s = Integer.toString(i);
136143
while (s.length() != 3) s = "0" + s;
137144
try {

net.lecousin.core/src/test/java/net/lecousin/framework/core/tests/xml/TestXMLStreamReader.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
package net.lecousin.framework.core.tests.xml;
22

3-
import org.junit.Assert;
4-
import org.junit.Test;
5-
63
import net.lecousin.framework.application.LCCore;
74
import net.lecousin.framework.concurrent.Task;
5+
import net.lecousin.framework.io.IO;
6+
import net.lecousin.framework.io.buffering.SimpleBufferedReadable;
87
import net.lecousin.framework.xml.XMLStreamEvents.Event;
98
import net.lecousin.framework.xml.XMLStreamReader;
109

10+
import org.junit.Assert;
11+
import org.junit.Test;
12+
1113
public class TestXMLStreamReader extends TestXMLStreamEventsSync {
1214

1315
@Override
1416
protected XMLStreamReader parse(String resource) {
1517
return new XMLStreamReader(LCCore.getApplication().getResource(resource, Task.PRIORITY_NORMAL), 512);
1618
}
1719

18-
@Test
20+
@Test(timeout=60000)
1921
public void testDocType() throws Exception {
2022
XMLStreamReader xml;
2123
xml = parse("xml-test-suite/mine/003.xml");
@@ -41,4 +43,18 @@ public void testDocType() throws Exception {
4143
Assert.assertEquals("mySystem", xml.event.system.asString());
4244
}
4345

46+
@SuppressWarnings("resource")
47+
@Test(timeout=60000)
48+
public void testStart() throws Exception {
49+
IO.Readable io = LCCore.getApplication().getResource("xml-test-suite/mine/001.xml", Task.PRIORITY_NORMAL);
50+
SimpleBufferedReadable bio = new SimpleBufferedReadable(io, 1024);
51+
XMLStreamReader.start(bio, 1024).blockResult(0);
52+
bio.close();
53+
54+
XMLStreamReader xml;
55+
xml = parse("xml-test-suite/mine/003.xml");
56+
xml.startRootElement();
57+
Assert.assertEquals("myRoot", xml.event.localName.asString());
58+
}
59+
4460
}

net.lecousin.core/src/test/resources/xml-test-suite/mine/002.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
1+
<?xml version="1.0"
2+
encoding="UTF-8"
3+
?>
24
<!DOCTYPE my002>
35
<myRoot>
46
<hello xmlns:language="http://language" language:code="fr">bonjour</hello>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
��

0 commit comments

Comments
 (0)