Revert StaticDisplayState; For hosted only allow debug to be used.
[SquirrelJME.git] / modules / midp-lcdui / src / test / java / mleui / forms / TestFormProperties.java
blob9b1a15f8c90918fd4ffb04b75a129d6b2c628e51
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.constants.UIItemType;
15 import cc.squirreljme.jvm.mle.constants.UIWidgetProperty;
16 import cc.squirreljme.jvm.mle.exceptions.MLECallError;
17 import cc.squirreljme.runtime.lcdui.mle.UIBackend;
18 import mleui.FailingExecution;
20 /**
21 * Tests that form properties are correct.
23 * @since 2020/10/11
25 public class TestFormProperties
26 extends BaseUIForm
28 /** Invalid string. */
29 private static final String _INVALID_STRING =
30 "\0\0\0\0INVALID\0STRING\0\0\0\0";
32 /**
33 * {@inheritDoc}
34 * @since 2020/10/11
36 @Override
37 protected void test(UIBackend __backend, UIDisplayBracket __display,
38 UIFormBracket __form)
40 // Add a button to give the form some size
41 __backend.formItemPosition(__form,
42 __backend.itemNew(UIItemType.BUTTON), 0);
43 __backend.flushEvents();
45 // Test each individual metric
46 for (int prop = -1; prop <= UIWidgetProperty.NUM_PROPERTIES; prop++)
47 try
49 this.testProperty(__backend, __form, prop);
51 // Should have failed
52 if (prop <= 0 || prop >= UIWidgetProperty.NUM_PROPERTIES)
53 this.secondary("bad-neg-pos", true);
55 catch (MLECallError e)
57 // Is okay to fail here
58 if (prop < 0)
59 this.secondary("neg-fails", true);
60 else if (prop == 0)
61 this.secondary("null-fails", true);
62 else if (prop >= UIWidgetProperty.NUM_PROPERTIES)
63 this.secondary("pos-fails", true);
65 // Fails here
66 else
68 e.printStackTrace();
70 this.secondary("fail-" + prop, true);
74 this.secondary("total", (int)UIWidgetProperty.NUM_PROPERTIES);
77 /**
78 * Tests that the given property are correctly implemented.
80 * @param __backend The backend to test.
81 * @param __property The {@link UIWidgetProperty} to test.
82 * @since 2020/10/11
84 private void testProperty(UIBackend __backend, UIFormBracket __form,
85 int __property)
87 MLECallError[] exceptions = new MLECallError[2];
89 // Try to obtain the integer value
90 Integer iVal = null;
91 try
93 iVal = __backend.widgetPropertyInt(__form, __property, 0);
95 catch (MLECallError e)
97 exceptions[0] = e;
100 // Try to obtain the string value
101 String sVal = TestFormProperties._INVALID_STRING;
104 sVal = __backend.widgetPropertyStr(__form, __property, 0);
106 catch (MLECallError e)
108 exceptions[1] = e;
111 // This may be a possible failure, if both could not be gotten
112 // noinspection StringEquality
113 boolean noEitherGet = (iVal == null &&
114 sVal == TestFormProperties._INVALID_STRING);
116 // Do actions based on whatever the property is...
117 switch (__property)
119 // These are just failing properties
120 case -1:
121 case UIWidgetProperty.NULL:
122 case UIWidgetProperty.NUM_PROPERTIES:
123 break;
125 case UIWidgetProperty.STRING_LABEL:
126 this.secondary("no-label", noEitherGet);
127 return;
129 case UIWidgetProperty.INT_SIGNAL_REPAINT:
130 this.secondary("no-repaint", noEitherGet);
131 return;
133 case UIWidgetProperty.INT_WIDTH:
134 if (iVal != null)
135 this.secondary("positive-width", iVal > 0);
136 break;
138 case UIWidgetProperty.INT_HEIGHT:
139 if (iVal != null)
140 this.secondary("positive-height", iVal > 0);
141 break;
143 case UIWidgetProperty.INT_X_POSITION:
144 this.secondary("has-x", !noEitherGet);
145 break;
147 case UIWidgetProperty.INT_Y_POSITION:
148 this.secondary("has-y", !noEitherGet);
149 break;
151 case UIWidgetProperty.INT_IS_SHOWN:
152 this.secondary("has-shown", !noEitherGet);
153 break;
155 case UIWidgetProperty.INT_WIDTH_AND_HEIGHT:
156 this.secondary("no-wah", noEitherGet);
157 return;
159 case UIWidgetProperty.INT_LIST_TYPE:
160 this.secondary("no-list-type", noEitherGet);
161 return;
163 case UIWidgetProperty.INT_LIST_ITEM_DISABLED:
164 this.secondary("no-list-enabled", noEitherGet);
165 return;
167 case UIWidgetProperty.INT_LIST_ITEM_ICON_DIMENSION:
168 this.secondary("no-list-paint", noEitherGet);
169 return;
171 case UIWidgetProperty.INT_LIST_ITEM_SELECTED:
172 this.secondary("no-list-selected", noEitherGet);
173 return;
175 case UIWidgetProperty.INT_NUM_ELEMENTS:
176 this.secondary("no-num-elements", noEitherGet);
177 return;
179 case UIWidgetProperty.STRING_LIST_ITEM_LABEL:
180 this.secondary("no-list-label", noEitherGet);
181 return;
183 case UIWidgetProperty.INT_LIST_ITEM_ID_CODE:
184 this.secondary("no-list-idcode", noEitherGet);
185 return;
187 case UIWidgetProperty.INT_LIST_ITEM_FONT:
188 this.secondary("no-list-font", noEitherGet);
189 return;
191 case UIWidgetProperty.INT_UIITEM_TYPE:
192 this.secondary("is-form", iVal == UIItemType.FORM);
193 break;
195 case UIWidgetProperty.INT_UPDATE_LIST_SELECTION_LOCK:
196 this.secondary("no-selection-lock", noEitherGet);
197 return;
199 case UIWidgetProperty.STRING_FORM_TITLE:
200 this.secondary("has-form-title", !noEitherGet);
201 return;
203 case UIWidgetProperty.INT_SIGNAL_FOCUS:
204 this.secondary("no-signal-focus", noEitherGet);
205 return;
207 default:
208 throw new FailingExecution("Missing " + __property);
211 // Could not get either of the two values, so fail
212 if (noEitherGet)
214 MLECallError fail = new MLECallError("No properties.");
215 for (MLECallError e : exceptions)
216 if (e != null)
217 fail.addSuppressed(e);
219 throw fail;