1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
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 // ---------------------------------------------------------------------------
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
;
21 * Tests that form properties are correct.
25 public class TestFormProperties
28 /** Invalid string. */
29 private static final String _INVALID_STRING
=
30 "\0\0\0\0INVALID\0STRING\0\0\0\0";
37 protected void test(UIBackend __backend
, UIDisplayBracket __display
,
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
++)
49 this.testProperty(__backend
, __form
, prop
);
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
59 this.secondary("neg-fails", true);
61 this.secondary("null-fails", true);
62 else if (prop
>= UIWidgetProperty
.NUM_PROPERTIES
)
63 this.secondary("pos-fails", true);
70 this.secondary("fail-" + prop
, true);
74 this.secondary("total", (int)UIWidgetProperty
.NUM_PROPERTIES
);
78 * Tests that the given property are correctly implemented.
80 * @param __backend The backend to test.
81 * @param __property The {@link UIWidgetProperty} to test.
84 private void testProperty(UIBackend __backend
, UIFormBracket __form
,
87 MLECallError
[] exceptions
= new MLECallError
[2];
89 // Try to obtain the integer value
93 iVal
= __backend
.widgetPropertyInt(__form
, __property
, 0);
95 catch (MLECallError 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
)
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...
119 // These are just failing properties
121 case UIWidgetProperty
.NULL
:
122 case UIWidgetProperty
.NUM_PROPERTIES
:
125 case UIWidgetProperty
.STRING_LABEL
:
126 this.secondary("no-label", noEitherGet
);
129 case UIWidgetProperty
.INT_SIGNAL_REPAINT
:
130 this.secondary("no-repaint", noEitherGet
);
133 case UIWidgetProperty
.INT_WIDTH
:
135 this.secondary("positive-width", iVal
> 0);
138 case UIWidgetProperty
.INT_HEIGHT
:
140 this.secondary("positive-height", iVal
> 0);
143 case UIWidgetProperty
.INT_X_POSITION
:
144 this.secondary("has-x", !noEitherGet
);
147 case UIWidgetProperty
.INT_Y_POSITION
:
148 this.secondary("has-y", !noEitherGet
);
151 case UIWidgetProperty
.INT_IS_SHOWN
:
152 this.secondary("has-shown", !noEitherGet
);
155 case UIWidgetProperty
.INT_WIDTH_AND_HEIGHT
:
156 this.secondary("no-wah", noEitherGet
);
159 case UIWidgetProperty
.INT_LIST_TYPE
:
160 this.secondary("no-list-type", noEitherGet
);
163 case UIWidgetProperty
.INT_LIST_ITEM_DISABLED
:
164 this.secondary("no-list-enabled", noEitherGet
);
167 case UIWidgetProperty
.INT_LIST_ITEM_ICON_DIMENSION
:
168 this.secondary("no-list-paint", noEitherGet
);
171 case UIWidgetProperty
.INT_LIST_ITEM_SELECTED
:
172 this.secondary("no-list-selected", noEitherGet
);
175 case UIWidgetProperty
.INT_NUM_ELEMENTS
:
176 this.secondary("no-num-elements", noEitherGet
);
179 case UIWidgetProperty
.STRING_LIST_ITEM_LABEL
:
180 this.secondary("no-list-label", noEitherGet
);
183 case UIWidgetProperty
.INT_LIST_ITEM_ID_CODE
:
184 this.secondary("no-list-idcode", noEitherGet
);
187 case UIWidgetProperty
.INT_LIST_ITEM_FONT
:
188 this.secondary("no-list-font", noEitherGet
);
191 case UIWidgetProperty
.INT_UIITEM_TYPE
:
192 this.secondary("is-form", iVal
== UIItemType
.FORM
);
195 case UIWidgetProperty
.INT_UPDATE_LIST_SELECTION_LOCK
:
196 this.secondary("no-selection-lock", noEitherGet
);
199 case UIWidgetProperty
.STRING_FORM_TITLE
:
200 this.secondary("has-form-title", !noEitherGet
);
203 case UIWidgetProperty
.INT_SIGNAL_FOCUS
:
204 this.secondary("no-signal-focus", noEitherGet
);
208 throw new FailingExecution("Missing " + __property
);
211 // Could not get either of the two values, so fail
214 MLECallError fail
= new MLECallError("No properties.");
215 for (MLECallError e
: exceptions
)
217 fail
.addSuppressed(e
);