MCPcopy Create free account
hub / github.com/BlueAndi/Pixelix / testTextWidget

Function testTextWidget

test/test_TextWidget/TestTextWidget.cpp:223–311  ·  view source on GitHub ↗

* Test text widget. */

Source from the content-addressed store, hash-verified

221 * Test text widget.
222 */
223static void testTextWidget()
224{
225 YAGfxTest testGfx;
226 TextWidget textWidget(YAGfxTest::WIDTH, YAGfxTest::HEIGHT);
227 String testStr = "test";
228 const Color TEXT_COLOR = 0x123456;
229 const char* WIDGET_NAME = "textWidgetName";
230
231 /* Verify widget type name */
232 TEST_ASSERT_EQUAL_STRING(TextWidget::WIDGET_TYPE, textWidget.getType());
233
234 /* No widget name is set, it must be empty. */
235 TEST_ASSERT_EQUAL_STRING("", textWidget.getName().c_str());
236
237 /* Set widget name and read back. */
238 textWidget.setName(WIDGET_NAME);
239 TEST_ASSERT_EQUAL_STRING(WIDGET_NAME, textWidget.getName().c_str());
240
241 /* Find widget with empty name.
242 * Expected: Not found
243 */
244 TEST_ASSERT_NULL(textWidget.find(""));
245
246 /* Find widget with its name.
247 * Expected: Widget is found
248 */
249 TEST_ASSERT_NOT_NULL(textWidget.find(WIDGET_NAME));
250 TEST_ASSERT_EQUAL_PTR(&textWidget, textWidget.find(WIDGET_NAME));
251
252 /* Default string is empty */
253 TEST_ASSERT_EQUAL_STRING("", textWidget.getStr().c_str());
254
255 /* Set/Get string */
256 textWidget.setFormatStr(testStr);
257 TEST_ASSERT_EQUAL_STRING(testStr.c_str(), textWidget.getStr().c_str());
258
259 /* Default string color */
260 TEST_ASSERT_EQUAL_UINT32(TextWidget::DEFAULT_TEXT_COLOR, dynamic_cast<YAGfxSolidBrush&>(textWidget.getBrush()).getColor());
261
262 /* Set/Get text color */
263 dynamic_cast<YAGfxSolidBrush&>(textWidget.getBrush()).setColor(TEXT_COLOR);
264 TEST_ASSERT_EQUAL_UINT32(TEXT_COLOR, dynamic_cast<YAGfxSolidBrush&>(textWidget.getBrush()).getColor(0, 0));
265
266 /* Check for default font */
267 TEST_ASSERT_NOT_NULL(textWidget.getFont().getGfxFont());
268 TEST_ASSERT_EQUAL_PTR(TextWidget::DEFAULT_FONT.getGfxFont(), textWidget.getFont().getGfxFont());
269
270 /* Font shall be used for drawing */
271 textWidget.update(testGfx);
272 TEST_ASSERT_NOT_NULL(textWidget.getFont().getGfxFont());
273 TEST_ASSERT_EQUAL_PTR(TextWidget::DEFAULT_FONT.getGfxFont(), textWidget.getFont().getGfxFont());
274
275 /* Set text with valid format keyword and get text without format keyword back. */
276 textWidget.setFormatStr("{hl}Hello World!");
277 TEST_ASSERT_EQUAL_STRING("Hello World!", textWidget.getStr().c_str());
278
279 textWidget.setFormatStr("{hc}Hello World!");
280 TEST_ASSERT_EQUAL_STRING("Hello World!", textWidget.getStr().c_str());

Callers

nothing calls this directly

Calls 11

c_strMethod · 0.80
getStrMethod · 0.80
setFormatStrMethod · 0.80
getGfxFontMethod · 0.80
getTypeMethod · 0.45
getNameMethod · 0.45
setNameMethod · 0.45
findMethod · 0.45
getColorMethod · 0.45
setColorMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected