View Javadoc

1   /*
2    * Copyright 2002 - 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: MathComponentTest.java,v b7608960db6b 2010/08/13 09:22:12 max $ */
18  
19  package net.sourceforge.jeuclid.test;
20  
21  import java.awt.BorderLayout;
22  import java.awt.Frame;
23  import java.awt.GraphicsEnvironment;
24  import java.awt.HeadlessException;
25  import java.io.StringReader;
26  
27  import javax.xml.parsers.DocumentBuilder;
28  import javax.xml.parsers.DocumentBuilderFactory;
29  
30  import net.sourceforge.jeuclid.ResourceEntityResolver;
31  import net.sourceforge.jeuclid.awt.MathComponent;
32  
33  import org.junit.Assume;
34  import org.junit.BeforeClass;
35  import org.junit.Test;
36  import org.w3c.dom.Document;
37  import org.xml.sax.InputSource;
38  
39  /**
40   * Tests the AWT math component.
41   *
42   * @version $Revision: b7608960db6b $
43   */
44  public class MathComponentTest {
45  
46      /** Run these tests only on non-headless nodes. */
47      @BeforeClass
48      public static void checkHeadless() {
49          Assume.assumeTrue(!GraphicsEnvironment.isHeadless());
50      }
51      
52      /**
53       * Test string with xml header.
54       */
55      private static String test = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><math mode=\"display\">"
56              + "<mrow><munderover><mo>&#x0222B;</mo><mn>1</mn><mi>x</mi></munderover>"
57              + "<mfrac><mi>dt</mi><mi>t</mi></mfrac></mrow></math>";
58  
59      /**
60       * Tests if AWT component starts up.
61       * @throws Exception if the test fails.
62       */
63      @Test
64      public void testAWTComponent() throws Exception {
65          Document document;
66  
67          final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory
68                  .newInstance();
69          final DocumentBuilder parser = documentBuilderFactory
70                  .newDocumentBuilder();
71          parser.setEntityResolver(new ResourceEntityResolver());
72          document = parser.parse(new InputSource(new StringReader(
73                  MathComponentTest.test)));
74  
75          final Frame frame = new Frame("Test MathComponent");
76          frame.setLayout(new BorderLayout());
77          final MathComponent component = new MathComponent();
78          component.setDocument(document);
79          component.setDebug(false);
80          frame.add(component, BorderLayout.CENTER);
81          frame.setVisible(true);
82          frame.pack();
83          frame.invalidate();
84          frame.validate();
85          frame.dispose();
86      }
87  
88  }