View | Details | Raw Unified | Return to bug 183164 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/equinox/bidi/internal/tests/ComplExpMathTest.java (+70 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.equinox.bidi.internal.tests;
13
14
import junit.framework.Test;
15
import junit.framework.TestCase;
16
import junit.framework.TestSuite;
17
18
import org.eclipse.equinox.bidi.complexp.IComplExpProcessor;
19
import org.eclipse.equinox.bidi.complexp.StringProcessor;
20
import org.eclipse.equinox.bidi.complexp.IBiDiProcessor;
21
22
/**
23
 * Tests RTL arithmetic
24
 */
25
public class ComplExpMathTest extends TestCase {
26
    public static Test suite() {
27
        return new TestSuite(ComplExpMathTest.class);
28
    }
29
30
    public ComplExpMathTest() {
31
        super();
32
    }
33
34
    public ComplExpMathTest(String name) {
35
        super(name);
36
    }
37
38
    static void test1(IComplExpProcessor complexp, String data,
39
                      String resLTR, String resRTL)
40
    {
41
        String full, lean;
42
43
        System.out.println();
44
        System.out.println(">>> text=" + data);
45
        lean = Tools.toUT16(data);
46
        complexp.assumeOrientation(IComplExpProcessor.ORIENT_LTR);
47
        full = complexp.leanToFullText(lean);
48
        Tools.verify("LTR full", full, resLTR);
49
        complexp.assumeOrientation(IComplExpProcessor.ORIENT_RTL);
50
        full = complexp.leanToFullText(lean);
51
        Tools.verify("RTL full", full, resRTL);
52
    }
53
54
    public static void testRTLarithmetic() {
55
        Tools.separ("ComplExpMathTest");
56
        IComplExpProcessor complexp = StringProcessor.getProcessor(IBiDiProcessor.RTL_ARITHMETIC);
57
        test1(complexp, "", "", "");
58
        test1(complexp, "1+abc", "<&1+abc&^", "1+abc");
59
        test1(complexp, "2+abc-def", "<&2+abc&-def&^", "2+abc&-def");
60
        test1(complexp, "a+3*bc/def", "<&a&+3*bc&/def&^", "a&+3*bc&/def");
61
        test1(complexp, "4+abc/def", "<&4+abc&/def&^", "4+abc&/def");
62
        test1(complexp, "13ABC", "<&13ABC&^", "13ABC");
63
        test1(complexp, "14ABC-DE", "<&14ABC-DE&^", "14ABC-DE");
64
        test1(complexp, "15ABC+DE", "<&15ABC+DE&^", "15ABC+DE");
65
        test1(complexp, "16ABC*DE", "<&16ABC*DE&^", "16ABC*DE");
66
        test1(complexp, "17ABC/DE", "<&17ABC/DE&^", "17ABC/DE");
67
68
        Tools.printStepErrorCount();
69
    }
70
}
(-)src/org/eclipse/equinox/bidi/internal/tests/ComplExpTest.java (+8 lines)
Lines 21-26 Link Here
21
		return;
21
		return;
22
	}
22
	}
23
23
24
	public void setOperators(String operators) {
25
        // empty
26
	}
27
	
28
	public String getOperators() {
29
	    return "";
30
	}
31
	
24
	public void selectBidiScript(boolean arabic, boolean hebrew) {
32
	public void selectBidiScript(boolean arabic, boolean hebrew) {
25
		// empty
33
		// empty
26
	}
34
	}
(-)src/org/eclipse/equinox/bidi/internal/tests/ComplExpUtilTest.java (+123 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.equinox.bidi.internal.tests;
13
14
import junit.framework.Test;
15
import junit.framework.TestCase;
16
import junit.framework.TestSuite;
17
18
import org.eclipse.equinox.bidi.complexp.*;
19
20
/**
21
 * Tests methods in ComplExpUtil
22
 */
23
24
public class ComplExpUtilTest extends TestCase {
25
    public static Test suite() {
26
        return new TestSuite(ComplExpUtilTest.class);
27
    }
28
29
    public ComplExpUtilTest() {
30
        super();
31
    }
32
33
    public ComplExpUtilTest(String name) {
34
        super(name);
35
    }
36
37
    static void doTest1(String data, String result)
38
    {
39
        String full = ComplExpUtil.process(Tools.toUT16(data));
40
        String ful2 = ComplExpUtil.process(Tools.toUT16(data), null);
41
        System.out.println();
42
        System.out.println(">>> process() text=" + data);
43
        Tools.verify("full", full, result);
44
        Tools.verify("ful2", ful2, result);
45
        String lean = ComplExpUtil.deprocess(full);
46
        Tools.verify("lean", lean, data);
47
    }
48
49
    static void doTest2(String data, String result)
50
    {
51
        doTest2(data, result, data);
52
    }
53
54
    static void doTest2(String data, String result, String resLean)
55
    {
56
        String full = ComplExpUtil.process(Tools.toUT16(data), "*");
57
        System.out.println();
58
        System.out.println(">>> process() ASTERISK text=" + data);
59
        Tools.verify("full", full, result);
60
        String lean = ComplExpUtil.deprocess(full);
61
        Tools.verify("lean", lean, resLean);
62
    }
63
64
    static void doTest3(String data, String result)
65
    {
66
        doTest3(data, result, data);
67
    }
68
69
    static void doTest3(String data, String result, String resLean)
70
    {
71
        String full = ComplExpUtil.processTyped(Tools.toUT16(data), IBiDiProcessor.COMMA_DELIMITED);
72
        System.out.println();
73
        System.out.println(">>> process() COMMA text=" + data);
74
        Tools.verify("full", full, result);
75
        String lean = ComplExpUtil.deprocess(full, IBiDiProcessor.COMMA_DELIMITED);
76
        Tools.verify("lean", lean, resLean);
77
    }
78
79
    static void doTest4(String data, int[] offsets, int direction, boolean affix,
80
                      String result)
81
    {
82
        System.out.println();
83
        System.out.println(">>> insertMarks() text=" + data);
84
        System.out.println("    offsets=" + Tools.array_display(offsets));
85
        System.out.print  ("    direction=" + direction);
86
        System.out.println("  affix=" + affix);
87
        String lean = Tools.toUT16(data);
88
        String full = ComplExpUtil.insertMarks(lean, offsets, direction, affix);
89
        Tools.verify("full", full, result);
90
    }
91
92
    public static void testComplExpUtil() {
93
        Tools.separ("ComplExpUtilTest");
94
95
        // Test process() and deprocess() with default delimiters
96
        doTest1("ABC/DEF/G", ">@ABC@/DEF@/G@^");
97
        // Test process() and deprocess() with specified delimiters
98
        doTest2("", "");
99
        doTest2(">@ABC@^", ">@ABC@^", "ABC");
100
        doTest2("abc", "abc");
101
        doTest2("!abc", ">@!abc@^");
102
        doTest2("abc!", ">@abc!@^");
103
        doTest2("ABC*DEF*G", ">@ABC@*DEF@*G@^");
104
        // Test process() and deprocess() with specified expression type
105
        doTest3("ABC,DEF,G", ">@ABC@,DEF@,G@^");
106
        doTest3("", "");
107
        doTest3(">@DEF@^", ">@DEF@^", "DEF");
108
        String str = ComplExpUtil.deprocess(Tools.toUT16("ABC,DE"), "wrong_type");
109
        Tools.verify("deprocess(9999)", str, "ABC,DE");
110
        Tools.verify("invalid type", ComplExpUtil.process("abc", "wrong_type"), "abc");
111
        // Test insertMarks()
112
        doTest4("ABCDEFG", new int[]{3, 6}, 0, false, "ABC@DEF@G");
113
        doTest4("ABCDEFG", new int[]{3, 6}, 0, true, ">@ABC@DEF@G@^");
114
        doTest4("ABCDEFG", new int[]{3, 6}, 1, false, "ABC&DEF&G");
115
        doTest4("ABCDEFG", new int[]{3, 6}, 1, true, "<&ABC&DEF&G&^");
116
        doTest4("", new int[]{3, 6}, 0, false, "");
117
        doTest4("", new int[]{3, 6}, 0, true, "");
118
        doTest4("ABCDEFG", null, 1, false, "ABCDEFG");
119
        doTest4("ABCDEFG", null, 1, true, "<&ABCDEFG&^");
120
121
        Tools.printStepErrorCount();
122
    }
123
}
(-)src/org/eclipse/equinox/bidi/internal/tests/ExtensionsTest.java (+208 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.equinox.bidi.internal.tests;
13
14
import junit.framework.Test;
15
import junit.framework.TestCase;
16
import junit.framework.TestSuite;
17
18
import org.eclipse.equinox.bidi.complexp.IComplExpProcessor;
19
import org.eclipse.equinox.bidi.complexp.StringProcessor;
20
import org.eclipse.equinox.bidi.complexp.IBiDiProcessor;
21
22
/**
23
 * Tests all plug-in extensions
24
 */
25
26
public class ExtensionsTest extends TestCase {
27
    public static Test suite() {
28
        return new TestSuite(ExtensionsTest.class);
29
    }
30
31
    public ExtensionsTest() {
32
        super();
33
    }
34
35
    public ExtensionsTest(String name) {
36
        super(name);
37
    }
38
39
    static int state = IComplExpProcessor.STATE_NOTHING_GOING;
40
41
    static void doTest1(IComplExpProcessor complexp, String label, String data, String result)
42
    {
43
        String full;
44
        full = complexp.leanToFullText(Tools.toUT16(data), state);
45
        state = complexp.getFinalState();
46
        Tools.verify(label + " data = " + data, full, result);
47
    }
48
49
    static void doTest2(IComplExpProcessor complexp, String label, String data, String result)
50
    {
51
        String full;
52
        full = complexp.leanToFullText(data, state);
53
        state = complexp.getFinalState();
54
        Tools.verify(label + " data = " + data, full, result);
55
    }
56
57
    public static void testExtensions() {
58
        Tools.separ("ExtensionsTest");
59
        IComplExpProcessor ce;
60
61
        ce = StringProcessor.getProcessor(IBiDiProcessor.COMMA_DELIMITED);
62
        assertNotNull(ce);
63
        state = IComplExpProcessor.STATE_NOTHING_GOING;
64
        doTest1(ce, "Comma #1", "ab,cd, AB, CD, EFG", "ab,cd, AB@, CD@, EFG");
65
66
        ce = StringProcessor.getProcessor(IBiDiProcessor.EMAIL);
67
        assertNotNull(ce);
68
        state = IComplExpProcessor.STATE_NOTHING_GOING;
69
        ce.assumeOrientation(IComplExpProcessor.ORIENT_LTR);
70
        doTest1(ce, "Email #1", "abc.DEF:GHI", "abc.DEF@:GHI");
71
        doTest1(ce, "Email #2", "DEF.GHI \"A.B\":JK ", "DEF@.GHI @\"A.B\"@:JK ");
72
        doTest1(ce, "Email #3", "DEF,GHI (A,B);JK ", "DEF@,GHI @(A,B)@;JK ");
73
        doTest1(ce, "Email #4", "DEF.GHI (A.B :JK ", "DEF@.GHI @(A.B :JK ");
74
75
        ce = StringProcessor.getProcessor(IBiDiProcessor.FILE);
76
        assertNotNull(ce);
77
        state = IComplExpProcessor.STATE_NOTHING_GOING;
78
        doTest1(ce, "File #1", "c:\\A\\B\\FILE.EXT", "c:\\A@\\B@\\FILE@.EXT");
79
80
        ce = StringProcessor.getProcessor(IBiDiProcessor.JAVA);
81
        assertNotNull(ce);
82
        state = IComplExpProcessor.STATE_NOTHING_GOING;
83
        doTest1(ce, "Java #1", "A = B + C;", "A@ = B@ + C;");
84
        doTest1(ce, "Java #2", "A   = B + C;", "A@   = B@ + C;");
85
        doTest1(ce, "Java #3", "A = \"B+C\"+D;", "A@ = \"B+C\"@+D;");
86
        doTest1(ce, "Java #4", "A = \"B+C+D;", "A@ = \"B+C+D;");
87
        doTest1(ce, "Java #5", "A = \"B\\\"C\"+D;", "A@ = \"B\\\"C\"@+D;");
88
        doTest1(ce, "Java #6", "A = /*B+C*/ D;", "A@ = /*B+C*/@ D;");
89
        doTest1(ce, "Java #7", "A = /*B+C* D;", "A@ = /*B+C* D;");
90
        doTest1(ce, "Java #8", "X+Y+Z */ B;  ", "X+Y+Z */@ B;  ");
91
        doTest1(ce, "Java #9", "A = //B+C* D;", "A@ = //B+C* D;");
92
        doTest1(ce, "Java #10", "A = //B+C`|D+E;", "A@ = //B+C`|D@+E;");
93
94
        ce = StringProcessor.getProcessor(IBiDiProcessor.PROPERTY);
95
        assertNotNull(ce);
96
        state = IComplExpProcessor.STATE_NOTHING_GOING;
97
        doTest1(ce, "Property #0", "NAME,VAL1,VAL2", "NAME,VAL1,VAL2");
98
        doTest1(ce, "Property #1", "NAME=VAL1,VAL2", "NAME@=VAL1,VAL2");
99
        doTest1(ce, "Property #2", "NAME=VAL1,VAL2=VAL3", "NAME@=VAL1,VAL2=VAL3");
100
101
        String data;
102
        ce = StringProcessor.getProcessor(IBiDiProcessor.REGEXP);
103
        assertNotNull(ce);
104
        state = IComplExpProcessor.STATE_NOTHING_GOING;
105
        data = Tools.toUT16("ABC(?")+"#"+Tools.toUT16("DEF)GHI");
106
        doTest2(ce, "Regex #0.0", data, "A@B@C@(?#DEF)@G@H@I");
107
        data = Tools.toUT16("ABC(?")+"#"+Tools.toUT16("DEF");
108
        doTest2(ce, "Regex #0.1", data, "A@B@C@(?#DEF");
109
        doTest1(ce, "Regex #0.2", "GHI)JKL", "GHI)@J@K@L");
110
        data = Tools.toUT16("ABC(?")+"<"+Tools.toUT16("DEF")+">"+Tools.toUT16("GHI");
111
        doTest2(ce, "Regex #1", data, "A@B@C@(?<DEF>@G@H@I");
112
        doTest1(ce, "Regex #2.0", "ABC(?'DEF'GHI", "A@B@C@(?'DEF'@G@H@I");
113
        doTest1(ce, "Regex #2.1", "ABC(?'DEFGHI", "A@B@C@(?'DEFGHI");
114
        data = Tools.toUT16("ABC(?(")+"<"+Tools.toUT16("DEF")+">"+Tools.toUT16(")GHI");
115
        doTest2(ce, "Regex #3", data, "A@B@C@(?(<DEF>)@G@H@I");
116
        doTest1(ce, "Regex #4", "ABC(?('DEF')GHI", "A@B@C@(?('DEF')@G@H@I");
117
        doTest1(ce, "Regex #5", "ABC(?(DEF)GHI", "A@B@C@(?(DEF)@G@H@I");
118
        data = Tools.toUT16("ABC(?")+"&"+Tools.toUT16("DEF)GHI");
119
        doTest2(ce, "Regex #6", data, "A@B@C@(?&DEF)@G@H@I");
120
        data = Tools.toUT16("ABC(?")+"P<"+Tools.toUT16("DEF")+">"+Tools.toUT16("GHI");
121
        doTest2(ce, "Regex #7", data, "A@B@C(?p<DEF>@G@H@I");
122
        data = Tools.toUT16("ABC\\k")+"<"+Tools.toUT16("DEF")+">"+Tools.toUT16("GHI");
123
        doTest2(ce, "Regex #8", data, "A@B@C\\k<DEF>@G@H@I");
124
        doTest1(ce, "Regex #9", "ABC\\k'DEF'GHI", "A@B@C\\k'DEF'@G@H@I");
125
        doTest1(ce, "Regex #10", "ABC\\k{DEF}GHI", "A@B@C\\k{DEF}@G@H@I");
126
        data = Tools.toUT16("ABC(?")+"P="+Tools.toUT16("DEF)GHI");
127
        doTest2(ce, "Regex #11", data, "A@B@C(?p=DEF)@G@H@I");
128
        doTest1(ce, "Regex #12", "ABC\\g{DEF}GHI", "A@B@C\\g{DEF}@G@H@I");
129
        data = Tools.toUT16("ABC\\g")+"<"+Tools.toUT16("DEF")+">"+Tools.toUT16("GHI");
130
        doTest2(ce, "Regex #13", data, "A@B@C\\g<DEF>@G@H@I");
131
        doTest1(ce, "Regex #14", "ABC\\g'DEF'GHI", "A@B@C\\g'DEF'@G@H@I");
132
        data = Tools.toUT16("ABC(?(")+"R&"+Tools.toUT16("DEF)GHI");
133
        doTest2(ce, "Regex #15", data, "A@B@C(?(r&DEF)@G@H@I");
134
        data = Tools.toUT16("ABC")+"\\Q"+Tools.toUT16("DEF")+"\\E"+Tools.toUT16("GHI");
135
        doTest2(ce, "Regex #16.0", data, "A@B@C\\qDEF\\eG@H@I");
136
        data = Tools.toUT16("ABC")+"\\Q"+Tools.toUT16("DEF");
137
        doTest2(ce, "Regex #16.1", data, "A@B@C\\qDEF");
138
        data = Tools.toUT16("GHI")+"\\E"+Tools.toUT16("JKL");
139
        doTest2(ce, "Regex #16.2", data, "GHI\\eJ@K@L");
140
        doTest1(ce, "Regex #17.0", "abc[d-h]ijk", "abc[d-h]ijk");
141
        doTest1(ce, "Regex #17.1", "aBc[d-H]iJk", "aBc[d-H]iJk");
142
        doTest1(ce, "Regex #17.2", "aB*[!-H]iJ2", "aB*[!-@H]iJ@2");
143
        doTest1(ce, "Regex #17.3", "aB*[1-2]J3", "aB*[@1-2]J@3");
144
        doTest1(ce, "Regex #17.4", "aB*[5-6]J3", "aB*[@5-@6]@J@3");
145
        doTest1(ce, "Regex #17.5", "a*[5-6]J3", "a*[5-@6]@J@3");
146
        doTest1(ce, "Regex #17.6", "aB*123", "aB*@123");
147
        doTest1(ce, "Regex #17.7", "aB*567", "aB*@567");
148
149
        ce = StringProcessor.getProcessor(IBiDiProcessor.SQL);
150
        assertNotNull(ce);
151
        state = IComplExpProcessor.STATE_NOTHING_GOING;
152
        doTest1(ce, "SQL #0", "abc GHI", "abc GHI");
153
        doTest1(ce, "SQL #1", "abc DEF   GHI", "abc DEF@   GHI");
154
        doTest1(ce, "SQL #2", "ABC, DEF,   GHI", "ABC@, DEF@,   GHI");
155
        doTest1(ce, "SQL #3", "ABC'DEF GHI' JKL,MN", "ABC@'DEF GHI'@ JKL@,MN");
156
        doTest1(ce, "SQL #4.0", "ABC'DEF GHI JKL", "ABC@'DEF GHI JKL");
157
        doTest1(ce, "SQL #4.1", "MNO PQ' RS,TUV", "MNO PQ'@ RS@,TUV");
158
        doTest1(ce, "SQL #5", "ABC\"DEF GHI\" JKL,MN", "ABC@\"DEF GHI\"@ JKL@,MN");
159
        doTest1(ce, "SQL #6", "ABC\"DEF GHI JKL", "ABC@\"DEF GHI JKL");
160
        doTest1(ce, "SQL #7", "ABC/*DEF GHI*/ JKL,MN", "ABC@/*DEF GHI@*/ JKL@,MN");
161
        doTest1(ce, "SQL #8.0", "ABC/*DEF GHI JKL", "ABC@/*DEF GHI JKL");
162
        doTest1(ce, "SQL #8.1", "MNO PQ*/RS,TUV", "MNO PQ@*/RS@,TUV");
163
        doTest1(ce, "SQL #9", "ABC--DEF GHI JKL", "ABC@--DEF GHI JKL");
164
        doTest1(ce, "SQL #10", "ABC--DEF--GHI,JKL", "ABC@--DEF--GHI,JKL");
165
        doTest1(ce, "SQL #11", "ABC'DEF '' G I' JKL,MN", "ABC@'DEF '' G I'@ JKL@,MN");
166
        doTest1(ce, "SQL #12", "ABC\"DEF \"\" G I\" JKL,MN", "ABC@\"DEF \"\" G I\"@ JKL@,MN");
167
        doTest1(ce, "SQL #13", "ABC--DEF GHI`|JKL MN", "ABC@--DEF GHI`|JKL@ MN");
168
169
        ce = StringProcessor.getProcessor(IBiDiProcessor.SYSTEM_USER);
170
        assertNotNull(ce);
171
        state = IComplExpProcessor.STATE_NOTHING_GOING;
172
        doTest1(ce, "System #1", "HOST(JACK)", "HOST@(JACK)");
173
174
        ce = StringProcessor.getProcessor(IBiDiProcessor.UNDERSCORE);
175
        assertNotNull(ce);
176
        state = IComplExpProcessor.STATE_NOTHING_GOING;
177
        doTest1(ce, "Underscore #1", "A_B_C_d_e_F_G", "A@_B@_C_d_e_F@_G");
178
179
        ce = StringProcessor.getProcessor(IBiDiProcessor.URL);
180
        assertNotNull(ce);
181
        state = IComplExpProcessor.STATE_NOTHING_GOING;
182
        doTest1(ce, "URL #1", "WWW.DOMAIN.COM/DIR1/DIR2/dir3/DIR4", "WWW@.DOMAIN@.COM@/DIR1@/DIR2/dir3/DIR4");
183
184
        ce = StringProcessor.getProcessor(IBiDiProcessor.XPATH);
185
        assertNotNull(ce);
186
        state = IComplExpProcessor.STATE_NOTHING_GOING;
187
        doTest1(ce, "Xpath #1", "abc(DEF)GHI", "abc(DEF@)GHI");
188
        doTest1(ce, "Xpath #2", "DEF.GHI \"A.B\":JK ", "DEF@.GHI@ \"A.B\"@:JK ");
189
        doTest1(ce, "Xpath #3", "DEF!GHI 'A!B'=JK ", "DEF@!GHI@ 'A!B'@=JK ");
190
        doTest1(ce, "Xpath #4", "DEF.GHI 'A.B :JK ", "DEF@.GHI@ 'A.B :JK ");
191
192
        ce = StringProcessor.getProcessor(IBiDiProcessor.EMAIL);
193
        state = IComplExpProcessor.STATE_NOTHING_GOING;
194
        String operators = ce.getOperators();
195
        assertEquals("<>.:,;@", operators);
196
        ce.setOperators("+-*/");
197
        doTest1(ce, "DelimsEsc #1", "abc+DEF-GHI", "abc+DEF@-GHI");
198
        doTest1(ce, "DelimsEsc #2", "DEF-GHI (A*B)/JK ", "DEF@-GHI @(A*B)@/JK ");
199
        doTest1(ce, "DelimsEsc #3", "DEF-GHI (A*B)/JK ", "DEF@-GHI @(A*B)@/JK ");
200
        doTest1(ce, "DelimsEsc #4", "DEF-GHI (A*B\\)*C) /JK ", "DEF@-GHI @(A*B\\)*C) @/JK ");
201
        doTest1(ce, "DelimsEsc #5", "DEF-GHI (A\\\\\\)*C) /JK ", "DEF@-GHI @(A\\\\\\)*C) @/JK ");
202
        doTest1(ce, "DelimsEsc #6", "DEF-GHI (A\\\\)*C /JK ", "DEF@-GHI @(A\\\\)@*C @/JK ");
203
        doTest1(ce, "DelimsEsc #7", "DEF-GHI (A\\)*C /JK ", "DEF@-GHI @(A\\)*C /JK ");
204
205
206
        Tools.printStepErrorCount();
207
    }
208
}
(-)src/org/eclipse/equinox/bidi/internal/tests/FullToLeanTest.java (+334 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.equinox.bidi.internal.tests;
13
14
import junit.framework.Test;
15
import junit.framework.TestCase;
16
import junit.framework.TestSuite;
17
18
import org.eclipse.equinox.bidi.complexp.IComplExpProcessor;
19
import org.eclipse.equinox.bidi.complexp.StringProcessor;
20
import org.eclipse.equinox.bidi.complexp.IBiDiProcessor;
21
22
/**
23
 * Tests fullToLean method
24
 */
25
26
public class FullToLeanTest extends TestCase {
27
    public static Test suite() {
28
        return new TestSuite(FullToLeanTest.class);
29
    }
30
31
    public FullToLeanTest() {
32
        super();
33
    }
34
35
    public FullToLeanTest(String name) {
36
        super(name);
37
    }
38
39
    static int[] getpos(IComplExpProcessor complexp, boolean leanToFull)
40
    {
41
        int[] pos = new int[5];
42
43
        if (leanToFull) {
44
            pos[0] = complexp.leanToFullPos(0);
45
            pos[1] = complexp.leanToFullPos(4);
46
            pos[2] = complexp.leanToFullPos(7);
47
            pos[3] = complexp.leanToFullPos(10);
48
            pos[4] = complexp.leanToFullPos(30);
49
        } else {
50
            pos[0] = complexp.fullToLeanPos(0);
51
            pos[1] = complexp.fullToLeanPos(4);
52
            pos[2] = complexp.fullToLeanPos(7);
53
            pos[3] = complexp.fullToLeanPos(10);
54
            pos[4] = complexp.fullToLeanPos(30);
55
        }
56
        return pos;
57
    }
58
59
    static void doTest1(IComplExpProcessor complexp, String data,
60
                      String leanLTR, String fullLTR,
61
                      int[] l2fPosLTR, int[] f2lPosLTR,
62
                      String leanRTL, String fullRTL,
63
                      int[] l2fPosRTL, int[] f2lPosRTL)
64
    {
65
        String text, full, lean;
66
        int[] pos;
67
68
        System.out.println();
69
        System.out.println(">>> text=" + data);
70
        text = Tools.toUT16(data);
71
        complexp.assumeOrientation(IComplExpProcessor.ORIENT_LTR);
72
        lean = complexp.fullToLeanText(text);
73
        Tools.verify("LTR lean", lean, leanLTR);
74
        full = complexp.leanToFullText(lean);
75
        Tools.verify("LTR full", full, fullLTR);
76
        pos = getpos(complexp, true);
77
        Tools.verify("leanToFullPos()", pos, l2fPosLTR);
78
        pos = getpos(complexp, false);
79
        Tools.verify("fullToLeanPos()", pos, f2lPosLTR);
80
        complexp.assumeOrientation(IComplExpProcessor.ORIENT_RTL);
81
        lean = complexp.fullToLeanText(text);
82
        Tools.verify("RTL lean", lean, leanRTL);
83
        full = complexp.leanToFullText(lean);
84
        Tools.verify("RTL full", full, fullRTL);
85
        pos = getpos(complexp, true);
86
        Tools.verify("leanToFullPos()", pos, l2fPosRTL);
87
        pos = getpos(complexp, false);
88
        Tools.verify("fullToLeanPos()", pos, f2lPosRTL);
89
        complexp.assumeOrientation(IComplExpProcessor.ORIENT_RTL);
90
        lean = complexp.fullToLeanText(text);
91
    }
92
93
    static void doTest2()
94
    {
95
        IComplExpProcessor complexp;
96
        String text, data, full, lean, model;
97
        int state, state2, state3;
98
99
        complexp = StringProcessor.getProcessor(IBiDiProcessor.SQL);
100
        complexp.assumeOrientation(IComplExpProcessor.ORIENT_LTR);
101
        System.out.println();
102
        data = "update \"AB_CDE\" set \"COL1\"@='01', \"COL2\"@='02' /* GH IJK";
103
        System.out.println(">>> text=" + data);
104
        text = Tools.toUT16(data);
105
        lean = complexp.fullToLeanText(text);
106
        state = complexp.getFinalState();
107
        model = "update \"AB_CDE\" set \"COL1\"='01', \"COL2\"='02' /* GH IJK";
108
        Tools.verify("LTR lean", lean, model);
109
        full = complexp.leanToFullText(lean);
110
        Tools.verify("LTR full", full, data);
111
        Tools.verify("state from leanToFullText", state, complexp.getFinalState());
112
        data = "THIS IS A COMMENT LINE";
113
        System.out.println(">>> text=" + data);
114
        text = Tools.toUT16(data);
115
        lean = complexp.fullToLeanText(text, state);
116
        state2 = complexp.getFinalState();
117
        model = "THIS IS A COMMENT LINE";
118
        Tools.verify("LTR lean", lean, model);
119
        full = complexp.leanToFullText(lean, state);
120
        Tools.verify("LTR full", full, data);
121
        Tools.verify("state from leanToFullText", state2, complexp.getFinalState());
122
        data = "SOME MORE */ where \"COL3\"@=123";
123
        System.out.println(">>> text=" + data);
124
        text = Tools.toUT16(data);
125
        lean = complexp.fullToLeanText(text, state2);
126
        state3 = complexp.getFinalState();
127
        model = "SOME MORE */ where \"COL3\"=123";
128
        Tools.verify("LTR lean", lean, model);
129
        full = complexp.leanToFullText(lean, state2);
130
        Tools.verify("LTR full", full, data);
131
        Tools.verify("state from leanToFullText", state3, complexp.getFinalState());
132
    }
133
134
    public static void testFullToLean() {
135
        Tools.separ("FullToLeanTest");
136
        IComplExpProcessor complexp = StringProcessor.getProcessor(IBiDiProcessor.COMMA_DELIMITED);
137
138
        doTest1(complexp, "",
139
              "", "",
140
              new int[]{0,4,7,10,30}, new int[]{0,0,0,0,0},
141
              "", "",
142
              new int[]{0,4,7,10,30}, new int[]{0,0,0,0,0});
143
        doTest1(complexp, "1.abc",
144
              "1.abc", "1.abc",
145
              new int[]{0,4,7,10,30}, new int[]{0,4,5,5,5},
146
              "1.abc", ">@1.abc@^",
147
              new int[]{2,6,9,12,32}, new int[]{0,2,5,5,5});
148
        doTest1(complexp, "2.abc,def",
149
              "2.abc,def", "2.abc,def",
150
              new int[]{0,4,7,10,30}, new int[]{0,4,7,9,9},
151
              "2.abc,def", ">@2.abc,def@^",
152
              new int[]{2,6,9,12,32}, new int[]{0,2,5,8,9});
153
        doTest1(complexp, "@a.3.bc,def",
154
              "a.3.bc,def", "a.3.bc,def",
155
              new int[]{0,4,7,10,30}, new int[]{0,4,7,10,10},
156
              "a.3.bc,def", ">@a.3.bc,def@^",
157
              new int[]{2,6,9,12,32}, new int[]{0,2,5,8,10});
158
        doTest1(complexp, "@@a.4.bc,def",
159
              "a.4.bc,def", "a.4.bc,def",
160
              new int[]{0,4,7,10,30}, new int[]{0,4,7,10,10},
161
              "a.4.bc,def", ">@a.4.bc,def@^",
162
              new int[]{2,6,9,12,32}, new int[]{0,2,5,8,10});
163
        doTest1(complexp, "@5.abc,def",
164
              "5.abc,def", "5.abc,def",
165
              new int[]{0,4,7,10,30}, new int[]{0,4,7,9,9},
166
              "5.abc,def", ">@5.abc,def@^",
167
              new int[]{2,6,9,12,32}, new int[]{0,2,5,8,9});
168
        doTest1(complexp, "@@6.abc,def",
169
              "6.abc,def", "6.abc,def",
170
              new int[]{0,4,7,10,30}, new int[]{0,4,7,9,9},
171
              "6.abc,def", ">@6.abc,def@^",
172
              new int[]{2,6,9,12,32}, new int[]{0,2,5,8,9});
173
        doTest1(complexp, "7abc,@def",
174
              "7abc,@def", "7abc,@def",
175
              new int[]{0,4,7,10,30}, new int[]{0,4,7,9,9},
176
              "7abc,@def", ">@7abc,@def@^",
177
              new int[]{2,6,9,12,32}, new int[]{0,2,5,8,9});
178
        doTest1(complexp, "8abc,@@def",
179
              "8abc,@def", "8abc,@def",
180
              new int[]{0,4,7,10,30}, new int[]{0,4,7,9,9},
181
              "8abc,@def", ">@8abc,@def@^",
182
              new int[]{2,6,9,12,32}, new int[]{0,2,5,8,9});
183
        doTest1(complexp, "9abc,def@",
184
              "9abc,def", "9abc,def",
185
              new int[]{0,4,7,10,30}, new int[]{0,4,7,8,8},
186
              "9abc,def", ">@9abc,def@^",
187
              new int[]{2,6,9,12,32}, new int[]{0,2,5,8,8});
188
        doTest1(complexp, "10abc,def@@",
189
              "10abc,def", "10abc,def",
190
              new int[]{0,4,7,10,30}, new int[]{0,4,7,9,9},
191
              "10abc,def", ">@10abc,def@^",
192
              new int[]{2,6,9,12,32}, new int[]{0,2,5,8,9});
193
        doTest1(complexp, "@a.11.bc,@def@",
194
              "a.11.bc,@def", "a.11.bc,@def",
195
              new int[]{0,4,7,10,30}, new int[]{0,4,7,10,12},
196
              "a.11.bc,@def", ">@a.11.bc,@def@^",
197
              new int[]{2,6,9,12,32}, new int[]{0,2,5,8,12});
198
        doTest1(complexp, "@@a.12.bc,@@def@@",
199
              "a.12.bc,@def", "a.12.bc,@def",
200
              new int[]{0,4,7,10,30}, new int[]{0,4,7,10,12},
201
              "a.12.bc,@def", ">@a.12.bc,@def@^",
202
              new int[]{2,6,9,12,32}, new int[]{0,2,5,8,12});
203
        doTest1(complexp, "13ABC",
204
              "13ABC", "13ABC",
205
              new int[]{0,4,7,10,30}, new int[]{0,4,5,5,5},
206
              "13ABC", ">@13ABC@^",
207
              new int[]{2,6,9,12,32}, new int[]{0,2,5,5,5});
208
        doTest1(complexp, "14ABC,DE",
209
              "14ABC,DE", "14ABC@,DE",
210
              new int[]{0,4,8,11,31}, new int[]{0,4,6,8,8},
211
              "14ABC,DE", ">@14ABC@,DE@^",
212
              new int[]{2,6,10,13,33}, new int[]{0,2,5,7,8});
213
        doTest1(complexp, "15ABC@,DE",
214
              "15ABC,DE", "15ABC@,DE",
215
              new int[]{0,4,8,11,31}, new int[]{0,4,6,8,8},
216
              "15ABC,DE", ">@15ABC@,DE@^",
217
              new int[]{2,6,10,13,33}, new int[]{0,2,5,7,8});
218
        doTest1(complexp, "16ABC@@,DE",
219
              "16ABC,DE", "16ABC@,DE",
220
              new int[]{0,4,8,11,31}, new int[]{0,4,6,8,8},
221
              "16ABC,DE", ">@16ABC@,DE@^",
222
              new int[]{2,6,10,13,33}, new int[]{0,2,5,7,8});
223
        doTest1(complexp, "17ABC,@@DE",
224
              "17ABC,@DE", "17ABC,@DE",
225
              new int[]{0,4,7,10,30}, new int[]{0,4,7,9,9},
226
              "17ABC,@DE", ">@17ABC,@DE@^",
227
              new int[]{2,6,9,12,32}, new int[]{0,2,5,8,9});
228
        doTest1(complexp, "18ABC,DE,FGH",
229
              "18ABC,DE,FGH", "18ABC@,DE@,FGH",
230
              new int[]{0,4,8,12,32}, new int[]{0,4,6,8,12},
231
              "18ABC,DE,FGH", ">@18ABC@,DE@,FGH@^",
232
              new int[]{2,6,10,14,34}, new int[]{0,2,5,7,12});
233
        doTest1(complexp, "19ABC@,DE@,FGH",
234
              "19ABC,DE,FGH", "19ABC@,DE@,FGH",
235
              new int[]{0,4,8,12,32}, new int[]{0,4,6,8,12},
236
              "19ABC,DE,FGH", ">@19ABC@,DE@,FGH@^",
237
              new int[]{2,6,10,14,34}, new int[]{0,2,5,7,12});
238
        doTest1(complexp, "20ABC,@DE,@FGH",
239
              "20ABC,@DE,@FGH", "20ABC,@DE,@FGH",
240
              new int[]{0,4,7,10,30}, new int[]{0,4,7,10,14},
241
              "20ABC,@DE,@FGH", ">@20ABC,@DE,@FGH@^",
242
              new int[]{2,6,9,12,32}, new int[]{0,2,5,8,14});
243
        doTest1(complexp, "21ABC@@,DE@@,FGH",
244
              "21ABC,DE,FGH", "21ABC@,DE@,FGH",
245
              new int[]{0,4,8,12,32}, new int[]{0,4,6,8,12},
246
              "21ABC,DE,FGH", ">@21ABC@,DE@,FGH@^",
247
              new int[]{2,6,10,14,34}, new int[]{0,2,5,7,12});
248
        doTest1(complexp, "22ABC,@@DE,@@FGH",
249
              "22ABC,@DE,@FGH", "22ABC,@DE,@FGH",
250
              new int[]{0,4,7,10,30}, new int[]{0,4,7,10,14},
251
              "22ABC,@DE,@FGH", ">@22ABC,@DE,@FGH@^",
252
              new int[]{2,6,9,12,32}, new int[]{0,2,5,8,14});
253
        doTest1(complexp, ">@23abc@^",
254
              "23abc", "23abc",
255
              new int[]{0,4,7,10,30}, new int[]{0,4,5,5,5},
256
              "23abc", ">@23abc@^",
257
              new int[]{2,6,9,12,32}, new int[]{0,2,5,5,5});
258
        doTest1(complexp, "24abc@^",
259
              "24abc", "24abc",
260
              new int[]{0,4,7,10,30}, new int[]{0,4,5,5,5},
261
              "24abc", ">@24abc@^",
262
              new int[]{2,6,9,12,32}, new int[]{0,2,5,5,5});
263
        doTest1(complexp, ">@25abc",
264
              "25abc", "25abc",
265
              new int[]{0,4,7,10,30}, new int[]{0,4,5,5,5},
266
              "25abc", ">@25abc@^",
267
              new int[]{2,6,9,12,32}, new int[]{0,2,5,5,5});
268
        doTest1(complexp, "26AB,CD@EF,GHI",
269
              "26AB,CD@EF,GHI", "26AB@,CD@EF@,GHI",
270
              new int[]{0,5,8,12,32}, new int[]{0,4,6,9,14},
271
              "26AB,CD@EF,GHI", ">@26AB@,CD@EF@,GHI@^",
272
              new int[]{2,7,10,14,34}, new int[]{0,2,4,7,14});
273
        doTest1(complexp, "27AB,CD@123ef,GHI",
274
              "27AB,CD@123ef,GHI", "27AB@,CD@123ef,GHI",
275
              new int[]{0,5,8,11,31}, new int[]{0,4,6,9,17},
276
              "27AB,CD@123ef,GHI", ">@27AB@,CD@123ef,GHI@^",
277
              new int[]{2,7,10,13,33}, new int[]{0,2,4,7,17});
278
        doTest1(complexp, ">28ABC@,DE@,FGH^",
279
              "28ABC,DE,FGH", "28ABC@,DE@,FGH",
280
              new int[]{0,4,8,12,32}, new int[]{0,4,6,8,12},
281
              "28ABC,DE,FGH", ">@28ABC@,DE@,FGH@^",
282
              new int[]{2,6,10,14,34}, new int[]{0,2,5,7,12});
283
        doTest1(complexp, ">>29ABC@,DE@,FGH^^",
284
              "29ABC,DE,FGH", "29ABC@,DE@,FGH",
285
              new int[]{0,4,8,12,32}, new int[]{0,4,6,8,12},
286
              "29ABC,DE,FGH", ">@29ABC@,DE@,FGH@^",
287
              new int[]{2,6,10,14,34}, new int[]{0,2,5,7,12});
288
        doTest1(complexp, ">30AB>C^@,DE@,FGH^",
289
              "30AB>C^,DE,FGH", "30AB>C^@,DE@,FGH",
290
              new int[]{0,4,8,12,32}, new int[]{0,4,7,9,14},
291
              "30AB>C^,DE,FGH", ">@30AB>C^@,DE@,FGH@^",
292
              new int[]{2,6,10,14,34}, new int[]{0,2,5,7,14});
293
        doTest1(complexp, ">31AB>C@,DE@,FGH^^",
294
              "31AB>C,DE,FGH", "31AB>C@,DE@,FGH",
295
              new int[]{0,4,8,12,32}, new int[]{0,4,6,9,13},
296
              "31AB>C,DE,FGH", ">@31AB>C@,DE@,FGH@^",
297
              new int[]{2,6,10,14,34}, new int[]{0,2,5,7,13});
298
        doTest1(complexp, ">@32ABC@,DE@,FGH@^",
299
              "32ABC,DE,FGH", "32ABC@,DE@,FGH",
300
              new int[]{0,4,8,12,32}, new int[]{0,4,6,8,12},
301
              "32ABC,DE,FGH", ">@32ABC@,DE@,FGH@^",
302
              new int[]{2,6,10,14,34}, new int[]{0,2,5,7,12});
303
        doTest1(complexp, "@33ABC@,DE@,FGH@^",
304
              "33ABC,DE,FGH", "33ABC@,DE@,FGH",
305
              new int[]{0,4,8,12,32}, new int[]{0,4,6,8,12},
306
              "33ABC,DE,FGH", ">@33ABC@,DE@,FGH@^",
307
              new int[]{2,6,10,14,34}, new int[]{0,2,5,7,12});
308
        doTest1(complexp, ">@34ABC@,DE@,FGH@",
309
              "34ABC,DE,FGH", "34ABC@,DE@,FGH",
310
              new int[]{0,4,8,12,32}, new int[]{0,4,6,8,12},
311
              "34ABC,DE,FGH", ">@34ABC@,DE@,FGH@^",
312
              new int[]{2,6,10,14,34}, new int[]{0,2,5,7,12});
313
        doTest1(complexp, "35ABC@@DE@@@GH@",
314
              "35ABC@DE@GH", "35ABC@DE@GH",
315
              new int[]{0,4,7,10,30}, new int[]{0,4,7,10,11},
316
              "35ABC@DE@GH", ">@35ABC@DE@GH@^",
317
              new int[]{2,6,9,12,32}, new int[]{0,2,5,8,11});
318
        doTest1(complexp, "36ABC@@DE@@@@@@",
319
              "36ABC@DE", "36ABC@DE",
320
              new int[]{0,4,7,10,30}, new int[]{0,4,7,8,8},
321
              "36ABC@DE", ">@36ABC@DE@^",
322
              new int[]{2,6,9,12,32}, new int[]{0,2,5,8,8});
323
        doTest1(complexp, ">>>@@@@@^^^",
324
              "", "",
325
              new int[]{0,4,7,10,30}, new int[]{0,0,0,0,0},
326
              "", "",
327
              new int[]{0,4,7,10,30}, new int[]{0,0,0,0,0});
328
329
        // test fullToLeanText with initial state
330
        doTest2();
331
332
        Tools.printStepErrorCount();
333
    }
334
}
(-)src/org/eclipse/equinox/bidi/internal/tests/MethodsTest.java (+437 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.equinox.bidi.internal.tests;
13
14
import junit.framework.Test;
15
import junit.framework.TestCase;
16
import junit.framework.TestSuite;
17
18
import org.eclipse.equinox.bidi.complexp.IComplExpProcessor;
19
import org.eclipse.equinox.bidi.complexp.IBiDiProcessor;
20
import org.eclipse.equinox.bidi.complexp.StringProcessor;
21
import org.eclipse.equinox.bidi.complexp.ComplExpUtil;
22
23
/**
24
 * Tests most public methods of ComplExpBasic
25
 */
26
27
public class MethodsTest extends TestCase {
28
    public static Test suite() {
29
        return new TestSuite(MethodsTest.class);
30
    }
31
32
    public MethodsTest() {
33
        super();
34
    }
35
36
    public MethodsTest(String name) {
37
        super(name);
38
    }
39
40
    final static int LTR = IComplExpProcessor.DIRECTION_LTR;
41
    final static int RTL = IComplExpProcessor.DIRECTION_RTL;
42
43
    static void doTestState(IComplExpProcessor complexp)
44
    {
45
        String data, lean, full, model;
46
        int state;
47
48
        data = "A=B+C;/* D=E+F;";
49
        System.out.println(">>> text=" + data);
50
        lean = Tools.toUT16(data);
51
        full = complexp.leanToFullText(lean);
52
        model = "A@=B@+C@;/* D=E+F;";
53
        Tools.verify("full1", full, model);
54
        state = complexp.getFinalState();
55
        System.out.println("    state=" + state);
56
        data = "A=B+C; D=E+F;";
57
        System.out.println(">>> text=" + data);
58
        lean = Tools.toUT16(data);
59
        full = complexp.leanToFullText(lean, state);
60
        model = "A=B+C; D=E+F;";
61
        Tools.verify("full2", full, model);
62
        state = complexp.getFinalState();
63
        System.out.println("    state=" + state);
64
        data = "A=B+C;*/ D=E+F;";
65
        System.out.println(">>> text=" + data);
66
        lean = Tools.toUT16(data);
67
        full = complexp.leanToFullText(lean, state);
68
        model = "A=B+C;*/@ D@=E@+F;";
69
        Tools.verify("full3", full, model);
70
    }
71
72
    static void doTestOrientation()
73
    {
74
        IComplExpProcessor complexp;
75
        int orient;
76
77
        complexp = StringProcessor.getProcessor(IBiDiProcessor.COMMA_DELIMITED);
78
        orient = complexp.recallOrientation();
79
// TBD: the following test cannot succeed with the current implementation.
80
//      it will need allocating separate data for each processor use.
81
//        Tools.verify("orient #1", orient, IComplExpProcessor.ORIENT_LTR);
82
83
        complexp.assumeOrientation(IComplExpProcessor.ORIENT_IGNORE);
84
        orient = complexp.recallOrientation();
85
        Tools.verify("orient #2", orient, IComplExpProcessor.ORIENT_IGNORE);
86
87
        complexp.assumeOrientation(IComplExpProcessor.ORIENT_CONTEXTUAL_RTL);
88
        orient = complexp.recallOrientation();
89
        complexp.leanToFullText("--!**");
90
        Tools.verify("orient #3", orient, IComplExpProcessor.ORIENT_CONTEXTUAL_RTL);
91
92
        complexp.assumeOrientation(9999);
93
        orient = complexp.recallOrientation();
94
        complexp.leanToFullText("--!**");
95
        Tools.verify("orient #4", orient, IComplExpProcessor.ORIENT_UNKNOWN);
96
    }
97
98
    static void doTestOrient(IComplExpProcessor complexp, String data,
99
                             String resLTR, String resRTL, String resCon)
100
    {
101
        String full, lean;
102
103
        System.out.println();
104
        System.out.println(">>> text=" + data);
105
        lean = Tools.toUT16(data);
106
        complexp.assumeOrientation(IComplExpProcessor.ORIENT_LTR);
107
        full = complexp.leanToFullText(lean);
108
        Tools.verify("LTR full", full, resLTR);
109
        complexp.assumeOrientation(IComplExpProcessor.ORIENT_RTL);
110
        full = complexp.leanToFullText(lean);
111
        Tools.verify("RTL full", full, resRTL);
112
        complexp.assumeOrientation(IComplExpProcessor.ORIENT_CONTEXTUAL_RTL);
113
        full = complexp.leanToFullText(lean);
114
        Tools.verify("CON full", full, resCon);
115
    }
116
117
    static void doTestScripts(IComplExpProcessor complexp)
118
    {
119
        boolean flag;
120
        flag = complexp.handlesArabicScript();
121
        Tools.verify("Handles Arabic 1", flag, true);
122
        flag = complexp.handlesHebrewScript();
123
        Tools.verify("Handles Hebrew 1", flag, true);
124
125
        complexp.selectBidiScript(false, false);
126
        flag = complexp.handlesArabicScript();
127
        Tools.verify("Handles Arabic 2", flag, false);
128
        flag = complexp.handlesHebrewScript();
129
        Tools.verify("Handles Hebrew 2", flag, false);
130
        doTestOrient(complexp, "BCD,EF", "BCD,EF", ">@BCD,EF@^", "@BCD,EF");
131
        complexp.selectBidiScript(true, false);
132
        flag = complexp.handlesArabicScript();
133
        Tools.verify("Handles Arabic 3", flag, true);
134
        flag = complexp.handlesHebrewScript();
135
        Tools.verify("Handles Hebrew 3", flag, false);
136
        doTestOrient(complexp, "d,EF", "d,EF", ">@d,EF@^", "d,EF");
137
        doTestOrient(complexp, "#,eF", "#,eF", ">@#,eF@^", "@#,eF");
138
        doTestOrient(complexp, "#,12", "#@,12", ">@#@,12@^", "@#@,12");
139
        doTestOrient(complexp, "#,##", "#@,##", ">@#@,##@^", "@#@,##");
140
        doTestOrient(complexp, "#,89", "#@,89", ">@#@,89@^", "@#@,89");
141
        doTestOrient(complexp, "#,ef", "#,ef", ">@#,ef@^", "@#,ef");
142
        doTestOrient(complexp, "#,", "#,", ">@#,@^", "@#,");
143
        doTestOrient(complexp, "9,ef", "9,ef", ">@9,ef@^", "9,ef");
144
        doTestOrient(complexp, "9,##", "9@,##", ">@9@,##@^", "9@,##");
145
        doTestOrient(complexp, "7,89", "7@,89", ">@7@,89@^", "7@,89");
146
        doTestOrient(complexp, "7,EF", "7,EF", ">@7,EF@^", "@7,EF");
147
        doTestOrient(complexp, "BCD,EF", "BCD,EF", ">@BCD,EF@^", "@BCD,EF");
148
149
        complexp.selectBidiScript(false, true);
150
        flag = complexp.handlesArabicScript();
151
        Tools.verify("Handles Arabic 4", flag, false);
152
        flag = complexp.handlesHebrewScript();
153
        Tools.verify("Handles Hebrew 4", flag, true);
154
        doTestOrient(complexp, "BCd,EF", "BCd,EF", ">@BCd,EF@^", "@BCd,EF");
155
        doTestOrient(complexp, "BCD,eF", "BCD,eF", ">@BCD,eF@^", "@BCD,eF");
156
        doTestOrient(complexp, "BCD,EF", "BCD@,EF", ">@BCD@,EF@^", "@BCD@,EF");
157
        doTestOrient(complexp, "BCD,12", "BCD@,12", ">@BCD@,12@^", "@BCD@,12");
158
        doTestOrient(complexp, "BCD,", "BCD,", ">@BCD,@^", "@BCD,");
159
160
        complexp.selectBidiScript(true, true);
161
        doTestOrient(complexp, "123,45|67", "123,45|67", ">@123,45|67@^", "@123,45|67");
162
        doTestOrient(complexp, "5,e", "5,e", ">@5,e@^", "5,e");
163
        doTestOrient(complexp, "5,#", "5@,#", ">@5@,#@^", "5@,#");
164
        doTestOrient(complexp, "5,6", "5@,6", ">@5@,6@^", "5@,6");
165
        doTestOrient(complexp, "5,D", "5@,D", ">@5@,D@^", "5@,D");
166
        doTestOrient(complexp, "5,--", "5,--", ">@5,--@^", "@5,--");
167
    }
168
169
    static void doTestLeanOffsets(IComplExpProcessor complexp)
170
    {
171
        String lean, data;
172
        int state;
173
        int[] offsets;
174
        int[] model;
175
176
        data = "A=B+C;/* D=E+F;";
177
        System.out.println(">>> text1=" + data);
178
        lean = Tools.toUT16(data);
179
        offsets = complexp.leanBidiCharOffsets(lean);
180
        model = new int[]{1, 3, 5};
181
        Tools.verify("leanBidiCharOffsets()", offsets, model);
182
        state = complexp.getFinalState();
183
        System.out.println("    state=" + state);
184
        data = "A=B+C;*/ D=E+F;";
185
        System.out.println(">>> text2=" + data);
186
        lean = Tools.toUT16(data);
187
        offsets = complexp.leanBidiCharOffsets(lean, state);
188
        model = new int[]{8, 10, 12};
189
        Tools.verify("leanBidiCharOffsets() #2", offsets, model);
190
        System.out.println(">>> text3=" + data);
191
        offsets = complexp.leanBidiCharOffsets();
192
        model = new int[]{8, 10, 12};
193
        Tools.verify("leanBidiCharOffsets() #3", offsets, model);
194
    }
195
196
    static void doTestFullOffsets(IComplExpProcessor complexp, String data,
197
                                  int[] resLTR, int[] resRTL, int[] resCon)
198
    {
199
        String full, lean;
200
        int[] offsets;
201
202
        System.out.println();
203
        System.out.println(">>> text=" + data);
204
        lean = Tools.toUT16(data);
205
        complexp.assumeOrientation(IComplExpProcessor.ORIENT_LTR);
206
        full = complexp.leanToFullText(lean);
207
        System.out.println("LTR full=" + Tools.toPseudo(full));
208
        offsets = complexp.fullBidiCharOffsets();
209
        Tools.verify("fullBidiCharOffsets() LTR", offsets, resLTR);
210
        complexp.assumeOrientation(IComplExpProcessor.ORIENT_RTL);
211
        full = complexp.leanToFullText(lean);
212
        System.out.println("RTL full=" + Tools.toPseudo(full));
213
        offsets = complexp.fullBidiCharOffsets();
214
        Tools.verify("fullBidiCharOffsets() RTL", offsets, resRTL);
215
        complexp.assumeOrientation(IComplExpProcessor.ORIENT_CONTEXTUAL_LTR);
216
        full = complexp.leanToFullText(lean);
217
        System.out.println("CON full=" + Tools.toPseudo(full));
218
        offsets = complexp.fullBidiCharOffsets();
219
        Tools.verify("fullBidiCharOffsets() CON", offsets, resCon);
220
    }
221
222
    static void doTestMirrored()
223
    {
224
        IComplExpProcessor complexp;
225
        boolean mirrored;
226
227
        mirrored = ComplExpUtil.isMirroredDefault();
228
        Tools.verify("mirrored #1", mirrored, false);
229
        complexp = StringProcessor.getProcessor(IBiDiProcessor.COMMA_DELIMITED);
230
        mirrored = complexp.isMirrored();
231
        Tools.verify("mirrored #2", mirrored, false);
232
        ComplExpUtil.assumeMirroredDefault(true);
233
        mirrored = ComplExpUtil.isMirroredDefault();
234
        Tools.verify("mirrored #3", mirrored, true);
235
        complexp = StringProcessor.getProcessor(IBiDiProcessor.COMMA_DELIMITED);
236
        mirrored = complexp.isMirrored();
237
// TBD: the following test cannot succeed with the current implementation.
238
//      it will need allocating separate data for each processor use.
239
//        Tools.verify("mirrored #4", mirrored, true);
240
        complexp.assumeMirrored(false);
241
        mirrored = complexp.isMirrored();
242
        Tools.verify("mirrored #5", mirrored, false);
243
    }
244
245
    static void doTestDirection()
246
    {
247
        IComplExpProcessor complexp;
248
        int[][] dir;
249
        int[][] modir;
250
        String data, lean, full, model;
251
252
        complexp = StringProcessor.getProcessor(IBiDiProcessor.COMMA_DELIMITED);
253
        dir = complexp.getDirection();
254
        modir = new int[][]{{LTR,LTR},{LTR,LTR}};
255
        Tools.verify("direction #1", dir, modir);
256
257
        complexp.setDirection(RTL);
258
        dir = complexp.getDirection();
259
        modir = new int[][]{{RTL,RTL},{RTL,RTL}};
260
        Tools.verify("direction #2", dir, modir);
261
262
        complexp.setDirection(LTR, RTL);
263
        dir = complexp.getDirection();
264
        modir = new int[][]{{LTR,RTL},{LTR,RTL}};
265
        Tools.verify("direction #3", dir, modir);
266
267
        complexp.setArabicDirection(RTL);
268
        dir = complexp.getDirection();
269
        modir = new int[][]{{RTL,RTL},{LTR,RTL}};
270
        Tools.verify("direction #4", dir, modir);
271
272
        complexp.setArabicDirection(RTL,LTR);
273
        dir = complexp.getDirection();
274
        modir = new int[][]{{RTL,LTR},{LTR,RTL}};
275
        Tools.verify("direction #5", dir, modir);
276
277
        complexp.setHebrewDirection(RTL);
278
        dir = complexp.getDirection();
279
        modir = new int[][]{{RTL,LTR},{RTL,RTL}};
280
        Tools.verify("direction #6", dir, modir);
281
282
        complexp.setHebrewDirection(RTL, LTR);
283
        dir = complexp.getDirection();
284
        modir = new int[][]{{RTL,LTR},{RTL,LTR}};
285
        Tools.verify("direction #7", dir, modir);
286
287
        complexp = StringProcessor.getProcessor(IBiDiProcessor.EMAIL);
288
        complexp.assumeMirrored(false);
289
        complexp.setArabicDirection(LTR,RTL);
290
        complexp.setHebrewDirection(LTR, LTR);
291
        data = "#ABC.#DEF:HOST.com";
292
        System.out.println(">>> text=" + data);
293
        lean = Tools.toUT16(data);
294
        full = complexp.leanToFullText(lean);
295
        model = "#ABC@.#DEF@:HOST.com";
296
        Tools.verify("full", full, model);
297
298
        data = "ABC.DEF:HOST.com";
299
        System.out.println(">>> text=" + data);
300
        lean = Tools.toUT16(data);
301
        full = complexp.leanToFullText(lean);
302
        model = "ABC@.DEF@:HOST.com";
303
        Tools.verify("full", full, model);
304
305
        complexp.assumeMirrored(true);
306
        data = "#ABC.#DEF:HOST.com";
307
        System.out.println(">>> text=" + data);
308
        lean = Tools.toUT16(data);
309
        full = complexp.leanToFullText(lean);
310
        model = "<&#ABC.#DEF:HOST.com&^";
311
        Tools.verify("full", full, model);
312
313
        data = "#ABc.#DEF:HOSt.COM";
314
        System.out.println(">>> text=" + data);
315
        lean = Tools.toUT16(data);
316
        full = complexp.leanToFullText(lean);
317
        model = "<&#ABc.#DEF:HOSt.COM&^";
318
        Tools.verify("full", full, model);
319
320
        data = "#ABc.#DEF:HOSt.";
321
        System.out.println(">>> text=" + data);
322
        lean = Tools.toUT16(data);
323
        full = complexp.leanToFullText(lean);
324
        model = "<&#ABc.#DEF:HOSt.&^";
325
        Tools.verify("full", full, model);
326
327
        data = "ABC.DEF:HOST.com";
328
        System.out.println(">>> text=" + data);
329
        lean = Tools.toUT16(data);
330
        full = complexp.leanToFullText(lean);
331
        model = "ABC@.DEF@:HOST.com";
332
        Tools.verify("full", full, model);
333
334
        data = "--.---:----";
335
        System.out.println(">>> text=" + data);
336
        lean = Tools.toUT16(data);
337
        full = complexp.leanToFullText(lean);
338
        model = "--.---:----";
339
        Tools.verify("full", full, model);
340
341
        data = "ABC.|DEF:HOST.com";
342
        System.out.println(">>> text=" + data);
343
        lean = Tools.toUT16(data);
344
        full = complexp.leanToFullText(lean);
345
        model = "ABC.|DEF@:HOST.com";
346
        Tools.verify("full", full, model);
347
348
        complexp.assumeOrientation(IComplExpProcessor.ORIENT_RTL);
349
        data = "#ABc.|#DEF:HOST.com";
350
        System.out.println(">>> text=" + data);
351
        lean = Tools.toUT16(data);
352
        full = complexp.leanToFullText(lean);
353
        model = "#ABc.|#DEF:HOST.com";
354
        Tools.verify("full", full, model);
355
    }
356
357
    public static void testMethods() {
358
        IComplExpProcessor complexp;
359
360
        Tools.separ("MethodsTest");
361
        System.out.println();
362
        System.out.println();
363
        System.out.println(">>>>>>>>>>  Test leanToFullText with initial state  <<<<<<<<<<");
364
        System.out.println();
365
        complexp = StringProcessor.getProcessor(IBiDiProcessor.JAVA);
366
        doTestState(complexp);
367
368
        System.out.println();
369
        System.out.println();
370
        System.out.println(">>>>>>>>>>  Test Orientation  <<<<<<<<<<");
371
        System.out.println();
372
        doTestOrientation();
373
374
        System.out.println();
375
        System.out.println();
376
        System.out.println(">>>>>>>>>>  Test Orient  <<<<<<<<<<");
377
        System.out.println();
378
        complexp = StringProcessor.getProcessor(IBiDiProcessor.COMMA_DELIMITED);
379
        doTestOrient(complexp, "", "", "", "");
380
        doTestOrient(complexp, "abc", "abc", ">@abc@^", "abc");
381
        doTestOrient(complexp, "ABC", "ABC", ">@ABC@^", "@ABC");
382
        doTestOrient(complexp, "bcd,ef", "bcd,ef", ">@bcd,ef@^", "bcd,ef");
383
        doTestOrient(complexp, "BCD,EF", "BCD@,EF", ">@BCD@,EF@^", "@BCD@,EF");
384
        doTestOrient(complexp, "cde,FG", "cde,FG", ">@cde,FG@^", "cde,FG");
385
        doTestOrient(complexp, "CDE,fg", "CDE,fg", ">@CDE,fg@^", "@CDE,fg");
386
        doTestOrient(complexp, "12..def,GH", "12..def,GH", ">@12..def,GH@^", "12..def,GH");
387
        doTestOrient(complexp, "34..DEF,gh", "34..DEF,gh", ">@34..DEF,gh@^", "@34..DEF,gh");
388
389
        System.out.println();
390
        System.out.println();
391
        System.out.println(">>>>>>>>>>  Test Scripts  <<<<<<<<<<");
392
        System.out.println();
393
        doTestScripts(complexp);
394
395
        System.out.println();
396
        System.out.println();
397
        System.out.println(">>>>>>>>>>  Test leanBidiCharOffsets()  <<<<<<<<<<");
398
        System.out.println();
399
        complexp = StringProcessor.getProcessor(IBiDiProcessor.JAVA);
400
        doTestLeanOffsets(complexp);
401
402
        System.out.println();
403
        System.out.println();
404
        System.out.println(">>>>>>>>>>  Test fullBidiCharOffsets()  <<<<<<<<<<");
405
        System.out.println();
406
        complexp = StringProcessor.getProcessor(IBiDiProcessor.COMMA_DELIMITED);
407
        doTestFullOffsets(complexp, "BCD,EF,G", new int[]{3,7},
408
                          new int[]{0,1,5,9,12,13}, new int[]{0,4,8});
409
410
        System.out.println();
411
        System.out.println();
412
        System.out.println(">>>>>>>>>>  Test mirrored  <<<<<<<<<<");
413
        System.out.println();
414
        doTestMirrored();
415
416
        System.out.println();
417
        System.out.println();
418
        System.out.println(">>>>>>>>>>  Test Direction  <<<<<<<<<<");
419
        System.out.println();
420
        doTestDirection();
421
422
        System.out.println();
423
        System.out.println();
424
        System.out.println(">>>>>>>>>>  Test Many Inserts  <<<<<<<<<<");
425
        System.out.println();
426
        complexp = StringProcessor.getProcessor(IBiDiProcessor.COMMA_DELIMITED);
427
        complexp.assumeOrientation(IComplExpProcessor.ORIENT_LTR);
428
        complexp.setDirection(LTR);
429
        String data = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
430
        String lean = Tools.toUT16(data);
431
        String full = complexp.leanToFullText(lean);
432
        String model = "A@,B@,C@,D@,E@,F@,G@,H@,I@,J@,K@,L@,M@,N@,O@,P@,Q@,R@,S@,T@,U@,V@,W@,X@,Y@,Z";
433
        Tools.verify("many inserts", full, model);
434
435
        Tools.printStepErrorCount();
436
    }
437
}
(-)src/org/eclipse/equinox/bidi/internal/tests/Tools.java (+413 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.equinox.bidi.internal.tests;
13
14
import junit.framework.Test;
15
import junit.framework.TestCase;
16
import junit.framework.TestSuite;
17
18
/**
19
 * Tools: common methods and their test.
20
 */
21
22
public class Tools extends TestCase {
23
    public static Test suite() {
24
        return new TestSuite(Tools.class);
25
    }
26
27
    public Tools() {
28
        super();
29
    }
30
31
    public Tools(String name) {
32
        super(name);
33
    }
34
35
    static final char LRM = 0x200E;
36
    static final char RLM = 0x200F;
37
    static final char LRE = 0x202A;
38
    static final char RLE = 0x202B;
39
    static final char PDF = 0x202C;
40
41
    static int errCnt;
42
    static int errCntTotal;
43
    static boolean isTestingTheTools;
44
45
    static String toPseudo(String text)
46
    {
47
        char[] chars = text.toCharArray();
48
        int len = chars.length;
49
        char c;
50
        int i;
51
        for (i = 0; i < len; i++) {
52
            c = chars[i];
53
            if (c >= 'A' && c <= 'Z') {
54
                chars[i] = (char)(c + 'a' - 'A');
55
            }
56
            else if (c >= 0x05D0 && c < 0x05EA) {
57
                chars[i] = (char)(c + 'A' - 0x05D0);
58
            }
59
            else if (c == 0x05EA) {
60
                chars[i] = '~';
61
            }
62
            else if (c == 0x0644) {
63
                chars[i] = '#';
64
            }
65
            else if (c >= 0x0665 && c <= 0x0669) {
66
                chars[i] = (char)(c + '5' - 0x0665);
67
            }
68
            else if (c == LRM) {
69
                chars[i] = '@';
70
            }
71
            else if (c == RLM) {
72
                chars[i] = '&';
73
            }
74
            else if (c == LRE) {
75
                chars[i] = '>';
76
            }
77
            else if (c == RLE) {
78
                chars[i] = '<';
79
            }
80
            else if (c == PDF) {
81
                chars[i] = '^';
82
            }
83
            else if (c == '\n') {
84
                chars[i] = '|';
85
            }
86
            else if (c == '\r') {
87
                chars[i] = '`';
88
            }
89
        }
90
        return new String(chars);
91
    }
92
93
    static String toUT16(String text)
94
    {
95
        char[] chars = text.toCharArray();
96
        int len = chars.length;
97
        char c;
98
        int i;
99
        for (i = 0; i < len; i++) {
100
            c = chars[i];
101
            if (c >= '5' && c <= '9') {
102
                chars[i] = (char)(0x0665 + c - '5');
103
            }
104
            if (c >= 'A' && c <= 'Z') {
105
                chars[i] = (char)(0x05D0 + c - 'A');
106
            }
107
            else if (c == '~') {
108
                chars[i] = (char)(0x05EA);
109
            }
110
            else if (c == '#') {
111
                chars[i] = (char)(0x0644);
112
            }
113
            else if (c == '@') {
114
                chars[i] = LRM;
115
            }
116
            else if (c == '&') {
117
                chars[i] = RLM;
118
            }
119
            else if (c == '>') {
120
                chars[i] = LRE;
121
            }
122
            else if (c == '<') {
123
                chars[i] = RLE;
124
            }
125
            else if (c == '^') {
126
                chars[i] = PDF;
127
            }
128
            else if (c == '|') {
129
                chars[i] = '\n';
130
            }
131
            else if (c == '`') {
132
                chars[i] = '\r';
133
            }
134
        }
135
        return new String(chars);
136
    }
137
138
    static boolean arrays_equal(int[] one, int[] two)
139
    {
140
        int len = one.length;
141
        if (len != two.length) {
142
            return false;
143
        }
144
        for (int i = 0; i < len; i++) {
145
            if (one[i] != two[i]) {
146
                return false;
147
            }
148
        }
149
        return true;
150
    }
151
152
    static boolean arrays2_equal(int[][] one, int[][] two)
153
    {
154
        int dim1, dim2;
155
        dim1 = one.length;
156
        if (dim1 != two.length) {
157
            return false;
158
        }
159
        for (int i = 0; i < dim1; i++) {
160
            dim2 = one[i].length;
161
            if (dim2 != two[i].length) {
162
                return false;
163
            }
164
            for (int j = 0; j < dim2; j++) {
165
                if (one[i][j] != two[i][j]) {
166
                    return false;
167
                }
168
            }
169
        }
170
        return true;
171
    }
172
173
    static String array_display(int[] array)
174
    {
175
        if (array == null) {
176
            return "null";
177
        }
178
        StringBuffer sb = new StringBuffer(50);
179
        int len = array.length;
180
        for (int i = 0; i < len; i++) {
181
            sb.append(array[i]);
182
            sb.append(' ');
183
        }
184
        return sb.toString();
185
    }
186
187
    static String array2_display(int[][] array)
188
    {
189
        int dim1, dim2;
190
        if (array == null) {
191
            return "null";
192
        }
193
        StringBuffer sb = new StringBuffer(50);
194
        dim1 = array.length;
195
        for (int i = 0; i < dim1; i++) {
196
            dim2 = array[i].length;
197
            for (int j = 0; j < dim2; j++) {
198
                sb.append(array[i][j]);
199
                sb.append(' ');
200
            }
201
        }
202
        return sb.toString();
203
    }
204
205
    static boolean verify(String msg, int result, int expected)
206
    {
207
        System.out.println("Testing: " + msg);
208
        System.out.println("    result   = " + result);
209
        if (result != expected) {
210
            System.out.println("!!! ******* ERROR ******* !!!");
211
            System.out.println("    result   = " + result);
212
            System.out.println("    expected = " + expected);
213
            errCnt++;
214
            if (!isTestingTheTools)
215
                assertEquals(expected, result);
216
            return false;
217
        }
218
        return true;
219
    }
220
221
    static boolean verify(String msg, boolean result, boolean expected)
222
    {
223
        System.out.println("Testing: " + msg);
224
        System.out.println("    result   = " + result);
225
        if (result != expected) {
226
            System.out.println("!!! ******* ERROR ******* !!!");
227
            System.out.println("    result   = " + result);
228
            System.out.println("    expected = " + expected);
229
            errCnt++;
230
            if (!isTestingTheTools)
231
                assertEquals(expected, result);
232
            return false;
233
        }
234
        return true;
235
    }
236
237
    static boolean verify(String msg, String result, String expected)
238
    {
239
        System.out.println("Testing: " + msg);
240
        String presult = Tools.toPseudo(result);
241
        System.out.println("    result   = " + presult);
242
        if (!presult.equals(expected)) {
243
            System.out.println("!!! ******* ERROR ******* !!!");
244
            System.out.println("    result   = " + presult);
245
            System.out.println("    expected = " + expected);
246
            errCnt++;
247
            if (!isTestingTheTools)
248
                assertEquals(expected, presult);
249
            return false;
250
        }
251
        return true;
252
    }
253
254
    static boolean verify(String msg, int[] result, int[] expected)
255
    {
256
        System.out.println("Testing: " + msg);
257
        System.out.println("    result   = " + array_display(result));
258
        if (!arrays_equal(result, expected)) {
259
            System.out.println("!!! ******* ERROR ******* !!!");
260
            System.out.println("    result   = " + array_display(result));
261
            System.out.println("    expected = " + array_display(expected));
262
            errCnt++;
263
            if (!isTestingTheTools)
264
                assertEquals(expected, result);
265
            return false;
266
        }
267
        return true;
268
    }
269
270
    static boolean verify(String msg, int[][] result, int[][] expected)
271
    {
272
        System.out.println("Testing: " + msg);
273
        System.out.println("    result   = " + array2_display(result));
274
        if (!arrays2_equal(result, expected)) {
275
            System.out.println("!!! ******* ERROR ******* !!!");
276
            System.out.println("    result   = " + array2_display(result));
277
            System.out.println("    expected = " + array2_display(expected));
278
            errCnt++;
279
            if (!isTestingTheTools)
280
                assertEquals(expected, result);
281
            return false;
282
        }
283
        return true;
284
    }
285
286
    static void printStepErrorCount()
287
    {
288
        System.out.println();
289
        System.out.println();
290
        if (errCnt == 0) {
291
            System.out.println("No errors were found.");
292
        } else {
293
            System.out.println("******* " + errCnt + " errors were found !!!!!!!");
294
            errCntTotal += errCnt;
295
            errCnt = 0;
296
        }
297
        System.out.println();
298
    }
299
300
    static void printTotalErrorCount()
301
    {
302
        errCntTotal += errCnt;
303
        errCnt = 0;
304
        System.out.println();
305
        System.out.println();
306
        if (errCntTotal == 0) {
307
            System.out.println("No total errors were found.");
308
        } else {
309
            System.out.println("******* " + errCntTotal + " total errors were found !!!!!!!");
310
            errCntTotal = 0;
311
        }
312
        System.out.println();
313
    }
314
315
    static void separ(String text)
316
    {
317
        System.out.println();
318
        System.out.println();
319
        System.out.println();
320
        System.out.println("*======================================*");
321
        System.out.println("*                                      *");
322
        System.out.println("               " + text);
323
        System.out.println("*                                      *");
324
        System.out.println("*======================================*");
325
        System.out.println();
326
        System.out.println();
327
    }
328
    
329
    public static void testTools() {
330
        separ("Test Tools");
331
        // The following statements are meant to test the methods within
332
        // this file.
333
        isTestingTheTools = true;
334
        String data = "56789ABCDEFGHIJKLMNOPQRSTUVWXYZ~#@&><^|`";
335
        String text = toUT16(data);
336
        String dat2 = toPseudo(text);
337
        assertEquals(data, dat2);
338
339
        text = toPseudo(data);
340
        assertEquals("56789abcdefghijklmnopqrstuvwxyz~#@&><^|`", text);
341
342
        int[] arA = new int[]{1,2};
343
        int[] arB = new int[]{3,4,5};
344
        assertFalse(arrays_equal(arA, arB));
345
346
        assertTrue(arrays_equal(arA, arA));
347
348
        arB = new int[]{3,4};
349
        assertFalse(arrays_equal(arA, arB));
350
351
        int[][] ar2A = new int[][]{{1},{1,2},{1,2,3}};
352
        int[][] ar2B = new int[][]{{1},{1,2}};
353
        assertTrue(arrays2_equal(ar2A, ar2A));
354
355
        assertFalse(arrays2_equal(ar2A, ar2B));
356
357
        ar2B = new int[][]{{1},{1,2},{1,2,3,4}};
358
        assertFalse(arrays2_equal(ar2A, ar2B));
359
360
        ar2B = new int[][]{{1},{1,2},{1,2,4}};
361
        assertFalse(arrays2_equal(ar2A, ar2B));
362
363
        text = array_display(null);
364
        assertEquals("null", text);
365
366
        text = array2_display(null);
367
        assertEquals("null", text);
368
369
        assertTrue(verify("An error is NOT expected below", 0, 0));
370
371
        assertFalse(verify("An error is expected below", 0, 1));
372
373
        assertTrue(verify("An error is NOT expected below", true, true));
374
375
        assertFalse(verify("An error is expected below", true, false));
376
377
        assertTrue(verify("An error is NOT expected below", "abc", "abc"));
378
379
        assertFalse(verify("An error is expected below", "abc", "def"));
380
381
        assertTrue(verify("An error is NOT expected below", new int[]{0,1}, new int[]{0,1}));
382
383
        assertFalse(verify("An error is expected below", new int[]{0,1}, new int[]{2,3}));
384
385
        assertTrue(verify("An error is NOT expected below", new int[][]{{0,1},{2,3}}, new int[][]{{0,1},{2,3}}));
386
387
        assertFalse(verify("An error is expected below", new int[][]{{0,1},{2,3}}, new int[][]{{4,5},{6,7}}));
388
        System.out.println();
389
        System.out.println();
390
        System.out.println("....... The next line should show 5 errors");
391
        assertEquals(5, errCnt);
392
        printStepErrorCount();
393
        errCnt = 9;
394
        System.out.println();
395
        System.out.println();
396
        System.out.println("....... The next line should show 9 errors");
397
        assertEquals(9, errCnt);
398
        printStepErrorCount();
399
        System.out.println();
400
        System.out.println();
401
        System.out.println("....... The next line should show 14 total errors");
402
        assertEquals(14, errCntTotal);
403
        printTotalErrorCount();
404
        errCnt = 0;
405
        errCntTotal = 0;
406
        System.out.println();
407
        System.out.println();
408
        System.out.println("....... Reset error counters to zero");
409
        printStepErrorCount();
410
        printTotalErrorCount();
411
        isTestingTheTools = false;
412
    }
413
}
(-)src/org/eclipse/equinox/bidi/tests/BiDiTestSuite.java (-1 / +9 lines)
Lines 11-17 Link Here
11
11
12
package org.eclipse.equinox.bidi.tests;
12
package org.eclipse.equinox.bidi.tests;
13
13
14
import org.eclipse.equinox.bidi.internal.tests.ExtensibilityTest;
14
import org.eclipse.equinox.bidi.internal.tests.*;
15
15
16
import junit.framework.Test;
16
import junit.framework.Test;
17
import junit.framework.TestSuite;
17
import junit.framework.TestSuite;
Lines 23-27 Link Here
23
23
24
	public BiDiTestSuite() {
24
	public BiDiTestSuite() {
25
		addTestSuite(ExtensibilityTest.class);
25
		addTestSuite(ExtensibilityTest.class);
26
        addTestSuite(Tools.class);
27
//        addTestSuite(TestDoNothing.class);
28
        addTestSuite(FullToLeanTest.class);
29
        addTestSuite(MethodsTest.class);
30
        addTestSuite(ComplExpMathTest.class);
31
// TBD: TestSubclass        
32
        addTestSuite(ExtensionsTest.class);
33
        addTestSuite(ComplExpUtilTest.class);
26
	}
34
	}
27
}
35
}

Return to bug 183164