-
Notifications
You must be signed in to change notification settings - Fork 7
/
AttributeUseTest.java
68 lines (57 loc) · 2.16 KB
/
AttributeUseTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* Copyright (c) 1998, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package com.sun.xml.dtdparser;
import java.io.StringReader;
import java.util.HashMap;
import java.util.Map;
import org.junit.Assert;
import org.junit.Test;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
public class AttributeUseTest {
Map<String, Short> attributes = new HashMap<>();
public AttributeUseTest() throws Exception {
StringBuilder dtd = new StringBuilder();
dtd.append(" <!ELEMENT root EMPTY>");
dtd.append(" <!ATTLIST root\n");
dtd.append(" normal CDATA \"default\"");
dtd.append(" implied CDATA #IMPLIED");
dtd.append(" required CDATA #REQUIRED");
dtd.append(" fixed CDATA #FIXED \"default\"");
dtd.append(" >");
DTDEventListener handler = new DTDHandlerBase() {
@Override
public void attributeDecl(String element, String name, String type, String[] enums, short use,
String defaultValue) throws SAXException {
attributes.put(name, use);
}
};
InputSource input = new InputSource(new StringReader(dtd.toString()));
DTDParser parser = new DTDParser();
parser.setDtdHandler(handler);
parser.parse(input);
}
@Test
public void testNormalAttribute() {
Assert.assertEquals(DTDEventListener.USE_NORMAL, attributes.get("normal").shortValue());
}
@Test
public void testImpliedAttribute() {
Assert.assertEquals(DTDEventListener.USE_IMPLIED, attributes.get("implied").shortValue());
}
@Test
public void testRequiredAttribute() {
Assert.assertEquals(DTDEventListener.USE_REQUIRED, attributes.get("required").shortValue());
}
@Test
public void testFixedAttribute() {
Assert.assertEquals(DTDEventListener.USE_FIXED, attributes.get("fixed").shortValue());
}
}