Create a unit test for the damage checker
parent
bacae1b515
commit
8eb6658162
|
@ -22,6 +22,12 @@
|
||||||
struct pixman_region16;
|
struct pixman_region16;
|
||||||
struct pixman_box16;
|
struct pixman_box16;
|
||||||
|
|
||||||
|
void damage_check_row(uint8_t* dst, const uint8_t* src, uint32_t width);
|
||||||
|
|
||||||
|
void damage_check_tile_row(struct pixman_region16* damage,
|
||||||
|
uint8_t* row_buffer, const uint8_t* buffer,
|
||||||
|
uint32_t y_start, uint32_t width, uint32_t height);
|
||||||
|
|
||||||
void damage_check(struct pixman_region16* damage, const uint8_t* buffer,
|
void damage_check(struct pixman_region16* damage, const uint8_t* buffer,
|
||||||
uint32_t width, uint32_t height, struct pixman_box16* hint);
|
uint32_t width, uint32_t height, struct pixman_box16* hint);
|
||||||
|
|
||||||
|
|
|
@ -114,3 +114,5 @@ executable(
|
||||||
include_directories: inc,
|
include_directories: inc,
|
||||||
install: true,
|
install: true,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
subdir('test')
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
test_inc = include_directories('../include')
|
||||||
|
|
||||||
|
test('damage',
|
||||||
|
executable('test-damage',
|
||||||
|
[
|
||||||
|
'test-damage.c',
|
||||||
|
'../src/damage.c',
|
||||||
|
],
|
||||||
|
include_directories: test_inc,
|
||||||
|
dependencies: [
|
||||||
|
pixman,
|
||||||
|
aml,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
|
@ -0,0 +1,104 @@
|
||||||
|
#include "damage.h"
|
||||||
|
#include "tst.h"
|
||||||
|
|
||||||
|
#include <pixman.h>
|
||||||
|
|
||||||
|
static int test_damage_check_row_aligned(void)
|
||||||
|
{
|
||||||
|
uint32_t width = 32;
|
||||||
|
uint8_t row[width];
|
||||||
|
uint8_t r = 0;
|
||||||
|
|
||||||
|
memset(row, 0, width);
|
||||||
|
damage_check_row(&r, row, width);
|
||||||
|
|
||||||
|
ASSERT_FALSE(r);
|
||||||
|
|
||||||
|
row[0] = 1;
|
||||||
|
r = 0;
|
||||||
|
damage_check_row(&r, row, width);
|
||||||
|
|
||||||
|
ASSERT_TRUE(r);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int test_damage_check_row_unaligned(void)
|
||||||
|
{
|
||||||
|
uint32_t width = 33;
|
||||||
|
uint8_t row[width];
|
||||||
|
uint8_t r[2] = { 0 };
|
||||||
|
|
||||||
|
memset(row, 0, width);
|
||||||
|
damage_check_row(r, row, width);
|
||||||
|
|
||||||
|
ASSERT_FALSE(r[0]);
|
||||||
|
ASSERT_FALSE(r[1]);
|
||||||
|
|
||||||
|
row[32] = 1;
|
||||||
|
r[0] = 0;
|
||||||
|
r[1] = 0;
|
||||||
|
damage_check_row(r, row, width);
|
||||||
|
|
||||||
|
ASSERT_FALSE(r[0]);
|
||||||
|
ASSERT_TRUE(r[1]);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int test_damage_check_tile_row_aligned(void)
|
||||||
|
{
|
||||||
|
uint32_t width = 32;
|
||||||
|
uint32_t height = 32;
|
||||||
|
uint8_t tile[width * height];
|
||||||
|
struct pixman_region16 damage;
|
||||||
|
uint8_t row = 0;
|
||||||
|
pixman_region_init(&damage);
|
||||||
|
|
||||||
|
memset(tile, 0, sizeof(tile));
|
||||||
|
damage_check_tile_row(&damage, &row, tile, 0, width, height);
|
||||||
|
ASSERT_FALSE(pixman_region_not_empty(&damage));
|
||||||
|
|
||||||
|
row = 0;
|
||||||
|
pixman_region_clear(&damage);
|
||||||
|
tile[0] = 1;
|
||||||
|
damage_check_tile_row(&damage, &row, tile, 0, width, height);
|
||||||
|
ASSERT_TRUE(pixman_region_not_empty(&damage));
|
||||||
|
|
||||||
|
pixman_region_fini(&damage);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int test_damage_check_tile_row_unaligned(void)
|
||||||
|
{
|
||||||
|
uint32_t width = 33;
|
||||||
|
uint32_t height = 32;
|
||||||
|
uint8_t tile[width * height];
|
||||||
|
struct pixman_region16 damage;
|
||||||
|
uint8_t row[2] = { 0 };
|
||||||
|
pixman_region_init(&damage);
|
||||||
|
|
||||||
|
memset(tile, 0, sizeof(tile));
|
||||||
|
damage_check_tile_row(&damage, row, tile, 0, width, height);
|
||||||
|
ASSERT_FALSE(pixman_region_not_empty(&damage));
|
||||||
|
|
||||||
|
row[0] = 0;
|
||||||
|
row[1] = 0;
|
||||||
|
pixman_region_clear(&damage);
|
||||||
|
tile[32] = 1;
|
||||||
|
damage_check_tile_row(&damage, row, tile, 0, width, height);
|
||||||
|
ASSERT_TRUE(pixman_region_not_empty(&damage));
|
||||||
|
|
||||||
|
pixman_region_fini(&damage);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int r = 0;
|
||||||
|
RUN_TEST(test_damage_check_row_aligned);
|
||||||
|
RUN_TEST(test_damage_check_row_unaligned);
|
||||||
|
RUN_TEST(test_damage_check_tile_row_aligned);
|
||||||
|
RUN_TEST(test_damage_check_tile_row_unaligned);
|
||||||
|
return r;
|
||||||
|
}
|
Loading…
Reference in New Issue