001 /* 002 * Copyright 2002 - 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: MathComponentTest.java,v b7608960db6b 2010/08/13 09:22:12 max $ */ 018 019 package net.sourceforge.jeuclid.test; 020 021 import java.awt.BorderLayout; 022 import java.awt.Frame; 023 import java.awt.GraphicsEnvironment; 024 import java.awt.HeadlessException; 025 import java.io.StringReader; 026 027 import javax.xml.parsers.DocumentBuilder; 028 import javax.xml.parsers.DocumentBuilderFactory; 029 030 import net.sourceforge.jeuclid.ResourceEntityResolver; 031 import net.sourceforge.jeuclid.awt.MathComponent; 032 033 import org.junit.Assume; 034 import org.junit.BeforeClass; 035 import org.junit.Test; 036 import org.w3c.dom.Document; 037 import org.xml.sax.InputSource; 038 039 /** 040 * Tests the AWT math component. 041 * 042 * @version $Revision: b7608960db6b $ 043 */ 044 public class MathComponentTest { 045 046 /** Run these tests only on non-headless nodes. */ 047 @BeforeClass 048 public static void checkHeadless() { 049 Assume.assumeTrue(!GraphicsEnvironment.isHeadless()); 050 } 051 052 /** 053 * Test string with xml header. 054 */ 055 private static String test = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><math mode=\"display\">" 056 + "<mrow><munderover><mo>∫</mo><mn>1</mn><mi>x</mi></munderover>" 057 + "<mfrac><mi>dt</mi><mi>t</mi></mfrac></mrow></math>"; 058 059 /** 060 * Tests if AWT component starts up. 061 * @throws Exception if the test fails. 062 */ 063 @Test 064 public void testAWTComponent() throws Exception { 065 Document document; 066 067 final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory 068 .newInstance(); 069 final DocumentBuilder parser = documentBuilderFactory 070 .newDocumentBuilder(); 071 parser.setEntityResolver(new ResourceEntityResolver()); 072 document = parser.parse(new InputSource(new StringReader( 073 MathComponentTest.test))); 074 075 final Frame frame = new Frame("Test MathComponent"); 076 frame.setLayout(new BorderLayout()); 077 final MathComponent component = new MathComponent(); 078 component.setDocument(document); 079 component.setDebug(false); 080 frame.add(component, BorderLayout.CENTER); 081 frame.setVisible(true); 082 frame.pack(); 083 frame.invalidate(); 084 frame.validate(); 085 frame.dispose(); 086 } 087 088 }