Commit a8e42a55 authored by Ghislain MARY's avatar Ghislain MARY

Handle dynamic writable directory for tester + Set correct writable directory for Windows 10.

parent 2f795533
......@@ -90,7 +90,7 @@ static void test_generate_and_parse_certificates(void) {
belle_sip_signing_key_t *key, *parsed_key;
char *pem_certificate, *pem_parsed_certificate, *pem_key, *pem_parsed_key;
int ret = 0;
char *belle_sip_certificate_temporary_dir = belle_sip_strdup_printf("%s%s", bc_tester_writable_dir_prefix, TEMPORARY_CERTIFICATE_DIR);
char *belle_sip_certificate_temporary_dir = bc_tester_file(TEMPORARY_CERTIFICATE_DIR);
/* create 2 certificates in the temporary certificate directory (TODO : set the directory in a absolute path?? where?)*/
ret = belle_sip_generate_self_signed_certificate(belle_sip_certificate_temporary_dir, "test_certificate1", &certificate, &key);
......@@ -100,7 +100,7 @@ static void test_generate_and_parse_certificates(void) {
/* parse directory to get the certificate2 */
ret = belle_sip_get_certificate_and_pkey_in_dir(belle_sip_certificate_temporary_dir, "test_certificate2", &parsed_certificate, &parsed_key, BELLE_SIP_CERTIFICATE_RAW_FORMAT_PEM);
belle_sip_free(belle_sip_certificate_temporary_dir);
free(belle_sip_certificate_temporary_dir);
BC_ASSERT_EQUAL_FATAL(0, ret, int, "%d");
/* get pem version of generated and parsed certificate and compare them */
......
......@@ -36,12 +36,6 @@
#define SRV_DOMAIN "linphone.org"
#define SIP_PORT 5060
#if __QNX__
#define WRITE_FILE_PATH "./tmp/"
#else
#define WRITE_FILE_PATH
#endif
typedef struct endpoint {
belle_sip_stack_t* stack;
belle_sip_resolver_context_t *resolver_ctx;
......@@ -436,7 +430,8 @@ static void no_query_needed(void) {
}
static void set_custom_resolv_conf(belle_sip_stack_t *stack, const char *ns[3]){
FILE *f=fopen(WRITE_FILE_PATH "tmp_resolv.conf","w");
char *resolv_file = bc_tester_file("tmp_resolv.conf");
FILE *f=fopen(resolv_file,"w");
BC_ASSERT_PTR_NOT_NULL(f);
if (f){
int i;
......@@ -447,7 +442,8 @@ static void set_custom_resolv_conf(belle_sip_stack_t *stack, const char *ns[3]){
}
fclose(f);
}
belle_sip_stack_set_dns_resolv_conf_file(stack,WRITE_FILE_PATH "tmp_resolv.conf");
belle_sip_stack_set_dns_resolv_conf_file(stack, resolv_file);
free(resolv_file);
}
static void dns_fallback(void) {
......
......@@ -4,9 +4,11 @@
using namespace belle_sip_tester_runtime_component;
using namespace Platform;
using namespace Windows::Storage;
#define MAX_TRACE_SIZE 512
#define MAX_SUITE_NAME_SIZE 128
#define MAX_WRITABLE_DIR_SIZE 1024
static OutputTraceListener^ sTraceListener;
static belle_sip_object_pool_t *pool;
......@@ -32,7 +34,13 @@ static void belleSipNativeOutputTraceHandler(belle_sip_log_level lev, const char
BelleSipTester::BelleSipTester()
{
char writable_dir[MAX_WRITABLE_DIR_SIZE];
StorageFolder ^folder = ApplicationData::Current->LocalFolder;
const wchar_t *wwritable_dir = folder->Path->Data();
wcstombs(writable_dir, wwritable_dir, sizeof(writable_dir));
belle_sip_tester_init(nativeOutputTraceHandler);
bc_tester_set_resource_dir_prefix("Assets");
bc_tester_set_writable_dir_prefix(writable_dir);
belle_sip_set_log_handler(belleSipNativeOutputTraceHandler);
}
......
......@@ -27,20 +27,25 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "CUnit/Basic.h"
#include "CUnit/Automated.h"
#if defined(BELLE_SIP_WINDOWS_PHONE) || defined(BELLE_SIP_WINDOWS_UNIVERSAL)
const char *bc_tester_read_dir_prefix="Assets";
#elif defined(__QNX__)
const char *bc_tester_read_dir_prefix="./app/native/assets/";
#else
const char *bc_tester_read_dir_prefix=".";
#ifdef _WIN32
#if defined(__MINGW32__) || !defined(WINAPI_FAMILY_PARTITION) || !defined(WINAPI_PARTITION_DESKTOP)
#define BC_TESTER_WINDOWS_DESKTOP 1
#elif defined(WINAPI_FAMILY_PARTITION)
#if defined(WINAPI_PARTITION_DESKTOP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
#define BC_TESTER_WINDOWS_DESKTOP 1
#endif
/* TODO: have the same "static" for QNX and windows as above? */
#ifdef ANDROID
const char *bc_tester_writable_dir_prefix = "/data/data/org.linphone.tester/cache";
#else
const char *bc_tester_writable_dir_prefix = ".";
#if defined(WINAPI_PARTITION_PHONE_APP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)
#define BC_TESTER_WINDOWS_PHONE 1
#endif
#if defined(WINAPI_PARTITION_APP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
#define BC_TESTER_WINDOWS_UNIVERSAL 1
#endif
#endif
#endif
static char *bc_tester_resource_dir_prefix = NULL;
static char *bc_tester_writable_dir_prefix = NULL;
int bc_printf_verbosity_info;
int bc_printf_verbosity_error;
......@@ -272,6 +277,22 @@ void bc_tester_helper(const char *name, const char* additionnal_helper) {
}
void bc_tester_init(void (*ftester_printf)(int level, const char *fmt, va_list args), int iverbosity_info, int iverbosity_error) {
#if defined(BC_TESTER_WINDOWS_PHONE) || defined(BC_TESTER_WINDOWS_UNIVERSAL)
bc_tester_set_resource_dir_prefix("Assets");
#elif defined(__QNX__)
bc_tester_set_resource_dir_prefix("./app/native/assets/");
#else
bc_tester_set_resource_dir_prefix(".");
#endif
#ifdef ANDROID
bc_tester_set_writable_dir_prefix("/data/data/org.linphone.tester/cache");
#elif defined(__QNX__)
bc_tester_set_writable_dir_prefix("./tmp");
#else
bc_tester_set_writable_dir_prefix(".");
#endif
tester_printf_va = ftester_printf;
bc_printf_verbosity_error = iverbosity_error;
bc_printf_verbosity_info = iverbosity_info;
......@@ -364,14 +385,56 @@ void bc_tester_uninit() {
test_suite = NULL;
nb_test_suites = 0;
}
if (bc_tester_resource_dir_prefix != NULL) {
free(bc_tester_resource_dir_prefix);
bc_tester_resource_dir_prefix = NULL;
}
if (bc_tester_writable_dir_prefix != NULL) {
free(bc_tester_writable_dir_prefix);
bc_tester_writable_dir_prefix = NULL;
}
}
char * bc_tester_res(const char *name) {
static bc_tester_set_dir_prefix(char **prefix, const char *name) {
size_t len = strlen(name);
if (*prefix != NULL) free(*prefix);
*prefix = malloc(len + 1);
strncpy(*prefix, name, len);
(*prefix)[len] = '\0';
}
const char * bc_tester_get_resource_dir_prefix(void) {
return bc_tester_resource_dir_prefix;
}
void bc_tester_set_resource_dir_prefix(const char *name) {
bc_tester_set_dir_prefix(&bc_tester_resource_dir_prefix, name);
}
const char * bc_tester_get_writable_dir_prefix(void) {
return bc_tester_writable_dir_prefix;
}
void bc_tester_set_writable_dir_prefix(const char *name) {
bc_tester_set_dir_prefix(&bc_tester_writable_dir_prefix, name);
}
static char * bc_tester_path(const char *prefix, const char *name) {
char* file = NULL;
if (name) {
size_t len = strlen(bc_tester_read_dir_prefix) + 1 + strlen(name) + 1;
size_t len = strlen(prefix) + 1 + strlen(name) + 1;
file = malloc(len);
snprintf(file, len, "%s/%s", bc_tester_read_dir_prefix, name);
snprintf(file, len, "%s/%s", prefix, name);
file[strlen(file)] = '\0';
}
return file;
}
char * bc_tester_res(const char *name) {
return bc_tester_path(bc_tester_resource_dir_prefix, name);
}
char * bc_tester_file(const char *name) {
return bc_tester_path(bc_tester_writable_dir_prefix, name);
}
......@@ -29,9 +29,6 @@
#define snprintf _snprintf
#endif
extern const char *bc_tester_read_dir_prefix;
extern const char *bc_tester_writable_dir_prefix;
extern int bc_printf_verbosity_info;
extern int bc_printf_verbosity_error;
......@@ -72,6 +69,10 @@ int bc_tester_start();
void bc_tester_add_suite(test_suite_t *suite);
void bc_tester_uninit();
void bc_tester_printf(int level, const char *fmt, ...);
const char * bc_tester_get_resource_dir_prefix(void);
void bc_tester_set_resource_dir_prefix(const char *name);
const char * bc_tester_get_writable_dir_prefix(void);
void bc_tester_set_writable_dir_prefix(const char *name);
int bc_tester_nb_suites();
int bc_tester_nb_tests(const char* name);
......@@ -87,11 +88,19 @@ int bc_tester_suite_index(const char *suite_name);
/**
* Get full path to the given resource
*
* @param name relative resource path (relative to bc_tester_writable_dir_prefix)
* @param name relative resource path
* @return path to the resource. Must be freed by caller.
*/
char * bc_tester_res(const char *name);
/**
* Get full path to the given writable_file
*
* @param name relative writable file path
* @return path to the writable file. Must be freed by caller.
*/
char * bc_tester_file(const char *name);
/*Redefine the CU_... macros WITHOUT final ';' semicolon, to allow IF conditions and with smarter error message */
extern int CU_assertImplementation(int bValue,
......
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