* Widget tests. */
| 140 | * Widget tests. |
| 141 | */ |
| 142 | static void testWidget() |
| 143 | { |
| 144 | YAGfxTest testGfx; |
| 145 | TestWidget testWidget; |
| 146 | int16_t posX = -1; |
| 147 | int16_t posY = -1; |
| 148 | const Color COLOR = 0x123456; |
| 149 | const char* testStr = "myWidget"; |
| 150 | |
| 151 | /* Verify widget type name */ |
| 152 | TEST_ASSERT_EQUAL_STRING(TestWidget::WIDGET_TYPE, testWidget.getType()); |
| 153 | |
| 154 | /* No widget name is set, it must be empty. */ |
| 155 | TEST_ASSERT_EQUAL_STRING("", testWidget.getName().c_str()); |
| 156 | |
| 157 | /* Set widget name and read back. */ |
| 158 | testWidget.setName(testStr); |
| 159 | TEST_ASSERT_EQUAL_STRING(testStr, testWidget.getName().c_str()); |
| 160 | |
| 161 | /* Find widget with empty name. |
| 162 | * Expected: Not found |
| 163 | */ |
| 164 | TEST_ASSERT_NULL(testWidget.find("")); |
| 165 | |
| 166 | /* Find widget with its name. |
| 167 | * Expected: Widget is found |
| 168 | */ |
| 169 | TEST_ASSERT_NOT_NULL(testWidget.find(testStr)); |
| 170 | TEST_ASSERT_EQUAL_PTR(&testWidget, testWidget.find(testStr)); |
| 171 | |
| 172 | /* Clear name */ |
| 173 | testWidget.setName(""); |
| 174 | TEST_ASSERT_EQUAL_STRING("", testWidget.getName().c_str()); |
| 175 | |
| 176 | /* Current position must be (0, 0) */ |
| 177 | testWidget.getPos(posX, posY); |
| 178 | TEST_ASSERT_EQUAL_INT16(0, posX); |
| 179 | TEST_ASSERT_EQUAL_INT16(0, posY); |
| 180 | |
| 181 | /* Move widget and verify position again. */ |
| 182 | testWidget.move(10, 20); |
| 183 | testWidget.getPos(posX, posY); |
| 184 | TEST_ASSERT_EQUAL_INT16(10, posX); |
| 185 | TEST_ASSERT_EQUAL_INT16(20, posY); |
| 186 | |
| 187 | /* Verify widget type name */ |
| 188 | TEST_ASSERT_EQUAL_STRING(TestWidget::WIDGET_TYPE, testWidget.getType()); |
| 189 | |
| 190 | /* For the whole test, set the widget color. */ |
| 191 | testWidget.setPenColor(COLOR); |
| 192 | |
| 193 | /* Draw widget at position (0, 0) */ |
| 194 | posX = 0; |
| 195 | posY = 0; |
| 196 | testWidget.move(posX, posY); |
| 197 | testGfx.fill(0); |
| 198 | testWidget.update(testGfx); |
| 199 | TEST_ASSERT_TRUE(testGfx.verify(posX, |