Commit 1d0495f8 authored by Ronan's avatar Ronan
Browse files

feat(tester): add random database file for each core

parent d59a4d1e
No preview for this file type
...@@ -300,6 +300,7 @@ typedef struct _LinphoneCoreManager { ...@@ -300,6 +300,7 @@ typedef struct _LinphoneCoreManager {
int number_of_bcunit_error_at_creation; int number_of_bcunit_error_at_creation;
char* phone_alias; char* phone_alias;
char *rc_path; char *rc_path;
char *database_path;
} LinphoneCoreManager; } LinphoneCoreManager;
typedef struct _LinphoneConferenceServer { typedef struct _LinphoneConferenceServer {
......
...@@ -17,14 +17,16 @@ ...@@ -17,14 +17,16 @@
*/ */
#include "address/address.h" #include "address/address.h"
#include "core/core.h" #include "core/core-p.h"
#include "db/main-db.h" #include "db/main-db.h"
#include "event-log/events.h" #include "event-log/events.h"
// TODO: Remove me later.
#include "private.h" #include "private.h"
#include "liblinphone_tester.h" #include "liblinphone_tester.h"
#include "tester_utils.h" #include "tester_utils.h"
#include "tools/tester.h"
// ============================================================================= // =============================================================================
...@@ -34,33 +36,23 @@ using namespace LinphonePrivate; ...@@ -34,33 +36,23 @@ using namespace LinphonePrivate;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
static const string getDatabasePath () {
static const string path = string(bc_tester_get_resource_dir_prefix()) + "db/linphone.db";
return path;
}
// -----------------------------------------------------------------------------
class MainDbProvider { class MainDbProvider {
public: public:
MainDbProvider () { MainDbProvider () {
mCoreManager = linphone_core_manager_new("marie_rc"); mCoreManager = linphone_core_manager_create("marie_rc");
mMainDb = new MainDb(mCoreManager->lc->cppPtr->getSharedFromThis()); linphone_core_manager_start(mCoreManager, false);
mMainDb->connect(MainDb::Sqlite3, getDatabasePath());
} }
~MainDbProvider () { ~MainDbProvider () {
delete mMainDb;
linphone_core_manager_destroy(mCoreManager); linphone_core_manager_destroy(mCoreManager);
} }
const MainDb &getMainDb () { const MainDb &getMainDb () {
return *mMainDb; return *L_GET_PRIVATE(mCoreManager->lc->cppPtr)->mainDb;
} }
private: private:
LinphoneCoreManager *mCoreManager; LinphoneCoreManager *mCoreManager;
MainDb *mMainDb;
}; };
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -130,7 +122,7 @@ static void get_history () { ...@@ -130,7 +122,7 @@ static void get_history () {
ChatRoomId(IdentityAddress("sip:test-1@sip.linphone.org"), IdentityAddress("sip:test-1@sip.linphone.org")), ChatRoomId(IdentityAddress("sip:test-1@sip.linphone.org"), IdentityAddress("sip:test-1@sip.linphone.org")),
0, -1, MainDb::Filter::ConferenceChatMessageFilter 0, -1, MainDb::Filter::ConferenceChatMessageFilter
).size(), ).size(),
862, 804,
int, int,
"%d" "%d"
); );
...@@ -149,11 +141,11 @@ static void get_conference_notified_events () { ...@@ -149,11 +141,11 @@ static void get_conference_notified_events () {
MainDbProvider provider; MainDbProvider provider;
const MainDb &mainDb = provider.getMainDb(); const MainDb &mainDb = provider.getMainDb();
list<shared_ptr<EventLog>> events = mainDb.getConferenceNotifiedEvents( list<shared_ptr<EventLog>> events = mainDb.getConferenceNotifiedEvents(
ChatRoomId(IdentityAddress("sip:fake-group-2@sip.linphone.org"), IdentityAddress("sip:fake-group-2@sip.linphone.org")), ChatRoomId(IdentityAddress("sip:test-44@sip.linphone.org"), IdentityAddress("sip:test-1@sip.linphone.org")),
1 -1
); );
BC_ASSERT_EQUAL(events.size(), 3, int, "%d"); BC_ASSERT_EQUAL(events.size(), 5, int, "%d");
if (events.size() != 3) if (events.size() != 5)
return; return;
shared_ptr<EventLog> event; shared_ptr<EventLog> event;
...@@ -199,7 +191,7 @@ test_t main_db_tests[] = { ...@@ -199,7 +191,7 @@ test_t main_db_tests[] = {
TEST_NO_TAG("Get messages count", get_messages_count), TEST_NO_TAG("Get messages count", get_messages_count),
TEST_NO_TAG("Get unread messages count", get_unread_messages_count), TEST_NO_TAG("Get unread messages count", get_unread_messages_count),
TEST_NO_TAG("Get history", get_history), TEST_NO_TAG("Get history", get_history),
TEST_NO_TAG("Get conference events", get_conference_notified_events) TEST_NO_TAG("Get conference notified events", get_conference_notified_events)
}; };
test_suite_t main_db_test_suite = { test_suite_t main_db_test_suite = {
......
...@@ -94,27 +94,25 @@ LinphoneAddress * create_linphone_address(const char * domain) { ...@@ -94,27 +94,25 @@ LinphoneAddress * create_linphone_address(const char * domain) {
} }
LinphoneAddress * create_linphone_address_for_algo(const char * domain, const char* username) { LinphoneAddress * create_linphone_address_for_algo(const char * domain, const char* username) {
LinphoneAddress *addr = linphone_address_new(NULL); LinphoneAddress *addr = linphone_address_new(NULL);
if (!BC_ASSERT_PTR_NOT_NULL(addr)) return NULL; if (!BC_ASSERT_PTR_NOT_NULL(addr)) return NULL;
/* For clients who support different algorithms, their usernames must be differnet for having diffrent forms of password */ /* For clients who support different algorithms, their usernames must be differnet for having diffrent forms of password */
if(username) linphone_address_set_username(addr,username); if(username) linphone_address_set_username(addr,username);
else linphone_address_set_username(addr,test_username); else linphone_address_set_username(addr,test_username);
if(username) BC_ASSERT_STRING_EQUAL(username,linphone_address_get_username(addr)); if(username) BC_ASSERT_STRING_EQUAL(username,linphone_address_get_username(addr));
else BC_ASSERT_STRING_EQUAL(test_username,linphone_address_get_username(addr)); else BC_ASSERT_STRING_EQUAL(test_username,linphone_address_get_username(addr));
if (!domain) domain= test_route; if (!domain) domain= test_route;
linphone_address_set_domain(addr,domain); linphone_address_set_domain(addr,domain);
BC_ASSERT_STRING_EQUAL(domain,linphone_address_get_domain(addr)); BC_ASSERT_STRING_EQUAL(domain,linphone_address_get_domain(addr));
linphone_address_set_display_name(addr, NULL); linphone_address_set_display_name(addr, NULL);
linphone_address_set_display_name(addr, "Mr Tester"); linphone_address_set_display_name(addr, "Mr Tester");
BC_ASSERT_STRING_EQUAL("Mr Tester",linphone_address_get_display_name(addr)); BC_ASSERT_STRING_EQUAL("Mr Tester",linphone_address_get_display_name(addr));
return addr; return addr;
} }
static void auth_info_requested(LinphoneCore *lc, const char *realm, const char *username, const char *domain) { static void auth_info_requested(LinphoneCore *lc, const char *realm, const char *username, const char *domain) {
stats* counters; stats* counters;
ms_message("Auth info requested for user id [%s] at realm [%s]\n" ms_message("Auth info requested for user id [%s] at realm [%s]\n", username, realm);
,username
,realm);
counters = get_stats(lc); counters = get_stats(lc);
counters->number_of_auth_info_requested++; counters->number_of_auth_info_requested++;
} }
...@@ -290,11 +288,11 @@ bool_t transport_supported(LinphoneTransportType transport) { ...@@ -290,11 +288,11 @@ bool_t transport_supported(LinphoneTransportType transport) {
} }
} }
void linphone_core_manager_configure (LinphoneCoreManager *mgr) { static void linphone_core_manager_configure (LinphoneCoreManager *mgr) {
LinphoneImNotifPolicy *im_notif_policy; LinphoneImNotifPolicy *im_notif_policy;
char *hellopath = bc_tester_res("sounds/hello8000.wav"); char *hellopath = bc_tester_res("sounds/hello8000.wav");
mgr->lc=configure_lc_from(&mgr->v_table, bc_tester_get_resource_dir_prefix(), mgr->rc_path, mgr); mgr->lc=configure_lc_from(&mgr->v_table, NULL, mgr->rc_path, mgr);
linphone_core_manager_check_accounts(mgr); linphone_core_manager_check_accounts(mgr);
im_notif_policy = linphone_core_get_im_notif_policy(mgr->lc); im_notif_policy = linphone_core_get_im_notif_policy(mgr->lc);
if (im_notif_policy != NULL) { if (im_notif_policy != NULL) {
...@@ -344,6 +342,57 @@ void linphone_core_manager_configure (LinphoneCoreManager *mgr) { ...@@ -344,6 +342,57 @@ void linphone_core_manager_configure (LinphoneCoreManager *mgr) {
linphone_core_enable_send_call_stats_periodical_updates(mgr->lc, TRUE); linphone_core_enable_send_call_stats_periodical_updates(mgr->lc, TRUE);
} }
// TODO: Remove me later. When C++ will be available in this (bullshit) file... :'(
static int copy_file (const char *from, const char *to) {
FILE *in, *out;
char buf[255];
size_t n;
in = fopen(from, "rb");
if (!in) {
bctbx_error("Can't open %s for reading: %s\n", from, strerror(errno));
return 1;
}
out = fopen(to, "wb");
if (!out) {
bctbx_error("Can't open %s for writing: %s\n", to, strerror(errno));
fclose(in);
return 1;
}
while ((n = fread(buf, sizeof buf[0], sizeof buf, in)) > 0)
if (!fwrite(buf, 1, n, out)) {
bctbx_error("Could not write in %s: %s\n", to, strerror(errno));
fclose(in);
fclose(out);
return 1;
}
fclose(in);
fclose(out);
return 0;
}
static void configure_random_database_path (LinphoneCoreManager *mgr) {
LinphoneConfig *config = linphone_config_new(mgr->rc_path);
if (!config)
bctbx_fatal("Unable to open linphone config from: %s", mgr->rc_path);
char random_id[32];
belle_sip_random_token(random_id, sizeof random_id);
char *database_path_format = bctbx_strdup_printf("linphone_%s.db", random_id);
mgr->database_path = bc_tester_file(database_path_format);
linphone_config_set_string(config, "storage", "backend", "sqlite3");
linphone_config_set_string(config, "storage", "uri", mgr->database_path);
linphone_config_sync(config);
linphone_config_unref(config);
bctbx_free(database_path_format);
}
#if __clang__ || ((__GNUC__ == 4 && __GNUC_MINOR__ >= 6) || __GNUC__ > 4) #if __clang__ || ((__GNUC__ == 4 && __GNUC_MINOR__ >= 6) || __GNUC__ > 4)
#pragma GCC diagnostic push #pragma GCC diagnostic push
#endif #endif
...@@ -377,7 +426,13 @@ void linphone_core_manager_init(LinphoneCoreManager *mgr, const char* rc_file, c ...@@ -377,7 +426,13 @@ void linphone_core_manager_init(LinphoneCoreManager *mgr, const char* rc_file, c
mgr->phone_alias = phone_alias ? ms_strdup(phone_alias) : NULL; mgr->phone_alias = phone_alias ? ms_strdup(phone_alias) : NULL;
reset_counters(&mgr->stat); reset_counters(&mgr->stat);
if (rc_file) mgr->rc_path = ms_strdup_printf("rcfiles/%s", rc_file); if (rc_file) {
char *src = bctbx_strdup_printf("%s/rcfiles/%s", bc_tester_get_resource_dir_prefix(), rc_file);
mgr->rc_path = bc_tester_file("rc_file");
copy_file(src, mgr->rc_path);
bctbx_free(src);
configure_random_database_path(mgr);
}
manager_count++; manager_count++;
...@@ -489,8 +544,14 @@ void linphone_core_manager_uninit(LinphoneCoreManager *mgr) { ...@@ -489,8 +544,14 @@ void linphone_core_manager_uninit(LinphoneCoreManager *mgr) {
if (mgr->identity) { if (mgr->identity) {
linphone_address_unref(mgr->identity); linphone_address_unref(mgr->identity);
} }
if (mgr->rc_path) if (mgr->rc_path) {
unlink(mgr->rc_path);
bctbx_free(mgr->rc_path); bctbx_free(mgr->rc_path);
}
if (mgr->database_path) {
unlink(mgr->database_path);
bctbx_free(mgr->database_path);
}
manager_count--; manager_count--;
linphone_core_set_log_level(old_log_level); linphone_core_set_log_level(old_log_level);
......
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