* Test text widget. */
| 221 | * Test text widget. |
| 222 | */ |
| 223 | static 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()); |
nothing calls this directly
no test coverage detected