using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace embedding
{
using org.uscxml;
class RunTests
{
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
private static extern void SetDllDirectory(string lpPathName);
static void Main(string[] args)
{
/*
* Make sure this path contains the uscxmlNativeCSharp.dll!
*/
if (System.Environment.Is64BitProcess)
{
SetDllDirectory("C:\\Users\\sradomski\\Desktop\\build\\uscxml64\\lib\\csharp");
}
else
{
SetDllDirectory("C:\\Users\\sradomski\\Desktop\\build\\uscxml\\lib\\csharp");
}
int i = 1;
while (i-- > 0)
{
testData();
testLifeCycle();
testExecutableContent();
testIOProcessor();
testInvoker();
}
Console.ReadKey();
}
public static void testData() {
byte[] origData = new byte[1024];
for (int i = 0; i < origData.Length; i++) {
origData[i] = (byte)i;
}
{
Blob blob = new Blob(origData, "application/octet-stream");
Debug.Assert(origData.Length == blob.getSize());
for (int i = 0; i < origData.Length; i++) {
Debug.Assert(origData[i] == blob.getData()[i]);
}
}
Data data = new Data(origData, "application/octet-stream");
Blob blob2 = data.getBinary();
byte[] newData = blob2.getData();
if (newData.Length == origData.Length);
for (int i = 0; i < origData.Length; i++) {
Debug.Assert(newData[i] == origData[i]);
}
}
public static void testInvoker() {
Console.WriteLine("testInvoker");
CustomInvoker invoker = new CustomInvoker();
// just register prototype at global factory
Factory.getInstance().registerInvoker(invoker);
String xml =
"" +
" " +
" " +
" Some string content" +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
"";
// parse and interpret
Interpreter interpreter = Interpreter.fromXML(xml, "");
interpreter.interpret();
}
public static void testIOProcessor()
{
Console.WriteLine("testIOProcessor");
CustomIOProc ioproc = new CustomIOProc();
// just register prototype at global factory
Factory.getInstance().registerIOProcessor(ioproc);
String xml =
"" +
" " +
" " +
" " +
" This is some content!" +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
"";
// parse and interpret
Interpreter interpreter = Interpreter.fromXML(xml, "");
interpreter.interpret();
}
public static void testExecutableContent()
{
Console.WriteLine("testExecutableContent");
CustomExecutableContent execContent = new CustomExecutableContent();
Factory.getInstance().registerExecutableContent(execContent);
Interpreter interpreter = Interpreter.fromXML(
"\n" +
" \n" +
" \n" +
" \n" +
" \n" +
" " +
" \n" +
" " +
"\n", ""
);
interpreter.interpret();
interpreter.Dispose();
}
public static void testLifeCycle()
{
Console.WriteLine("testLifeCycle");
// syntactic xml parse error -> throws
try
{
String xml = " throws
try
{
String xml = "";
Interpreter interpreter = Interpreter.fromXML(xml, "");
Debug.Assert(interpreter.getState() == InterpreterState.USCXML_INSTANTIATED);
interpreter.step();
Debug.Assert(false);
}
catch (InterpreterException e)
{
// Console.WriteLine(e);
}
// request unknown datamodel
try
{
string xml =
"" +
" " +
" " +
" " +
" " +
"";
Interpreter interpreter = Interpreter.fromXML(xml, "");
Debug.Assert(interpreter.getState() == InterpreterState.USCXML_INSTANTIATED);
interpreter.step();
Debug.Assert(false);
}
catch (InterpreterException e)
{
// Console.WriteLine(e);
}
try
{
// two microsteps
string xml =
"" +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
"";
Interpreter interpreter = Interpreter.fromXML(xml, "");
Debug.Assert(interpreter.getState() == InterpreterState.USCXML_INSTANTIATED);
Debug.Assert(interpreter.step() == InterpreterState.USCXML_MICROSTEPPED);
Debug.Assert(interpreter.step() == InterpreterState.USCXML_MICROSTEPPED);
Debug.Assert(interpreter.step() == InterpreterState.USCXML_FINISHED);
}
catch (InterpreterException e)
{
Console.WriteLine(e);
}
try
{
// single macrostep, multiple runs
string xml =
"" +
" " +
" " +
" " +
" " +
"";
Interpreter interpreter = Interpreter.fromXML(xml, "");
Debug.Assert(interpreter.getState() == InterpreterState.USCXML_INSTANTIATED);
Debug.Assert(interpreter.step() == InterpreterState.USCXML_MICROSTEPPED);
Debug.Assert(interpreter.step() == InterpreterState.USCXML_FINISHED);
interpreter.reset();
Debug.Assert(interpreter.getState() == InterpreterState.USCXML_INSTANTIATED);
Debug.Assert(interpreter.step() == InterpreterState.USCXML_MICROSTEPPED);
Debug.Assert(interpreter.step() == InterpreterState.USCXML_FINISHED);
}
catch (InterpreterException e)
{
Console.WriteLine(e);
}
try
{
// macrostep in between
string xml =
"" +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
"";
Interpreter interpreter = Interpreter.fromXML(xml, "");
Debug.Assert(interpreter.getState() == InterpreterState.USCXML_INSTANTIATED);
Debug.Assert(interpreter.step() == InterpreterState.USCXML_IDLE);
Debug.Assert(interpreter.step(true) == InterpreterState.USCXML_MACROSTEPPED);
Debug.Assert(interpreter.step() == InterpreterState.USCXML_MICROSTEPPED);
Debug.Assert(interpreter.step() == InterpreterState.USCXML_FINISHED);
}
catch (InterpreterException e)
{
Console.WriteLine(e);
}
}
}
}