jdk/test/javax/swing/JFormattedTextField/Test6462562.java
author mfang
Wed, 17 Aug 2011 14:18:26 -0700
changeset 10294 8fcdae2a7ec7
parent 6374 e214162c907e
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6102
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
     1
/*
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
     2
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
     4
 *
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
     7
 * published by the Free Software Foundation.
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
     8
 *
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    13
 * accompanied this code).
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    14
 *
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    18
 *
6374
e214162c907e 6982137: Rebranding pass 2 - missed copyright changes
ohair
parents: 6102
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e214162c907e 6982137: Rebranding pass 2 - missed copyright changes
ohair
parents: 6102
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e214162c907e 6982137: Rebranding pass 2 - missed copyright changes
ohair
parents: 6102
diff changeset
    21
 * questions.
6102
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    22
 */
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    23
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    24
/* @test
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    25
   @bug 6462562
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    26
   @summary Tests text input into JFormattedTextField
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    27
            with an InternationalFormatter
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    28
   @author Peter Zhelezniakov
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    29
   @run main Test6462562
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    30
*/
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    31
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    32
import java.awt.event.ActionEvent;
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    33
import java.text.DateFormat;
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    34
import java.text.NumberFormat;
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    35
import java.text.ParseException;
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    36
import java.text.SimpleDateFormat;
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    37
import java.util.Date;
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    38
import java.util.Locale;
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    39
import javax.swing.Action;
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    40
import javax.swing.JFormattedTextField;
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    41
import javax.swing.SwingUtilities;
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    42
import javax.swing.text.Caret;
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    43
import javax.swing.text.DateFormatter;
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    44
import javax.swing.text.DefaultEditorKit;
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    45
import javax.swing.text.InternationalFormatter;
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    46
import javax.swing.text.NumberFormatter;
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    47
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    48
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    49
public class Test6462562
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    50
{
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    51
    static final String BACKSPACE = new String("backspace");
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    52
    static final String DELETE = new String("delete");
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    53
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    54
    boolean failed = false;
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    55
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    56
    void test() {
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    57
        testPercentFormat();
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    58
        testCurrencyFormat();
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    59
        testIntegerFormat();
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    60
        testDateFormat();
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    61
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    62
        if (failed) {
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    63
            throw new RuntimeException("Some testcases failed, see output above");
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    64
        }
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    65
        System.err.println("(-;  All testcases passed  ;-)");
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    66
    }
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    67
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    68
    TestFormattedTextField create(NumberFormat format) {
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    69
        format.setMaximumFractionDigits(0);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    70
        NumberFormatter fmt = new NumberFormatter(format);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    71
        return new TestFormattedTextField(fmt);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    72
    }
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    73
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    74
    TestFormattedTextField create(DateFormat format) {
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    75
        DateFormatter fmt = new DateFormatter(format);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    76
        return new TestFormattedTextField(fmt);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    77
    }
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    78
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    79
    public static void main(String[] args) throws Exception {
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    80
        SwingUtilities.invokeAndWait(new Runnable() {
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    81
            public void run() {
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    82
                new Test6462562().test();
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    83
            }
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    84
        });
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    85
    }
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    86
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    87
    class TestFormattedTextField extends JFormattedTextField
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    88
    {
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    89
        final Action backspace;
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    90
        final Action delete;
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    91
        final Action insert;
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    92
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    93
        final ActionEvent dummyEvent;
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    94
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    95
        public TestFormattedTextField(InternationalFormatter fmt) {
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    96
            super(fmt);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    97
            fmt.setAllowsInvalid(false);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    98
            fmt.setOverwriteMode(true);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
    99
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   100
            backspace = getActionMap().get(DefaultEditorKit.deletePrevCharAction);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   101
            delete = getActionMap().get(DefaultEditorKit.deleteNextCharAction);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   102
            insert = getActionMap().get(DefaultEditorKit.insertContentAction);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   103
            dummyEvent = new ActionEvent(this, 0, null);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   104
        }
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   105
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   106
        public boolean test(int pos, int selectionLength, String todo, Object expectedResult) {
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   107
            Object v0 = getValue();
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   108
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   109
            Caret caret = getCaret();
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   110
            caret.setDot(pos);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   111
            if (selectionLength > 0) {
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   112
                caret.moveDot(pos + selectionLength);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   113
            }
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   114
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   115
            String desc = todo;
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   116
            if (todo == BACKSPACE) {
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   117
                backspace.actionPerformed(dummyEvent);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   118
            } else if (todo == DELETE) {
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   119
                delete.actionPerformed(dummyEvent);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   120
            } else {
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   121
                desc = "insert('" + todo + "')";
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   122
                insert.actionPerformed(new ActionEvent(this, 0, todo));
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   123
            }
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   124
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   125
            try {
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   126
                commitEdit();
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   127
            } catch (ParseException e) {
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   128
                e.printStackTrace();
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   129
                failed = true;
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   130
                return false;
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   131
            }
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   132
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   133
            Object v1 = getValue();
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   134
            if (! v1.equals(expectedResult)) {
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   135
                System.err.printf("Failure: value='%s', mark=%d, dot=%d, action=%s\n",
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   136
                        v0, pos, pos + selectionLength, desc);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   137
                System.err.printf("   Result: '%s', expected: '%s'\n", v1, expectedResult);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   138
                failed = true;
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   139
                return false;
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   140
            }
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   141
            return true;
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   142
        }
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   143
    }
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   144
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   145
    void testPercentFormat() {
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   146
        NumberFormat format = NumberFormat.getPercentInstance(Locale.US);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   147
        TestFormattedTextField ftf = create(format);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   148
        ftf.setValue(.34);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   149
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   150
        System.err.println("Testing NumberFormat.getPercentInstance(Locale.US)");
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   151
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   152
        // test inserting individual characters
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   153
        ftf.test(0, 0, "1", .14);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   154
        ftf.test(2, 0, "2", 1.42);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   155
        ftf.test(1, 0, "0", 1.02);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   156
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   157
        // test inserting several characters at once - e.g. from clipboard
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   158
        ftf.test(0, 0, "1024", 10.24);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   159
        ftf.test(3, 0, "333", 103.33);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   160
        ftf.test(6, 0, "77", 10333.77);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   161
        ftf.test(4, 0, "99", 10399.77);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   162
        ftf.test(6, 0, "00", 10390.07);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   163
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   164
        // test inserting strings that contain some formatting
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   165
        ftf.test(0, 0, "2,2", 2290.07);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   166
        ftf.test(2, 0, "2,2", 222.27);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   167
        ftf.test(4, 0, "2,2", 222.22);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   168
        ftf.test(6, 0, "33,33", 2222233.33);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   169
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   170
        // test delete
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   171
        ftf.test(0, 0, DELETE, 222233.33);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   172
        ftf.test(10, 0, DELETE, 222233.33);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   173
        ftf.test(5, 0, DELETE, 22223.33);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   174
        ftf.test(6, 0, DELETE, 2222.33);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   175
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   176
        // test backspace
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   177
        ftf.test(0, 0, BACKSPACE, 2222.33);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   178
        ftf.test(7, 0, BACKSPACE, 222.23);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   179
        ftf.test(4, 0, BACKSPACE, 22.23);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   180
        ftf.test(2, 0, BACKSPACE, 2.23);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   181
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   182
        // test replacing selection
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   183
        ftf.test(0, 1, "555", 555.23);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   184
        ftf.test(4, 2, "555", 5555.55);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   185
        ftf.test(2, 3, "1", 551.55);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   186
        ftf.test(3, 2, "6", 55.65);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   187
        ftf.test(4, 2, "12", 556.12);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   188
        ftf.test(3, 4, "0", 5.5);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   189
        ftf.test(0, 3, "111222333444555", 1112223334445.55);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   190
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   191
        // test deleting selection
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   192
        ftf.test(0, 2, DELETE, 12223334445.55);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   193
        ftf.test(0, 3, BACKSPACE, 223334445.55);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   194
        ftf.test(12, 2, DELETE, 2233344.45);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   195
        ftf.test(9, 2, BACKSPACE, 22333.44);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   196
        ftf.test(4, 3, DELETE, 223.44);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   197
        ftf.test(1, 2, BACKSPACE, 23.44);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   198
        ftf.test(3, 3, DELETE, .23);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   199
        ftf.test(1, 2, BACKSPACE, .02);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   200
    }
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   201
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   202
    void testCurrencyFormat() {
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   203
        NumberFormat format = NumberFormat.getCurrencyInstance(Locale.US);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   204
        TestFormattedTextField ftf = create(format);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   205
        ftf.setValue(56L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   206
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   207
        System.err.println("Testing NumberFormat.getCurrencyInstance(Locale.US)");
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   208
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   209
        // test inserting individual characters
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   210
        ftf.test(1, 0, "1", 16L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   211
        ftf.test(3, 0, "2", 162L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   212
        ftf.test(2, 0, "0", 102L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   213
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   214
        // test inserting several characters at once - e.g. from clipboard
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   215
        ftf.test(1, 0, "1024", 1024L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   216
        ftf.test(4, 0, "333", 10333L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   217
        ftf.test(7, 0, "77", 1033377L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   218
        ftf.test(5, 0, "99", 1039977L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   219
        ftf.test(7, 0, "00", 1039007L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   220
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   221
        // test inserting strings that contain some formatting
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   222
        ftf.test(1, 0, "2,2", 229007L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   223
        ftf.test(3, 0, "2,2", 22227L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   224
        ftf.test(4, 0, "2,2", 2222L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   225
        ftf.test(6, 0, "33,33", 22223333L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   226
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   227
        // test delete
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   228
        ftf.test(1, 0, DELETE, 2223333L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   229
        ftf.test(10, 0, DELETE, 2223333L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   230
        ftf.test(5, 0, DELETE, 222333L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   231
        ftf.test(5, 0, DELETE, 22233L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   232
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   233
        // test backspace
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   234
        ftf.test(1, 0, BACKSPACE, 22233L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   235
        ftf.test(7, 0, BACKSPACE, 2223L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   236
        ftf.test(4, 0, BACKSPACE, 223L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   237
        ftf.test(2, 0, BACKSPACE, 23L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   238
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   239
        // test replacing selection
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   240
        ftf.test(1, 1, "555", 5553L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   241
        ftf.test(4, 2, "555", 55555L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   242
        ftf.test(2, 3, "1", 5155L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   243
        ftf.test(3, 2, "6", 565L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   244
        ftf.test(1, 3, "111222333444555", 111222333444555L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   245
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   246
        // test deleting selection
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   247
        ftf.test(1, 2, DELETE, 1222333444555L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   248
        ftf.test(1, 3, BACKSPACE, 22333444555L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   249
        ftf.test(13, 2, DELETE, 223334445L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   250
        ftf.test(10, 2, BACKSPACE, 2233344L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   251
        ftf.test(4, 4, DELETE, 2244L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   252
        ftf.test(1, 4, BACKSPACE, 4L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   253
    }
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   254
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   255
    void testIntegerFormat() {
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   256
        NumberFormat format = NumberFormat.getIntegerInstance(Locale.US);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   257
        TestFormattedTextField ftf = create(format);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   258
        ftf.setValue(56L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   259
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   260
        System.err.println("Testing NumberFormat.getIntegerInstance(Locale.US)");
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   261
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   262
        // test inserting individual characters
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   263
        ftf.test(0, 0, "1", 16L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   264
        ftf.test(2, 0, "2", 162L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   265
        ftf.test(1, 0, "0", 102L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   266
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   267
        // test inserting several characters at once - e.g. from clipboard
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   268
        ftf.test(0, 0, "1024", 1024L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   269
        ftf.test(3, 0, "333", 10333L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   270
        ftf.test(6, 0, "77", 1033377L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   271
        ftf.test(4, 0, "99", 1039977L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   272
        ftf.test(6, 0, "00", 1039007L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   273
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   274
        // test inserting strings that contain some formatting
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   275
        ftf.test(0, 0, "2,2", 229007L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   276
        ftf.test(2, 0, "2,2", 22227L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   277
        ftf.test(3, 0, "2,2", 2222L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   278
        ftf.test(5, 0, "33,33", 22223333L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   279
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   280
        // test delete
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   281
        ftf.test(0, 0, DELETE, 2223333L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   282
        ftf.test(9, 0, DELETE, 2223333L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   283
        ftf.test(4, 0, DELETE, 222333L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   284
        ftf.test(4, 0, DELETE, 22233L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   285
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   286
        // test backspace
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   287
        ftf.test(0, 0, BACKSPACE, 22233L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   288
        ftf.test(6, 0, BACKSPACE, 2223L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   289
        ftf.test(2, 0, BACKSPACE, 223L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   290
        ftf.test(2, 0, BACKSPACE, 23L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   291
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   292
        // test replacing selection
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   293
        ftf.test(0, 1, "555", 5553L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   294
        ftf.test(3, 2, "555", 55555L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   295
        ftf.test(1, 3, "1", 5155L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   296
        ftf.test(2, 2, "6", 565L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   297
        ftf.test(0, 3, "111222333444555", 111222333444555L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   298
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   299
        // test deleting selection
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   300
        ftf.test(0, 2, DELETE, 1222333444555L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   301
        ftf.test(0, 3, BACKSPACE, 22333444555L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   302
        ftf.test(12, 2, DELETE, 223334445L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   303
        ftf.test(9, 2, BACKSPACE, 2233344L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   304
        ftf.test(3, 4, DELETE, 2244L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   305
        ftf.test(0, 4, BACKSPACE, 4L);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   306
    }
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   307
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   308
    Date date(DateFormat format, String spec) {
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   309
        try {
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   310
            return format.parse(spec);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   311
        } catch (ParseException e) {
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   312
            throw new Error("Error in test");
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   313
        }
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   314
    }
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   315
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   316
    void testDateFormat() {
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   317
        DateFormat format = new SimpleDateFormat("MM/dd/yyyy", Locale.US);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   318
        TestFormattedTextField ftf = create(format);
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   319
        ftf.setValue(date(format, "12/05/2005"));
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   320
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   321
        System.err.println("Testing SimpleDateFormat(\"MM/dd/yyyy\", Locale.US)");
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   322
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   323
        // test inserting individual characters
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   324
        ftf.test(0, 0, "0", date(format, "02/05/2005"));
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   325
        ftf.test(4, 0, "4", date(format, "02/04/2005"));
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   326
        ftf.test(6, 0, "1", date(format, "02/04/1005"));
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   327
        ftf.test(9, 0, "9", date(format, "02/04/1009"));
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   328
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   329
        // test inserting several characters at once - e.g. from clipboard
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   330
        ftf.test(0, 0, "11", date(format, "11/04/1009"));
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   331
        ftf.test(3, 0, "23", date(format, "11/23/1009"));
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   332
        ftf.test(6, 0, "191", date(format, "11/23/1919"));
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   333
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   334
        // test delete
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   335
        ftf.test(0, 0, DELETE, date(format, "01/23/1919"));
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   336
        ftf.test(3, 0, DELETE, date(format, "01/03/1919"));
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   337
        ftf.test(10, 0, DELETE, date(format, "01/03/1919"));
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   338
        ftf.test(1, 0, DELETE, date(format, "12/03/1918"));
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   339
        ftf.test(4, 0, DELETE, date(format, "11/30/1918"));
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   340
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   341
        // test backspace
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   342
        ftf.test(0, 0, BACKSPACE, date(format, "11/30/1918"));
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   343
        ftf.test(1, 0, BACKSPACE, date(format, "01/30/1918"));
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   344
        ftf.test(4, 0, BACKSPACE, date(format, "12/31/1917"));
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   345
        ftf.test(10, 0, BACKSPACE, date(format, "12/31/0191"));
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   346
        ftf.test(3, 0, BACKSPACE, date(format, "01/31/0191"));
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   347
        ftf.test(5, 0, BACKSPACE, date(format, "01/03/0191"));
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   348
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   349
        // test replacing selection
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   350
        ftf.test(0, 1, "1", date(format, "11/03/0191"));
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   351
        ftf.test(3, 1, "2", date(format, "11/23/0191"));
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   352
        ftf.test(6, 2, "20", date(format, "11/23/2091"));
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   353
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   354
        // test deleting selection
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   355
        ftf.test(0, 1, BACKSPACE, date(format, "01/23/2091"));
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   356
        ftf.test(3, 1, DELETE, date(format, "01/03/2091"));
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   357
        ftf.test(6, 2, BACKSPACE, date(format, "01/03/0091"));
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   358
        ftf.test(8, 1, DELETE, date(format, "01/03/0001"));
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   359
    }
06e0e43b3f09 6462562: InternationalFormatter inserts text incorrectly
peterz
parents:
diff changeset
   360
}