Revert StaticDisplayState; For hosted only allow debug to be used.
[SquirrelJME.git] / modules / midp-lcdui / src / test / java / mleui / forms / TestItemRemoveShift.java
blob83fd54dcda2f4e7929b99ae0abfb6ee052ce0022
1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the GNU General Public License v3+, or later.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package mleui.forms;
12 import cc.squirreljme.jvm.mle.brackets.UIDisplayBracket;
13 import cc.squirreljme.jvm.mle.brackets.UIFormBracket;
14 import cc.squirreljme.jvm.mle.brackets.UIItemBracket;
15 import cc.squirreljme.jvm.mle.constants.UIItemType;
16 import cc.squirreljme.runtime.lcdui.mle.UIBackend;
17 import java.util.ArrayList;
18 import java.util.List;
19 import java.util.Random;
21 /**
22 * Tests that removing items shifts them accordingly.
24 * @since 2020/07/19
26 public class TestItemRemoveShift
27 extends BaseUIForm
29 /**
30 * {@inheritDoc}
31 * @since 2020/07/19
33 @Override
34 protected void test(UIBackend __backend, UIDisplayBracket __display,
35 UIFormBracket __form)
37 // Setup all the items and add to the form beforehand
38 List<__Holder__> items = new ArrayList<>();
39 for (int i = 0; i < UIItemType.NUM_TYPES; i++)
41 UIItemBracket item = __backend.itemNew(i);
43 items.add(new __Holder__(item));
44 __backend.formItemPosition(__form, item, i);
47 // We will be removing random elements!
48 Random random = new Random(12);
49 int removalCount = 0;
50 while (!items.isEmpty())
52 int count = items.size();
54 // Determine index to be removed
55 int dx = (count == 1 ? 0 : random.nextInt(count));
57 // Remove that item
58 UIItemBracket old = __backend.formItemRemove(__form, dx);
60 // Should both be the same items from the list
61 this.secondary("same-" + removalCount,
62 __backend.equals(old, items.remove(dx).item));
64 // Count should be reduced by one
65 int subCount = count - 1;
66 this.secondary("subcount-" + removalCount,
67 subCount == __backend.formItemCount(__form));
69 // All of these should be the same item in the list
70 boolean[] matches = new boolean[subCount];
71 for (int j = 0; j < subCount; j++)
72 matches[j] = __backend.equals(items.get(j).item,
73 __backend.formItemAtPosition(__form, j));
74 this.secondary("sameitems-" + removalCount, matches);
76 // For the next run (in testing)
77 removalCount++;
80 // Form should be empty
81 this.secondary("empty", __backend.formItemCount(__form));