mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-22 21:58:08 +00:00
feat(tester): add random database file for each core
This commit is contained in:
parent
d59a4d1eec
commit
1d0495f826
4 changed files with 95 additions and 41 deletions
Binary file not shown.
|
|
@ -300,6 +300,7 @@ typedef struct _LinphoneCoreManager {
|
|||
int number_of_bcunit_error_at_creation;
|
||||
char* phone_alias;
|
||||
char *rc_path;
|
||||
char *database_path;
|
||||
} LinphoneCoreManager;
|
||||
|
||||
typedef struct _LinphoneConferenceServer {
|
||||
|
|
|
|||
|
|
@ -17,14 +17,16 @@
|
|||
*/
|
||||
|
||||
#include "address/address.h"
|
||||
#include "core/core.h"
|
||||
#include "core/core-p.h"
|
||||
#include "db/main-db.h"
|
||||
#include "event-log/events.h"
|
||||
|
||||
// TODO: Remove me later.
|
||||
#include "private.h"
|
||||
|
||||
#include "liblinphone_tester.h"
|
||||
#include "tester_utils.h"
|
||||
#include "tools/tester.h"
|
||||
|
||||
// =============================================================================
|
||||
|
||||
|
|
@ -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 {
|
||||
public:
|
||||
MainDbProvider () {
|
||||
mCoreManager = linphone_core_manager_new("marie_rc");
|
||||
mMainDb = new MainDb(mCoreManager->lc->cppPtr->getSharedFromThis());
|
||||
mMainDb->connect(MainDb::Sqlite3, getDatabasePath());
|
||||
mCoreManager = linphone_core_manager_create("marie_rc");
|
||||
linphone_core_manager_start(mCoreManager, false);
|
||||
}
|
||||
|
||||
~MainDbProvider () {
|
||||
delete mMainDb;
|
||||
linphone_core_manager_destroy(mCoreManager);
|
||||
}
|
||||
|
||||
const MainDb &getMainDb () {
|
||||
return *mMainDb;
|
||||
return *L_GET_PRIVATE(mCoreManager->lc->cppPtr)->mainDb;
|
||||
}
|
||||
|
||||
private:
|
||||
LinphoneCoreManager *mCoreManager;
|
||||
MainDb *mMainDb;
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
@ -130,7 +122,7 @@ static void get_history () {
|
|||
ChatRoomId(IdentityAddress("sip:test-1@sip.linphone.org"), IdentityAddress("sip:test-1@sip.linphone.org")),
|
||||
0, -1, MainDb::Filter::ConferenceChatMessageFilter
|
||||
).size(),
|
||||
862,
|
||||
804,
|
||||
int,
|
||||
"%d"
|
||||
);
|
||||
|
|
@ -149,11 +141,11 @@ static void get_conference_notified_events () {
|
|||
MainDbProvider provider;
|
||||
const MainDb &mainDb = provider.getMainDb();
|
||||
list<shared_ptr<EventLog>> events = mainDb.getConferenceNotifiedEvents(
|
||||
ChatRoomId(IdentityAddress("sip:fake-group-2@sip.linphone.org"), IdentityAddress("sip:fake-group-2@sip.linphone.org")),
|
||||
1
|
||||
ChatRoomId(IdentityAddress("sip:test-44@sip.linphone.org"), IdentityAddress("sip:test-1@sip.linphone.org")),
|
||||
-1
|
||||
);
|
||||
BC_ASSERT_EQUAL(events.size(), 3, int, "%d");
|
||||
if (events.size() != 3)
|
||||
BC_ASSERT_EQUAL(events.size(), 5, int, "%d");
|
||||
if (events.size() != 5)
|
||||
return;
|
||||
|
||||
shared_ptr<EventLog> event;
|
||||
|
|
@ -199,7 +191,7 @@ test_t main_db_tests[] = {
|
|||
TEST_NO_TAG("Get messages count", get_messages_count),
|
||||
TEST_NO_TAG("Get unread messages count", get_unread_messages_count),
|
||||
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 = {
|
||||
|
|
|
|||
103
tester/tester.c
103
tester/tester.c
|
|
@ -94,27 +94,25 @@ LinphoneAddress * create_linphone_address(const char * domain) {
|
|||
}
|
||||
|
||||
LinphoneAddress * create_linphone_address_for_algo(const char * domain, const char* username) {
|
||||
LinphoneAddress *addr = linphone_address_new(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 */
|
||||
if(username) linphone_address_set_username(addr,username);
|
||||
else linphone_address_set_username(addr,test_username);
|
||||
if(username) BC_ASSERT_STRING_EQUAL(username,linphone_address_get_username(addr));
|
||||
else BC_ASSERT_STRING_EQUAL(test_username,linphone_address_get_username(addr));
|
||||
if (!domain) domain= test_route;
|
||||
linphone_address_set_domain(addr,domain);
|
||||
BC_ASSERT_STRING_EQUAL(domain,linphone_address_get_domain(addr));
|
||||
linphone_address_set_display_name(addr, NULL);
|
||||
linphone_address_set_display_name(addr, "Mr Tester");
|
||||
BC_ASSERT_STRING_EQUAL("Mr Tester",linphone_address_get_display_name(addr));
|
||||
return addr;
|
||||
LinphoneAddress *addr = linphone_address_new(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 */
|
||||
if(username) linphone_address_set_username(addr,username);
|
||||
else linphone_address_set_username(addr,test_username);
|
||||
if(username) BC_ASSERT_STRING_EQUAL(username,linphone_address_get_username(addr));
|
||||
else BC_ASSERT_STRING_EQUAL(test_username,linphone_address_get_username(addr));
|
||||
if (!domain) domain= test_route;
|
||||
linphone_address_set_domain(addr,domain);
|
||||
BC_ASSERT_STRING_EQUAL(domain,linphone_address_get_domain(addr));
|
||||
linphone_address_set_display_name(addr, NULL);
|
||||
linphone_address_set_display_name(addr, "Mr Tester");
|
||||
BC_ASSERT_STRING_EQUAL("Mr Tester",linphone_address_get_display_name(addr));
|
||||
return addr;
|
||||
}
|
||||
|
||||
static void auth_info_requested(LinphoneCore *lc, const char *realm, const char *username, const char *domain) {
|
||||
stats* counters;
|
||||
ms_message("Auth info requested for user id [%s] at realm [%s]\n"
|
||||
,username
|
||||
,realm);
|
||||
ms_message("Auth info requested for user id [%s] at realm [%s]\n", username, realm);
|
||||
counters = get_stats(lc);
|
||||
counters->number_of_auth_info_requested++;
|
||||
}
|
||||
|
|
@ -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;
|
||||
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);
|
||||
im_notif_policy = linphone_core_get_im_notif_policy(mgr->lc);
|
||||
if (im_notif_policy != NULL) {
|
||||
|
|
@ -344,6 +342,57 @@ void linphone_core_manager_configure (LinphoneCoreManager *mgr) {
|
|||
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)
|
||||
#pragma GCC diagnostic push
|
||||
#endif
|
||||
|
|
@ -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;
|
||||
|
||||
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++;
|
||||
|
||||
|
|
@ -489,8 +544,14 @@ void linphone_core_manager_uninit(LinphoneCoreManager *mgr) {
|
|||
if (mgr->identity) {
|
||||
linphone_address_unref(mgr->identity);
|
||||
}
|
||||
if (mgr->rc_path)
|
||||
if (mgr->rc_path) {
|
||||
unlink(mgr->rc_path);
|
||||
bctbx_free(mgr->rc_path);
|
||||
}
|
||||
if (mgr->database_path) {
|
||||
unlink(mgr->database_path);
|
||||
bctbx_free(mgr->database_path);
|
||||
}
|
||||
|
||||
manager_count--;
|
||||
linphone_core_set_log_level(old_log_level);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue