belle_generic_uri_tester.c 6.11 KB
Newer Older
1
/*
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 * Copyright (c) 2012-2019 Belledonne Communications SARL.
 *
 * This file is part of belle-sip.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
19 20 21 22 23

#include "belle-sip/belle-sip.h"
#include "belle_sip_tester.h"


24
static void test_basic_uri(void) {
25 26 27 28 29 30 31 32
	belle_generic_uri_t* source_uri = belle_generic_uri_parse("http://www.linphone.org/index.html");
	char* source_uri_raw = belle_sip_object_to_string(source_uri);
	belle_generic_uri_t* first_uri = belle_generic_uri_parse(source_uri_raw);
	belle_generic_uri_t* uri=BELLE_GENERIC_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(first_uri)));
	belle_sip_free(source_uri_raw);
	belle_sip_object_unref(source_uri);
	belle_sip_object_unref(first_uri);

33 34 35
	BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_scheme(uri),"http");
	BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_host(uri),"www.linphone.org");
	BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_path(uri),"/index.html");
36 37 38

	belle_sip_object_unref(uri);

39
	source_uri = belle_generic_uri_parse("http://www.linphone.org/");
40
	BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_path(source_uri),"/");
41 42 43
	belle_sip_object_unref(source_uri);

	source_uri = belle_generic_uri_parse("http://www.linphone.org/a/b/c");
44 45
	BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_path(source_uri),"/a/b/c");
	BC_ASSERT_STRING_EQUAL("http://www.linphone.org/a/b/c",source_uri_raw = belle_sip_object_to_string(source_uri));
46 47
	belle_sip_free(source_uri_raw);
	belle_sip_object_unref(source_uri);
48
}
49

50
static void test_complex_uri(void) {
51 52 53 54 55 56 57 58 59

	belle_generic_uri_t* source_uri = belle_generic_uri_parse("ftp://toto:secret@ftp.linphone.fr:1234/url?sa=t&rct=j&url=http%3A%2F%2Ftranslate.google.fr");
	char* source_uri_raw = belle_generic_uri_to_string(source_uri);
	belle_generic_uri_t* first_uri = belle_generic_uri_parse(source_uri_raw);
	belle_generic_uri_t* uri=BELLE_GENERIC_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(first_uri)));
	belle_sip_free(source_uri_raw);
	belle_sip_object_unref(source_uri);
	belle_sip_object_unref(first_uri);

60 61 62 63 64 65 66 67
	BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_scheme(uri),"ftp");
	BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_host(uri),"ftp.linphone.fr");
	BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_user(uri),"toto");
	BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_user_password(uri),"secret");
	BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_host(uri),"ftp.linphone.fr");
	BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_path(uri),"/url");
	BC_ASSERT_EQUAL(belle_generic_uri_get_port(uri),1234,int,"%d");
	BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_query(uri),"sa=t&rct=j&url=http://translate.google.fr");
68 69 70 71

	belle_sip_object_unref(uri);
}

72
static void test_file_path(void) {
jehan's avatar
jehan committed
73 74 75 76 77 78 79 80
	belle_generic_uri_t* source_uri = belle_generic_uri_parse("/index.html");
	char* source_uri_raw = belle_sip_object_to_string(source_uri);
	belle_generic_uri_t* first_uri = belle_generic_uri_parse(source_uri_raw);
	belle_generic_uri_t* uri=BELLE_GENERIC_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(first_uri)));
	belle_sip_free(source_uri_raw);
	belle_sip_object_unref(source_uri);
	belle_sip_object_unref(first_uri);

81 82 83
	BC_ASSERT_PTR_NULL(belle_generic_uri_get_scheme(uri));
	BC_ASSERT_PTR_NULL(belle_generic_uri_get_host(uri));
	BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_path(uri),"/index.html");
jehan's avatar
jehan committed
84

85 86 87
	belle_sip_object_unref(uri);

	source_uri = belle_generic_uri_parse("file:///tmp/absolute-file");
88
	BC_ASSERT_PTR_NOT_NULL(source_uri);
89
	if (source_uri!=NULL){
90 91 92
		BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_scheme(source_uri),"file");
		BC_ASSERT_PTR_NULL(belle_generic_uri_get_host(source_uri));
		BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_path(source_uri),"/tmp/absolute-file");
93 94
		belle_sip_object_unref(source_uri);
	}
95

96 97
	/*this is INVALID*/
	source_uri = belle_generic_uri_parse("file://./relative-file");
98
	BC_ASSERT_PTR_NOT_NULL(source_uri);
Simon Morlat's avatar
Simon Morlat committed
99
	if (source_uri) belle_sip_object_unref(source_uri);
100

101
	/* PATH segment always start by / */
102
	source_uri = belle_generic_uri_parse("./relative-file");
103
	BC_ASSERT_PTR_NULL(source_uri);
104 105 106
	if (source_uri!=NULL){
		belle_sip_object_unref(source_uri);
	}
jehan's avatar
jehan committed
107
}
108
static void test_absolute_uri(void) {
109

110 111 112 113 114 115 116 117
	belle_generic_uri_t* source_uri = belle_generic_uri_parse("tel:+33123457");
	char* source_uri_raw = belle_generic_uri_to_string(source_uri);
	belle_generic_uri_t* first_uri = belle_generic_uri_parse(source_uri_raw);
	belle_generic_uri_t* uri=BELLE_GENERIC_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(first_uri)));
	belle_sip_free(source_uri_raw);
	belle_sip_object_unref(source_uri);
	belle_sip_object_unref(first_uri);

118 119
	BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_scheme(uri),"tel");
	BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_opaque_part(uri),"+33123457");
120 121 122 123 124 125 126 127 128 129
	belle_sip_object_unref(uri);

	source_uri = belle_generic_uri_parse("tel:11234567888;phone-context=vzims.com");
	source_uri_raw = belle_generic_uri_to_string(source_uri);
	first_uri = belle_generic_uri_parse(source_uri_raw);
	uri=BELLE_GENERIC_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(first_uri)));
	belle_sip_free(source_uri_raw);
	belle_sip_object_unref(source_uri);
	belle_sip_object_unref(first_uri);

130 131
	BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_scheme(uri),"tel");
	BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_opaque_part(uri),"11234567888;phone-context=vzims.com");
132 133 134
	belle_sip_object_unref(uri);

}
135 136

static test_t tests[] = {
137 138 139 140
	TEST_NO_TAG("Simple uri", test_basic_uri),
	TEST_NO_TAG("Complex uri", test_complex_uri),
	TEST_NO_TAG("File path", test_file_path),
	TEST_NO_TAG("Absolute uri", test_absolute_uri)
141 142
};

143 144
test_suite_t generic_uri_test_suite = {"Generic uri", NULL, NULL, belle_sip_tester_before_each,
									   belle_sip_tester_after_each, sizeof(tests) / sizeof(tests[0]), tests};