Commit 3bd6242f authored by Ghislain MARY's avatar Ghislain MARY

Use WebBrowser component to display output traces.

parent 502daf22
......@@ -12,7 +12,7 @@ using namespace Platform;
static OutputTraceListener^ sTraceListener;
static void nativeOutputTraceHandler(int lev, const char *fmt, va_list args)
static void nativeOutputTraceHandler(OutputTraceLevel lev, const char *fmt, va_list args)
{
if (sTraceListener) {
wchar_t wstr[MAX_TRACE_SIZE];
......@@ -21,15 +21,27 @@ static void nativeOutputTraceHandler(int lev, const char *fmt, va_list args)
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);
sTraceListener->outputTrace(lev, msg);
}
}
static void CUnitNativeOutputTraceHandler(int lev, const char *fmt, va_list args)
{
nativeOutputTraceHandler(Raw, fmt, args);
}
static void Mediastreamer2NativeOutputTraceHandler(OrtpLogLevel lev, const char *fmt, va_list args)
{
OutputTraceLevel level = Message;
char fmt2[MAX_TRACE_SIZE];
snprintf(fmt2, MAX_TRACE_SIZE, "%s\n", fmt);
nativeOutputTraceHandler((int)lev, fmt2, args);
if (lev == ORTP_DEBUG) level = Debug;
else if (lev == ORTP_MESSAGE) level = Message;
else if (lev == ORTP_TRACE) level = Message;
else if (lev == ORTP_WARNING) level = Warning;
else if (lev == ORTP_ERROR) level = Error;
else if (lev == ORTP_FATAL) level = Error;
nativeOutputTraceHandler(level, fmt2, args);
}
......@@ -64,7 +76,7 @@ void Mediastreamer2TesterNative::run(Platform::String^ suiteName, Platform::Stri
ortp_set_log_level_mask(ORTP_ERROR|ORTP_FATAL);
}
ortp_set_log_handler(Mediastreamer2NativeOutputTraceHandler);
CU_set_trace_handler(nativeOutputTraceHandler);
CU_set_trace_handler(CUnitNativeOutputTraceHandler);
mediastreamer2_tester_run_tests(wssuitename == all ? 0 : csuitename, wscasename == all ? 0 : ccasename);
}
......
......@@ -4,10 +4,18 @@
namespace mediastreamer2_tester_native
{
enum OutputTraceLevel {
Debug,
Message,
Warning,
Error,
Raw
};
public interface class OutputTraceListener
{
public:
void outputTrace(Platform::String^ msg);
void outputTrace(int level, Platform::String^ msg);
};
public ref class Mediastreamer2TesterNative sealed
......
......@@ -31,10 +31,8 @@
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ScrollViewer HorizontalScrollBarVisibility="Visible">
<TextBlock x:Name="TestResults" TextWrapping="Wrap" Style="{StaticResource PhoneTextNormalStyle}" FontFamily="Courier New" FontSize="16"/>
</ScrollViewer>
<Grid x:Name="ContentPanel" Grid.Row="2" Margin="12,0,12,0">
<phone:WebBrowser x:Name="Browser" IsScriptEnabled="True" LoadCompleted="Browser_LoadCompleted" Background="{StaticResource PhoneBackgroundBrush}"/>
</Grid>
</Grid>
......
......@@ -14,18 +14,18 @@ using mediastreamer2_tester_wp8;
namespace mediastreamer2_tester_wp8
{
public delegate void OutputDisplayDelegate(String msg);
public delegate void OutputDisplayDelegate(int level, String msg);
public partial class TestResultPage : PhoneApplicationPage
{
public TestResultPage()
{
InitializeComponent();
Browser.Navigate(new Uri("log.html", UriKind.Relative));
}
protected override void OnNavigatedTo(NavigationEventArgs e)
private void Browser_LoadCompleted(object sender, NavigationEventArgs e)
{
base.OnNavigatedTo(e);
string suiteName = NavigationContext.QueryString["SuiteName"];
string caseName;
if (NavigationContext.QueryString.ContainsKey("CaseName"))
......@@ -42,11 +42,49 @@ namespace mediastreamer2_tester_wp8
app.suite.run();
}
public void OutputDisplay(String msg)
public void OutputDisplay(int level, String msg)
{
this.Dispatcher.BeginInvoke(() =>
{
TestResults.Text += msg;
msg = msg.Replace("\r\n", "\n");
string[] lines = msg.Split('\n');
bool insertNewLine = false;
foreach (string line in lines)
{
if (line.Length == 0)
{
insertNewLine = false;
Browser.InvokeScript("append_nl");
}
else
{
if (insertNewLine == true)
{
Browser.InvokeScript("append_nl");
}
if (level == 0)
{
Browser.InvokeScript("append_trace", line, "debug");
}
else if (level == 1)
{
Browser.InvokeScript("append_trace", line, "message");
}
else if (level == 2)
{
Browser.InvokeScript("append_trace", line, "warning");
}
else if (level == 3)
{
Browser.InvokeScript("append_trace", line, "error");
}
else
{
Browser.InvokeScript("append_text", line);
}
insertNewLine = true;
}
}
});
}
}
......@@ -78,11 +116,11 @@ namespace mediastreamer2_tester_wp8
Running = false;
}
public void outputTrace(String msg)
public void outputTrace(int level, String msg)
{
if (OutputDisplay != null)
{
OutputDisplay(msg);
OutputDisplay(level, msg);
}
System.Diagnostics.Debug.WriteLine(msg);
}
......
<html>
<head>
<style>
html { background-color: black; font-family:'Courier New'; font-size: 16pt; color: white; }
.debug { color: light-grey; }
.message { color: white; }
.warning { color: orange; }
.error { color: red; }
</style>
<script>
function append_text(msg) {
var content = document.getElementById("content");
var new_text = document.createTextNode(msg);
content.appendChild(new_text);
}
function append_trace(msg, level) {
var content = document.getElementById("content");
var span_elem = document.createElement('span');
span_elem.className = level;
var new_text = document.createTextNode(msg);
span_elem.appendChild(new_text);
content.appendChild(span_elem);
}
function append_nl() {
var content = document.getElementById("content");
var element = document.createElement('br');
content.appendChild(element);
}
</script>
</head>
<body>
<p><pre id="content"></pre></p>
</body>
</html>
......@@ -153,6 +153,7 @@
<Content Include="Assets\Tiles\IconicTileSmall.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="log.html" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\AppResources.resx">
......
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