001 /* 002 * Copyright 2007 - 2010 JEuclid, http://jeuclid.sf.net 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017 /* $Id: ContentTest.java,v 92b6a7c39d7f 2010/08/11 20:23:17 max $ */ 018 019 package net.sourceforge.jeuclid.test.elements; 020 021 import net.sourceforge.jeuclid.DOMBuilder; 022 import net.sourceforge.jeuclid.MathMLParserSupport; 023 import net.sourceforge.jeuclid.MathMLSerializer; 024 025 import org.junit.Assert; 026 import org.junit.Test; 027 import org.w3c.dom.Document; 028 import org.w3c.dom.mathml.MathMLAnnotationElement; 029 import org.w3c.dom.mathml.MathMLDocument; 030 import org.w3c.dom.mathml.MathMLMathElement; 031 import org.w3c.dom.mathml.MathMLSemanticsElement; 032 033 /** 034 * Various tests for the DOM model. 035 * 036 * @version $Revision: 92b6a7c39d7f $ 037 */ 038 public class ContentTest { 039 040 /** 041 * Tests is the Annotation element. 042 * 043 * @throws Exception 044 * if anything goes wrong. 045 */ 046 @Test 047 public void testAnnotation() throws Exception { 048 final Document docWithID = MathMLParserSupport 049 .parseString("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><math mode=\"display\">" 050 + "<semantics><apply><plus/><apply><sin/><ci> x </ci></apply><cn> 5 </cn>" 051 + "</apply><annotation encoding=\"TeX\">\\sin x + 5</annotation></semantics></math>"); 052 053 final MathMLDocument docElement = DOMBuilder.getInstance() 054 .createJeuclidDom(docWithID); 055 final MathMLMathElement mathElement = (MathMLMathElement) docElement 056 .getFirstChild(); 057 final MathMLSemanticsElement semElement = (MathMLSemanticsElement) mathElement 058 .getFirstChild(); 059 final MathMLAnnotationElement anno = (MathMLAnnotationElement) semElement 060 .getAnnotation(1); 061 Assert.assertEquals(anno.getEncoding(), "TeX"); 062 Assert.assertEquals(anno.getBody(), "\\sin x + 5"); 063 064 anno.setEncoding("text/plain"); 065 anno.setBody("sin(x)+5"); 066 067 final Document reserial = MathMLParserSupport 068 .parseString("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><math mode=\"display\">" 069 + "<semantics><apply><plus/><apply><sin/><ci> x </ci></apply><cn> 5 </cn>" 070 + "</apply><annotation encoding=\"text/plain\">sin(x)+5</annotation></semantics></math>"); 071 final MathMLDocument docElement2 = DOMBuilder.getInstance() 072 .createJeuclidDom(reserial); 073 // TODO 074 Assert.assertEquals(MathMLSerializer.serializeDocument(docElement, 075 false, false), MathMLSerializer.serializeDocument( 076 docElement2, false, false)); 077 } 078 079 }