Skip to content

Commit f1ea3b2

Browse files
committed
Adding more unit tests
1 parent 5602cfa commit f1ea3b2

File tree

6 files changed

+188
-22
lines changed

6 files changed

+188
-22
lines changed

libxrdp/libxrdp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1919,12 +1919,13 @@ libxrdp_process_monitor_stream(struct stream *s,
19191919
default:
19201920
LOG(LOG_LEVEL_WARNING, "libxrdp_process_monitor_stream:"
19211921
" Orientation is not one of %d, %d, %d, or %d."
1922-
" Value was %d and ignored.",
1922+
" Value was %d and ignored and set to default value of LANDSCAPE.",
19231923
ORIENTATION_LANDSCAPE,
19241924
ORIENTATION_PORTRAIT,
19251925
ORIENTATION_LANDSCAPE_FLIPPED,
19261926
ORIENTATION_PORTRAIT_FLIPPED,
19271927
monitor_layout->orientation);
1928+
monitor_layout->orientation = ORIENTATION_LANDSCAPE;
19281929
}
19291930

19301931
in_uint32_le(s, monitor_layout->desktop_scale_factor);

tests/libxrdp/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ check_PROGRAMS = test_libxrdp
1414
test_libxrdp_SOURCES = \
1515
test_libxrdp.h \
1616
test_libxrdp_main.c \
17-
test_monitor_processing.c
17+
test_libxrdp_process_monitor_stream.c \
18+
test_xrdp_sec_process_mcs_data_monitors.c
1819

1920
test_libxrdp_CFLAGS = \
2021
@CHECK_CFLAGS@

tests/libxrdp/test_libxrdp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <check.h>
55

6+
Suite *make_suite_test_xrdp_sec_process_mcs_data_monitors(void);
67
Suite *make_suite_test_monitor_processing(void);
78

89
#endif /* TEST_LIBXRDP_H */

tests/libxrdp/test_libxrdp_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ int main (void)
1111
int number_failed;
1212
SRunner *sr;
1313

14-
sr = srunner_create (make_suite_test_monitor_processing());
15-
// srunner_add_suite(sr, make_list_suite());
14+
sr = srunner_create(make_suite_test_xrdp_sec_process_mcs_data_monitors());
15+
srunner_add_suite(sr, make_suite_test_monitor_processing());
1616

1717
srunner_set_tap(sr, "-");
1818
srunner_run_all (sr, CK_ENV);
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
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+
}

tests/libxrdp/test_monitor_processing.c renamed to tests/libxrdp/test_xrdp_sec_process_mcs_data_monitors.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void teardown(void)
2929
g_free(rdp_layer);
3030
}
3131

32-
START_TEST(test_process_monitors__when_flags_is_not_zero__fail)
32+
START_TEST(test_xrdp_sec_process_mcs_data_monitors__when_flags_is_not_zero__fail)
3333
{
3434
struct stream *s = (struct stream *)NULL;
3535
make_stream(s);
@@ -48,7 +48,7 @@ START_TEST(test_process_monitors__when_flags_is_not_zero__fail)
4848
}
4949
END_TEST
5050

51-
START_TEST(test_process_monitors__when_mounter_count_is_greater_than_sixteen__fail)
51+
START_TEST(test_xrdp_sec_process_mcs_data_monitors__when_monitor_count_is_greater_than_sixteen__fail)
5252
{
5353
struct stream *s = (struct stream *)NULL;
5454
make_stream(s);
@@ -67,7 +67,7 @@ START_TEST(test_process_monitors__when_mounter_count_is_greater_than_sixteen__fa
6767
}
6868
END_TEST
6969

70-
START_TEST(test_process_monitors__with_single_monitor_happy_path)
70+
START_TEST(test_xrdp_sec_process_mcs_data_monitors__with_single_monitor_happy_path)
7171
{
7272
struct xrdp_client_info *client_info = &(rdp_layer->client_info);
7373
struct stream *s = (struct stream *)NULL;
@@ -116,7 +116,7 @@ START_TEST(test_process_monitors__with_single_monitor_happy_path)
116116
}
117117
END_TEST
118118

119-
START_TEST(test_process_monitors__when_no_primary_monitor_is_specified_one_is_selected)
119+
START_TEST(test_xrdp_sec_process_mcs_data_monitors__when_no_primary_monitor_is_specified_one_is_selected)
120120
{
121121
struct xrdp_client_info *client_info = &(rdp_layer->client_info);
122122
struct stream *s = (struct stream *)NULL;
@@ -165,7 +165,7 @@ START_TEST(test_process_monitors__when_no_primary_monitor_is_specified_one_is_se
165165
}
166166
END_TEST
167167

168-
START_TEST(test_process_monitors__when_virtual_desktop_width_is_too_large)
168+
START_TEST(test_xrdp_sec_process_mcs_data_monitors__when_virtual_desktop_width_is_too_large)
169169
{
170170
struct stream *s = (struct stream *)NULL;
171171
make_stream(s);
@@ -193,7 +193,7 @@ START_TEST(test_process_monitors__when_virtual_desktop_width_is_too_large)
193193
}
194194
END_TEST
195195

196-
START_TEST(test_process_monitors__when_virtual_desktop_width_is_too_small)
196+
START_TEST(test_xrdp_sec_process_mcs_data_monitors__when_virtual_desktop_width_is_too_small)
197197
{
198198
struct stream *s = (struct stream *)NULL;
199199
make_stream(s);
@@ -221,7 +221,7 @@ START_TEST(test_process_monitors__when_virtual_desktop_width_is_too_small)
221221
}
222222
END_TEST
223223

224-
START_TEST(test_process_monitors__when_virtual_desktop_height_is_too_large)
224+
START_TEST(test_xrdp_sec_process_mcs_data_monitors__when_virtual_desktop_height_is_too_large)
225225
{
226226
struct stream *s = (struct stream *)NULL;
227227
make_stream(s);
@@ -249,7 +249,7 @@ START_TEST(test_process_monitors__when_virtual_desktop_height_is_too_large)
249249
}
250250
END_TEST
251251

252-
START_TEST(test_process_monitors__when_virtual_desktop_height_is_too_small)
252+
START_TEST(test_xrdp_sec_process_mcs_data_monitors__when_virtual_desktop_height_is_too_small)
253253
{
254254
struct stream *s = (struct stream *)NULL;
255255
make_stream(s);
@@ -279,23 +279,23 @@ END_TEST
279279

280280
/******************************************************************************/
281281
Suite *
282-
make_suite_test_monitor_processing(void)
282+
make_suite_test_xrdp_sec_process_mcs_data_monitors(void)
283283
{
284284
Suite *s;
285285
TCase *tc_process_monitors;
286286

287-
s = suite_create("Monitor_Processing");
287+
s = suite_create("test_xrdp_sec_process_mcs_data_monitors");
288288

289289
tc_process_monitors = tcase_create("xrdp_sec_process_mcs_data_monitors");
290290
tcase_add_checked_fixture(tc_process_monitors, setup, teardown);
291-
tcase_add_test(tc_process_monitors, test_process_monitors__when_flags_is_not_zero__fail);
292-
tcase_add_test(tc_process_monitors, test_process_monitors__when_mounter_count_is_greater_than_sixteen__fail);
293-
tcase_add_test(tc_process_monitors, test_process_monitors__with_single_monitor_happy_path);
294-
tcase_add_test(tc_process_monitors, test_process_monitors__when_no_primary_monitor_is_specified_one_is_selected);
295-
tcase_add_test(tc_process_monitors, test_process_monitors__when_virtual_desktop_width_is_too_large);
296-
tcase_add_test(tc_process_monitors, test_process_monitors__when_virtual_desktop_width_is_too_small);
297-
tcase_add_test(tc_process_monitors, test_process_monitors__when_virtual_desktop_height_is_too_large);
298-
tcase_add_test(tc_process_monitors, test_process_monitors__when_virtual_desktop_height_is_too_small);
291+
tcase_add_test(tc_process_monitors, test_xrdp_sec_process_mcs_data_monitors__when_flags_is_not_zero__fail);
292+
tcase_add_test(tc_process_monitors, test_xrdp_sec_process_mcs_data_monitors__when_monitor_count_is_greater_than_sixteen__fail);
293+
tcase_add_test(tc_process_monitors, test_xrdp_sec_process_mcs_data_monitors__with_single_monitor_happy_path);
294+
tcase_add_test(tc_process_monitors, test_xrdp_sec_process_mcs_data_monitors__when_no_primary_monitor_is_specified_one_is_selected);
295+
tcase_add_test(tc_process_monitors, test_xrdp_sec_process_mcs_data_monitors__when_virtual_desktop_width_is_too_large);
296+
tcase_add_test(tc_process_monitors, test_xrdp_sec_process_mcs_data_monitors__when_virtual_desktop_width_is_too_small);
297+
tcase_add_test(tc_process_monitors, test_xrdp_sec_process_mcs_data_monitors__when_virtual_desktop_height_is_too_large);
298+
tcase_add_test(tc_process_monitors, test_xrdp_sec_process_mcs_data_monitors__when_virtual_desktop_height_is_too_small);
299299

300300
suite_add_tcase(s, tc_process_monitors);
301301

0 commit comments

Comments
 (0)