xrdp/tests/libxrdp/test_libxrdp_process_monitor_stream.c
Christopher Pitstick bd9147d18f Updating to refactor xrdp_client_info
- Eliminate duplicaiton for display_size_description
- monitorCount needs to be uint32_t
- width/height -> session_width/session_height
- Update CLIENT_INFO_CURRENT_VERSION
- Also some misc unit test updates.
- Minor log updates.
2022-03-27 16:38:32 -04:00

407 lines
17 KiB
C

#if defined(HAVE_CONFIG_H)
#include "config_ac.h"
#endif
#include "libxrdp.h"
#include "os_calls.h"
#include "test_libxrdp.h"
START_TEST(test_libxrdp_process_monitor_stream__when_description_is_null__fail)
{
struct stream *s = (struct stream *)NULL;
make_stream(s);
init_stream(s, 4);
//Dummy data.
out_uint32_le(s, 0);
s_mark_end(s);
//Reset the read counter of the stream so the processing function handles it properly.
s->p = s->data;
int error = libxrdp_process_monitor_stream(s, NULL, 1);
ck_assert_int_eq(error, SEC_PROCESS_MONITORS_ERR);
free_stream(s);
}
END_TEST
START_TEST(test_libxrdp_process_monitor_stream__when_stream_is_too_small__fail)
{
struct stream *s = (struct stream *)NULL;
make_stream(s);
init_stream(s, 2);
//Dummy data.
out_uint16_le(s, 0);
s_mark_end(s);
//Reset the read counter of the stream so the processing function handles it properly.
s->p = s->data;
struct display_size_description *description =
(struct display_size_description *)
g_malloc(sizeof(struct display_size_description), 1);
int error = libxrdp_process_monitor_stream(s, description, 1);
ck_assert_int_eq(error, SEC_PROCESS_MONITORS_ERR);
free(description);
free_stream(s);
}
END_TEST
START_TEST(test_libxrdp_process_monitor_stream__when_monitor_count_is_greater_than_sixteen__fail)
{
struct stream *s = (struct stream *)NULL;
make_stream(s);
init_stream(s, 4);
//Dummy data.
out_uint32_le(s, 17);
s_mark_end(s);
//Reset the read counter of the stream so the processing function handles it properly.
s->p = s->data;
struct display_size_description *description =
(struct display_size_description *)
g_malloc(sizeof(struct display_size_description), 1);
int error = libxrdp_process_monitor_stream(s, description, 1);
ck_assert_int_eq(error, SEC_PROCESS_MONITORS_ERR_TOO_MANY_MONITORS);
free(description);
free_stream(s);
}
END_TEST
START_TEST(test_libxrdp_process_monitor_stream__with_single_monitor_happy_path)
{
struct stream *s = (struct stream *)NULL;
make_stream(s);
init_stream(s, 44);
out_uint32_le(s, 1); //monitorCount
// Pretend we have a 4k monitor
out_uint32_le(s, TS_MONITOR_PRIMARY); //flags
out_uint32_le(s, 0); //monitor left
out_uint32_le(s, 0); //monitor top
out_uint32_le(s, 3840); //monitor right
out_uint32_le(s, 2160); //monitor bottom
out_uint32_le(s, 2000); //physical width
out_uint32_le(s, 2000); //physical height
out_uint32_le(s, 0); //orientation
out_uint32_le(s, 100); //desktop scale factor
out_uint32_le(s, 100); //device scale factor
s_mark_end(s);
//Reset the read counter of the stream so the processing function handles it properly.
s->p = s->data;
struct display_size_description *description =
(struct display_size_description *)
g_malloc(sizeof(struct display_size_description), 1);
int error = libxrdp_process_monitor_stream(s, description, 1);
//Verify function call passed.
ck_assert_int_eq(error, 0);
ck_assert_int_eq(description->monitorCount, 1);
// Verify normal monitor
ck_assert_int_eq(description->minfo[0].left, 0);
ck_assert_int_eq(description->minfo[0].top, 0);
ck_assert_int_eq(description->minfo[0].right, 3840);
ck_assert_int_eq(description->minfo[0].bottom, 2160);
ck_assert_int_eq(description->minfo[0].physical_width, 2000);
ck_assert_int_eq(description->minfo[0].physical_height, 2000);
ck_assert_int_eq(description->minfo[0].orientation, 0);
ck_assert_int_eq(description->minfo[0].desktop_scale_factor, 100);
ck_assert_int_eq(description->minfo[0].device_scale_factor, 100);
ck_assert_int_eq(description->minfo[0].is_primary, 1);
// Verify normalized monitor
ck_assert_int_eq(description->minfo_wm[0].left, 0);
ck_assert_int_eq(description->minfo_wm[0].top, 0);
ck_assert_int_eq(description->minfo_wm[0].right, 3840);
ck_assert_int_eq(description->minfo_wm[0].bottom, 2160);
ck_assert_int_eq(description->minfo_wm[0].physical_width, 2000);
ck_assert_int_eq(description->minfo_wm[0].physical_height, 2000);
ck_assert_int_eq(description->minfo_wm[0].orientation, 0);
ck_assert_int_eq(description->minfo_wm[0].desktop_scale_factor, 100);
ck_assert_int_eq(description->minfo_wm[0].device_scale_factor, 100);
ck_assert_int_eq(description->minfo_wm[0].is_primary, 1);
// Verify geometry (+1 greater than )
ck_assert_int_eq(description->session_width, 3841);
ck_assert_int_eq(description->session_height, 2161);
free(description);
free_stream(s);
}
END_TEST
START_TEST(test_libxrdp_process_monitor_stream__with_sextuple_monitor_happy_path)
{
struct stream *s = (struct stream *)NULL;
make_stream(s);
init_stream(s, 233);
out_uint32_le(s, 6); //monitorCount
// 4k monitor at position (0, 0)
out_uint32_le(s, 0); //flags
out_uint32_le(s, 0); //monitor left
out_uint32_le(s, 0); //monitor top
out_uint32_le(s, 3840); //monitor width
out_uint32_le(s, 2160); //monitor height
out_uint32_le(s, 9); //physical width
out_uint32_le(s, 9); //physical height
out_uint32_le(s, -10); //orientation
out_uint32_le(s, -100); //desktop scale factor
out_uint32_le(s, 600); //device scale factor
// 4k monitor at position (1, 0)
out_uint32_le(s, TS_MONITOR_PRIMARY); //flags
out_uint32_le(s, 3841); //monitor left
out_uint32_le(s, 0); //monitor top
out_uint32_le(s, 3840); //monitor right
out_uint32_le(s, 2160); //monitor bottom
out_uint32_le(s, 5); //physical width
out_uint32_le(s, 11000); //physical height
out_uint32_le(s, 10); //orientation (Expect to be reset to 0)
out_uint32_le(s, 360); //desktop scale factor
out_uint32_le(s, 720); //device scale factor
// 4k monitor at position (2, 0)
out_uint32_le(s, 0); //flags
out_uint32_le(s, 7682); //monitor left
out_uint32_le(s, 0); //monitor top
out_uint32_le(s, 3840); //monitor width
out_uint32_le(s, 2160); //monitor height
out_uint32_le(s, 1000); //physical width
out_uint32_le(s, 1000); //physical height
out_uint32_le(s, 5000); //orientation
out_uint32_le(s, 80); //desktop scale factor
out_uint32_le(s, 140); //device scale factor
// 4k monitor at position (0, 1)
out_uint32_le(s, 0); //flags
out_uint32_le(s, 0); //monitor left
out_uint32_le(s, 2161); //monitor top
out_uint32_le(s, 3840); //monitor width
out_uint32_le(s, 2160); //monitor height
out_uint32_le(s, 1000); //physical width
out_uint32_le(s, 1000); //physical height
out_uint32_le(s, 91); //orientation
out_uint32_le(s, 180); //desktop scale factor
out_uint32_le(s, 100); //device scale factor
// 4k monitor at position (1, 1)
out_uint32_le(s, 0); //flags
out_uint32_le(s, 3841); //monitor left
out_uint32_le(s, 2161); //monitor top
out_uint32_le(s, 3840); //monitor width
out_uint32_le(s, 2160); //monitor height
out_uint32_le(s, 1000); //physical width
out_uint32_le(s, 1000); //physical height
out_uint32_le(s, 0); //orientation
out_uint32_le(s, 20); //desktop scale factor
out_uint32_le(s, 50); //device scale factor
// 4k monitor at position (2, 1)
out_uint32_le(s, 0); //flags
out_uint32_le(s, 7682); //monitor left
out_uint32_le(s, 2161); //monitor top
out_uint32_le(s, 3840); //monitor width
out_uint32_le(s, 2160); //monitor height
out_uint32_le(s, 1000); //physical width
out_uint32_le(s, 1000); //physical height
out_uint32_le(s, 0); //orientation
out_uint32_le(s, 300); //desktop scale factor
out_uint32_le(s, 400); //device scale factor
s_mark_end(s);
// Reset the read counter of the stream so the processing function handles it properly.
s->p = s->data;
struct display_size_description *description =
(struct display_size_description *)
g_malloc(sizeof(struct display_size_description), 1);
int error = libxrdp_process_monitor_stream(s, description, 1);
//Verify function call passed.
ck_assert_int_eq(error, 0);
ck_assert_int_eq(description->monitorCount, 6);
/*************************************************
* Verify standard monitors
*************************************************/
ck_assert_int_eq(description->minfo[0].left, 0);
ck_assert_int_eq(description->minfo[0].top, 0);
ck_assert_int_eq(description->minfo[0].right, 3840);
ck_assert_int_eq(description->minfo[0].bottom, 2160);
ck_assert_int_eq(description->minfo[0].physical_width, 0);
ck_assert_int_eq(description->minfo[0].physical_height, 0);
ck_assert_int_eq(description->minfo[0].orientation, 0);
ck_assert_int_eq(description->minfo[0].desktop_scale_factor, 100);
ck_assert_int_eq(description->minfo[0].device_scale_factor, 100);
ck_assert_int_eq(description->minfo[0].is_primary, 0);
ck_assert_int_eq(description->minfo[1].left, 3841);
ck_assert_int_eq(description->minfo[1].top, 0);
ck_assert_int_eq(description->minfo[1].right, 7681);
ck_assert_int_eq(description->minfo[1].bottom, 2160);
ck_assert_int_eq(description->minfo[1].physical_width, 0);
ck_assert_int_eq(description->minfo[1].physical_height, 0);
ck_assert_int_eq(description->minfo[1].orientation, 0);
ck_assert_int_eq(description->minfo[1].desktop_scale_factor, 100);
ck_assert_int_eq(description->minfo[1].device_scale_factor, 100);
ck_assert_int_eq(description->minfo[1].is_primary, 1);
ck_assert_int_eq(description->minfo[2].left, 7682);
ck_assert_int_eq(description->minfo[2].top, 0);
ck_assert_int_eq(description->minfo[2].right, 11522);
ck_assert_int_eq(description->minfo[2].bottom, 2160);
ck_assert_int_eq(description->minfo[2].physical_width, 1000);
ck_assert_int_eq(description->minfo[2].physical_height, 1000);
ck_assert_int_eq(description->minfo[2].orientation, 0);
ck_assert_int_eq(description->minfo[2].desktop_scale_factor, 100);
ck_assert_int_eq(description->minfo[2].device_scale_factor, 140);
ck_assert_int_eq(description->minfo[2].is_primary, 0);
ck_assert_int_eq(description->minfo[3].left, 0);
ck_assert_int_eq(description->minfo[3].top, 2161);
ck_assert_int_eq(description->minfo[3].right, 3840);
ck_assert_int_eq(description->minfo[3].bottom, 4321);
ck_assert_int_eq(description->minfo[3].physical_width, 1000);
ck_assert_int_eq(description->minfo[3].physical_height, 1000);
ck_assert_int_eq(description->minfo[3].orientation, 0);
ck_assert_int_eq(description->minfo[3].desktop_scale_factor, 180);
ck_assert_int_eq(description->minfo[3].device_scale_factor, 100);
ck_assert_int_eq(description->minfo[3].is_primary, 0);
ck_assert_int_eq(description->minfo[4].left, 3841);
ck_assert_int_eq(description->minfo[4].top, 2161);
ck_assert_int_eq(description->minfo[4].right, 7681);
ck_assert_int_eq(description->minfo[4].bottom, 4321);
ck_assert_int_eq(description->minfo[4].physical_width, 1000);
ck_assert_int_eq(description->minfo[4].physical_height, 1000);
ck_assert_int_eq(description->minfo[4].orientation, 0);
ck_assert_int_eq(description->minfo[4].desktop_scale_factor, 100);
ck_assert_int_eq(description->minfo[4].device_scale_factor, 100);
ck_assert_int_eq(description->minfo[4].is_primary, 0);
ck_assert_int_eq(description->minfo[5].left, 7682);
ck_assert_int_eq(description->minfo[5].top, 2161);
ck_assert_int_eq(description->minfo[5].right, 11522);
ck_assert_int_eq(description->minfo[5].bottom, 4321);
ck_assert_int_eq(description->minfo[5].physical_width, 1000);
ck_assert_int_eq(description->minfo[5].physical_height, 1000);
ck_assert_int_eq(description->minfo[5].orientation, 0);
ck_assert_int_eq(description->minfo[5].desktop_scale_factor, 100);
ck_assert_int_eq(description->minfo[5].device_scale_factor, 100);
ck_assert_int_eq(description->minfo[5].is_primary, 0);
/*************************************************
* Verify normalized monitors
*************************************************/
ck_assert_int_eq(description->minfo_wm[0].left, 0);
ck_assert_int_eq(description->minfo_wm[0].top, 0);
ck_assert_int_eq(description->minfo_wm[0].right, 3840);
ck_assert_int_eq(description->minfo_wm[0].bottom, 2160);
ck_assert_int_eq(description->minfo_wm[0].physical_width, 0);
ck_assert_int_eq(description->minfo_wm[0].physical_height, 0);
ck_assert_int_eq(description->minfo_wm[0].orientation, 0);
ck_assert_int_eq(description->minfo_wm[0].desktop_scale_factor, 100);
ck_assert_int_eq(description->minfo_wm[0].device_scale_factor, 100);
ck_assert_int_eq(description->minfo_wm[0].is_primary, 0);
ck_assert_int_eq(description->minfo_wm[1].left, 3841);
ck_assert_int_eq(description->minfo_wm[1].top, 0);
ck_assert_int_eq(description->minfo_wm[1].right, 7681);
ck_assert_int_eq(description->minfo_wm[1].bottom, 2160);
ck_assert_int_eq(description->minfo_wm[1].physical_width, 0);
ck_assert_int_eq(description->minfo_wm[1].physical_height, 0);
ck_assert_int_eq(description->minfo_wm[1].orientation, 0);
ck_assert_int_eq(description->minfo_wm[1].desktop_scale_factor, 100);
ck_assert_int_eq(description->minfo_wm[1].device_scale_factor, 100);
ck_assert_int_eq(description->minfo_wm[1].is_primary, 1);
ck_assert_int_eq(description->minfo_wm[2].left, 7682);
ck_assert_int_eq(description->minfo_wm[2].top, 0);
ck_assert_int_eq(description->minfo_wm[2].right, 11522);
ck_assert_int_eq(description->minfo_wm[2].bottom, 2160);
ck_assert_int_eq(description->minfo_wm[2].physical_width, 1000);
ck_assert_int_eq(description->minfo_wm[2].physical_height, 1000);
ck_assert_int_eq(description->minfo_wm[2].orientation, 0);
ck_assert_int_eq(description->minfo_wm[2].desktop_scale_factor, 100);
ck_assert_int_eq(description->minfo_wm[2].device_scale_factor, 140);
ck_assert_int_eq(description->minfo_wm[2].is_primary, 0);
ck_assert_int_eq(description->minfo_wm[3].left, 0);
ck_assert_int_eq(description->minfo_wm[3].top, 2161);
ck_assert_int_eq(description->minfo_wm[3].right, 3840);
ck_assert_int_eq(description->minfo_wm[3].bottom, 4321);
ck_assert_int_eq(description->minfo_wm[3].physical_width, 1000);
ck_assert_int_eq(description->minfo_wm[3].physical_height, 1000);
ck_assert_int_eq(description->minfo_wm[3].orientation, 0);
ck_assert_int_eq(description->minfo_wm[3].desktop_scale_factor, 180);
ck_assert_int_eq(description->minfo_wm[3].device_scale_factor, 100);
ck_assert_int_eq(description->minfo_wm[3].is_primary, 0);
ck_assert_int_eq(description->minfo_wm[4].left, 3841);
ck_assert_int_eq(description->minfo_wm[4].top, 2161);
ck_assert_int_eq(description->minfo_wm[4].right, 7681);
ck_assert_int_eq(description->minfo_wm[4].bottom, 4321);
ck_assert_int_eq(description->minfo_wm[4].physical_width, 1000);
ck_assert_int_eq(description->minfo_wm[4].physical_height, 1000);
ck_assert_int_eq(description->minfo_wm[4].orientation, 0);
ck_assert_int_eq(description->minfo_wm[4].desktop_scale_factor, 100);
ck_assert_int_eq(description->minfo_wm[4].device_scale_factor, 100);
ck_assert_int_eq(description->minfo_wm[4].is_primary, 0);
ck_assert_int_eq(description->minfo_wm[5].left, 7682);
ck_assert_int_eq(description->minfo_wm[5].top, 2161);
ck_assert_int_eq(description->minfo_wm[5].right, 11522);
ck_assert_int_eq(description->minfo_wm[5].bottom, 4321);
ck_assert_int_eq(description->minfo_wm[5].physical_width, 1000);
ck_assert_int_eq(description->minfo_wm[5].physical_height, 1000);
ck_assert_int_eq(description->minfo_wm[5].orientation, 0);
ck_assert_int_eq(description->minfo_wm[5].desktop_scale_factor, 100);
ck_assert_int_eq(description->minfo_wm[5].device_scale_factor, 100);
ck_assert_int_eq(description->minfo_wm[5].is_primary, 0);
// Verify geometry
ck_assert_int_eq(description->session_width, 11523);
ck_assert_int_eq(description->session_height, 4322);
free(description);
free_stream(s);
}
END_TEST
/******************************************************************************/
Suite *
make_suite_test_monitor_processing(void)
{
Suite *s;
TCase *tc_process_monitors;
s = suite_create("test_libxrdp_process_monitor_stream");
tc_process_monitors = tcase_create("libxrdp_process_monitor_stream");
tcase_add_test(tc_process_monitors, test_libxrdp_process_monitor_stream__when_description_is_null__fail);
tcase_add_test(tc_process_monitors, test_libxrdp_process_monitor_stream__when_stream_is_too_small__fail);
tcase_add_test(tc_process_monitors, test_libxrdp_process_monitor_stream__when_monitor_count_is_greater_than_sixteen__fail);
tcase_add_test(tc_process_monitors, test_libxrdp_process_monitor_stream__with_single_monitor_happy_path);
tcase_add_test(tc_process_monitors, test_libxrdp_process_monitor_stream__with_sextuple_monitor_happy_path);
suite_add_tcase(s, tc_process_monitors);
return s;
}