conference-tester.cpp 4.45 KB
Newer Older
Benjamin REIS's avatar
Benjamin REIS committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*
 * conference-event-tester.cpp
 * Copyright (C) 2017  Belledonne Communications SARL
 *
 * 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/>.
 */

#include "linphone/core.h"
#include "private.h"
#include "liblinphone_tester.h"
#include "conference/local-conference.h"
#include "conference/remote-conference.h"

using namespace LinphonePrivate;
using namespace std;

28
static const string firstInvite = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
Benjamin REIS's avatar
Benjamin REIS committed
29 30 31
"<resource-lists xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:ietf:params:xml:ns:resource-lists\">"
"<list>"
" <entry uri=\"sip:alice@sip.linphone.org\"/>"
32
" <entry uri=\"sip:bob@sip.linphone.org\"><display-name>Le Bricoleur</display-name></entry>"
Benjamin REIS's avatar
Benjamin REIS committed
33 34
" <entry uri=\"sip:john-doe@sip.linphone.org\"/>"
" <entry uri=\"sip:anne-onyme@sip.linphone.org\"/>"
35
" <entry uri=\"sip:sarah-bache@sip.linphone.org\"><display-name>Sarah</display-name></entry>"
Benjamin REIS's avatar
Benjamin REIS committed
36 37 38
"</list>"
"</resource-lists>";

39 40 41 42 43
static const string aliceAddr = "sip:alice@sip.linphone.org";
static const string bobAddr = "sip:bob@sip.linphone.org";
static const string johnAddr = "sip:john-doe@sip.linphone.org";
static const string anneAddr = "sip:anne-onyme@sip.linphone.org";
static const string sarahAddr = "sip:sarah-bache@sip.linphone.org";
Benjamin REIS's avatar
Benjamin REIS committed
44

45 46
static const string bobName = "Le Bricoleur";
static const string sarahName = "Sarah";
Benjamin REIS's avatar
Benjamin REIS committed
47

48 49 50
static void check_first_invite(LinphoneCore *core, const Address &address, string invite) {
	LocalConference localConf(core, address);
	list<Address> addresses = localConf.parseResourceLists(invite);
Benjamin REIS's avatar
Benjamin REIS committed
51
	BC_ASSERT_EQUAL(addresses.size(), 5, int, "%d");
52
	if (addresses.size() != 5)
53
		return;
54
	BC_ASSERT_TRUE(addresses.front().asStringUriOnly() == aliceAddr);
55
	BC_ASSERT_TRUE(addresses.front().getDisplayName().empty());
Benjamin REIS's avatar
Benjamin REIS committed
56 57
	addresses.pop_front();

58 59
	BC_ASSERT_TRUE(addresses.front().asStringUriOnly() == bobAddr);
	BC_ASSERT_TRUE(addresses.front().getDisplayName() == bobName);
Benjamin REIS's avatar
Benjamin REIS committed
60 61
	addresses.pop_front();

62
	BC_ASSERT_TRUE(addresses.front().asStringUriOnly() == johnAddr);
63
	BC_ASSERT_TRUE(addresses.front().getDisplayName().empty());
Benjamin REIS's avatar
Benjamin REIS committed
64 65
	addresses.pop_front();

66
	BC_ASSERT_TRUE(addresses.front().asStringUriOnly() == anneAddr);
67
	BC_ASSERT_TRUE(addresses.front().getDisplayName().empty());
Benjamin REIS's avatar
Benjamin REIS committed
68 69
	addresses.pop_front();

70 71
	BC_ASSERT_TRUE(addresses.front().asStringUriOnly() == sarahAddr);
	BC_ASSERT_TRUE(addresses.front().getDisplayName() == sarahName);
Benjamin REIS's avatar
Benjamin REIS committed
72
	addresses.pop_front();
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
}

void first_invite_parsing () {
	LinphoneCoreManager *marie = linphone_core_manager_new("marie_rc");
	const Address marieIdentity(linphone_address_as_string_uri_only(marie->identity));
	check_first_invite(marie->lc, marieIdentity, firstInvite);
	linphone_core_manager_destroy(marie);
}

void first_invite_serializing() {
	LinphoneCoreManager *marie = linphone_core_manager_new("marie_rc");
	const Address marieIdentity(linphone_address_as_string_uri_only(marie->identity));
	RemoteConference remoteConf(marie->lc, marieIdentity);
	list<Address> addresses = list<Address>();
	string xmlBody;

	Address aliceIdentity(aliceAddr);
	Address bobIdentity(bobAddr);
	Address johnIdentity(johnAddr);
	Address anneIdentity(anneAddr);
	Address sarahIdentity(sarahAddr);

	bobIdentity.setDisplayName(bobName);
	sarahIdentity.setDisplayName(sarahName);

	addresses.push_back(aliceIdentity);
	addresses.push_back(bobIdentity);
	addresses.push_back(johnIdentity);
	addresses.push_back(anneIdentity);
	addresses.push_back(sarahIdentity);

	xmlBody = remoteConf.getResourceLists(addresses);
	check_first_invite(marie->lc, marieIdentity, xmlBody);
Benjamin REIS's avatar
Benjamin REIS committed
106 107 108 109
	linphone_core_manager_destroy(marie);
}

test_t conference_tests[] = {
110 111
	TEST_NO_TAG("First invite parsing", first_invite_parsing),
	TEST_NO_TAG("First invite serializing", first_invite_serializing)
Benjamin REIS's avatar
Benjamin REIS committed
112 113 114 115 116 117 118 119 120 121
};

test_suite_t conference_test_suite = {
	"Conference",
	nullptr,
	nullptr,
	liblinphone_tester_before_each,
	liblinphone_tester_after_each,
	sizeof(conference_tests) / sizeof(conference_tests[0]), conference_tests
};