Commit 6aec329b authored by Ghislain MARY's avatar Ghislain MARY

Define trace handlers for belle-sip and cunit.

parent c6b8e34c
......@@ -2,12 +2,37 @@
#include "belle-sip-tester-native.h"
#include "belle-sip/belle-sip.h"
#include "cunit/Util.h"
using namespace belle_sip_tester_native;
using namespace Platform;
CainSipTesterNative::CainSipTesterNative()
#define MAX_TRACE_SIZE 512
static OutputTraceListener^ sTraceListener;
static void nativeOutputTraceHandler(int lev, const char *fmt, va_list args)
{
if (sTraceListener) {
wchar_t wstr[MAX_TRACE_SIZE];
std::string str;
str.resize(MAX_TRACE_SIZE);
vsnprintf((char *)str.c_str(), MAX_TRACE_SIZE, fmt, args);
mbstowcs(wstr, str.c_str(), sizeof(wstr));
String^ msg = ref new String(wstr);
sTraceListener->outputTrace(msg);
}
}
static void belleSipNativeOutputTraceHandler(belle_sip_log_level lev, const char *fmt, va_list args)
{
nativeOutputTraceHandler((int)lev, fmt, args);
}
CainSipTesterNative::CainSipTesterNative(OutputTraceListener^ traceListener)
{
sTraceListener = traceListener;
}
void CainSipTesterNative::run(Platform::String^ name, Platform::Boolean verbose)
......@@ -22,6 +47,8 @@ void CainSipTesterNative::run(Platform::String^ name, Platform::Boolean verbose)
} else {
belle_sip_set_log_level(BELLE_SIP_LOG_ERROR);
}
belle_sip_set_log_handler(belleSipNativeOutputTraceHandler);
CU_set_trace_handler(nativeOutputTraceHandler);
belle_sip_tester_run_tests(suitename == all ? 0 : cname, 0);
}
#pragma once
#include "belle-sip/belle-sip.h"
#ifdef __cplusplus
extern "C" {
#endif
......@@ -10,10 +12,16 @@ extern "C" {
namespace belle_sip_tester_native
{
public interface class OutputTraceListener
{
public:
void outputTrace(Platform::String^ msg);
};
public ref class CainSipTesterNative sealed
{
public:
CainSipTesterNative();
CainSipTesterNative(OutputTraceListener^ traceListener);
void run(Platform::String^ name, Platform::Boolean verbose);
};
}
\ No newline at end of file
......@@ -20,18 +20,18 @@ namespace belle_sip_tester_wp8
{
InitializeComponent();
List<UnitTest> source = new List<UnitTest>();
source.Add(new UnitTest("ALL"));
source.Add(new UnitTest("Authentication-helper"));
source.Add(new UnitTest("Dialog"));
source.Add(new UnitTest("Headers"));
source.Add(new UnitTest("Message"));
source.Add(new UnitTest("Object inheritence"));
source.Add(new UnitTest("Refresher"));
source.Add(new UnitTest("Register"));
source.Add(new UnitTest("Resolver"));
source.Add(new UnitTest("SDP"));
source.Add(new UnitTest("Uri"));
List<UnitTestSuiteName> source = new List<UnitTestSuiteName>();
source.Add(new UnitTestSuiteName("ALL"));
source.Add(new UnitTestSuiteName("Authentication-helper"));
source.Add(new UnitTestSuiteName("Dialog"));
source.Add(new UnitTestSuiteName("Headers"));
source.Add(new UnitTestSuiteName("Message"));
source.Add(new UnitTestSuiteName("Object inheritence"));
source.Add(new UnitTestSuiteName("Refresher"));
source.Add(new UnitTestSuiteName("Register"));
source.Add(new UnitTestSuiteName("Resolver"));
source.Add(new UnitTestSuiteName("SDP"));
source.Add(new UnitTestSuiteName("Uri"));
Tests.ItemsSource = source;
Tests.SelectionChanged += tests_selectionChanged;
......@@ -40,18 +40,12 @@ namespace belle_sip_tester_wp8
//BuildLocalizedApplicationBar();
}
async void tests_selectionChanged(object sender, EventArgs e)
void tests_selectionChanged(object sender, EventArgs e)
{
UnitTest test = (sender as LongListSelector).SelectedItem as UnitTest;
var tup = new Tuple<String, bool>(test.Name, Verbose.IsChecked.GetValueOrDefault());
(sender as LongListSelector).Visibility = Visibility.Collapsed;
var t = Task.Factory.StartNew((object parameters) =>
{
var tester = new CainSipTesterNative();
var p = parameters as Tuple<String, bool>;
tester.run(p.Item1, p.Item2);
}, tup);
await t;
UnitTestSuiteName test = (sender as LongListSelector).SelectedItem as UnitTestSuiteName;
var suite = new UnitTestSuite(test, Verbose.IsChecked.GetValueOrDefault());
suite.run();
(sender as LongListSelector).Visibility = Visibility.Visible;
}
......@@ -72,7 +66,36 @@ namespace belle_sip_tester_wp8
//}
}
public class UnitTest
public class UnitTestSuite : OutputTraceListener
{
public UnitTestSuite(UnitTestSuiteName test, bool verbose)
{
this.test = test;
this.verbose = verbose;
}
async public void run()
{
var tup = new Tuple<String, bool>(test.Name, verbose);
var t = Task.Factory.StartNew((object parameters) =>
{
var tester = new CainSipTesterNative(this);
var p = parameters as Tuple<String, bool>;
tester.run(p.Item1, p.Item2);
}, tup);
await t;
}
public void outputTrace(String msg)
{
System.Diagnostics.Debug.WriteLine(msg);
}
private UnitTestSuiteName test;
private bool verbose;
}
public class UnitTestSuiteName
{
public string Name
{
......@@ -80,7 +103,7 @@ namespace belle_sip_tester_wp8
set;
}
public UnitTest(string name)
public UnitTestSuiteName(string name)
{
this.Name = name;
}
......
......@@ -125,8 +125,8 @@ static inline void belle_sip_fatal(const char *fmt,...)
void belle_sip_set_log_file(FILE *file);
void belle_sip_set_log_handler(belle_sip_log_function_t func);
BELLESIP_EXPORT void belle_sip_set_log_file(FILE *file);
BELLESIP_EXPORT void belle_sip_set_log_handler(belle_sip_log_function_t func);
BELLESIP_EXPORT void belle_sip_set_log_level(int 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