From baa898789a2b70b4b969ac36a096c3fa77806ca5 Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Wed, 24 May 2017 13:37:19 +0200 Subject: CSharp bindings and regression tests --- CMakeLists.txt | 3 ++ contrib/csharp/bindings/TestStatePass.cs | 29 +++++++++++++++ src/bindings/swig/csharp/CMakeLists.txt | 15 ++++---- src/bindings/swig/csharp/uscxml.i | 19 +++++----- src/uscxml/util/URL.cpp | 2 +- test/CMakeLists.txt | 62 ++++++++++++++++++++++++++++++++ 6 files changed, 115 insertions(+), 15 deletions(-) create mode 100644 contrib/csharp/bindings/TestStatePass.cs diff --git a/CMakeLists.txt b/CMakeLists.txt index c591ab5..8112d10 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,9 @@ ELSE() SET(CMAKE_BUILD_TYPE Release CACHE STRING ${BUILD_TYPE_HELP}) ENDIF() +# swig_add_module complains quite verbosly on newer cmake versions +SET(CMAKE_WARN_DEPRECATED OFF) + PROJECT(uSCXML) ################################################# diff --git a/contrib/csharp/bindings/TestStatePass.cs b/contrib/csharp/bindings/TestStatePass.cs new file mode 100644 index 0000000..b4712a4 --- /dev/null +++ b/contrib/csharp/bindings/TestStatePass.cs @@ -0,0 +1,29 @@ +using System; +using System.Runtime.InteropServices; + +namespace uscxml_test { + using org.uscxml; + + class TestStatePass + { + [DllImport("kernel32.dll", CharSet = CharSet.Auto)] + private static extern void SetDllDirectory(string lpPathName); + + [STAThread] + static void Main(string[] args) { + + if (args.Length < 1) { + System.Console.WriteLine("Expected SCXML filename and optional dllPath as arguments"); + Environment.Exit(-1); + } + + try { + if (args.Length > 1) + SetDllDirectory(args[1]); + } catch (System.EntryPointNotFoundException) {} + + Interpreter sc = Interpreter.fromURL(args[0]); + while(sc.step() != InterpreterState.USCXML_FINISHED) {} + } + } +} diff --git a/src/bindings/swig/csharp/CMakeLists.txt b/src/bindings/swig/csharp/CMakeLists.txt index 966f740..fc07676 100644 --- a/src/bindings/swig/csharp/CMakeLists.txt +++ b/src/bindings/swig/csharp/CMakeLists.txt @@ -56,27 +56,30 @@ if (DMCS_EXECUTABLE OR CSC_EXECUTABLE) # build managed code part if (CSC_EXECUTABLE) - ADD_CUSTOM_TARGET(csharp + ADD_CUSTOM_COMMAND( # ADD_CUSTOM_TARGET is always considered outdated + OUTPUT ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/uscxmlCSharp.dll COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/org/uscxml/InterpreterException.cs ${PROJECT_BINARY_DIR}/src/bindings/swig/csharp/org/uscxml COMMAND ${CSC_EXECUTABLE} /target:library /out:${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/uscxmlCSharp.dll *.cs - WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/src/bindings/swig/csharp/org/uscxml - COMMENT "Creating umundoCSharp.dll for C# ...") + WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/src/bindings/swig/csharp/org/uscxml + COMMENT "Creating uscxmlCSharp.dll for C# ...") else() - ADD_CUSTOM_TARGET(csharp + ADD_CUSTOM_COMMAND( + OUTPUT ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/uscxmlCSharp.dll COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/org/uscxml/InterpreterException.cs ${PROJECT_BINARY_DIR}/src/bindings/swig/csharp/org/uscxml COMMAND ${DMCS_EXECUTABLE} -target:library /out:${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/uscxmlCSharp.dll *.cs - WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/src/bindings/swig/csharp/org/uscxml + WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/src/bindings/swig/csharp/org/uscxml COMMENT "Creating umundoCSharp.dll for Mono ...") endif() - + ADD_CUSTOM_TARGET(csharp DEPENDS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/uscxmlCSharp.dll) + add_dependencies(csharp uscxmlNativeCSharp) if (BUILD_TESTS) add_dependencies(ALL_TESTS csharp) diff --git a/src/bindings/swig/csharp/uscxml.i b/src/bindings/swig/csharp/uscxml.i index ac154c5..154bda3 100644 --- a/src/bindings/swig/csharp/uscxml.i +++ b/src/bindings/swig/csharp/uscxml.i @@ -178,7 +178,6 @@ WRAP_TO_STRING(uscxml::InterpreterIssue); // Beautify important classes //*********************************************** - // byte[] signature for Blob get/setData // see http://permalink.gmane.org/gmane.comp.programming.swig/5804 @@ -216,6 +215,9 @@ WRAP_TO_STRING(uscxml::InterpreterIssue); $result = (char *)result; } +%include "../uscxml_beautify.i" + +#if 0 %csmethodmodifiers uscxml::Event::getParamMap() "private"; @@ -228,7 +230,6 @@ WRAP_TO_STRING(uscxml::InterpreterIssue); %csmethodmodifiers uscxml::Interpreter::getIOProcessors() "private"; %csmethodmodifiers uscxml::Data::getCompoundKeys() "private"; -%include "../uscxml_beautify.i" %typemap(csimports) uscxml::Interpreter %{ using System; @@ -241,7 +242,7 @@ using System.Runtime.InteropServices; Dictionary ioProcs = new Dictionary(); StringVector keys = getIOProcessorKeys(); IOProcMap ioProcMap = getIOProcessorsNative(); - for (size_t i = 0; i < keys.Count; i++) { + for (int i = 0; i < keys.Count; i++) { ioProcs[keys[i]] = ioProcMap[keys[i]]; } return ioProcs; @@ -251,7 +252,7 @@ using System.Runtime.InteropServices; Dictionary invokers = new Dictionary(); StringVector keys = getInvokerKeys(); InvokerMap invokerMap = getInvokersNative(); - for (size_t i = 0; i < keys.Count; i++) { + for (int i = 0; i < keys.Count; i++) { invokers[keys[i]] = invokerMap[keys[i]]; } return invokers; @@ -293,7 +294,7 @@ using System.Runtime.InteropServices; Dictionary compound = new Dictionary(); DataMap dataMap = getCompoundNative(); StringVector dataMapKeys = getCompoundKeys(); - for (size_t i = 0; i < dataMapKeys.Count; i++) { + for (int i = 0; i < dataMapKeys.Count; i++) { compound[dataMapKeys[i]] = dataMap[dataMapKeys[i]]; } return compound; @@ -310,7 +311,7 @@ using System.Runtime.InteropServices; public List getArray() { List arr = new List(); DataList dataList = getArrayNative(); - for (size_t i = 0; i < dataList.size(); i++) { + for (int i = 0; i < dataList.size(); i++) { arr.Add(dataList.get(i)); } return arr; @@ -350,7 +351,7 @@ using System.Runtime.InteropServices; foreach (KeyValuePair entry in paramMap) { DataList dataList = entry.Value; List paramList = new List(); - for (size_t i = 0; i < dataList.size(); i++) { + for (int i = 0; i < dataList.size(); i++) { Data data = dataList.get(i); paramList.Add(data); } @@ -375,7 +376,7 @@ using System.Runtime.InteropServices; Dictionary nameList = new Dictionary(); DataMap nameListMap = getNameListNative(); StringVector nameListMapKeys = getNameListKeys(); - for (size_t i = 0; i < nameListMapKeys.Count; i++) { + for (int i = 0; i < nameListMapKeys.Count; i++) { nameList[nameListMapKeys[i]] = nameListMap[nameListMapKeys[i]]; } return nameList; @@ -390,6 +391,8 @@ using System.Runtime.InteropServices; } %} +#endif + //*********************************************** // Parse the header file to generate wrappers //*********************************************** diff --git a/src/uscxml/util/URL.cpp b/src/uscxml/util/URL.cpp index 3fcb387..b429e22 100644 --- a/src/uscxml/util/URL.cpp +++ b/src/uscxml/util/URL.cpp @@ -968,7 +968,7 @@ void URLFetcher::perform() { case -1: { /* select error */ #if 0 - // this is not an actual error - there was just nothing to process + // this is not an actual error - there was just nothing to process #ifdef _WIN32 char *s = NULL; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7f8187f..efbc2fa 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -12,6 +12,9 @@ endif() find_program(PERL_BIN perl) find_program(PYTHON_BIN python) find_program(GHDL_BIN ghdl) +find_program(DMCS_BIN dmcs) +find_program(MONO_BIN mono) +find_program(CSC_BIN csc) set(GHDL_VERSION "0") if (GHDL_BIN) @@ -92,6 +95,38 @@ add_executable(test-state-pass src/test-state-pass.cpp ${GETOPT_FILES}) target_link_libraries(test-state-pass uscxml) set_target_properties(test-state-pass PROPERTIES FOLDER "Tests") +if (TARGET csharp) + if (DMCS_BIN) + ADD_CUSTOM_TARGET(testStatePassCSharp ALL + COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/bin/csharp + COMMAND + ${DMCS_BIN} + ${PROJECT_SOURCE_DIR}/contrib/csharp/bindings/TestStatePass.cs + -r:${CMAKE_BINARY_DIR}/lib/uscxmlCSharp.dll + -out:${CMAKE_BINARY_DIR}/bin/csharp/TestStatePass.exe + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/lib/uscxmlCSharp.dll ${CMAKE_BINARY_DIR}/bin/csharp + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/lib/csharp/* ${CMAKE_BINARY_DIR}/bin/csharp + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin + COMMENT "Compiling C# TestStatePass" + ) + add_dependencies(testStatePassCSharp csharp) + else() + ADD_CUSTOM_TARGET(testStatePassCSharp ALL + COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/bin/csharp + COMMAND + ${CSC_BIN} + ${PROJECT_SOURCE_DIR}/contrib/csharp/bindings/TestStatePass.cs + -r:${CMAKE_BINARY_DIR}/lib/uscxmlCSharp.dll + -out:${CMAKE_BINARY_DIR}/bin/csharp/TestStatePass.exe + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_BINARY_DIR}/lib/csharp ${CMAKE_BINARY_DIR}/bin/csharp + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/lib/uscxmlCSharp.dll ${CMAKE_BINARY_DIR}/bin/csharp + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin + COMMENT "Compiling C# TestStatePass" + ) + add_dependencies(testStatePassCSharp csharp) + endif() +endif() + if (WIN32 AND BUILD_SHARED_LIBS) # do not build test-gen-c on windows with shared libraries active # due to __declspec(dllexport) being activated. We would need to @@ -273,6 +308,8 @@ if (NOT BUILD_MINIMAL) # bindings "binding/java/jexl" "binding/python/ecma" + "binding/csharp/ecma" + "binding/csharp/lua" # state-machine interpreters # "fsm/ecma" @@ -433,6 +470,31 @@ if (NOT BUILD_MINIMAL) set(TEST_ADDED ON) endif () + if (TARGET csharp AND TEST_LANG STREQUAL "csharp") + + if (MONO_BIN) + add_test(NAME "${TEST_NAME}" + COMMAND + ${MONO_BIN} + ${CMAKE_BINARY_DIR}/bin/csharp/TestStatePass.exe + ${W3C_TEST} + ${CMAKE_BINARY_DIR}/lib + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/lib/csharp) + else() + add_test(NAME "${TEST_NAME}" + COMMAND + ${CMAKE_BINARY_DIR}/bin/csharp/TestStatePass.exe + ${W3C_TEST} + ${CMAKE_BINARY_DIR}/lib + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/lib/csharp) + endif() + set_property(TEST ${TEST_NAME} PROPERTY ENVIRONMENT "USCXML_PYTHON_PATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}") + set_property(TEST ${TEST_NAME} APPEND PROPERTY ENVIRONMENT "USCXML_PLUGIN_PATH=${CMAKE_BINARY_DIR}/lib/plugins") + set_property(TEST ${TEST_NAME} APPEND PROPERTY DEPENDS testStatePassCSharp) + + set(TEST_ADDED ON) + endif () + elseif (TEST_TYPE MATCHES "^spin.*") if (NOT ${TEST_DATAMODEL} STREQUAL "promela") -- cgit v0.12