001 /* 002 * Copyright 2010 - 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: JMathComponentTest.java,v b7608960db6b 2010/08/13 09:22:12 max $ */ 018 019 package net.sourceforge.jeuclid.test.swing; 020 021 import java.awt.Dimension; 022 import java.awt.GraphicsEnvironment; 023 024 import net.sourceforge.jeuclid.swing.JMathComponent; 025 026 import org.junit.Assert; 027 import org.junit.Assume; 028 import org.junit.BeforeClass; 029 import org.junit.Test; 030 import org.w3c.dom.Node; 031 032 /** 033 * Tests for {@link JMathComponent}. 034 * 035 * @version $Revision: b7608960db6b $ 036 */ 037 public class JMathComponentTest { 038 039 /** Run these tests only on non-headless nodes. */ 040 @BeforeClass 041 public static void checkHeadless() { 042 Assume.assumeTrue(!GraphicsEnvironment.isHeadless()); 043 } 044 045 /** 046 * Checks if {@link JMathComponent#getPreferredSize() works and updates if 047 * the content changes. 048 */ 049 @Test 050 public void testPreferredSize() { 051 final JMathComponent jmc = new JMathComponent(); 052 final Dimension d = jmc.getPreferredSize(); 053 Assert.assertEquals(d.getHeight(), 0.0, 0.01); 054 Assert.assertEquals(d.getWidth(), 0.0, 0.01); 055 jmc.setContent("<math><mtext>x</mtext></math>"); 056 final Dimension d2 = jmc.getPreferredSize(); 057 Assert.assertTrue(d2.getHeight() > 1); 058 Assert.assertTrue(d2.getWidth() > 1); 059 final Node mtext = jmc.getDocument().getFirstChild().getFirstChild(); 060 mtext.setTextContent("xxx"); 061 final Dimension d3 = jmc.getPreferredSize(); 062 Assert.assertEquals(d3.getHeight(), d2.getHeight(), 0.001); 063 Assert.assertTrue(d3.getWidth() > d2.getWidth()); 064 } 065 }