Package javax.swing.text

Examples of javax.swing.text.StringContent$UndoPosRef


  }
 
  public void testConstructor1(TestHarness harness)
  {
    harness.checkPoint("()");
    StringContent sc = new StringContent();
    harness.check(sc.length(), 1);
   
    boolean pass = false;
    try
    {
      pass = sc.getString(0, 1).equals("\n");
    }
    catch (BadLocationException e)
    {
      harness.fail(e.toString());
    }
View Full Code Here


  }
 
  public void testConstructor2(TestHarness harness)
  {
    harness.checkPoint("(int)");
    StringContent sc = new StringContent(10);
    harness.check(sc.length(), 1);
    boolean pass = false;
    try
    {
      pass = sc.getString(0, 1).equals("\n");
    }
    catch (BadLocationException e)
    {
      harness.fail(e.toString());
    }
View Full Code Here

   *
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)     
  {
    StringContent sc = new StringContent();
    // regular insert
    try
    {
      sc.insertString(0, "ABC");
      // ignoring undo/redo here - see insertUndo.java
    }
    catch (BadLocationException e)
    {
      // ignore - checks below will fail if this happens
    }
    harness.check(sc.length(), 4);
   
    // insert at location before start
    boolean pass = false;
    try
    {
      sc.insertString(-1, "XYZ");
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // insert at index of last character - this is OK
    try
    {
      sc.insertString(3, "XYZ");
    }
    catch (BadLocationException e)
    {
      // ignore
    }
    harness.check(sc.length(), 7);
   
    // insert at index of last character + 1 - this raises BadLocationException
    pass = false;
    try
    {
      sc.insertString(7, "XYZ");
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(pass);

    // insert empty string
    try
    {
      sc.insertString(0, "");
    }
    catch (BadLocationException e)
    {
      // ignore
    }
    harness.check(sc.length(), 7);
   
    // insert null string
    pass = false;
    try
    {
      sc.insertString(0, null);
    }
    catch (BadLocationException e)
    {
      // ignore
    }
View Full Code Here

   *
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)     
  {
    StringContent sc = new StringContent();
    char[] ch = new char[] { 'A', 'B', 'C' };
    Segment seg = new Segment(ch, 0, 3);
   
    // check default result
    try
    {
      sc.getChars(0, 1, seg);
    }
    catch (BadLocationException e)
    {
      // ignore - tests below will fail if this happens
    }
    harness.check(seg.offset, 0);
    harness.check(seg.count, 1);
    harness.check(seg.array != ch);
    harness.check(seg.array[0], '\n');

    // if len goes past end of range, should get BadLocationException
    boolean pass = false;
    try
    {
      sc.getChars(0, 2, seg);
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(pass);

    // add some more text
    try
    {
      sc.insertString(0, "ABCDEFG");
    }
    catch (BadLocationException e)
    {
    }
    harness.check(sc.length(), 8);
   
    // if index < 0 should get BadLocationException
    pass = false;
    try
    {
      sc.getChars(-1, 3, seg);
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // if index > end of text should get BadLocationException
    pass = false;
    try
    {
      sc.getChars(99, 1, seg);
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // if len goes past end of range, should get BadLocationException
    pass = false;
    try
    {
      sc.getChars(0, 99, seg);
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // try a zero length string
    try
    {
      sc.getChars(1, 0, seg);
    }
    catch (BadLocationException e)
    {
    }
    harness.check(seg.offset, 1);
    harness.check(seg.count, 0);
   
    // what happens for null Segment
    pass = false;
    try
    {
      sc.getChars(0, 1, null);
    }
    catch (NullPointerException e)
    {
      pass = true;
    }
    catch (BadLocationException e)
    {
      // ignore
    }
    harness.check(pass);
   
    // what happens if we update the Segment array, does that change the
    // StringContent
    Segment seg2 = new Segment();
    Segment seg3 = new Segment();
    StringContent sc2 = new StringContent();
    try
    {
      sc2.insertString(0, "XYZ");
      sc2.getChars(0, 3, seg2);
      seg2.array[1] = '5';
      sc2.getChars(0, 3, seg3);
    }
    catch (BadLocationException e)
    {
      // ignore
    }
View Full Code Here

{
  public void test(TestHarness h)
  {
    h.checkPoint("BadLocationTest");
    java.util.Locale.setDefault(java.util.Locale.US);
    StringContent sc = new StringContent();
    try
      {
        sc.insertString(-1, "path");
        h.fail("badlocation");
      }
    catch (BadLocationException ble)
      {
        h.check("Invalid location", ble.getMessage(), "BadLocation message should be 'Invalid location' and is: " + ble.getMessage());
        h.check(1, ble.offsetRequested(), "OffsetRequested() should be 1 and is: " + ble.offsetRequested());
      }
    try
      {
        sc.insertString(1, "path");
        h.fail("badlocation");
      }
    catch (BadLocationException ble)
      {
        h.check("Invalid location", ble.getMessage(), "BadLocation message should be 'Invalid location' and is: " + ble.getMessage());
        h.check(1, ble.offsetRequested(), "OffsetRequested() should be 1 and is: " + ble.offsetRequested());
      }
    try
      {
        sc.insertString(4, "path");
        h.fail("badlocation");
      }
    catch (BadLocationException ble)
      {
        h.check("Invalid location", ble.getMessage(), "BadLocation message should be 'Invalid location' and is: " + ble.getMessage());
        h.check(1, ble.offsetRequested(), "OffsetRequested() should be 1 and is: " + ble.offsetRequested());
      }
    try
      {
        sc.insertString(0, "path");
        sc.getString(1, sc.length());
        h.fail("badlocation");
      }
    catch (BadLocationException ble)
      {
        h.check("Invalid range", ble.getMessage(), "BadLocation message should be 'Invalid range' and is: " + ble.getMessage());
        h.check(5, ble.offsetRequested(), "OffsetRequested() should be 5 and is: " + ble.offsetRequested());
      }
    try
      {
        sc.insertString(0, "path");
        sc.getString(0, sc.length()+1);
        h.fail("badlocation");
      }
    catch (BadLocationException ble)
      {
        h.check("Invalid range", ble.getMessage(), "BadLocation message should be 'Invalid range' and is: " + ble.getMessage());
View Full Code Here

   *
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)     
  {
    StringContent sc = new StringContent();
   
    // check default result
    boolean pass = false;
    try
    {
      pass = sc.getString(0, 1).equals("\n");
    }
    catch (BadLocationException e)
    {
    }
    harness.check(pass);

    // if len goes past end of range, should get BadLocationException
    pass = false;
    try
    {
      sc.getString(0, 2);
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(pass);

    // add some more text
    try
    {
      sc.insertString(0, "ABCDEFG");
    }
    catch (BadLocationException e)
    {
    }
    harness.check(sc.length(), 8);
   
    // if index < 0 should get BadLocationException
    pass = false;
    try
    {
      /*String s =*/ sc.getString(-1, 3);
    }
    catch (StringIndexOutOfBoundsException e)
    {
      pass = false// JDK does this, API docs say it should be a
                     // BadLocationException
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // if index > end of text should get BadLocationException
    pass = false;
    try
    {
      /*String s =*/ sc.getString(99, 1);
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // if len goes past end of range, should get BadLocationException
    pass = false;
    try
    {
      /* String s =*/ sc.getString(0, 99);
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // try a zero length string
    pass = false;
    try
    {
      pass = sc.getString(1, 0).equals("");
    }
    catch (BadLocationException e)
    {
    }
    harness.check(pass);
View Full Code Here

{
  public void test(TestHarness h)
  {
    h.checkPoint("StringContent");

    StringContent sc = new StringContent();
    try
      {
        h.checkPoint("StringContent -- insertString()");
        sc.insertString(0, "path");
        h.check("path\n", sc.getString(0, sc.length()),
                "StringContent.insertString(): insert 'path' at 0 getString() is: " + sc.getString(0, sc.length()));
        h.checkPoint("StringContent -- length()");
        h.check(5, sc.length(),
                "StringContent.length(): should be 5, is: " + sc.length());
        h.checkPoint("StringContent -- insertString() part2");
        sc.insertString(0, "class");
        h.checkPoint("StringContent -- getString()");
        h.check("classpath\n", sc.getString(0, sc.length()),
                "StringContent.insertString(): put 'class' at 0 should be 'classpath' and is: " + sc.getString(0, sc.length()));
        h.checkPoint("StringContent -- length() part2");
        h.check(10, sc.length(),
                "StringContent.length(): should be 10, is: " + sc.length());
        h.checkPoint("StringContent -- remove()");
        sc.remove(1, 4);
        h.checkPoint("StringContent -- getString() part2");
        h.check("cpath\n", sc.getString(0, sc.length()),
                "StringContent.remove(): should be 'cpath' is '"
                + sc.getString(0, sc.length()) + "'");
        h.checkPoint("StringContent -- remove() part2");
        sc.remove(2, 3);
        h.checkPoint("StringContent -- getString() part3");
        h.check("cp\n", sc.getString(0, sc.length()),
                "StringContent.remove(): should be 'cp' is '"
                + sc.getString(0, sc.length()) + "'");
        h.checkPoint("StringContent -- getChars()");
        char[] ctab = { 'c', 'p' , '\n'};
        Segment s = new Segment(ctab, 0, 3);
        Segment s2 = new Segment();
        sc.getChars(0, sc.length(), s2);
        h.check(s.toString(), s2.toString(),
                "StringContent.getChars(): "
                + "compare to javax.swing.text.Segment "
                + "(first Segment: " + s + "; second Segment: " + s2 + ")");
        h.checkPoint("StringContent -- StringContent()");
        sc = new StringContent(100);
        h.check("\n", sc.getString(0, sc.length()), "StringContent(100): getString(0, lenght) should be '\\n'");
        h.check(1, sc.length(), "StringContent(100): length() should be 1 and is : " + sc.length());
        h.checkPoint("StringContent -- StringContent() part2");
        sc = new StringContent(1);
        h.check(1, sc.length(), "StringContent(1): length() should be 1 and is : " + sc.length());
        h.checkPoint("StringContent -- StringContent() part3");
        sc = new StringContent(0);
        h.check(1, sc.length(), "StringContent(0): length() should be 1 and is : " + sc.length());
        h.checkPoint("StringContent -- StringContent() part4");
        sc = new StringContent();
        h.check(1, sc.length(), "StringContent(): length() should be 1 and is : " + sc.length());
      }
    catch (BadLocationException ble)
      {
        h.fail("BadLocation! " + ble.getMessage());
      }
View Full Code Here

{
  public void test(TestHarness h)
  {
    h.checkPoint("StringContent -- InsertUndo");

    StringContent sc = new StringContent();
    UndoableEdit ue = null;
    UndoableEdit ue2 = null;
    UndoableEdit ue3 = null;
    try
      {
        h.checkPoint("StringContent -- insertString()");
        ue = sc.insertString(0, "path");
        h.check("path\n", sc.getString(0, sc.length()),
                "StringContent.insertString(): insert 'path' at 0");
        java.util.Locale.setDefault(java.util.Locale.US);
        String presentationName = ue.getPresentationName();
        h.check("", presentationName, "PresentationName should be '' and is: " + presentationName);
        String redoPresentationName = ue.getRedoPresentationName();
        h.check("Redo", redoPresentationName, "RedoPresentationName should be Redo and is: " + redoPresentationName);
        String undoPresentationName = ue.getUndoPresentationName();
        h.check("Undo", undoPresentationName, "UndoPresentationName should be Undo and is: " + undoPresentationName);
        h.check(false, ue.canRedo(), "canRedo? () (" + ue.canRedo() + ")");
        h.check(true, ue.canUndo(), "canUndo? () (" + ue.canUndo() + ")");
        ue.undo();
        h.check("\n", sc.getString(0, sc.length()),
                "Undo: should be '\\n' and is: " + sc.getString(0, sc.length()));
        h.check(true, ue.canRedo(), "canRedo? () (" + ue.canRedo() + ")");
        h.check(false, ue.canUndo(), "canUndo? () (" + ue.canUndo() + ")");
        ue.redo();
        h.check("path\n", sc.getString(0, sc.length()),
                "Redo: should be '\\n' and is: " + sc.getString(0, sc.length()));
        ue.die();
        h.debug("UndoableEdit.die() no more undo/redo");
        h.check(false, ue.canUndo(), "die, no more undo");
        h.check(false, ue.canRedo(), "die, no more redo");
        sc = new StringContent();
        ue = sc.insertString(0, "path");
        ue2 = sc.insertString(0, "class");
        h.check("classpath\n", sc.getString(0, sc.length()), "should be classpath and is: " + sc.getString(0, sc.length()));
        h.check(true, ue.canUndo(), "double undo can undo?");
        ue.undo();
        h.check("spath\n", sc.getString(0, sc.length()), "double undo: should be 'spath\\n' and is: " + sc.getString(0, sc.length()));
        ue2.undo();
        h.check("\n", sc.getString(0, sc.length()), "double undo: should be '\\n' and is: " + sc.getString(0, sc.length()));
        ue.redo();
        h.check("clas\n", sc.getString(0, sc.length()), "double undo: should be 'clas\\n' and is: " + sc.getString(0, sc.length()));
        ue2.redo();
        h.check("spathclas\n", sc.getString(0, sc.length()), "double undo: should be 'spathclas\\n' and is: " + sc.getString(0, sc.length()));
        ue3 = sc.insertString(9, "X");
        h.check("spathclasX\n", sc.getString(0, sc.length()), "add an X: should be 'spathclasX\\n' and is: " + sc.getString(0, sc.length()));
        ue.undo();
        h.check("hclasX\n", sc.getString(0, sc.length()), "undo first position: should be 'hclasX\\n' and is: " + sc.getString(0, sc.length()));
      }
    catch (BadLocationException ble)
      {
        h.fail("BadLocation! " + ble.getMessage());
      }
    try{
      ue3.undo();
      h.fail("should not be able to undo!");
    }
    catch (CannotUndoException cannot)
      {
        h.checkPoint("cannot undo");
      }
    try
      {
        sc = new StringContent();
        ue = sc.insertString(0, "class");
        ue2 = sc.insertString(0, "super ");
        ue3 = sc.insertString(11, "path");
        h.check("super classpath\n", sc.getString(0, sc.length()), "insert 'super classpath': " + sc.getString(0, sc.length()));
        ue.undo();
        h.check(" classpath\n", sc.getString(0, sc.length()), "undo ' classpath': " + sc.getString(0, sc.length()));
        ue.undo();
        h.fail("should not be able to undo two times");
      }
    catch (BadLocationException ble)
      {
View Full Code Here

   *
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)     
  {
    StringContent sc = new StringContent();
    harness.check(sc.length(), 1);
    try
    {
      sc.insertString(0, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
      harness.check(sc.length(), 27);
      sc.remove(0, 3);
      harness.check(sc.length(), 24);
      sc.insertString(4, "123");
      harness.check(sc.length(), 27);
      sc.remove(20, 5);
      harness.check(sc.length(), 22)
    }
    catch (BadLocationException e)
    {
      harness.fail(e.toString())
    }
View Full Code Here

    testRemoveLast(harness);
  }
 
  public void testGeneral(TestHarness harness)
  {
    StringContent sc = new StringContent();
    // regular insert
    try
    {
      sc.insertString(0, "ABCDEFG");
      // ignoring undo/redo here - see insertUndo.java
    }
    catch (BadLocationException e)
    {
      // ignore - checks below will fail if this happens
    }
    harness.check(sc.length(), 8);
   
    // remove from location before start
    boolean pass = false;
    try
    {
      sc.remove(-1, 3);
    }
    catch (BadLocationException e)
    {
      pass = true// Classpath does this
    }
    catch (StringIndexOutOfBoundsException e)
    {
      pass = false// JDK does this - it is a bug given the API spec
    }
    harness.check(pass);
   
    // remove from location after end
    pass = false;
    try
    {
      sc.remove(99, 1);
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // doesn't allow removal of last char
    pass = false;
    try
    {
      sc.remove(7, 1);
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(pass);
    harness.check(sc.length(), 8);

    // remove 0 chars
    pass = true;
    try
    {
      sc.remove(0, 0);
    }
    catch (BadLocationException e)
    {
      pass = false;
    }
    harness.check(pass);
    harness.check(sc.length(), 8);
   
  }
View Full Code Here

TOP

Related Classes of javax.swing.text.StringContent$UndoPosRef

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.