View Javadoc

1   /*
2    * Copyright 2007 - 2010 JEuclid, http://jeuclid.sf.net
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  /* $Id: ContentTest.java,v 92b6a7c39d7f 2010/08/11 20:23:17 max $ */
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   * Various tests for the DOM model.
35   *
36   * @version $Revision: 92b6a7c39d7f $
37   */
38  public class ContentTest {
39  
40      /**
41       * Tests is the Annotation element.
42       *
43       * @throws Exception
44       *             if anything goes wrong.
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          // TODO
74          Assert.assertEquals(MathMLSerializer.serializeDocument(docElement,
75                  false, false), MathMLSerializer.serializeDocument(
76                  docElement2, false, false));
77      }
78  
79  }