property-container-tester.cpp 2.13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * property-container-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 "object/property-container.h"

#include "liblinphone_tester.h"
Benjamin REIS's avatar
Benjamin REIS committed
22
#include "tester_utils.h"
23 24 25 26 27 28 29

// =============================================================================

using namespace std;

using namespace LinphonePrivate;

30
static void set_int_property () {
31 32 33 34 35
	PropertyContainer properties;
	properties.setProperty("integer", 42);
	BC_ASSERT_EQUAL(properties.getProperty("integer").getValue<int>(), 42, int, "%d");
}

36 37 38 39 40 41 42 43 44 45 46
static void set_string_property () {
	PropertyContainer properties;
	const string text = "Hey listen!";
	properties.setProperty("string", text);

	{
		string textToCheck = properties.getProperty("string").getValue<string>();
		BC_ASSERT_STRING_EQUAL(textToCheck.c_str(), text.c_str());
	}
}

47 48 49 50 51 52
static void set_generic_property () {
	PropertyContainer properties;
	properties.setProperty("generic", reinterpret_cast<void *>(0x42));
	BC_ASSERT_EQUAL(properties.getProperty("generic").getValue<void *>(), reinterpret_cast<void *>(0x42), void *, "%p");
}

53
test_t property_container_tests[] = {
54
	TEST_NO_TAG("Set int property", set_int_property),
55
	TEST_NO_TAG("Set string property", set_string_property),
56
	TEST_NO_TAG("Set generic property", set_generic_property)
57 58 59 60 61 62
};

test_suite_t property_container_test_suite = {
	"PropertyContainer", NULL, NULL, liblinphone_tester_before_each, liblinphone_tester_after_each,
	sizeof(property_container_tests) / sizeof(property_container_tests[0]), property_container_tests
};