awtk/tests/lcd_mem_test.cc

76 lines
2.3 KiB
C++
Raw Normal View History

2018-06-27 13:46:42 +08:00
#include "base/canvas.h"
2018-04-18 16:58:51 +08:00
#include "gtest/gtest.h"
2018-05-27 06:44:02 +08:00
#include "lcd/lcd_mem_rgba8888.h"
2018-04-18 16:58:51 +08:00
2018-04-18 17:33:40 +08:00
static void test_draw_points(canvas_t* c) {
2018-04-18 16:58:51 +08:00
int i = 0;
color_t color;
color_t stroke_color = color_init(0xff, 0x0, 0x0, 0xff);
2018-04-20 21:49:47 +08:00
point_t points[] = {{0, 0}, {100, 100}, {100, 101}, {100, 102}, {100, 103}, {199, 199}};
2018-04-18 16:58:51 +08:00
ASSERT_EQ(canvas_set_stroke_color(c, stroke_color), RET_OK);
ASSERT_EQ(canvas_draw_points(c, points, ARRAY_SIZE(points)), RET_OK);
2018-04-20 21:49:47 +08:00
for (i = 0; i < ARRAY_SIZE(points); i++) {
point_t* p = points + i;
color = lcd_get_point_color(c->lcd, p->x, p->y);
2018-04-18 16:58:51 +08:00
ASSERT_EQ(color.color, stroke_color.color);
2018-04-20 21:49:47 +08:00
color = lcd_get_point_color(c->lcd, p->x + 10, p->y);
2018-04-18 16:58:51 +08:00
ASSERT_EQ(color.color, 0);
}
2018-04-18 17:33:40 +08:00
}
static void test_fill_rect(canvas_t* c) {
color_t color;
lcd_t* lcd = c->lcd;
color_t fill_color = color_init(0xff, 0xff, 0x0, 0xff);
ASSERT_EQ(canvas_set_fill_color(c, fill_color), RET_OK);
ASSERT_EQ(canvas_fill_rect(c, 0, 0, lcd->w, lcd->h), RET_OK);
color = lcd_get_point_color(c->lcd, 0, 0);
ASSERT_EQ(color.color, fill_color.color);
2018-04-20 21:49:47 +08:00
2018-04-18 17:33:40 +08:00
color = lcd_get_point_color(c->lcd, 10, 10);
ASSERT_EQ(color.color, fill_color.color);
2018-04-20 21:49:47 +08:00
2018-04-18 17:33:40 +08:00
color = lcd_get_point_color(c->lcd, 199, 199);
ASSERT_EQ(color.color, fill_color.color);
}
static void test_stroke_rect(canvas_t* c) {
color_t color;
lcd_t* lcd = c->lcd;
color_t stroke_color = color_init(0xff, 0x0, 0x0, 0xff);
ASSERT_EQ(canvas_set_stroke_color(c, stroke_color), RET_OK);
ASSERT_EQ(canvas_stroke_rect(c, 0, 0, lcd->w, lcd->h), RET_OK);
color = lcd_get_point_color(c->lcd, 0, 0);
ASSERT_EQ(color.color, stroke_color.color);
2018-04-20 21:49:47 +08:00
2018-04-18 17:33:40 +08:00
color = lcd_get_point_color(c->lcd, 0, 199);
ASSERT_EQ(color.color, stroke_color.color);
2018-04-20 21:49:47 +08:00
2018-04-18 17:33:40 +08:00
color = lcd_get_point_color(c->lcd, 199, 0);
ASSERT_EQ(color.color, stroke_color.color);
2018-04-20 21:49:47 +08:00
2018-04-18 17:33:40 +08:00
color = lcd_get_point_color(c->lcd, 199, 199);
ASSERT_EQ(color.color, stroke_color.color);
}
TEST(LCDMem, basic) {
canvas_t canvas;
font_manager_t font_manager;
font_manager_init(&font_manager);
2018-05-27 06:44:02 +08:00
lcd_t* lcd = lcd_mem_rgba8888_create(200, 200, TRUE);
2018-04-18 17:33:40 +08:00
canvas_t* c = canvas_init(&canvas, lcd, &font_manager);
ASSERT_EQ(c, &canvas);
2018-04-22 16:57:05 +08:00
ASSERT_EQ(canvas_begin_frame(c, NULL, LCD_DRAW_NORMAL), RET_OK);
2018-04-18 17:33:40 +08:00
test_draw_points(c);
test_fill_rect(c);
test_stroke_rect(c);
2018-04-18 16:58:51 +08:00
lcd_destroy(lcd);
}