events-db-tester.cpp 2.85 KB
Newer Older
Ronan's avatar
Ronan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * events-db-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/>.
 */

19
#include "db/main-db.h"
Ronan's avatar
Ronan committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

#include "liblinphone_tester.h"

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

using namespace std;

using namespace LinphonePrivate;

// -----------------------------------------------------------------------------

static const string getDatabasePath () {
	static const string path = string(bc_tester_get_resource_dir_prefix()) + "/db/linphone.db";
	return path;
}

// -----------------------------------------------------------------------------

static void open_database () {
Ronan's avatar
Ronan committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
	MainDb eventsDb;
	BC_ASSERT_TRUE(eventsDb.connect(MainDb::Sqlite3, getDatabasePath()));
}

static void get_events_count () {
	MainDb eventsDb;
	BC_ASSERT_TRUE(eventsDb.connect(MainDb::Sqlite3, getDatabasePath()));
	BC_ASSERT_EQUAL(eventsDb.getEventsCount(), 4976, int, "%d");
	BC_ASSERT_EQUAL(eventsDb.getEventsCount(MainDb::CallFilter), 0, int, "%d");
	BC_ASSERT_EQUAL(eventsDb.getEventsCount(MainDb::ConferenceFilter), 0, int, "%d");
	BC_ASSERT_EQUAL(eventsDb.getEventsCount(MainDb::MessageFilter), 4976, int, "%d");
	BC_ASSERT_EQUAL(eventsDb.getEventsCount(MainDb::NoFilter), 4976, int, "%d");
}

static void get_messages_count () {
	MainDb eventsDb;
	BC_ASSERT_TRUE(eventsDb.connect(MainDb::Sqlite3, getDatabasePath()));
	BC_ASSERT_EQUAL(eventsDb.getMessagesCount(), 4976, int, "%d");
	BC_ASSERT_EQUAL(eventsDb.getMessagesCount("sip:test-7@sip.linphone.org"), 3, int, "%d");
}

static void get_unread_messages_count () {
	MainDb eventsDb;
	BC_ASSERT_TRUE(eventsDb.connect(MainDb::Sqlite3, getDatabasePath()));
	BC_ASSERT_EQUAL(eventsDb.getUnreadMessagesCount(), 2, int, "%d");
	BC_ASSERT_EQUAL(eventsDb.getUnreadMessagesCount("sip:test-7@sip.linphone.org"), 0, int, "%d");
Ronan's avatar
Ronan committed
65 66 67
}

test_t events_db_tests[] = {
Ronan's avatar
Ronan committed
68 69 70 71
	TEST_NO_TAG("Open database", open_database),
	TEST_NO_TAG("Get events count", get_events_count),
	TEST_NO_TAG("Get messages count", get_messages_count),
	TEST_NO_TAG("Get unread messages count", get_unread_messages_count)
Ronan's avatar
Ronan committed
72 73 74 75 76 77
};

test_suite_t events_db_test_suite = {
	"EventsDb", NULL, NULL, liblinphone_tester_before_each, liblinphone_tester_after_each,
	sizeof(events_db_tests) / sizeof(events_db_tests[0]), events_db_tests
};