Commit babe09e5 authored by Ghislain MARY's avatar Ghislain MARY
Browse files

Add tester for migration of messages database + load chat rooms from DB after...

Add tester for migration of messages database + load chat rooms from DB after migration + fix duplicated sip addresses in database during migration.
parent f99300cb
......@@ -6709,11 +6709,13 @@ int linphone_core_get_video_dscp(const LinphoneCore *lc){
void linphone_core_set_chat_database_path (LinphoneCore *lc, const char *path) {
if (!linphone_core_conference_server_enabled(lc)) {
auto &mainDb = L_GET_PRIVATE(lc->cppPtr)->mainDb;
if (mainDb)
auto &mainDb = L_GET_PRIVATE_FROM_C_OBJECT(lc)->mainDb;
if (mainDb) {
mainDb->import(LinphonePrivate::MainDb::Sqlite3, path);
else
L_GET_PRIVATE_FROM_C_OBJECT(lc)->loadChatRooms();
} else {
ms_warning("linphone_core_set_chat_database_path() needs to be called once linphone_core_start() has been called");
}
}
}
......
......@@ -118,6 +118,11 @@ void CorePrivate::insertChatRoomWithDb (const shared_ptr<AbstractChatRoom> &chat
mainDb->insertChatRoom(chatRoom);
}
void CorePrivate::loadChatRooms () {
for (auto &chatRoom : mainDb->getChatRooms())
insertChatRoom(chatRoom);
}
void CorePrivate::replaceChatRoom (const shared_ptr<AbstractChatRoom> &replacedChatRoom, const shared_ptr<AbstractChatRoom> &newChatRoom) {
const ChatRoomId &replacedChatRoomId = replacedChatRoom->getChatRoomId();
const ChatRoomId &newChatRoomId = newChatRoom->getChatRoomId();
......
......@@ -57,6 +57,7 @@ public:
void postConfigureAudioStream (AudioStream *stream, bool muted);
void setPlaybackGainDb (AudioStream *stream, float gain);
void loadChatRooms ();
void insertChatRoom (const std::shared_ptr<AbstractChatRoom> &chatRoom);
void insertChatRoomWithDb (const std::shared_ptr<AbstractChatRoom> &chatRoom);
std::shared_ptr<AbstractChatRoom> createBasicChatRoom (const ChatRoomId &chatRoomId, AbstractChatRoom::CapabilitiesMask capabilities);
......
......@@ -57,8 +57,7 @@ void CorePrivate::init () {
if (!mainDb->connect(backend, uri))
lFatal() << "Unable to open linphone database.";
for (auto &chatRoom : mainDb->getChatRooms())
insertChatRoom(chatRoom);
loadChatRooms();
}
void CorePrivate::registerListener (CoreListener *listener) {
......
......@@ -1423,8 +1423,12 @@ void MainDbPrivate::importLegacyHistory (DbSession &inDbSession) {
soci::use(eventType), soci::use(creationTime);
const long long &eventId = dbSession.getLastInsertId();
const long long &localSipAddressId = insertSipAddress(message.get<string>(LegacyMessageColLocalAddress));
const long long &remoteSipAddressId = insertSipAddress(message.get<string>(LegacyMessageColRemoteAddress));
const long long &localSipAddressId = insertSipAddress(
IdentityAddress(message.get<string>(LegacyMessageColLocalAddress)).asString()
);
const long long &remoteSipAddressId = insertSipAddress(
IdentityAddress(message.get<string>(LegacyMessageColRemoteAddress)).asString()
);
const long long &chatRoomId = insertOrUpdateImportedBasicChatRoom(
remoteSipAddressId,
localSipAddressId,
......
No preview for this file type
......@@ -1467,7 +1467,7 @@ static void lime_unit(void) {
* Destination file is truncated if existing.
* Return 0 on success, positive value on error.
*/
int message_tester_copy_file(const char *from, const char *to)
static int message_tester_copy_file(const char *from, const char *to)
{
FILE *in, *out;
char buf[256];
......@@ -2309,7 +2309,7 @@ static void message_received_callback(LinphoneCore *lc, LinphoneChatRoom *room,
}
BC_ASSERT_EQUAL(0, linphone_chat_room_get_unread_messages_count(room), int, "%d");
}
void unread_message_count_callback(void) {
LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc");
LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc");
......@@ -2328,6 +2328,26 @@ void unread_message_count_callback(void) {
linphone_core_manager_destroy(pauline);
}
static void migration_from_messages_db (void) {
LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc");
char *src_db = bc_tester_res("db/messages.db");
char *tmp_db = bc_tester_file("tmp.db");
BC_ASSERT_EQUAL(message_tester_copy_file(src_db, tmp_db), 0, int, "%d");
// The messages.db has 10000 dummy messages with the very first DB scheme.
// This will test the migration procedure
linphone_core_set_chat_database_path(marie->lc, tmp_db);
const bctbx_list_t *chatrooms = linphone_core_get_chat_rooms(marie->lc);
BC_ASSERT(bctbx_list_size(chatrooms) > 0);
linphone_core_manager_destroy(marie);
remove(tmp_db);
bctbx_free(src_db);
bctbx_free(tmp_db);
}
test_t message_tests[] = {
TEST_NO_TAG("Text message", text_message),
TEST_NO_TAG("Text message with credentials from auth callback", text_message_with_credential_from_auth_callback),
......@@ -2404,6 +2424,7 @@ test_t message_tests[] = {
TEST_NO_TAG("Crash during file transfer", crash_during_file_transfer),
TEST_NO_TAG("Text status after destroying chat room", text_status_after_destroying_chat_room),
TEST_NO_TAG("Transfer io error after destroying chatroom", file_transfer_io_error_after_destroying_chatroom),
TEST_NO_TAG("Migration from messages db", migration_from_messages_db)
};
static int message_tester_before_suite(void) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment