Add new scale tests

* tests/scale_test.c (enum test_kind): New test for 2x5 scale.
(test_names): Add new test name.
(LAST_TEST): Set to new test.
(do_verify_window_size): New function.
(test_single_step): Verify window sizes as well.  Implement new
test.

* tests/test_harness.c (verify_window_size): New function.
* tests/test_harness.h: New prototype.
This commit is contained in:
hujianwei 2022-11-17 01:52:55 +00:00
parent 897035e531
commit 7deac88eae
3 changed files with 55 additions and 1 deletions

View file

@ -28,6 +28,7 @@ enum test_kind
BUFFER_SCALE_2_KIND,
BUFFER_SCALE_1_2_KIND,
BUFFER_SCALE_2_2_KIND,
BUFFER_SCALE_2_5_KIND,
};
static const char *test_names[] =
@ -37,9 +38,10 @@ static const char *test_names[] =
"buffer_scale_2",
"buffer_scale_1_2",
"buffer_scale_2_2",
"buffer_scale_2_5",
};
#define LAST_TEST BUFFER_SCALE_2_2_KIND
#define LAST_TEST BUFFER_SCALE_2_5_KIND
/* The display. */
static struct test_display *display;
@ -64,6 +66,30 @@ static void wait_frame_callback (struct wl_surface *);
static void
do_verify_window_size (int scale, int output_scale)
{
int scale_factor;
double buffer_factor;
/* Verify the window size. The window size is determined by first
calculating a scale factor, which is the output scale minus the
scale. The scale factor describes how many times to scale down
the buffer contents. */
scale_factor = scale - output_scale;
/* Next, compute how much the buffer should actually be scaled
by. */
buffer_factor = (scale_factor > 0
? 1.0 / (scale_factor + 1)
: -scale_factor + 1);
/* And verify the window size. */
verify_window_size (display, test_surface_window,
ceil (500 * buffer_factor),
ceil (500 * buffer_factor));
}
static void
do_scale_damage_test (int scale, const char *dump_1_name,
const char *dump_2_name)
@ -140,12 +166,14 @@ test_single_step (enum test_kind kind)
case BUFFER_SCALE_1_KIND:
do_scale_damage_test (1, "buffer_scale_1_1.dump",
"buffer_scale_1_2.dump");
do_verify_window_size (1, 1);
test_single_step (BUFFER_SCALE_2_KIND);
break;
case BUFFER_SCALE_2_KIND:
do_scale_damage_test (2, "buffer_scale_2_1.dump",
"buffer_scale_2_2.dump");
do_verify_window_size (2, 1);
test_single_step (BUFFER_SCALE_1_2_KIND);
break;
@ -154,6 +182,7 @@ test_single_step (enum test_kind kind)
test_set_scale (display, 2);
do_scale_damage_test (1, "buffer_scale_1_2_1.dump",
"buffer_scale_1_2_2.dump");
do_verify_window_size (1, 2);
test_single_step (BUFFER_SCALE_2_2_KIND);
break;
@ -162,6 +191,16 @@ test_single_step (enum test_kind kind)
test_set_scale (display, 2);
do_scale_damage_test (2, "buffer_scale_2_2_1.dump",
"buffer_scale_2_2_2.dump");
do_verify_window_size (2, 2);
test_single_step (BUFFER_SCALE_2_5_KIND);
break;
case BUFFER_SCALE_2_5_KIND:
/* The buffer should be made three times larger. */
test_set_scale (display, 5);
do_scale_damage_test (2, "buffer_scale_2_5_1.dump",
"buffer_scale_2_5_2.dump");
do_verify_window_size (2, 5);
break;
}

View file

@ -930,3 +930,17 @@ test_get_serial (struct test_display *display)
return display->serial;
}
void
verify_window_size (struct test_display *display,
Window window, int width, int height)
{
XWindowAttributes attrs;
XGetWindowAttributes (display->x_display, window, &attrs);
if (width != attrs.width || height != attrs.height)
report_test_failure ("window is incorrect size. expected: %d %d"
", actual: %d %d", width, height,
attrs.width, attrs.height);
}

View file

@ -159,6 +159,7 @@ extern void test_complete (void) __attribute__ ((noreturn));
extern void test_set_scale (struct test_display *, int);
extern void test_init_seat (struct test_display *);
extern uint32_t test_get_serial (struct test_display *);
extern void verify_window_size (struct test_display *, Window, int, int);
#define ARRAYELTS(arr) (sizeof (arr) / sizeof (arr)[0])