belle_generic_uri_tester.c 6.13 KB
Newer Older
1 2 3 4 5 6
/*
	belle-sip - SIP (RFC3261) library.
    Copyright (C) 2013  Belledonne Communications SARL, Grenoble, France

    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
7
    the Free Software Foundation, either version 2 of the License, or
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
    (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/>.
*/

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


23
static void test_basic_uri(void) {
24 25 26 27 28 29 30 31
	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);

32 33 34
	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");
35 36 37

	belle_sip_object_unref(uri);

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

	source_uri = belle_generic_uri_parse("http://www.linphone.org/a/b/c");
43 44
	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));
45 46
	belle_sip_free(source_uri_raw);
	belle_sip_object_unref(source_uri);
47
}
48

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

	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);

59 60 61 62 63 64 65 66
	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");
67 68 69 70

	belle_sip_object_unref(uri);
}

71
static void test_file_path(void) {
jehan's avatar
jehan committed
72 73 74 75 76 77 78 79
	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);

80 81 82
	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
83

84 85 86
	belle_sip_object_unref(uri);

	source_uri = belle_generic_uri_parse("file:///tmp/absolute-file");
87
	BC_ASSERT_PTR_NOT_NULL(source_uri);
88
	if (source_uri!=NULL){
89 90 91
		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");
92 93
		belle_sip_object_unref(source_uri);
	}
94

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

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

109 110 111 112 113 114 115 116
	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);

117 118
	BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_scheme(uri),"tel");
	BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_opaque_part(uri),"+33123457");
119 120 121 122 123 124 125 126 127 128
	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);

129 130
	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");
131 132 133
	belle_sip_object_unref(uri);

}
134 135

static test_t tests[] = {
136 137 138 139
	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)
140 141
};

142 143
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};