1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sourceforge.jeuclid.test.elements;
20
21 import net.sourceforge.jeuclid.DOMBuilder;
22 import net.sourceforge.jeuclid.MathMLParserSupport;
23 import net.sourceforge.jeuclid.MathMLSerializer;
24
25 import org.junit.Assert;
26 import org.junit.Test;
27 import org.w3c.dom.Document;
28 import org.w3c.dom.mathml.MathMLAnnotationElement;
29 import org.w3c.dom.mathml.MathMLDocument;
30 import org.w3c.dom.mathml.MathMLMathElement;
31 import org.w3c.dom.mathml.MathMLSemanticsElement;
32
33
34
35
36
37
38 public class ContentTest {
39
40
41
42
43
44
45
46 @Test
47 public void testAnnotation() throws Exception {
48 final Document docWithID = MathMLParserSupport
49 .parseString("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><math mode=\"display\">"
50 + "<semantics><apply><plus/><apply><sin/><ci> x </ci></apply><cn> 5 </cn>"
51 + "</apply><annotation encoding=\"TeX\">\\sin x + 5</annotation></semantics></math>");
52
53 final MathMLDocument docElement = DOMBuilder.getInstance()
54 .createJeuclidDom(docWithID);
55 final MathMLMathElement mathElement = (MathMLMathElement) docElement
56 .getFirstChild();
57 final MathMLSemanticsElement semElement = (MathMLSemanticsElement) mathElement
58 .getFirstChild();
59 final MathMLAnnotationElement anno = (MathMLAnnotationElement) semElement
60 .getAnnotation(1);
61 Assert.assertEquals(anno.getEncoding(), "TeX");
62 Assert.assertEquals(anno.getBody(), "\\sin x + 5");
63
64 anno.setEncoding("text/plain");
65 anno.setBody("sin(x)+5");
66
67 final Document reserial = MathMLParserSupport
68 .parseString("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><math mode=\"display\">"
69 + "<semantics><apply><plus/><apply><sin/><ci> x </ci></apply><cn> 5 </cn>"
70 + "</apply><annotation encoding=\"text/plain\">sin(x)+5</annotation></semantics></math>");
71 final MathMLDocument docElement2 = DOMBuilder.getInstance()
72 .createJeuclidDom(reserial);
73
74 Assert.assertEquals(MathMLSerializer.serializeDocument(docElement,
75 false, false), MathMLSerializer.serializeDocument(
76 docElement2, false, false));
77 }
78
79 }