Initial commit - from Precise source
[freerdp-ubuntu-pcb-backport.git] / cunit / test_ber.c
1 /**
2  * FreeRDP: A Remote Desktop Protocol Client
3  * Basic Encoding Rules (BER) Unit Tests
4  *
5  * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 #include <freerdp/freerdp.h>
21 #include <freerdp/utils/hexdump.h>
22 #include <freerdp/utils/stream.h>
23
24 #include "test_ber.h"
25 #include "libfreerdp-core/ber.h"
26
27 int init_ber_suite(void)
28 {
29         return 0;
30 }
31
32 int clean_ber_suite(void)
33 {
34         return 0;
35 }
36
37 int add_ber_suite(void)
38 {
39         add_test_suite(ber);
40
41         add_test_function(ber_write_length);
42         add_test_function(ber_write_universal_tag);
43         add_test_function(ber_write_application_tag);
44
45         return 0;
46 }
47
48 uint8 ber_length_expected_1[1] = "\x40"; /* 64 */
49 uint8 ber_length_expected_2[3] = "\x82\x01\x94"; /* 404 */
50
51 void test_ber_write_length(void)
52 {
53         STREAM *s1, *s2;
54
55         s1 = stream_new(sizeof(ber_length_expected_1));
56         s2 = stream_new(sizeof(ber_length_expected_2));
57
58         ber_write_length(s1, 64);
59         ASSERT_STREAM(s1, (uint8*) ber_length_expected_1, sizeof(ber_length_expected_1));
60
61         ber_write_length(s2, 404);
62         ASSERT_STREAM(s2, (uint8*) ber_length_expected_2, sizeof(ber_length_expected_2));
63
64         stream_free(s1);
65         stream_free(s2);
66 }
67
68 /* BOOLEAN, length 1, without value */
69 uint8 ber_universal_tag_expected[1] = "\x01";
70
71 void test_ber_write_universal_tag(void)
72 {
73         STREAM* s;
74
75         s = stream_new(sizeof(ber_universal_tag_expected));
76         ber_write_universal_tag(s, 1, false);
77
78         ASSERT_STREAM(s, (uint8*) ber_universal_tag_expected, sizeof(ber_universal_tag_expected));
79
80         stream_free(s);
81 }
82
83 /* T.125 MCS Application 101 (Connect-Initial), length 404 */
84 uint8 ber_application_tag_expected[5] = "\x7F\x65\x82\x01\x94";
85
86 void test_ber_write_application_tag(void)
87 {
88         STREAM* s;
89
90         s = stream_new(sizeof(ber_application_tag_expected));
91         ber_write_application_tag(s, 101, 404);
92
93         ASSERT_STREAM(s, (uint8*) ber_application_tag_expected, sizeof(ber_application_tag_expected));
94
95         stream_free(s);
96 }