2 *******************************************************************************
3 * Copyright (C) 2007-2011, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 *******************************************************************************
8 package com.ibm.icu.dev.test.bidi;
10 import com.ibm.icu.text.Bidi;
13 * Regression test for doing transformations in context
15 * @author Matitiahu Allouche
18 public class TestContext extends BidiTest {
20 private class ContextCase {
27 ContextCase(String pro, String src, String epi, String exp, byte lev) {
36 private final ContextCase[] contextData = {
37 /*00*/ new ContextCase("", "", "", "", Bidi.LTR),
38 /*01*/ new ContextCase("", ".-=JKL-+*", "", ".-=LKJ-+*", Bidi.LTR),
39 /*02*/ new ContextCase(" ", ".-=JKL-+*", " ", ".-=LKJ-+*", Bidi.LTR),
40 /*03*/ new ContextCase("a", ".-=JKL-+*", "b", ".-=LKJ-+*", Bidi.LTR),
41 /*04*/ new ContextCase("D", ".-=JKL-+*", "", "LKJ=-.-+*", Bidi.LTR),
42 /*05*/ new ContextCase("", ".-=JKL-+*", " D", ".-=*+-LKJ", Bidi.LTR),
43 /*06*/ new ContextCase("", ".-=JKL-+*", " 2", ".-=*+-LKJ", Bidi.LTR),
44 /*07*/ new ContextCase("", ".-=JKL-+*", " 7", ".-=*+-LKJ", Bidi.LTR),
45 /*08*/ new ContextCase(" G 1", ".-=JKL-+*", " H", "*+-LKJ=-.", Bidi.LTR),
46 /*09*/ new ContextCase("7", ".-=JKL-+*", " H", ".-=*+-LKJ", Bidi.LTR),
47 /*10*/ new ContextCase("", ".-=abc-+*", "", "*+-abc=-.", Bidi.RTL),
48 /*11*/ new ContextCase(" ", ".-=abc-+*", " ", "*+-abc=-.", Bidi.RTL),
49 /*12*/ new ContextCase("D", ".-=abc-+*", "G", "*+-abc=-.", Bidi.RTL),
50 /*13*/ new ContextCase("x", ".-=abc-+*", "", "*+-.-=abc", Bidi.RTL),
51 /*14*/ new ContextCase("", ".-=abc-+*", " y", "abc-+*=-.", Bidi.RTL),
52 /*15*/ new ContextCase("", ".-=abc-+*", " 2", "abc-+*=-.", Bidi.RTL),
53 /*16*/ new ContextCase(" x 1", ".-=abc-+*", " 2", ".-=abc-+*", Bidi.RTL),
54 /*17*/ new ContextCase(" x 7", ".-=abc-+*", " 8", "*+-.-=abc", Bidi.RTL),
55 /*18*/ new ContextCase("x|", ".-=abc-+*", " 8", "*+-abc=-.", Bidi.RTL),
56 /*19*/ new ContextCase("G|y", ".-=abc-+*", " 8", "*+-.-=abc", Bidi.RTL),
57 /*20*/ new ContextCase("", ".-=", "", ".-=", Bidi.LEVEL_DEFAULT_LTR),
58 /*21*/ new ContextCase("D", ".-=", "", "=-.", Bidi.LEVEL_DEFAULT_LTR),
59 /*22*/ new ContextCase("G", ".-=", "", "=-.", Bidi.LEVEL_DEFAULT_LTR),
60 /*23*/ new ContextCase("xG", ".-=", "", ".-=", Bidi.LEVEL_DEFAULT_LTR),
61 /*24*/ new ContextCase("x|G", ".-=", "", "=-.", Bidi.LEVEL_DEFAULT_LTR),
62 /*25*/ new ContextCase("x|G", ".-=|-+*", "", "=-.|-+*", Bidi.LEVEL_DEFAULT_LTR),
64 private final int CONTEXT_COUNT = contextData.length;
66 public void testContext()
68 String prologue, epilogue, src, dest;
69 Bidi bidi = new Bidi();
73 logln("\nEntering TestContext\n");
75 bidi.orderParagraphsLTR(true);
77 for (tc = 0; tc < CONTEXT_COUNT; tc++) {
79 prologue = pseudoToU16(cc.prologue);
80 epilogue = pseudoToU16(cc.epilogue);
81 /* in the call below, prologue and epilogue are swapped to show
82 that the next call will override this call */
83 bidi.setContext(epilogue, prologue);
84 bidi.setContext(prologue, epilogue);
85 src = pseudoToU16(cc.source);
86 bidi.setPara(src, cc.paraLevel, null);
87 dest = bidi.writeReordered(Bidi.DO_MIRRORING);
88 dest = u16ToPseudo(dest);
89 assertEquals("\nActual and expected output mismatch on case "+tc+"." +
90 "\nPrologue: " + cc.prologue +
91 "\nInput: " + cc.source +
92 "\nEpilogue: " + cc.epilogue +
93 "\nParagraph level: " + Byte.toString(bidi.getParaLevel()) + "\n",
97 logln("\nExiting TestContext\n");
100 public static void main(String[] args) {
102 new TestContext().run(args);
104 catch (Exception e) {
105 System.out.println(e);