Commit b83fe641 authored by Ronan's avatar Ronan

feat(EventsDb): fixes + add new test

parent 7dab187b
......@@ -18,6 +18,7 @@
#include "abstract-db-p.h"
#include "db/provider/db-session-provider.h"
#include "logger/logger.h"
#include "abstract-db.h"
......@@ -32,12 +33,22 @@ AbstractDb::AbstractDb (AbstractDbPrivate &p) : Object(*new AbstractDbPrivate) {
bool AbstractDb::connect (Backend backend, const string &parameters) {
L_D(AbstractDb);
d->backend = backend;
d->dbSession = DbSessionProvider::getInstance()->getSession(
(backend == Mysql ? "mysql://" : "sqlite3://") + parameters
);
if (d->dbSession)
init();
if (d->dbSession) {
try {
init();
} catch (const exception &e) {
lWarning() << "Unable to init database: " << e.what();
// Reset session.
d->dbSession = DbSession();
}
}
return d->dbSession;
}
......
......@@ -140,7 +140,7 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {}
*session <<
"CREATE TABLE IF NOT EXISTS event_type ("
" id" + primaryKeyAutoIncrementStr("TINYINT") + ","
" id TINYINT UNSIGNED,"
" value VARCHAR(255) NOT NULL"
")";
......@@ -156,14 +156,14 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {}
*session <<
"CREATE TABLE IF NOT EXISTS message_state ("
" id" + primaryKeyAutoIncrementStr("TINYINT") + ","
" state VARCHAR(255) NOT NULL"
" id TINYINT UNSIGNED,"
" value VARCHAR(255) NOT NULL"
")";
*session <<
"CREATE TABLE IF NOT EXISTS message_direction ("
" id" + primaryKeyAutoIncrementStr("TINYINT") + ","
" direction VARCHAR(255) NOT NULL"
" id TINYINT UNSIGNED,"
" value VARCHAR(255) NOT NULL"
")";
*session <<
......@@ -188,9 +188,9 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {}
" state_id TINYINT UNSIGNED NOT NULL,"
" direction_id TINYINT UNSIGNED NOT NULL,"
" imdn_message_id VARCHAR(255) NOT NULL," // See: https://tools.ietf.org/html/rfc5438#section-6.3
" content_type VARCHAR(255) NOT NULL,"
" content_type VARCHAR(255) NOT NULL," // Content type of text. (Html or text for example.)
" is_secured BOOLEAN NOT NULL,"
" app_data VARCHAR(2048),"
" app_data VARCHAR(2048)," // App user data.
" FOREIGN KEY (dialog_id)"
" REFERENCES dialog(id)"
" ON DELETE CASCADE,"
......
......@@ -76,6 +76,11 @@ set(CERTIFICATE_CLIENT_FILES
set(CERTIFICATE_FILES ${CERTIFICATE_ALT_FILES} ${CERTIFICATE_CN_FILES} ${CERTIFICATE_CLIENT_FILES})
set(DB_FILES
db/linphone.db
db/messages.db
)
set(RC_FILES
rcfiles/account_creator_rc
rcfiles/assistant_create.rc
......@@ -146,11 +151,11 @@ set(VCARD_FILES
set(OTHER_FILES
tester_hosts
local_tester_hosts
messages.db
)
set(IOS_RESOURCES_FILES
${OTHER_FILES}
${DB_FILES}
certificates
images
rcfiles
......@@ -195,6 +200,7 @@ set(SOURCE_FILES_C
set(SOURCE_FILES_CXX
clonable-object-tester.cpp
cpim-tester.cpp
events-db-tester.cpp
)
set(SOURCE_FILES_OBJC )
......@@ -308,14 +314,15 @@ if (NOT ANDROID AND NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
install(FILES ${OTHER_FILES} DESTINATION "${CMAKE_INSTALL_DATADIR}/liblinphone_tester")
install(FILES ${SOUND_FILES} DESTINATION "${CMAKE_INSTALL_DATADIR}/liblinphone_tester/sounds")
install(FILES ${SIPP_FILES} DESTINATION "${CMAKE_INSTALL_DATADIR}/liblinphone_tester/sipp")
install(FILES ${CERTIFICATE_ALT_FILES} DESTINATION "${CMAKE_INSTALL_DATADIR}/liblinphone_tester/certificates/altname")
install(FILES ${CERTIFICATE_CN_FILES} DESTINATION "${CMAKE_INSTALL_DATADIR}/liblinphone_tester/certificates/cn")
install(FILES ${CERTIFICATE_CLIENT_FILES} DESTINATION "${CMAKE_INSTALL_DATADIR}/liblinphone_tester/certificates/client")
install(FILES ${RC_FILES} DESTINATION "${CMAKE_INSTALL_DATADIR}/liblinphone_tester/rcfiles")
install(FILES ${CERTIFICATE_CN_FILES} DESTINATION "${CMAKE_INSTALL_DATADIR}/liblinphone_tester/certificates/cn")
install(FILES ${DB_FILES} DESTINATION "${CMAKE_INSTALL_DATADIR}/liblinphone_tester/db")
install(FILES ${IMAGE_FILES} DESTINATION "${CMAKE_INSTALL_DATADIR}/liblinphone_tester/images")
install(FILES ${OTHER_FILES} DESTINATION "${CMAKE_INSTALL_DATADIR}/liblinphone_tester")
install(FILES ${RC_FILES} DESTINATION "${CMAKE_INSTALL_DATADIR}/liblinphone_tester/rcfiles")
install(FILES ${SIPP_FILES} DESTINATION "${CMAKE_INSTALL_DATADIR}/liblinphone_tester/sipp")
install(FILES ${SOUND_FILES} DESTINATION "${CMAKE_INSTALL_DATADIR}/liblinphone_tester/sounds")
install(FILES ${VCARD_FILES} DESTINATION "${CMAKE_INSTALL_DATADIR}/liblinphone_tester/vcards")
endif()
endif()
/*
* 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/>.
*/
#include "db/events-db.h"
#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 () {
EventsDb eventsDb;
eventsDb.connect(EventsDb::Sqlite3, getDatabasePath());
}
test_t events_db_tests[] = {
TEST_NO_TAG("Open database", open_database)
};
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
};
......@@ -46,6 +46,7 @@ extern test_suite_t clonable_object_test_suite;
extern test_suite_t cpim_test_suite;
extern test_suite_t dtmf_test_suite;
extern test_suite_t event_test_suite;
extern test_suite_t events_db_test_suite;
extern test_suite_t flexisip_test_suite;
extern test_suite_t log_collection_test_suite;
extern test_suite_t message_test_suite;
......
......@@ -575,6 +575,7 @@ void liblinphone_tester_add_suites() {
bc_tester_add_suite(&dtmf_test_suite);
bc_tester_add_suite(&cpim_test_suite);
bc_tester_add_suite(&clonable_object_test_suite);
bc_tester_add_suite(&events_db_test_suite);
#if defined(VIDEO_ENABLED) && defined(HAVE_GTK)
bc_tester_add_suite(&video_test_suite);
#endif
......
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