tester: fix resource directory detection and compilation

parent f6f5e00c
......@@ -185,7 +185,7 @@ static void _belle_sip_object_uninit(belle_sip_object_t *obj){
}
static void _belle_sip_object_clone(belle_sip_object_t *obj, const belle_sip_object_t *orig){
if (orig->name!=NULL) obj->name=belle_sip_strdup(obj->name);
if (orig->name!=NULL) obj->name=belle_sip_strdup(orig->name);
}
static belle_sip_error_code _belle_object_marshal(belle_sip_object_t* obj, char* buff, size_t buff_size, size_t *offset) {
......
......@@ -112,6 +112,19 @@ void belle_sip_tester_uninit(void) {
bc_tester_uninit();
}
void belle_sip_tester_before_each() {
belle_sip_object_enable_leak_detector(TRUE);
leaked_objects_count = belle_sip_object_get_object_count();
}
void belle_sip_tester_after_each() {
int leaked_objects = belle_sip_object_get_object_count() - leaked_objects_count;
BC_ASSERT_EQUAL(leaked_objects, 0, int, "%d");
if (leaked_objects > 0) {
belle_sip_object_dump_active_objects();
belle_sip_error("%d objects were leaked in latest test, please fix that!\n", leaked_objects);
}
}
#if !defined(ANDROID) && !defined(TARGET_OS_IPHONE) && !(defined(BELLE_SIP_WINDOWS_PHONE) || defined(BELLE_SIP_WINDOWS_UNIVERSAL))
......@@ -190,18 +203,4 @@ int main (int argc, char *argv[]) {
return ret;
}
void belle_sip_tester_before_each() {
belle_sip_object_enable_leak_detector(TRUE);
leaked_objects_count = belle_sip_object_get_object_count();
}
void belle_sip_tester_after_each() {
int leaked_objects = belle_sip_object_get_object_count() - leaked_objects_count;
BC_ASSERT_EQUAL(leaked_objects, 0, int, "%d");
if (leaked_objects > 0) {
belle_sip_object_dump_active_objects();
belle_sip_error("%d objects were leaked in latest test, please fix that!\n", leaked_objects);
}
}
#endif
......@@ -39,17 +39,16 @@ extern test_suite_t dialog_test_suite;
extern test_suite_t refresher_test_suite;
extern test_suite_t http_test_suite;
extern int belle_sip_tester_ipv6_available(void);
extern const char * belle_sip_tester_get_root_ca_path(void);
extern void belle_sip_tester_set_root_ca_path(const char *root_ca_path);
extern void belle_sip_tester_init(void(*ftester_printf)(int level, const char *fmt, va_list args));
extern void belle_sip_tester_uninit(void);
extern const char* belle_sip_tester_client_cert;
extern const char* belle_sip_tester_client_cert_fingerprint;
extern const char* belle_sip_tester_private_key;
extern const char* belle_sip_tester_private_key_passwd;
int belle_sip_tester_ipv6_available(void);
const char * belle_sip_tester_get_root_ca_path(void);
void belle_sip_tester_set_root_ca_path(const char *root_ca_path);
void belle_sip_tester_init(void(*ftester_printf)(int level, const char *fmt, va_list args));
void belle_sip_tester_uninit(void);
void belle_sip_tester_before_each();
void belle_sip_tester_after_each();
......
......@@ -331,12 +331,12 @@ static int file_exists(const char* root_path) {
int found;
FILE* file;
char * sounds_path = malloc(sizeof(char)*(strlen(root_path)+strlen("sounds")+1));
sprintf(sounds_path, "%ssounds", root_path);
file = fopen(sounds_path, "r");
char * res_path = malloc(sizeof(char)*(strlen(root_path)+strlen("/common/bc_completion")+1));
sprintf(res_path, "%s/common/bc_completion", root_path);
file = fopen(res_path, "r");
found = (file != NULL);
if (file) fclose(file);
free(sounds_path);
free(res_path);
return found;
}
......@@ -356,17 +356,20 @@ static void detect_res_prefix(const char* prog) {
bc_tester_set_writable_dir_prefix("./tmp");
#endif
if (strchr(prog, '/') != NULL) {
progpath[strrchr(prog, '/') - prog + 1] = '\0';
} else if (strchr(prog, '\\') != NULL) {
progpath[strrchr(prog, '\\') - prog + 1] = '\0';
if (prog != NULL) {
progpath = strdup(prog);
if (strchr(prog, '/') != NULL) {
progpath[strrchr(prog, '/') - prog + 1] = '\0';
} else if (strchr(prog, '\\') != NULL) {
progpath[strrchr(prog, '\\') - prog + 1] = '\0';
}
}
if (file_exists(".")) {
prefix = strdup(".");
} else if (file_exists("..")) {
prefix = strdup("..");
} else if (file_exists(progpath)) {
} else if (progpath && file_exists(progpath)) {
prefix = strdup(progpath);
}
......@@ -381,6 +384,7 @@ static void detect_res_prefix(const char* prog) {
}
free(prefix);
} else if (bc_tester_resource_dir_prefix == NULL || bc_tester_writable_dir_prefix == NULL) {
printf("Failed to detect resources for %s.\n", prog);
printf("Could not find resource directory in %s! Please try again using option --resource-dir and/or --writable-dir.\n", progpath);
abort();
}
......
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