|
| 1 | +#if defined(HAVE_CONFIG_H) |
| 2 | +#include "config_ac.h" |
| 3 | +#endif |
| 4 | + |
| 5 | +#include "libxrdp.h" |
| 6 | +#include "os_calls.h" |
| 7 | + |
| 8 | +#include "test_libxrdp.h" |
| 9 | + |
| 10 | +START_TEST(test_libxrdp_process_monitor_stream__when_description_is_null__fail) |
| 11 | +{ |
| 12 | + struct stream *s = (struct stream *)NULL; |
| 13 | + make_stream(s); |
| 14 | + init_stream(s, 4); |
| 15 | + |
| 16 | + //Dummy data. |
| 17 | + out_uint32_le(s, 0); |
| 18 | + s_mark_end(s); |
| 19 | + //Reset the read counter of the stream so the processing function handles it properly. |
| 20 | + s->p = s->data; |
| 21 | + |
| 22 | + int error = libxrdp_process_monitor_stream(s, NULL, 1); |
| 23 | + ck_assert_int_eq(error, SEC_PROCESS_MONITORS_ERR); |
| 24 | + |
| 25 | + free_stream(s); |
| 26 | +} |
| 27 | +END_TEST |
| 28 | + |
| 29 | +START_TEST(test_libxrdp_process_monitor_stream__when_stream_is_too_small__fail) |
| 30 | +{ |
| 31 | + struct stream *s = (struct stream *)NULL; |
| 32 | + make_stream(s); |
| 33 | + init_stream(s, 2); |
| 34 | + |
| 35 | + //Dummy data. |
| 36 | + out_uint16_le(s, 0); |
| 37 | + s_mark_end(s); |
| 38 | + //Reset the read counter of the stream so the processing function handles it properly. |
| 39 | + s->p = s->data; |
| 40 | + |
| 41 | + struct display_size_description *description = |
| 42 | + (struct display_size_description *) |
| 43 | + g_malloc(sizeof(struct display_size_description), 1); |
| 44 | + |
| 45 | + int error = libxrdp_process_monitor_stream(s, description, 1); |
| 46 | + ck_assert_int_eq(error, SEC_PROCESS_MONITORS_ERR); |
| 47 | + |
| 48 | + free(description); |
| 49 | + free_stream(s); |
| 50 | +} |
| 51 | +END_TEST |
| 52 | + |
| 53 | +START_TEST(test_libxrdp_process_monitor_stream__when_monitor_count_is_greater_than_sixteen__fail) |
| 54 | +{ |
| 55 | + struct stream *s = (struct stream *)NULL; |
| 56 | + make_stream(s); |
| 57 | + init_stream(s, 4); |
| 58 | + |
| 59 | + //Dummy data. |
| 60 | + out_uint32_le(s, 17); |
| 61 | + s_mark_end(s); |
| 62 | + //Reset the read counter of the stream so the processing function handles it properly. |
| 63 | + s->p = s->data; |
| 64 | + |
| 65 | + struct display_size_description *description = |
| 66 | + (struct display_size_description *) |
| 67 | + g_malloc(sizeof(struct display_size_description), 1); |
| 68 | + |
| 69 | + int error = libxrdp_process_monitor_stream(s, description, 1); |
| 70 | + ck_assert_int_eq(error, SEC_PROCESS_MONITORS_ERR_TOO_MANY_MONITORS); |
| 71 | + |
| 72 | + free(description); |
| 73 | + free_stream(s); |
| 74 | +} |
| 75 | +END_TEST |
| 76 | + |
| 77 | +START_TEST(test_libxrdp_process_monitor_stream__with_single_monitor_happy_path) |
| 78 | +{ |
| 79 | + struct stream *s = (struct stream *)NULL; |
| 80 | + make_stream(s); |
| 81 | + init_stream(s, 44); |
| 82 | + |
| 83 | + out_uint32_le(s, 1); //monitorCount |
| 84 | + |
| 85 | + // Pretend we have a 4k monitor |
| 86 | + out_uint32_le(s, TS_MONITOR_PRIMARY); //flags |
| 87 | + out_uint32_le(s, 0); //monitor left |
| 88 | + out_uint32_le(s, 0); //monitor top |
| 89 | + out_uint32_le(s, 3840); //monitor right |
| 90 | + out_uint32_le(s, 2160); //monitor bottom |
| 91 | + out_uint32_le(s, 2000); //physical width |
| 92 | + out_uint32_le(s, 2000); //physical height |
| 93 | + out_uint32_le(s, 0); //orientation |
| 94 | + out_uint32_le(s, 100); //desktop scale factor |
| 95 | + out_uint32_le(s, 100); //device scale factor |
| 96 | + |
| 97 | + s_mark_end(s); |
| 98 | + //Reset the read counter of the stream so the processing function handles it properly. |
| 99 | + s->p = s->data; |
| 100 | + |
| 101 | + struct display_size_description *description = |
| 102 | + (struct display_size_description *) |
| 103 | + g_malloc(sizeof(struct display_size_description), 1); |
| 104 | + |
| 105 | + int error = libxrdp_process_monitor_stream(s, description, 1); |
| 106 | + |
| 107 | + //Verify function call passed. |
| 108 | + ck_assert_int_eq(error, 0); |
| 109 | + |
| 110 | + ck_assert_int_eq(description->monitorCount, 1); |
| 111 | + |
| 112 | + // Verify normal monitor |
| 113 | + ck_assert_int_eq(description->minfo[0].left, 0); |
| 114 | + ck_assert_int_eq(description->minfo[0].top, 0); |
| 115 | + ck_assert_int_eq(description->minfo[0].right, 3840); |
| 116 | + ck_assert_int_eq(description->minfo[0].bottom, 2160); |
| 117 | + ck_assert_int_eq(description->minfo[0].physical_width, 2000); |
| 118 | + ck_assert_int_eq(description->minfo[0].physical_height, 2000); |
| 119 | + ck_assert_int_eq(description->minfo[0].orientation, 0); |
| 120 | + ck_assert_int_eq(description->minfo[0].desktop_scale_factor, 100); |
| 121 | + ck_assert_int_eq(description->minfo[0].device_scale_factor, 100); |
| 122 | + ck_assert_int_eq(description->minfo[0].is_primary, 1); |
| 123 | + |
| 124 | + // Verify normalized monitor |
| 125 | + ck_assert_int_eq(description->minfo_wm[0].left, 0); |
| 126 | + ck_assert_int_eq(description->minfo_wm[0].top, 0); |
| 127 | + ck_assert_int_eq(description->minfo_wm[0].right, 3840); |
| 128 | + ck_assert_int_eq(description->minfo_wm[0].bottom, 2160); |
| 129 | + ck_assert_int_eq(description->minfo_wm[0].physical_width, 2000); |
| 130 | + ck_assert_int_eq(description->minfo_wm[0].physical_height, 2000); |
| 131 | + ck_assert_int_eq(description->minfo_wm[0].orientation, 0); |
| 132 | + ck_assert_int_eq(description->minfo_wm[0].desktop_scale_factor, 100); |
| 133 | + ck_assert_int_eq(description->minfo_wm[0].device_scale_factor, 100); |
| 134 | + ck_assert_int_eq(description->minfo_wm[0].is_primary, 1); |
| 135 | + |
| 136 | + // Verify geometry (+1 greater than ) |
| 137 | + ck_assert_int_eq(description->session_width, 3841); |
| 138 | + ck_assert_int_eq(description->session_height, 2161); |
| 139 | + |
| 140 | + free(description); |
| 141 | + free_stream(s); |
| 142 | +} |
| 143 | +END_TEST |
| 144 | + |
| 145 | +/******************************************************************************/ |
| 146 | +Suite * |
| 147 | +make_suite_test_monitor_processing(void) |
| 148 | +{ |
| 149 | + Suite *s; |
| 150 | + TCase *tc_process_monitors; |
| 151 | + |
| 152 | + s = suite_create("test_libxrdp_process_monitor_stream"); |
| 153 | + |
| 154 | + tc_process_monitors = tcase_create("libxrdp_process_monitor_stream"); |
| 155 | + tcase_add_test(tc_process_monitors, test_libxrdp_process_monitor_stream__when_description_is_null__fail); |
| 156 | + tcase_add_test(tc_process_monitors, test_libxrdp_process_monitor_stream__when_stream_is_too_small__fail); |
| 157 | + tcase_add_test(tc_process_monitors, test_libxrdp_process_monitor_stream__when_monitor_count_is_greater_than_sixteen__fail); |
| 158 | + tcase_add_test(tc_process_monitors, test_libxrdp_process_monitor_stream__with_single_monitor_happy_path); |
| 159 | + |
| 160 | + suite_add_tcase(s, tc_process_monitors); |
| 161 | + |
| 162 | + return s; |
| 163 | +} |
0 commit comments