main-db-tester.cpp 3.59 KB
Newer Older
1
/*
Ronan's avatar
Ronan committed
2
 * main-db-tester.cpp
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 * 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"
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
	MainDb mainDb;
	BC_ASSERT_TRUE(mainDb.connect(MainDb::Sqlite3, getDatabasePath()));
41 42 43
}

static void get_events_count () {
Ronan's avatar
Ronan committed
44 45 46 47 48 49 50
	MainDb mainDb;
	BC_ASSERT_TRUE(mainDb.connect(MainDb::Sqlite3, getDatabasePath()));
	BC_ASSERT_EQUAL(mainDb.getEventsCount(), 4976, int, "%d");
	BC_ASSERT_EQUAL(mainDb.getEventsCount(MainDb::ConferenceCallFilter), 0, int, "%d");
	BC_ASSERT_EQUAL(mainDb.getEventsCount(MainDb::ConferenceInfoFilter), 0, int, "%d");
	BC_ASSERT_EQUAL(mainDb.getEventsCount(MainDb::ConferenceChatMessageFilter), 4976, int, "%d");
	BC_ASSERT_EQUAL(mainDb.getEventsCount(MainDb::NoFilter), 4976, int, "%d");
51 52 53
}

static void get_messages_count () {
Ronan's avatar
Ronan committed
54 55 56
	MainDb mainDb;
	BC_ASSERT_TRUE(mainDb.connect(MainDb::Sqlite3, getDatabasePath()));
	BC_ASSERT_EQUAL(mainDb.getMessagesCount(), 4976, int, "%d");
57
	BC_ASSERT_EQUAL(mainDb.getMessagesCount("sip:test-39@sip.linphone.org"), 3, int, "%d");
58 59 60
}

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

67
static void get_history () {
Ronan's avatar
Ronan committed
68 69
	MainDb mainDb;
	BC_ASSERT_TRUE(mainDb.connect(MainDb::Sqlite3, getDatabasePath()));
70
	BC_ASSERT_EQUAL(
71
		mainDb.getHistoryRange("sip:test-39@sip.linphone.org", 0, -1, MainDb::Filter::ConferenceChatMessageFilter).size(),
72 73 74 75
		3,
		int,
		"%d"
	);
Ronan's avatar
Ronan committed
76
	BC_ASSERT_EQUAL(
77
		mainDb.getHistoryRange("sip:test-7@sip.linphone.org", 0, -1, MainDb::Filter::ConferenceCallFilter).size(),
Ronan's avatar
Ronan committed
78 79 80 81
		0,
		int,
		"%d"
	);
82 83 84 85 86 87 88 89 90 91 92 93
	BC_ASSERT_EQUAL(
		mainDb.getHistoryRange("sip:test-1@sip.linphone.org", 0, -1, MainDb::Filter::ConferenceChatMessageFilter).size(),
		862,
		int,
		"%d"
	);
	BC_ASSERT_EQUAL(
		mainDb.getHistory("sip:test-1@sip.linphone.org", 100, MainDb::Filter::ConferenceChatMessageFilter).size(),
		100,
		int,
		"%d"
	);
94 95
}

Ronan's avatar
Ronan committed
96
test_t main_db_tests[] = {
97 98 99
	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),
100 101
	TEST_NO_TAG("Get unread messages count", get_unread_messages_count),
	TEST_NO_TAG("Get history", get_history)
102 103
};

Ronan's avatar
Ronan committed
104 105 106
test_suite_t main_db_test_suite = {
	"MainDb", NULL, NULL, liblinphone_tester_before_each, liblinphone_tester_after_each,
	sizeof(main_db_tests) / sizeof(main_db_tests[0]), main_db_tests
107
};