1 /*
2  * Copyright (c) 2024 TOKITA Hiroshi
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/drivers/display.h>
8 #include <zephyr/ztest.h>
9 #include <zephyr/device.h>
10 #include <zephyr/logging/log.h>
11 #include <zephyr/display/cfb.h>
12 
13 #include "testdata.h"
14 #include "utils.h"
15 
16 LOG_MODULE_REGISTER(clear, CONFIG_DISPLAY_LOG_LEVEL);
17 
18 static const struct device *dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
19 static const uint32_t display_width = DT_PROP(DT_CHOSEN(zephyr_display), width);
20 static const uint32_t display_height = DT_PROP(DT_CHOSEN(zephyr_display), height);
21 
22 /**
23  * Fill the buffer with 0xAA before running tests.
24  */
cfb_test_before(void * text_fixture)25 static void cfb_test_before(void *text_fixture)
26 {
27 	struct display_buffer_descriptor desc = {
28 		.height = display_height,
29 		.pitch = display_width,
30 		.width = display_width,
31 		.buf_size = display_height * display_width / 8,
32 	};
33 
34 	memset(read_buffer, 0xAA, sizeof(read_buffer));
35 	zassert_ok(display_write(dev, 0, 0, &desc, read_buffer));
36 
37 	zassert_ok(display_blanking_off(dev));
38 
39 	zassert_ok(cfb_framebuffer_init(dev));
40 }
41 
cfb_test_after(void * test_fixture)42 static void cfb_test_after(void *test_fixture)
43 {
44 	cfb_framebuffer_deinit(dev);
45 }
46 
ZTEST(clear,test_clear_false)47 ZTEST(clear, test_clear_false)
48 {
49 	zassert_ok(cfb_framebuffer_clear(dev, false));
50 
51 	/* checking memory not updated */
52 	zassert_false(verify_color_inside_rect(0, 0, 320, 240, 0x0));
53 }
54 
ZTEST(clear,test_clear_true)55 ZTEST(clear, test_clear_true)
56 {
57 	zassert_ok(cfb_framebuffer_clear(dev, true));
58 
59 	zassert_true(verify_color_inside_rect(0, 0, 320, 240, 0x0));
60 }
61 
62 ZTEST_SUITE(clear, NULL, NULL, cfb_test_before, cfb_test_after, NULL);
63