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