[Spedit-commits] CVS: prototype/Sources/net/sourceforge/spedit/core/test StyleableTestCase.java,NONE
Status: Planning
Brought to you by:
krunte
Update of /cvsroot/spedit/prototype/Sources/net/sourceforge/spedit/core/test In directory usw-pr-cvs1:/tmp/cvs-serv21181/net/sourceforge/spedit/core/test Added Files: StyleableTestCase.java XMLBridgeTestCase.java XMLDocumentTestCase.java XMLElementTestCase.java XMLTextTestCase.java Log Message: New element menu, add element bug fix. --- NEW FILE: StyleableTestCase.java --- // ---------------------------------------------------@RisingSun//Java//1.0//EN // Project : SPEdit-Prototypes-TestCases // ClassName : StyleableTestCase // Version : 0.08 // Type : Test case // // ThreadSafe : - // Description : A test case for Styleable.Utils class. // // URL : <http://SPEdit.sourceforge.net> // ---------------------------------------------------------------------------- // Authors : Sebastien Pierre <sp...@is...> // ---------------------------------------------------------------------------- // Creation date : 26-Sep-2001 // Last mod. : 26-Sep-2001 // History : // 26-Sep-2001 First implementation.(SP) // // Bugs : // - // // To do : // - // - // package net.sourceforge.spedit.core.test; import junit.framework.*; import javax.swing.text.*; import java.util.*; import java.awt.Color; import net.sourceforge.spedit.core.*; public class StyleableTestCase extends TestCase { public StyleableTestCase(String name) { super(name); } protected void setUp() { } //------------------------------------------------------------------------- // // Test suite // //------------------------------------------------------------------------- /** * Test the recognition of colors */ public void testIdentifyColor() { assertEquals(Styleable.Utils.COLOR, Styleable.Utils.identify("#FFFFFF")); assertEquals(new Color(255,255,255), Styleable.Utils.parseColor("#FFFFFF")); assertEquals(Styleable.Utils.COLOR, Styleable.Utils.identify("#FF201009")); assertEquals(new Color(255,32,16,9), Styleable.Utils.parseColor("#FF201009")); assertEquals(Styleable.Utils.UNKNOWN, Styleable.Utils.identify("#FFFFF")); assertEquals(Styleable.Utils.UNKNOWN, Styleable.Utils.identify("#FFFF")); } /** * Test the recognition of pixels */ public void testIdentifyPixel() { assertEquals(Styleable.Utils.PIXEL, Styleable.Utils.identify("10")); assertEquals(10, Styleable.Utils.parsePixel("10")); assertEquals(Styleable.Utils.UNKNOWN, Styleable.Utils.identify("10a")); } /** * Test the recognition of points */ public void testIdentifyPoint() { assertEquals(Styleable.Utils.POINT, Styleable.Utils.identify("10pt")); assertEquals(Styleable.Utils.POINT, Styleable.Utils.identify("10.1pt")); assert(10.0==Styleable.Utils.parsePoint("10.0pt")); assert(10.1==Styleable.Utils.parsePoint("10.1pt")); assertEquals(Styleable.Utils.UNKNOWN, Styleable.Utils.identify("10.0p")); } /** * Test the splitStyle method. This tests a simple property, a property * nested in two groups, and a property nested in three groups. */ public void testSplitStyle() { String[] st = Styleable.Utils.splitStyle("block"); assertEquals(1, st.length); assertEquals("block", st[0]); st = Styleable.Utils.splitStyle("block.border"); assertEquals(2, st.length); assertEquals("block", st[0]); assertEquals("border", st[1]); st = Styleable.Utils.splitStyle("block.border.color"); assertEquals(3, st.length); assertEquals("block", st[0]); assertEquals("border", st[1]); assertEquals("color", st[2]); } //------------------------------------------------------------------------- // // Testing the style object // //------------------------------------------------------------------------- /** * Tests the <code>Style</code> object. */ public void testStyle() { Styleable.StyleSheet stylea = new Styleable.StyleSheet(); Styleable.StyleSheet styleb = new Styleable.StyleSheet(); stylea.setStyleClass("font.name", String.class); assertEquals(String.class, stylea.getStyleClass("font.name")); stylea.setStyle("font.name", "Times"); assertEquals("Times", stylea.getStyle("font.name")); //We test the inheritance of the fonts styleb.inheritStyle("font", stylea); assertEquals("Times", styleb.getStyle("font.name")); assertEquals(String.class, stylea.getStyleClass("font.name")); //We check the dynamicity stylea.setStyle("font.name", "Arial"); assertEquals("Arial", stylea.getStyle("font.name")); assertEquals("Arial", styleb.getStyle("font.name")); //We mask the font.name property in styleb styleb.setStyle("font.name", "AvantGarde"); assertEquals("Arial", stylea.getStyle("font.name")); assertEquals("AvantGarde", styleb.getStyle("font.name")); styleb.inheritStyle(stylea); stylea.setStyle("border.size",new Integer(1)); assertEquals(new Integer(1), stylea.getStyle("border.size")); assertEquals(new Integer(1), styleb.getStyle("border.size")); } //------------------------------------------------------------------------- // // Integration // //------------------------------------------------------------------------- public static Test suite() { TestSuite suite = new TestSuite(StyleableTestCase.class); return suite; } public static void main(String args[]) { String[] testCaseName = {StyleableTestCase.class.getName()}; junit.swingui.TestRunner.main(testCaseName); } } // EOF-Unix/ASCII--------------------------------------@RisingSun//Java/1.0//EN --- NEW FILE: XMLBridgeTestCase.java --- // ---------------------------------------------------@RisingSun//Java//1.0//EN // Project : SPEdit-Prototypes-TestCases // ClassName : XMLBridgeTestCase // Version : 0.08 // Type : Package test case // // ThreadSafe : - // Description : A test case for testing every component of the // XMLBridge package. // // URL : <http://SPEdit.sourceforge.net> // ---------------------------------------------------------------------------- // Authors : Sebastien Pierre <sp...@is...> // ---------------------------------------------------------------------------- // Creation date : 10-Sep-2001 // Last mod. : 10-Sep-2001 // History : // 10-Sep-2001 First implementation.(SP) // // Bugs : // - // // To do : // - // package net.sourceforge.spedit.core.test; import java.util.*; import junit.framework.*; import net.sourceforge.spedit.core.*; public class XMLBridgeTestCase extends TestCase { public XMLBridgeTestCase(String name) { super(name); } //------------------------------------------------------------------------- // // Integration // //------------------------------------------------------------------------- public static Test suite() { TestSuite suite = new TestSuite(); suite.addTest(XMLDocumentTestCase.suite()); suite.addTest(XMLElementTestCase.suite()); suite.addTest(XMLTextTestCase.suite()); suite.addTest(StyleableTestCase.suite()); return suite; } public static void main(String args[]) { String[] testCaseName = {XMLBridgeTestCase.class.getName()}; junit.swingui.TestRunner.main(testCaseName); } } // EOF-Unix/ASCII-------------------------------------@RisingSun//Java//1.0//EN --- NEW FILE: XMLDocumentTestCase.java --- // ---------------------------------------------------@RisingSun//Java//1.0//EN // Project : SPEdit-Prototypes-TestCases // ClassName : XMLDocumentTestCase // Version : 0.40 // Type : Test case // // ThreadSafe : - // Description : A test case for the XMLDocument class. // // URL : <http://SPEdit.sourceforge.net> // ---------------------------------------------------------------------------- // Authors : Sebastien Pierre <sp...@is...> // ---------------------------------------------------------------------------- // Creation date : 10-Sep-2001 // Last mod. : 27-Sep-2001 // History : // 27-Sep-2001 Position test case.(SP) // 10-Sep-2001 First implementation.(SP) // // Bugs : // - // // To do : // -Test events (seems like difficult). // -Extensive test of the getText method // // package net.sourceforge.spedit.core.test; import junit.framework.*; import javax.swing.event.*; import javax.swing.text.*; import java.util.*; import net.sourceforge.spedit.core.*; public class XMLDocumentTestCase extends TestCase { XMLDocument doc; DocumentEvent docEvent; public XMLDocumentTestCase(String name) { super(name); } protected void setUp() { doc = new XMLDocument(); } //------------------------------------------------------------------------- // // Test suite // //------------------------------------------------------------------------- /** * The purpose of this test is to check that the properties can be set and * retrieved properly. */ public void testProperties() { Vector value = new Vector(); value.add("Pouet"); doc.putProperty("Spam", value); assert(value==doc.getProperty("Spam")); value.add("Poupou"); assert(value==doc.getProperty("Spam")); doc.removeProperty("Spam"); assert(doc.getProperty("Spam")==null); } /** * The purpose of this test is to check that when positions are registered * into the document they follow any change made to it. */ public void testPositions() { XMLElement root = new XMLElement("root"); XMLElement child= new XMLElement("child"); XMLDocument doc = new XMLDocument(root); root.addContent("01234"); root.addContent(child); child.addContent("56789"); root.addContent("VWXY"); Position start = doc.createPosition(0); Position end = doc.createPosition(14); Position cpos = doc.createPosition(5); //We check position update after insertion assertEquals("0123456789VWXY", root.getWrapper().getWholeText()); assertEquals(root.getWrapper().getWholeText(), root.getWrapper().getWholeText(0,14)); root.getWrapper().insert("ABCD", 3, Position.Bias.Forward) ; assertEquals(0, start.getOffset()); assertEquals(18, end.getOffset()); assertEquals(9, cpos.getOffset()); assertEquals("0123ABCD456789VWXY", root.getWrapper().getWholeText()); assertEquals(root.getWrapper().getWholeText(), root.getWrapper().getWholeText(0,18)); try{ assertEquals(root.getWrapper().getWholeText(), doc.getTextContent().getString(0, doc.getTextContent().length())); } catch (Exception e) { assertEquals(0,1); } //We check position update after removal System.out.println("Before removal"+root.getWrapper().getWholeText()); root.getWrapper().remove(4,8); System.out.println("After removal"+root.getWrapper().getWholeText()); assertEquals(0, start.getOffset()); assertEquals(14, end.getOffset()); assertEquals(5, cpos.getOffset()); assertEquals(root.getWrapper().getWholeText(), root.getWrapper().getWholeText(0,14)); try{ assertEquals(root.getWrapper().getWholeText(), doc.getTextContent().getString(0, doc.getTextContent().length())); } catch (Exception e) { assertEquals(0,1); } } //------------------------------------------------------------------------- // // Integration // //------------------------------------------------------------------------- public static Test suite() { TestSuite suite = new TestSuite(XMLDocumentTestCase.class); return suite; } public static void main(String args[]) { String[] testCaseName = {XMLDocumentTestCase.class.getName()}; junit.swingui.TestRunner.main(testCaseName); } } // EOF-Unix/ASCII--------------------------------------@RisingSun//Java/1.0//EN --- NEW FILE: XMLElementTestCase.java --- // ---------------------------------------------------@RisingSun//Java//1.0//EN // Project : SPEdit-Prototypes-TestCases // ClassName : XMLAttributeSetTestCase // Version : 0.30 // Type : Test case // // ThreadSafe : - // Description : A test case for the XMLElement and XMLTest classes. // // URL : <http://SPEdit.sourceforge.net> // ---------------------------------------------------------------------------- // Authors : Sebastien Pierre <sp...@is...> // ---------------------------------------------------------------------------- // Creation date : 10-Sep-2001 // Last mod. : 14-Sep-2001 // History : // 14-Sep-2001 Lots of other test case. // 11-Sep-2001 Fixed small bugs.(SP) // 10-Sep-2001 First implementation.(SP) // // Bugs : // - // // To do : // -Test case for testElementInsertion is weak.(SP) // package net.sourceforge.spedit.core.test; import java.util.*; import junit.framework.*; import javax.swing.text.*; import net.sourceforge.spedit.core.*; public class XMLElementTestCase extends TestCase { private XMLDocument doc; private XMLElement docroot; public XMLElementTestCase(String name) { super(name); } protected void setUp() { doc = new XMLDocument(new XMLElement("root")); docroot = (XMLElement)doc.getRootElement(); } protected void tearDown() { } //------------------------------------------------------------------------- // // Tools testing // //------------------------------------------------------------------------- public void testGetOperation() { XMLElementWrapper wrp = new XMLElement().getWrapper(); //We test the left cut assertEquals(wrp.CUT_LEFT,wrp.getOperation(10,10,5,15)); assertEquals(wrp.CUT_LEFT,wrp.getOperation(10,10,10,15)); assertEquals(wrp.CUT_LEFT,wrp.getOperation(10,10,10,19)); //We test the right cut assertEquals(wrp.CUT_RIGHT,wrp.getOperation(10,10,15,25)); assertEquals(wrp.CUT_RIGHT,wrp.getOperation(10,10,15,20)); assertEquals(wrp.CUT_RIGHT, wrp.getOperation(10,10,11,20)); //We test the inside cut assertEquals(wrp.CUT_INSIDE, wrp.getOperation(10,10,11,19)); //We test the deletion assertEquals(wrp.DELETE, wrp.getOperation(10,10,10,20)); assertEquals(wrp.DELETE, wrp.getOperation(10,10,9,20)); assertEquals(wrp.DELETE, wrp.getOperation(10,10,9,21)); //We test the leave assertEquals(wrp.LEAVE, wrp.getOperation(10,10,0,10)); assertEquals(wrp.LEAVE, wrp.getOperation(10,10,0,9)); assertEquals(wrp.LEAVE, wrp.getOperation(10,10,20,22)); } public void testCutString() { XMLElementWrapper wrp = new XMLElement().getWrapper(); String s = new String("ABCDEF"); //We test the left cut assertEquals("BCDEF", wrp.cutString(s,3,0,4)); assertEquals("BCDEF", wrp.cutString(s,3,2,4)); assertEquals("EF", wrp.cutString(s,3,3,7)); assertEquals("F", wrp.cutString(s,3,3,8)); //We test the right cut assertEquals("ABCDE",wrp.cutString(s,3,8,10)); assertEquals("A",wrp.cutString(s,3,4,10)); assertEquals("ABCDE",wrp.cutString(s,3,8,9)); //We test the inside cut assertEquals("ABF",wrp.cutString(s,3,5,8)); assertEquals("ABF",wrp.cutString(s,3,5,8)); assertEquals("ACDEF",wrp.cutString(s,3,4,5)); //We test the deletion assert(wrp.cutString(s,3,3,9)==null); } public void testStaticInsert() { String source="ABCDE"; XMLElementWrapper wrp = new XMLElement().getWrapper(); assertEquals("XABCDE", wrp.insertString(source,"X",0,Position.Bias.Backward)); assertEquals("AXBCDE", wrp.insertString(source,"X",0,Position.Bias.Forward)); assertEquals("ABCDXE", wrp.insertString(source,"X",4,Position.Bias.Backward)); assertEquals("ABCDEX", wrp.insertString(source,"X",4,Position.Bias.Forward)); assertEquals("ABXCDE", wrp.insertString(source,"X",2,Position.Bias.Backward)); assertEquals("ABXCDE", wrp.insertString(source,"X",1,Position.Bias.Forward)); } //------------------------------------------------------------------------- // // XMLElement test // //------------------------------------------------------------------------- public void testElementCreation() { //We check the values of the element at construction XMLElement elem = new XMLElement("Pouet"); assert(elem.getDocument()==null); assert(elem.getParent()==null); assertEquals(elem.getName(), "Pouet"); //Then we add a child XMLElement elem2 = new XMLElement("Pouet-2"); elem.addContent(elem2); //And make sure the axioms are verified assert(elem.getWrapper().getElementCount()==1); assert(elem.getWrapper().getElement(0)==elem2.getWrapper()); assert(elem2.getParent()==elem); assert(elem2.getDocument()==null); //We check that the wrapping count is different from the core element //count elem.addContent("qweqwqe"); assert(elem.getWrapper().getElementCount()==2); assert(elem.getWrapper().getElement(0)==elem2.getWrapper()); //Do the same for elem2 elem2.addContent("qweqwqe"); assert(elem2.getWrapper().getElementCount()==1); XMLElement pouet = new XMLElement(); elem2.addContent(pouet); assert(elem2.getWrapper().getElementCount()==2); assertEquals(pouet.getWrapper(), elem2.getWrapper().getElement(1)); //Then we change the parent document, and check that the //child has also changed of document elem.setDocument(doc); assert(elem.getDocument()!=null); assert(elem2.getDocument()==elem.getDocument()); //Then we remove the child and verify the axioms elem.removeContent(elem2); assert(elem2.getParent()!=elem); assert(elem.getWrapper().getElementCount()==1); } public void testElementInsertion() { XMLElement elem = new XMLElement("Pouet1"); XMLElement elem2 = new XMLElement("Spam1"); //We add the elements to the document docroot.addContent(elem); //We add a structured content elem.addContent("123890"); elem2.addContent("4567"); elem.getWrapper().insert(elem2,3,Position.Bias.Backward); assertEquals("1234567890", elem.getWrapper().getWholeText()); assertEquals(elem2.getWrapper(), elem.getWrapper().getElement(1)); //We add the elements to the document docroot.removeContent(elem); docroot.removeContent(elem2); } public void testElementWrapper() { XMLElement elem = new XMLElement("Pouet2"); XMLElement elem2 = new XMLElement("Spam2"); XMLElement elem3 = new XMLElement("Foobar2"); //We add a structured content elem.addContent("12345"); elem.addContent(elem2); elem.addContent(elem3); elem2.addContent("6789"); elem3.addContent("0123"); elem.addContent("45"); //Verify the attribute axioms assert(elem.getWrapper().getElementCount()==4); assert(elem.getWrapper().getElement(1)==elem2.getWrapper()); assert(elem.getWrapper().getStartOffset()==0); assert(elem.getWrapper().getLength()==15); assert(elem.getWrapper().getEndOffset()==15); assertEquals(5, elem2.getWrapper().getStartOffset()); assertEquals(4, elem2.getWrapper().getLength()); assertEquals(9, elem2.getWrapper().getEndOffset()); //And verify that the wrapper works well assertEquals("123456789012345", elem.getWrapper().getWholeText()); assertEquals( 0, elem.getWrapper().getElementIndex(-1)); assertEquals( 0, elem.getWrapper().getElementIndex(4)); assertEquals( 1, elem.getWrapper().getElementIndex(5)); assertEquals( 1, elem.getWrapper().getElementIndex(8)); assertEquals( 2, elem.getWrapper().getElementIndex(9)); assertEquals( 2, elem.getWrapper().getElementIndex(10)); assertEquals( 2, elem.getWrapper().getElementIndex(12)); assertEquals( 3, elem.getWrapper().getElementIndex(13)); assertEquals( 3, elem.getWrapper().getElementIndex(14)); assertEquals( 3, elem.getWrapper().getElementIndex(15)); } public void testElementOffsets() { XMLElement elem = new XMLElement("Pouet"); XMLElement elem2 = new XMLElement("Spam"); XMLElement elem3 = new XMLElement("Spam"); elem.setDocument(doc); elem.addContent("012345"); elem2.addContent("6789"); elem3.addContent("01"); elem.addContent(elem2); //We check that a child related to its parent assert(elem.getWrapper().getStartOffset()==0); assert(elem.getWrapper().getEndOffset()==10); assert(elem2.getWrapper().getStartOffset()==6); assert(elem2.getWrapper().getEndOffset()==10); //Even when the parent is moved to another parent elem2.addContent(elem3); assert(elem.getWrapper().getStartOffset()==0); assert(elem.getWrapper().getEndOffset()==12); assert(elem2.getWrapper().getStartOffset()==6); assert(elem2.getWrapper().getEndOffset()==12); assert(elem3.getWrapper().getStartOffset()==10); assert(elem3.getWrapper().getEndOffset()==12); } public void testElementRange() { XMLElement elem = new XMLElement("Pouet"); XMLElement elem2 = new XMLElement("Spam"); //We add a structured content elem.addContent("12345"); elem.addContent(elem2); elem2.addContent("6789"); elem.addContent("012345"); //We check that the range work well assert(elem.getWrapper().contains(0,15)); assert(elem.getWrapper().contains(0,16)); assert(elem.getWrapper().contains(14,16)); assert(!elem.getWrapper().contains(15,16)); assert(elem2.getWrapper().contains(0,15)); assert(!elem2.getWrapper().contains(0,4)); assert(elem2.getWrapper().contains(0,5)); assert(elem2.getWrapper().contains(5,15)); assert(elem2.getWrapper().contains(5,8)); assert(elem2.getWrapper().contains(5,9)); assert(!elem2.getWrapper().contains(9,10)); } /** * Tests the following aspects: * <ul> * <li>Removal of a part of a text node.</li> * <li>Removal of an element inside an element</li> * <li>Coherence of the node content during and after the removals.</li> * </ul> */ public void testElementTextRemoval() { XMLElement elem = new XMLElement("Pouet"); XMLElement elem2 = new XMLElement("Spam"); //We add a structured content elem.addContent("12345"); elem.addContent(elem2); elem2.addContent("6789"); elem.addContent("ABCDE"); //We check that the range work well elem.getWrapper().remove(10,15); assertEquals("123456789A",elem.getWrapper().getWholeText()); assert(elem.getWrapper().getElementCount()==3); assert(elem.getWrapper().getElement(1)==elem2.getWrapper()); //And we remove an element elem.getWrapper().remove(elem2.getWrapper().getStartOffset(),elem2.getWrapper().getEndOffset()); assert(elem2.getParent()==null); assertEquals("12345A",elem.getWrapper().getWholeText()); } /** * Test the coeherence of an element after adding text in it. */ public void testElementTextInsertion() { XMLElement elem = new XMLElement("Pouet"); XMLElement elem2 = new XMLElement("Spam"); //We add a structured content elem.addContent("12345"); elem.addContent(elem2); elem2.addContent("6789"); elem.addContent("ABCDE"); //We have text content "123456789ABCDE" //with offsets 01234567890123" // 00000000001111 elem.getWrapper().insert("XX",3,Position.Bias.Forward); assertEquals("1234XX56789ABCDE", elem.getWrapper().getWholeText()); elem.getWrapper().insert("YY",7,Position.Bias.Backward); assertEquals("1234XX5YY6789ABCDE", elem.getWrapper().getWholeText()); assertEquals("YY6789", elem2.getWrapper().getWholeText()); } //------------------------------------------------------------------------- // // XMLAttributes test // //------------------------------------------------------------------------- public void testSetAttribute() { XMLElement elem = new XMLElement("Pouet"); String sampleKey = "Spam"; String sampleValue = "Foobar"; elem.setAttribute(sampleKey, sampleValue); AttributeSet attrs = elem.getWrapper().getAttributes(); //We check what happens when we add the attribute. assert(attrs.isDefined(sampleKey)); assert(attrs.containsAttribute(sampleKey, sampleValue)); assert(attrs.getAttributeCount()==1); assertEquals( sampleValue, attrs.getAttribute(sampleKey) ); assert(attrs.containsAttributes(attrs)); } public void testRemoveAttribute() { XMLElement elem = new XMLElement("Pouet"); String sampleKey = "Spam"; String sampleValue = "Foobar"; elem.setAttribute(sampleKey, sampleValue); AttributeSet attrs = elem.getWrapper().getAttributes(); assert(attrs.containsAttribute(sampleKey, sampleValue)); assert(attrs.getAttributeCount()==1); //And what happens when we remove it. elem.removeAttribute(sampleKey); assert(attrs.getAttributeCount()==0); assert(!attrs.containsAttribute(sampleKey, sampleValue)); assert(!attrs.isDefined(sampleKey)); assert(attrs.containsAttributes(attrs)); } public void testClone() { XMLElement elem = new XMLElement("Pouet"); String sampleKey = "Spam"; String spam = "pouet"; elem.setAttribute(sampleKey, spam); AttributeSet attrs = elem.getWrapper().getAttributes(); AttributeSet attrs2 = attrs.copyAttributes(); AttributeSet attrs3 = attrs.copyAttributes(); assert(attrs2.containsAttributes(attrs)); assert(attrs3.containsAttributes(attrs)); //We change the attr value, and check that attrs2 has not changed. elem.setAttribute(sampleKey, spam+"c"); assert(!attrs.containsAttributes(attrs2)); assert(attrs3.containsAttributes(attrs2)); } //------------------------------------------------------------------------- // // Integration // //------------------------------------------------------------------------- public static Test suite() { TestSuite suite = new TestSuite(XMLElementTestCase.class); return suite; } public static void main(String args[]) { String[] testCaseName = {XMLElementTestCase.class.getName()}; junit.swingui.TestRunner.main(testCaseName); } } // EOF-Unix/ASCII-------------------------------------@RisingSun//Java//1.0//EN --- NEW FILE: XMLTextTestCase.java --- // ---------------------------------------------------@RisingSun//Java//1.0//EN // Project : SPEdit-Prototypes-TestCases // ClassName : XMLTextTestCase // Version : 0.08 // Type : Test case // // ThreadSafe : - // Description : A test case for the XMLText and XMLTextWrapper classes. // // URL : <http://SPEdit.sourceforge.net> // ---------------------------------------------------------------------------- // Authors : Sebastien Pierre <sp...@is...> // ---------------------------------------------------------------------------- // Creation date : 20-Sep-2001 // Last mod. : 20-Sep-2001 // History : // -Sep-2001 First implementation.(SP) // // Bugs : // - // // To do : // - // - // package net.sourceforge.spedit.core.test; import junit.framework.*; import javax.swing.text.*; import java.util.*; import net.sourceforge.spedit.core.*; public class XMLTextTestCase extends TestCase { public XMLTextTestCase(String name) { super(name); } protected void setUp() { } //------------------------------------------------------------------------- // // Test suite // //------------------------------------------------------------------------- /** * The purpose of this test is to check that: * <ul> * <li>When the text content of an XMLElement is changed, the given * XMLText is changed too.</li> * <li>When test is added after an XMLText node then the XMLText node is * extended with the given text</li> * <li>Same test when appending in the middle, and appending at the * beginning.</li> * </ul> */ public void testDynamicity() { XMLElement elem1 = new XMLElement("Spam"); XMLElement elem2 = new XMLElement("Foo"); XMLText text1 = new XMLText("1234"); XMLText text2 = new XMLText("9012"); //We create the test case data elem1.addContent(text1); elem1.addContent(elem2); elem2.addContent("popo"); elem1.addContent(text2); assertEquals("1234", text1.getValue()); assertEquals("9012", text2.getValue()); //We check that the offsets are OK assertEquals(0, text1.getWrapper().getStartOffset()); assertEquals(4, text1.getWrapper().getEndOffset()); assertEquals(4, text1.getWrapper().getLength()); assertEquals(8, text2.getWrapper().getStartOffset()); assertEquals(12,text2.getWrapper().getEndOffset()); assertEquals(4, text2.getWrapper().getLength()); //We check that the text has been dynamically changed when prepending elem1.getWrapper().insert("AB", 0, Position.Bias.Backward); assertEquals("AB1234", text1.getValue()); assertEquals(0, text1.getWrapper().getStartOffset()); assertEquals(6, text1.getWrapper().getEndOffset()); assertEquals(6, text1.getWrapper().getLength()); assertEquals(10, text2.getWrapper().getStartOffset()); assertEquals(14, text2.getWrapper().getEndOffset()); assertEquals(4, text2.getWrapper().getLength()); //That it has been changed when appending elem1.getWrapper().insert("XY", 13, Position.Bias.Forward); assertEquals("9012XY", text2.getValue()); assertEquals(10, text2.getWrapper().getStartOffset()); assertEquals(16, text2.getWrapper().getEndOffset()); assertEquals(6, text2.getWrapper().getLength()); //That is has been changed when inserting elem1.getWrapper().insert("OP", 11, Position.Bias.Forward); assertEquals("90OP12XY", text2.getValue()); assertEquals(10, text2.getWrapper().getStartOffset()); assertEquals(18, text2.getWrapper().getEndOffset()); assertEquals(8, text2.getWrapper().getLength()); } public void testStripping() { XMLText text1 = new XMLText("1234"); XMLText text2 = new XMLText(" 1234"); XMLText text3 = new XMLText(" 1234"); XMLText text4 = new XMLText(" 1234 "); XMLText text5 = new XMLText(" "); XMLText text6 = new XMLText(" "); XMLText text7 = new XMLText(""); text1.strip(); text2.strip(); text3.strip(); text4.strip(); text5.strip(); text6.strip(); text7.strip(); assertEquals("1234",text1.getValue()); assertEquals("1234",text2.getValue()); assertEquals("1234",text3.getValue()); assertEquals("1234",text4.getValue()); assertEquals("",text5.getValue()); assertEquals("",text6.getValue()); assertEquals("",text7.getValue()); } //------------------------------------------------------------------------- // // Integration // //------------------------------------------------------------------------- public static Test suite() { TestSuite suite = new TestSuite(XMLTextTestCase.class); return suite; } public static void main(String args[]) { String[] testCaseName = {XMLTextTestCase.class.getName()}; junit.swingui.TestRunner.main(testCaseName); } } // EOF-Unix/ASCII--------------------------------------@RisingSun//Java/1.0//EN |