1/* GENERATED SOURCE. DO NOT MODIFY. */ 2// © 2016 and later: Unicode, Inc. and others. 3// License & terms of use: http://www.unicode.org/copyright.html#License 4/* 5******************************************************************************* 6* Copyright (C) 2007-2011, International Business Machines 7* Corporation and others. All Rights Reserved. 8******************************************************************************* 9*/ 10 11package android.icu.dev.test.bidi; 12 13import org.junit.Test; 14 15import android.icu.text.Bidi; 16import android.icu.testsharding.MainTestShard; 17 18/** 19 * Regression test for doing transformations in context 20 * 21 * @author Matitiahu Allouche 22 */ 23 24@MainTestShard 25public class TestContext extends BidiFmwk { 26 27 private class ContextCase { 28 String prologue; 29 String source; 30 String epilogue; 31 String expected; 32 byte paraLevel; 33 34 ContextCase(String pro, String src, String epi, String exp, byte lev) { 35 prologue = pro; 36 source = src; 37 epilogue = epi; 38 expected = exp; 39 paraLevel = lev; 40 } 41 }; 42 43 private final ContextCase[] contextData = { 44 /*00*/ new ContextCase("", "", "", "", Bidi.LTR), 45 /*01*/ new ContextCase("", ".-=JKL-+*", "", ".-=LKJ-+*", Bidi.LTR), 46 /*02*/ new ContextCase(" ", ".-=JKL-+*", " ", ".-=LKJ-+*", Bidi.LTR), 47 /*03*/ new ContextCase("a", ".-=JKL-+*", "b", ".-=LKJ-+*", Bidi.LTR), 48 /*04*/ new ContextCase("D", ".-=JKL-+*", "", "LKJ=-.-+*", Bidi.LTR), 49 /*05*/ new ContextCase("", ".-=JKL-+*", " D", ".-=*+-LKJ", Bidi.LTR), 50 /*06*/ new ContextCase("", ".-=JKL-+*", " 2", ".-=*+-LKJ", Bidi.LTR), 51 /*07*/ new ContextCase("", ".-=JKL-+*", " 7", ".-=*+-LKJ", Bidi.LTR), 52 /*08*/ new ContextCase(" G 1", ".-=JKL-+*", " H", "*+-LKJ=-.", Bidi.LTR), 53 /*09*/ new ContextCase("7", ".-=JKL-+*", " H", ".-=*+-LKJ", Bidi.LTR), 54 /*10*/ new ContextCase("", ".-=abc-+*", "", "*+-abc=-.", Bidi.RTL), 55 /*11*/ new ContextCase(" ", ".-=abc-+*", " ", "*+-abc=-.", Bidi.RTL), 56 /*12*/ new ContextCase("D", ".-=abc-+*", "G", "*+-abc=-.", Bidi.RTL), 57 /*13*/ new ContextCase("x", ".-=abc-+*", "", "*+-.-=abc", Bidi.RTL), 58 /*14*/ new ContextCase("", ".-=abc-+*", " y", "abc-+*=-.", Bidi.RTL), 59 /*15*/ new ContextCase("", ".-=abc-+*", " 2", "abc-+*=-.", Bidi.RTL), 60 /*16*/ new ContextCase(" x 1", ".-=abc-+*", " 2", ".-=abc-+*", Bidi.RTL), 61 /*17*/ new ContextCase(" x 7", ".-=abc-+*", " 8", "*+-.-=abc", Bidi.RTL), 62 /*18*/ new ContextCase("x|", ".-=abc-+*", " 8", "*+-abc=-.", Bidi.RTL), 63 /*19*/ new ContextCase("G|y", ".-=abc-+*", " 8", "*+-.-=abc", Bidi.RTL), 64 /*20*/ new ContextCase("", ".-=", "", ".-=", Bidi.LEVEL_DEFAULT_LTR), 65 /*21*/ new ContextCase("D", ".-=", "", "=-.", Bidi.LEVEL_DEFAULT_LTR), 66 /*22*/ new ContextCase("G", ".-=", "", "=-.", Bidi.LEVEL_DEFAULT_LTR), 67 /*23*/ new ContextCase("xG", ".-=", "", ".-=", Bidi.LEVEL_DEFAULT_LTR), 68 /*24*/ new ContextCase("x|G", ".-=", "", "=-.", Bidi.LEVEL_DEFAULT_LTR), 69 /*25*/ new ContextCase("x|G", ".-=|-+*", "", "=-.|-+*", Bidi.LEVEL_DEFAULT_LTR), 70 }; 71 private final int CONTEXT_COUNT = contextData.length; 72 73 @Test 74 public void testContext() 75 { 76 String prologue, epilogue, src, dest; 77 Bidi bidi = new Bidi(); 78 int tc; 79 ContextCase cc; 80 81 logln("\nEntering TestContext\n"); 82 83 bidi.orderParagraphsLTR(true); 84 85 for (tc = 0; tc < CONTEXT_COUNT; tc++) { 86 cc = contextData[tc]; 87 prologue = pseudoToU16(cc.prologue); 88 epilogue = pseudoToU16(cc.epilogue); 89 /* in the call below, prologue and epilogue are swapped to show 90 that the next call will override this call */ 91 bidi.setContext(epilogue, prologue); 92 bidi.setContext(prologue, epilogue); 93 src = pseudoToU16(cc.source); 94 bidi.setPara(src, cc.paraLevel, null); 95 dest = bidi.writeReordered(Bidi.DO_MIRRORING); 96 dest = u16ToPseudo(dest); 97 assertEquals("\nActual and expected output mismatch on case "+tc+"." + 98 "\nPrologue: " + cc.prologue + 99 "\nInput: " + cc.source + 100 "\nEpilogue: " + cc.epilogue + 101 "\nParagraph level: " + Byte.toString(bidi.getParaLevel()) + "\n", 102 cc.expected, dest); 103 } 104 105 logln("\nExiting TestContext\n"); 106 } 107} 108