From 7f83038a1ef642b883417cc984d1f8ca9f0bc64b Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Fri, 27 Jan 2017 22:54:43 +0100 Subject: Reactivated BUILD_AS_PLUGINS --- CMakeLists.txt | 30 +- apps/uscxml-browser.cpp | 2 +- config.h.in | 1 + contrib/src/Pluma/PluginManager.cpp | 5 +- src/uscxml/CMakeLists.txt | 10 +- src/uscxml/Interpreter.cpp | 3 +- src/uscxml/interpreter/BasicDelayedEventQueue.cpp | 3 +- src/uscxml/interpreter/BasicEventQueue.cpp | 2 +- src/uscxml/interpreter/FastMicroStep.cpp | 12 +- src/uscxml/messages/Data.cpp | 7 +- src/uscxml/messages/Data.h | 8 +- src/uscxml/messages/Event.cpp | 5 +- src/uscxml/plugins/Factory.cpp | 92 +- src/uscxml/plugins/Factory.h | 4 +- src/uscxml/plugins/Plugins.cpp | 31 + src/uscxml/plugins/Plugins.h | 41 + src/uscxml/plugins/datamodel/CMakeLists.txt | 94 +- .../ecmascript/JavaScriptCore/JSCDataModel.cpp | 11 +- .../ecmascript/JavaScriptCore/JSCDataModel.h | 2 +- .../datamodel/ecmascript/v8/V8DataModel.cpp | 12 + .../plugins/datamodel/ecmascript/v8/V8DataModel.h | 1 + src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp | 31 +- src/uscxml/plugins/datamodel/lua/LuaDataModel.h | 3 +- .../plugins/datamodel/null/NULLDataModel.cpp | 18 +- src/uscxml/plugins/datamodel/null/NULLDataModel.h | 9 +- .../plugins/datamodel/promela/PromelaDataModel.cpp | 6 +- .../plugins/datamodel/promela/PromelaDataModel.h | 3 +- .../plugins/datamodel/promela/PromelaParser.cpp | 4 +- .../plugins/datamodel/promela/PromelaParser.h | 2 +- src/uscxml/plugins/invoker/CMakeLists.txt | 22 + .../plugins/invoker/dirmon/DirMonInvoker.cpp | 4 +- src/uscxml/plugins/invoker/dirmon/DirMonInvoker.h | 3 +- src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp | 6 +- src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h | 3 +- src/uscxml/plugins/ioprocessor/CMakeLists.txt | 27 +- .../ioprocessor/basichttp/BasicHTTPIOProcessor.h | 9 +- .../plugins/ioprocessor/scxml/SCXMLIOProcessor.cpp | 12 + .../plugins/ioprocessor/scxml/SCXMLIOProcessor.h | 9 +- src/uscxml/transform/ChartToC.cpp | 13 +- src/uscxml/transform/ChartToPromela.cpp | 36 +- src/uscxml/transform/ChartToPromela.h | 14 +- src/uscxml/transform/ChartToVHDL.cpp | 8 +- src/uscxml/transform/Trie.cpp | 4 +- src/uscxml/transform/Trie.h | 2 +- src/uscxml/transform/promela/PromelaCodeAnalyzer.h | 4 +- src/uscxml/util/DOM.cpp | 288 +++-- src/uscxml/util/DOM.h | 27 +- test/CMakeLists.txt | 40 +- test/ctest/scripts/test_generated_c.cmake | 31 +- test/src/test-gen-c.cpp | 4 +- test/src/test-utils.cpp | 74 ++ test/src/test-validating.cpp | 1323 +++++++++++--------- 52 files changed, 1528 insertions(+), 887 deletions(-) create mode 100644 src/uscxml/plugins/Plugins.cpp create mode 100644 src/uscxml/plugins/Plugins.h create mode 100644 test/src/test-utils.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index a7c4cdc..764fd8c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,6 +86,11 @@ set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +# additional system library directories +# if (EXISTS "/usr/lib/x86_64-linux-gnu") +# LIST(APPEND CMAKE_FIND_ROOT_PATH "/usr/lib/x86_64-linux-gnu") +# endif() + # setup header include paths include_directories(src) include_directories(contrib/src) @@ -249,10 +254,11 @@ else() # make a quick attempt to find xerces INCLUDE(FindPackageHandleStandardArgs) find_path(XercesC_INCLUDE_DIR NAMES "xercesc/util/PlatformUtils.hpp") - find_library(XercesC_LIBRARY NAMES "xerces-c" "xerces-c_3") + find_library(XercesC_LIBRARIES NAMES "xerces-c" "xerces-c_3") mark_as_advanced(XercesC_LIBRARIES) mark_as_advanced(XercesC_INCLUDE_DIR) if (XercesC_INCLUDE_DIR AND XercesC_LIBRARIES) + message(STATUS "Found XercesC: ${XercesC_LIBRARIES}") set(XercesC_FOUND ON) else() message(STATUS "Could NOT find XercesC (your CMake distribution does not include the FindXercesC module)") @@ -409,14 +415,30 @@ endif() add_subdirectory(src/uscxml) add_subdirectory(src/bindings) -add_library(uscxml ${USCXML_FILES}) +if (BUILD_AS_PLUGINS) + file(GLOB USCXML_PLUGINS + ${CMAKE_SOURCE_DIR}/contrib/src/Pluma/*.cpp + ) + include_directories(${CMAKE_SOURCE_DIR}/contrib/src) + source_group("Plugins" FILES ${USCXML_PLUGINS}) + list (APPEND USCXML_FILES ${USCXML_PLUGINS}) + + add_library(uscxml ${USCXML_FILES}) + target_link_libraries(uscxml ${USCXML_CORE_LIBS}) + set_target_properties(uscxml PROPERTIES COMPILE_FLAGS "-DUSCXML_EXPORT") +# set_target_properties(uscxml PROPERTIES COMPILE_FLAGS "-DPLUMA_EXPORTS") + add_definitions(-DPLUMA_EXPORTS) +else() + add_library(uscxml ${USCXML_FILES}) + target_link_libraries(uscxml ${USCXML_OPT_LIBS} ${USCXML_CORE_LIBS}) +endif() + set_property(TARGET uscxml PROPERTY CXX_STANDARD 11) set_property(TARGET uscxml PROPERTY CXX_STANDARD_REQUIRED ON) set_property(TARGET uscxml PROPERTY SOVERSION ${USCXML_VERSION}) +add_dependencies(uscxml ${USCXML_PREREQS}) install_library(TARGETS uscxml) -add_dependencies(uscxml ${USCXML_PREREQS}) -target_link_libraries(uscxml ${USCXML_OPT_LIBS} ${USCXML_CORE_LIBS}) add_library(uscxml_transform ${USCXML_TRANSFORM_FILES}) set_property(TARGET uscxml_transform PROPERTY CXX_STANDARD 11) diff --git a/apps/uscxml-browser.cpp b/apps/uscxml-browser.cpp index b421f3f..626ad60 100644 --- a/apps/uscxml-browser.cpp +++ b/apps/uscxml-browser.cpp @@ -52,7 +52,7 @@ int main(int argc, char** argv) { // instantiate and configure interpreters std::list interpreters; - for(int i = 0; i < options.interpreters.size(); i++) { + for(size_t i = 0; i < options.interpreters.size(); i++) { // InterpreterOptions* currOptions = options.interpreters[0].second; std::string documentURL = options.interpreters[0].first; diff --git a/config.h.in b/config.h.in index cdead01..ae184c0 100644 --- a/config.h.in +++ b/config.h.in @@ -73,6 +73,7 @@ #cmakedefine WITH_DM_C89 #cmakedefine WITH_DM_PROMELA +#cmakedefine BUILD_AS_PLUGINS /** Optional libraries we found */ #cmakedefine UMUNDO_FOUND diff --git a/contrib/src/Pluma/PluginManager.cpp b/contrib/src/Pluma/PluginManager.cpp index 1124505..3463377 100755 --- a/contrib/src/Pluma/PluginManager.cpp +++ b/contrib/src/Pluma/PluginManager.cpp @@ -53,10 +53,10 @@ bool PluginManager::load(const std::string& path){ if (!lib) return false; fnRegisterPlugin* registerFunction; - registerFunction = reinterpret_cast(lib->getSymbol("connect")); + registerFunction = reinterpret_cast(lib->getSymbol("pluginConnect")); if(!registerFunction){ - fprintf(stderr, "Failed to initialize plugin \"%s\": connect function not found\n", plugName.c_str()); + fprintf(stderr, "Failed to initialize plugin \"%s\": pluginConnect function not found\n", plugName.c_str()); delete lib; return false; } @@ -68,6 +68,7 @@ bool PluginManager::load(const std::string& path){ delete lib; return false; } + // Store the library if addictions are confirmed if (host.confirmAddictions()) libraries[plugName] = lib; diff --git a/src/uscxml/CMakeLists.txt b/src/uscxml/CMakeLists.txt index 459fe23..e1881e4 100644 --- a/src/uscxml/CMakeLists.txt +++ b/src/uscxml/CMakeLists.txt @@ -62,7 +62,6 @@ file(GLOB USCXML_CORE source_group("Interpreter" FILES ${USCXML_CORE}) list (APPEND USCXML_FILES ${USCXML_CORE}) - file(GLOB USCXML_PLUGINS plugins/*.cpp plugins/*.h @@ -78,6 +77,15 @@ file(GLOB_RECURSE USCXML_TRANSFORM source_group("Interpreter" FILES ${USCXML_TRANSFORM}) list (APPEND USCXML_TRANSFORM_FILES ${USCXML_TRANSFORM}) +if (BUILD_AS_PLUGINS) + file(GLOB_RECURSE PROMELA_PARSER + plugins/datamodel/promela/parser/*.cpp + plugins/datamodel/promela/PromelaParser.cpp + ) + list (APPEND USCXML_TRANSFORM_FILES ${PROMELA_PARSER}) + +endif() + add_subdirectory(plugins/datamodel) # add_subdirectory(plugins/element) add_subdirectory(plugins/invoker) diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp index d5f764d..4630cf2 100644 --- a/src/uscxml/Interpreter.cpp +++ b/src/uscxml/Interpreter.cpp @@ -61,6 +61,7 @@ static URL normalizeURL(const std::string url) { } Interpreter Interpreter::fromXML(const std::string& xml, const std::string& baseURL) { + URL absUrl = normalizeURL(baseURL); std::shared_ptr interpreterImpl(new InterpreterImpl()); @@ -197,7 +198,7 @@ std::string Interpreter::serialize() { InterpreterState Interpreter::step(size_t blockMs) { return _impl->step(blockMs); -}; +} void loadState(const std::string& encodedState); diff --git a/src/uscxml/interpreter/BasicDelayedEventQueue.cpp b/src/uscxml/interpreter/BasicDelayedEventQueue.cpp index 74ab757..ef194ca 100644 --- a/src/uscxml/interpreter/BasicDelayedEventQueue.cpp +++ b/src/uscxml/interpreter/BasicDelayedEventQueue.cpp @@ -196,7 +196,8 @@ Data BasicDelayedEventQueue::serialize() { for (auto event : _queue) { struct callbackData cb = _callbackData[event.uuid]; - struct timeval delay, now; + struct timeval delay = {0, 0}; + struct timeval now = {0, 0}; uint64_t delayMs = 0; evutil_gettimeofday(&now, NULL); diff --git a/src/uscxml/interpreter/BasicEventQueue.cpp b/src/uscxml/interpreter/BasicEventQueue.cpp index bb7c78b..5b3e9f8 100644 --- a/src/uscxml/interpreter/BasicEventQueue.cpp +++ b/src/uscxml/interpreter/BasicEventQueue.cpp @@ -42,7 +42,7 @@ Event BasicEventQueue::dequeue(size_t blockMs) { system_clock::time_point endTime = now + milliseconds(blockMs); // now + milliseconds(blockMs) may not have fitted into a duration type - limit to maximum duration - if (blockMs > system_clock::duration::max().count() - duration_cast(now.time_since_epoch()).count()) { + if (blockMs > (size_t)(system_clock::duration::max().count() - duration_cast(now.time_since_epoch()).count())) { endTime = system_clock::time_point::max(); } diff --git a/src/uscxml/interpreter/FastMicroStep.cpp b/src/uscxml/interpreter/FastMicroStep.cpp index 3edd3e4..33ffebd 100644 --- a/src/uscxml/interpreter/FastMicroStep.cpp +++ b/src/uscxml/interpreter/FastMicroStep.cpp @@ -420,7 +420,17 @@ COMPLETION_STABLISHED: /** -- All things transitions -- */ - tmp = DOMUtils::inPostFixOrder({_xmlPrefix.str() + "transition"}, _scxml); +// tmp = DOMUtils::inPostFixOrder({_xmlPrefix.str() + "transition"}, _scxml); + tmp = DOMUtils::inPostFixOrder({ + XML_PREFIX(_scxml).str() + "scxml", + XML_PREFIX(_scxml).str() + "state", + XML_PREFIX(_scxml).str() + "final", + XML_PREFIX(_scxml).str() + "history", + XML_PREFIX(_scxml).str() + "initial", + XML_PREFIX(_scxml).str() + "parallel" + }, _scxml); + tmp = DOMUtils::filterChildElements(XML_PREFIX(_scxml).str() + "transition", tmp); + _transitions.resize(tmp.size()); for (i = 0; i < _transitions.size(); i++) { diff --git a/src/uscxml/messages/Data.cpp b/src/uscxml/messages/Data.cpp index 6c48c46..8853b19 100644 --- a/src/uscxml/messages/Data.cpp +++ b/src/uscxml/messages/Data.cpp @@ -73,6 +73,7 @@ void Data::merge(const Data& other) { } Data Data::fromJSON(const std::string& jsonString) { + Data data; std::string trimmed = boost::trim_copy(jsonString); @@ -129,7 +130,7 @@ Data Data::fromJSON(const std::string& jsonString) { return data; } - if (t[0].end != trimmed.length()) + if ((size_t)t[0].end != trimmed.length()) return data; // jsmntok_t* token = t; @@ -218,7 +219,7 @@ std::string Data::toJSON(const Data& data) { } if (false) { } else if (data.compound.size() > 0) { - int longestKey = 0; + size_t longestKey = 0; std::map::const_iterator compoundIter = data.compound.begin(); while(compoundIter != data.compound.end()) { if (compoundIter->first.size() > longestKey) @@ -226,7 +227,7 @@ std::string Data::toJSON(const Data& data) { compoundIter++; } std::string keyPadding; - for (unsigned int i = 0; i < longestKey; i++) + for (size_t i = 0; i < longestKey; i++) keyPadding += " "; std::string seperator; diff --git a/src/uscxml/messages/Data.h b/src/uscxml/messages/Data.h index 48323ed..5e4df87 100644 --- a/src/uscxml/messages/Data.h +++ b/src/uscxml/messages/Data.h @@ -39,7 +39,7 @@ class DOMNode; namespace uscxml { -static int _dataIndentation = 1; +static unsigned int _dataIndentation = 1; class USCXML_API Data { public: @@ -48,7 +48,10 @@ public: INTERPRETED, }; - Data() : node(NULL), type(INTERPRETED) {} + Data() : node(NULL), type(INTERPRETED) { + // silence stupid not used error for statics in gcc + (void)_dataIndentation; + } explicit Data(const char* data, size_t size, const std::string& mimeType, bool adopt = false); @@ -87,7 +90,6 @@ public: compound.clear(); array.clear(); atom.clear(); -// adoptedDoc.reset(); binary = Blob(); node = NULL; } diff --git a/src/uscxml/messages/Event.cpp b/src/uscxml/messages/Event.cpp index f372798..f667e92 100644 --- a/src/uscxml/messages/Event.cpp +++ b/src/uscxml/messages/Event.cpp @@ -84,7 +84,10 @@ std::ostream& operator<< (std::ostream& os, const Event& event) { indent += " "; } -// os << indent << (event.eventType == Event::EXTERNAL ? "External" : "Internal") << " Event " << (event.dom ? "with DOM attached" : "") << std::endl; + os << indent + << (event.eventType == Event::INTERNAL ? "Internal" : "") + << (event.eventType == Event::EXTERNAL ? "External" : "") + << (event.eventType == Event::PLATFORM ? "Platform" : "") << " Event " << std::endl; if (event.name.size() > 0) os << indent << " name: " << event.name << std::endl; diff --git a/src/uscxml/plugins/Factory.cpp b/src/uscxml/plugins/Factory.cpp index b609955..0b9104e 100644 --- a/src/uscxml/plugins/Factory.cpp +++ b/src/uscxml/plugins/Factory.cpp @@ -33,10 +33,21 @@ #include "uscxml/plugins/InvokerImpl.h" #include "uscxml/plugins/DataModelImpl.h" +#include +#include +#include "uscxml/util/DOM.h" + +#include // see http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system +/*** BEGIN PLUGINS ***/ + +#ifdef BUILD_AS_PLUGINS +# include "uscxml/plugins/Plugins.h" +#else + #ifdef WITH_IOPROC_SCXML # include "uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.h" #endif @@ -45,10 +56,9 @@ # include "uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.h" #endif +#include "uscxml/plugins/datamodel/null/NullDataModel.h" -#include "uscxml/plugins/datamodel/null/NULLDataModel.h" - -#ifdef WITH_DM_ECMA_V8 +#if defined WITH_DM_ECMA_V8 # include "uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h" #endif @@ -77,6 +87,9 @@ # include "uscxml/plugins/invoker/dirmon/DirMonInvoker.h" #endif +#endif +/*** END PLUGINS ***/ + namespace uscxml { @@ -98,8 +111,62 @@ std::string Factory::getDefaultPluginPath() { return _defaultPluginPath; } +Factory::~Factory() { +#ifdef BUILD_AS_PLUGINS + pluma.unloadAll(); +#endif +} + void Factory::registerPlugins() { + /*** PLUGINS ***/ +#ifdef BUILD_AS_PLUGINS + + if (_pluginPath.length() == 0) { + // try to read USCXML_PLUGIN_PATH environment variable + _pluginPath = (getenv("USCXML_PLUGIN_PATH") != NULL ? getenv("USCXML_PLUGIN_PATH") : ""); + } + if (_pluginPath.length() > 0) { + pluma.acceptProviderType(); + pluma.acceptProviderType(); + pluma.acceptProviderType(); + pluma.acceptProviderType(); + pluma.loadFromFolder(_pluginPath, true); + + std::vector invokerProviders; + pluma.getProviders(invokerProviders); + for (auto provider : invokerProviders) { + InvokerImpl* invoker = provider->create(); + registerInvoker(invoker); + } + + std::vector ioProcessorProviders; + pluma.getProviders(ioProcessorProviders); + for (auto provider : ioProcessorProviders) { + IOProcessorImpl* ioProcessor = provider->create(); + registerIOProcessor(ioProcessor); + } + + std::vector dataModelProviders; + pluma.getProviders(dataModelProviders); + for (auto provider : dataModelProviders) { + DataModelImpl* dataModel = provider->create(); + registerDataModel(dataModel); + } + + std::vector execContentProviders; + pluma.getProviders(execContentProviders); + for (auto provider : execContentProviders) { + ExecutableContentImpl* execContent = provider->create(); + registerExecutableContent(execContent); + } + + } else { + ERROR_EXECUTION_THROW("No path to plugins known, export USCXML_PLUGIN_PATH or pass path as parameter"); + } + +#else + #ifdef WITH_IOPROC_SCXML { SCXMLIOProcessor* ioProcessor = new SCXMLIOProcessor(); @@ -150,11 +217,10 @@ void Factory::registerPlugins() { #endif { - NULLDataModel* dataModel = new NULLDataModel(); + NullDataModel* dataModel = new NullDataModel(); registerDataModel(dataModel); } - #ifdef WITH_INV_SCXML { USCXMLInvoker* invoker = new USCXMLInvoker(); @@ -169,12 +235,9 @@ void Factory::registerPlugins() { } #endif -} - -Factory::~Factory() { -#ifdef BUILD_AS_PLUGINS - pluma.unloadAll(); #endif + /*** PLUGINS ***/ + } #define LIST_COMPONENTS(type, name) \ @@ -476,6 +539,13 @@ size_t DataModelImpl::replaceExpressions(std::string& content) { Factory* Factory::getInstance() { + // this needs to be here as some plugins use xercesc + try { + ::xercesc_3_1::XMLPlatformUtils::Initialize(); + } catch (const XERCESC_NS::XMLException& toCatch) { + ERROR_PLATFORM_THROW("Cannot initialize XercesC: " + X(toCatch.getMessage()).str()); + } + if (_instance == NULL) { _instance = new Factory(Factory::_defaultPluginPath); } @@ -530,6 +600,6 @@ void InvokerImpl::eventToSCXML(Event& event, } } -Factory* Factory::_instance = NULL; std::string Factory::_defaultPluginPath; +Factory* Factory::_instance = NULL; } diff --git a/src/uscxml/plugins/Factory.h b/src/uscxml/plugins/Factory.h index 48bfae8..0026df1 100644 --- a/src/uscxml/plugins/Factory.h +++ b/src/uscxml/plugins/Factory.h @@ -92,10 +92,10 @@ protected: Factory(const std::string&); ~Factory(); - Factory* _parentFactory; + Factory* _parentFactory = NULL; std::string _pluginPath; - static Factory* _instance; static std::string _defaultPluginPath; + static Factory* _instance; }; diff --git a/src/uscxml/plugins/Plugins.cpp b/src/uscxml/plugins/Plugins.cpp new file mode 100644 index 0000000..0c9a23c --- /dev/null +++ b/src/uscxml/plugins/Plugins.cpp @@ -0,0 +1,31 @@ +/** + * @file + * @author 2012-2013 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see . + * @endcond + */ + +#include "Plugins.h" + +namespace uscxml { + +#ifdef BUILD_AS_PLUGINS +PLUMA_PROVIDER_SOURCE(DataModelImpl, 1, 1) +PLUMA_PROVIDER_SOURCE(IOProcessorImpl, 1, 1) +PLUMA_PROVIDER_SOURCE(InvokerImpl, 1, 1) +PLUMA_PROVIDER_SOURCE(ExecutableContentImpl, 1, 1) +#endif + +} diff --git a/src/uscxml/plugins/Plugins.h b/src/uscxml/plugins/Plugins.h new file mode 100644 index 0000000..eb1c9cb --- /dev/null +++ b/src/uscxml/plugins/Plugins.h @@ -0,0 +1,41 @@ +/** + * @file + * @author 2012-2013 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see . + * @endcond + */ + +#ifndef PLUGINS_H_M6G1NF1E +#define PLUGINS_H_M6G1NF1E + +#include "uscxml/config.h" +#include +#include "uscxml/plugins/DataModelImpl.h" +#include "uscxml/plugins/IOProcessorImpl.h" +#include "uscxml/plugins/InvokerImpl.h" +#include "uscxml/plugins/ExecutableContentImpl.h" + +namespace uscxml { + +#ifdef BUILD_AS_PLUGINS +PLUMA_PROVIDER_HEADER(IOProcessorImpl) +PLUMA_PROVIDER_HEADER(InvokerImpl) +PLUMA_PROVIDER_HEADER(ExecutableContentImpl) +PLUMA_PROVIDER_HEADER(DataModelImpl) +#endif + +} + +#endif /* end of include guard: PLUGINS_H_M6G1NF1E */ diff --git a/src/uscxml/plugins/datamodel/CMakeLists.txt b/src/uscxml/plugins/datamodel/CMakeLists.txt index a208856..24a1ea0 100644 --- a/src/uscxml/plugins/datamodel/CMakeLists.txt +++ b/src/uscxml/plugins/datamodel/CMakeLists.txt @@ -5,8 +5,19 @@ file(GLOB NULL_DATAMODEL null/*.cpp null/*.h ) -list (APPEND USCXML_FILES ${NULL_DATAMODEL}) - +if (BUILD_AS_PLUGINS) + source_group("Null" FILES ${NULL_DATAMODEL}) + add_library( + datamodel_null SHARED + ${NULL_DATAMODEL} + "../Plugins.cpp") + target_link_libraries(datamodel_null uscxml) + set_target_properties(datamodel_null PROPERTIES FOLDER "Plugins//DataModel") + set_target_properties(datamodel_null PROPERTIES COMPILE_FLAGS "-DPLUMA_EXPORTS") + set_target_properties(datamodel_null PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/plugins") +else() + list (APPEND USCXML_FILES ${NULL_DATAMODEL}) +endif() if (JSC_FOUND) set(USCXML_DATAMODELS "ecmascript(JSC) ${USCXML_DATAMODELS}") @@ -17,8 +28,20 @@ if (JSC_FOUND) ecmascript/*.cpp ecmascript/*.h ) - list (APPEND USCXML_FILES ${JSC_DATAMODEL}) - list (APPEND USCXML_OPT_LIBS ${JSC_LIBRARY}) + if (BUILD_AS_PLUGINS) + source_group("JavaScriptCore" FILES ${JSC_DATAMODEL}) + add_library( + datamodel_jsc SHARED + ${JSC_DATAMODEL} + "../Plugins.cpp") + target_link_libraries(datamodel_jsc uscxml ${JSC_LIBRARY}) + set_target_properties(datamodel_jsc PROPERTIES FOLDER "Plugins//DataModel") + set_target_properties(datamodel_jsc PROPERTIES COMPILE_FLAGS "-DPLUMA_EXPORTS") + set_target_properties(datamodel_jsc PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/plugins") + else() + list (APPEND USCXML_FILES ${JSC_DATAMODEL}) + list (APPEND USCXML_OPT_LIBS ${JSC_LIBRARY}) + endif() endif() @@ -31,8 +54,21 @@ if (V8_FOUND) ecmascript/*.cpp ecmascript/*.h ) - list (APPEND USCXML_FILES ${V8_DATAMODEL}) - list (APPEND USCXML_OPT_LIBS ${V8_LIBRARY}) + if (BUILD_AS_PLUGINS) + source_group("V8" FILES ${V8_DATAMODEL}) + + add_library( + datamodel_v8 SHARED + ${V8_DATAMODEL} + "../Plugins.cpp") + target_link_libraries(datamodel_v8 uscxml ${V8_LIBRARY}) + set_target_properties(datamodel_v8 PROPERTIES FOLDER "Plugins//DataModel") + set_target_properties(datamodel_v8 PROPERTIES COMPILE_FLAGS "-DPLUMA_EXPORTS") + set_target_properties(datamodel_v8 PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/plugins") + else() + list (APPEND USCXML_FILES ${V8_DATAMODEL}) + list (APPEND USCXML_OPT_LIBS ${V8_LIBRARY}) + endif() endif() @@ -43,8 +79,20 @@ if (LUA51_FOUND AND WITH_DM_LUA) lua/*.cpp lua/*.h ) - list (APPEND USCXML_FILES ${LUA_DATAMODEL}) - list (APPEND USCXML_OPT_LIBS ${LUA_LIBRARY}) + if (BUILD_AS_PLUGINS) + source_group("" FILES ${LUA_DATAMODEL}) + add_library(datamodel_lua SHARED ${LUA_DATAMODEL} "../Plugins.cpp") + target_link_libraries(datamodel_lua + uscxml + ${LUA_LIBRARIES} + ) + set_target_properties(datamodel_lua PROPERTIES FOLDER "Plugins//DataModel") + set_target_properties(datamodel_lua PROPERTIES COMPILE_FLAGS "-DPLUMA_EXPORTS") + set_target_properties(datamodel_lua PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/plugins") + else() + list (APPEND USCXML_FILES ${LUA_DATAMODEL}) + list (APPEND USCXML_OPT_LIBS ${LUA_LIBRARY}) + endif() endif() if (WITH_DM_C89) @@ -55,7 +103,18 @@ if (WITH_DM_C89) c89/*.c c89/*.h ) - list (APPEND USCXML_FILES ${C89_DATAMODEL}) + if (BUILD_AS_PLUGINS) + source_group("" FILES ${C89_DATAMODEL}) + add_library(datamodel_c89 SHARED ${C89_DATAMODEL} "../Plugins.cpp") + target_link_libraries(datamodel_c89 + uscxml + ) + set_target_properties(datamodel_c89 PROPERTIES FOLDER "Plugins//DataModel") + set_target_properties(datamodel_c89 PROPERTIES COMPILE_FLAGS "-DPLUMA_EXPORTS") + set_target_properties(datamodel_c89 PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/plugins") + else() + list (APPEND USCXML_FILES ${C89_DATAMODEL}) + endif() endif() if (WITH_DM_PROMELA) @@ -66,7 +125,22 @@ if (WITH_DM_PROMELA) promela/*.c promela/*.h ) - list (APPEND USCXML_FILES ${PROMELA_DATAMODEL}) + if (BUILD_AS_PLUGINS) + source_group("" FILES ${PROMELA_DATAMODEL}) + add_library(datamodel_promela SHARED ${PROMELA_DATAMODEL} "../Plugins.cpp") + target_link_libraries(datamodel_promela + uscxml + ) + # SET_SOURCE_FILES_PROPERTIES is directory scope + if (${CMAKE_CXX_COMPILER_ID} STREQUAL Clang) + SET_SOURCE_FILES_PROPERTIES(promela/parser/promela.lex.yy.cpp PROPERTIES COMPILE_FLAGS -Wno-deprecated-register ) + endif() + set_target_properties(datamodel_promela PROPERTIES FOLDER "Plugins//DataModel") + set_target_properties(datamodel_promela PROPERTIES COMPILE_FLAGS "-DPLUMA_EXPORTS") + set_target_properties(datamodel_promela PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/plugins") + else() + list (APPEND USCXML_FILES ${PROMELA_DATAMODEL}) + endif() endif() if (NOT SWIG_FOUND) diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp index 5ce6128..66bf45a 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp @@ -22,7 +22,6 @@ #include "uscxml/util/String.h" #include "JSCDataModel.h" -//#include "JSCSCXMLEvent.h" #include "uscxml/messages/Event.h" #include "uscxml/util/DOM.h" @@ -32,6 +31,10 @@ #include #include +#ifdef BUILD_AS_PLUGINS +#include +#endif + #define EVENT_STRING_OR_UNDEF(field, cond) \ JSStringRef field##Name = JSStringCreateWithUTF8CString( #field ); \ JSStringRef field##Val = JSStringCreateWithUTF8CString(event.field.c_str()); \ @@ -193,7 +196,7 @@ bool JSCNodeListHasPropertyCallback(JSContextRef ctx, JSObjectRef object, JSStri return false; } - int index = strTo(propName); + size_t index = strTo(propName); SwigPrivData* t = (SwigPrivData*) JSObjectGetPrivate(object); DOMNodeList* nodeList = (DOMNodeList*)t->swigCObject; @@ -216,7 +219,7 @@ JSValueRef JSCNodeListGetPropertyCallback(JSContextRef context, JSObjectRef obje return JSValueMakeUndefined(context); } - int index = strTo(propName); + size_t index = strTo(propName); SwigPrivData* t = (SwigPrivData*) JSObjectGetPrivate(object); DOMNodeList* nodeList = (DOMNodeList*)t->swigCObject; @@ -316,7 +319,7 @@ void JSCDataModel::setEvent(const Event& event) { case Event::INTERNAL: eventTypeVal = JSStringCreateWithUTF8CString("internal"); break; - case Event::PLATFORM: + default: eventTypeVal = JSStringCreateWithUTF8CString("platform"); break; } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h index 3a53da2..cd992ea 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h @@ -126,7 +126,7 @@ protected: }; #ifdef BUILD_AS_PLUGINS -PLUMA_INHERIT_PROVIDER(JSCDataModel, DataModelImpl); +PLUMA_INHERIT_PROVIDER(JSCDataModel, DataModelImpl) #endif } diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp index 61eb815..84cfa81 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp @@ -35,6 +35,10 @@ #include +#ifdef BUILD_AS_PLUGINS +#include +#endif + using namespace XERCESC_NS; static v8::Local XMLString2JS(const XMLCh* input) { @@ -56,6 +60,14 @@ static XMLCh* JS2XMLString(const v8::Local& value) { namespace uscxml { +#ifdef BUILD_AS_PLUGINS +PLUMA_CONNECTOR +bool pluginConnect(pluma::Host& host) { + host.add( new V8DataModelProvider() ); + return true; +} +#endif + V8DataModel::V8DataModel() { // _contexts.push_back(v8::Context::New()); } diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h index a9dbca1..00a871b 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h @@ -20,6 +20,7 @@ #ifndef V8DATAMODEL_H_KN8TWG0V #define V8DATAMODEL_H_KN8TWG0V +#include "uscxml/config.h" #include "uscxml/plugins/DataModelImpl.h" #include diff --git a/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp b/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp index fccc5f0..607f994 100644 --- a/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp +++ b/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp @@ -42,8 +42,20 @@ //#include "LuaDOM.cpp.inc" +#ifdef BUILD_AS_PLUGINS +#include +#endif + namespace uscxml { +#ifdef BUILD_AS_PLUGINS +PLUMA_CONNECTOR +bool pluginConnect(pluma::Host& host) { + host.add( new LuaDataModelProvider() ); + return true; +} +#endif + //static int luaInspect(lua_State * l) { // return 0; //} @@ -194,20 +206,23 @@ int LuaDataModel::luaInFunction(lua_State * l) { std::shared_ptr LuaDataModel::create(DataModelCallbacks* callbacks) { std::shared_ptr dm(new LuaDataModel()); + dm->_callbacks = callbacks; dm->_luaState = luaL_newstate(); luaL_openlibs(dm->_luaState); try { const luabridge::LuaRef& requireFunc = luabridge::getGlobal(dm->_luaState, "require"); - const luabridge::LuaRef& resultLxp = requireFunc("lxp"); - const luabridge::LuaRef& resultLxpLOM = requireFunc("lxp.lom"); - - // MSVC compiler bug with implicit cast operators, see comments in LuaRef class - if ((bool)resultLxp && (bool)resultLxpLOM) { - _luaHasXMLParser = true; - luabridge::setGlobal(dm->_luaState, resultLxp, "lxp"); - luabridge::setGlobal(dm->_luaState, resultLxpLOM, "lxp.lom"); + if (requireFunc.isFunction()) { + const luabridge::LuaRef& resultLxp = requireFunc("lxp"); + const luabridge::LuaRef& resultLxpLOM = requireFunc("lxp.lom"); + + // MSVC compiler bug with implicit cast operators, see comments in LuaRef class + if ((bool)resultLxp && (bool)resultLxpLOM) { + _luaHasXMLParser = true; + luabridge::setGlobal(dm->_luaState, resultLxp, "lxp"); + luabridge::setGlobal(dm->_luaState, resultLxpLOM, "lxp.lom"); + } } } catch (luabridge::LuaException e) { LOG(_callbacks->getLogger(), USCXML_INFO) << e.what(); diff --git a/src/uscxml/plugins/datamodel/lua/LuaDataModel.h b/src/uscxml/plugins/datamodel/lua/LuaDataModel.h index 85d7b53..ad86872 100644 --- a/src/uscxml/plugins/datamodel/lua/LuaDataModel.h +++ b/src/uscxml/plugins/datamodel/lua/LuaDataModel.h @@ -20,6 +20,7 @@ #ifndef LUADATAMODEL_H_113E014C #define LUADATAMODEL_H_113E014C +#include "uscxml/config.h" #include "uscxml/plugins/DataModelImpl.h" #include @@ -92,7 +93,7 @@ protected: }; #ifdef BUILD_AS_PLUGINS -PLUMA_INHERIT_PROVIDER(LuaDataModel, DataModelImpl); +PLUMA_INHERIT_PROVIDER(LuaDataModel, DataModelImpl) #endif } diff --git a/src/uscxml/plugins/datamodel/null/NULLDataModel.cpp b/src/uscxml/plugins/datamodel/null/NULLDataModel.cpp index 53c414f..efa77fa 100644 --- a/src/uscxml/plugins/datamodel/null/NULLDataModel.cpp +++ b/src/uscxml/plugins/datamodel/null/NULLDataModel.cpp @@ -20,7 +20,7 @@ #include #include "uscxml/Common.h" -#include "NULLDataModel.h" +#include "NullDataModel.h" #include "uscxml/util/DOM.h" #ifdef BUILD_AS_PLUGINS @@ -32,24 +32,24 @@ namespace uscxml { #ifdef BUILD_AS_PLUGINS PLUMA_CONNECTOR bool pluginConnect(pluma::Host& host) { - host.add( new NULLDataModelProvider() ); + host.add( new NullDataModelProvider() ); return true; } #endif -NULLDataModel::NULLDataModel() { +NullDataModel::NullDataModel() { } -std::shared_ptr NULLDataModel::create(DataModelCallbacks* callbacks) { - std::shared_ptr dm(new NULLDataModel()); +std::shared_ptr NullDataModel::create(DataModelCallbacks* callbacks) { + std::shared_ptr dm(new NullDataModel()); dm->_callbacks = callbacks; return dm; } -NULLDataModel::~NULLDataModel() { +NullDataModel::~NullDataModel() { } -Data NULLDataModel::getAsData(const std::string& content) { +Data NullDataModel::getAsData(const std::string& content) { Data data = Data::fromJSON(content); if (data.empty()) { data = Data(content, Data::VERBATIM); @@ -63,7 +63,7 @@ Data NULLDataModel::getAsData(const std::string& content) { * The predicate must return 'true' if and only if that state is in the current * state configuration. */ -bool NULLDataModel::evalAsBool(const XERCESC_NS::DOMElement* scriptNode, const std::string& expr) { +bool NullDataModel::evalAsBool(const XERCESC_NS::DOMElement* scriptNode, const std::string& expr) { std::string trimmedExpr = expr; boost::trim(trimmedExpr); if (!boost::istarts_with(trimmedExpr, "in")) @@ -105,4 +105,4 @@ bool NULLDataModel::evalAsBool(const XERCESC_NS::DOMElement* scriptNode, const s return true; } -} \ No newline at end of file +} diff --git a/src/uscxml/plugins/datamodel/null/NULLDataModel.h b/src/uscxml/plugins/datamodel/null/NULLDataModel.h index fba8577..8c9f5b9 100644 --- a/src/uscxml/plugins/datamodel/null/NULLDataModel.h +++ b/src/uscxml/plugins/datamodel/null/NULLDataModel.h @@ -20,6 +20,7 @@ #ifndef NULLDATAMODEL_H_KN8TWG0V #define NULLDATAMODEL_H_KN8TWG0V +#include "uscxml/config.h" #include "uscxml/plugins/DataModelImpl.h" #include @@ -38,10 +39,10 @@ namespace uscxml { * @ingroup datamodel * NULL data-model. */ -class NULLDataModel : public DataModelImpl { +class NullDataModel : public DataModelImpl { public: - NULLDataModel(); - virtual ~NULLDataModel(); + NullDataModel(); + virtual ~NullDataModel(); virtual std::shared_ptr create(DataModelCallbacks* callbacks); virtual std::list getNames() { @@ -104,7 +105,7 @@ protected: }; #ifdef BUILD_AS_PLUGINS -PLUMA_INHERIT_PROVIDER(NULLDataModel, DataModelImpl); +PLUMA_INHERIT_PROVIDER(NullDataModel, DataModelImpl) #endif } diff --git a/src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp b/src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp index 14d24c3..5adf337 100644 --- a/src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp +++ b/src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp @@ -17,15 +17,13 @@ * @endcond */ -#include - #include "uscxml/Common.h" -#include "uscxml/config.h" #include "uscxml/util/String.h" #include "PromelaDataModel.h" #include "uscxml/util/DOM.h" #include +#include #include "PromelaParser.h" #include "parser/promela.tab.hpp" @@ -337,7 +335,7 @@ void PromelaDataModel::setEvent(const Event& event) { int size = dataToInt(evaluateExpr(*opIterAsgn++)); variable.compound["size"] = Data(size); - for (size_t i = 0; i < size; i++) { + for (int i = 0; i < size; i++) { variable.compound["value"].array.push_back(Data(0, Data::INTERPRETED)); } diff --git a/src/uscxml/plugins/datamodel/promela/PromelaDataModel.h b/src/uscxml/plugins/datamodel/promela/PromelaDataModel.h index 4a763ac..f19bd5d 100644 --- a/src/uscxml/plugins/datamodel/promela/PromelaDataModel.h +++ b/src/uscxml/plugins/datamodel/promela/PromelaDataModel.h @@ -20,6 +20,7 @@ #ifndef PROMELADATAMODEL_H_4VG0TDMU #define PROMELADATAMODEL_H_4VG0TDMU +#include "uscxml/config.h" #include "uscxml/plugins/DataModelImpl.h" #include @@ -96,7 +97,7 @@ protected: }; #ifdef BUILD_AS_PLUGINS -PLUMA_INHERIT_PROVIDER(PromelaDataModel, DataModelImpl); +PLUMA_INHERIT_PROVIDER(PromelaDataModel, DataModelImpl) #endif } diff --git a/src/uscxml/plugins/datamodel/promela/PromelaParser.cpp b/src/uscxml/plugins/datamodel/promela/PromelaParser.cpp index 57f694a..44f8bdd 100644 --- a/src/uscxml/plugins/datamodel/promela/PromelaParser.cpp +++ b/src/uscxml/plugins/datamodel/promela/PromelaParser.cpp @@ -43,7 +43,7 @@ void promela_error (void* yylloc_param, uscxml::PromelaParser* ctx, void* yyscan excEvent.data.compound["col"] = uscxml::Data(yylloc->first_column, uscxml::Data::VERBATIM); std::stringstream ssUnderline; - for (size_t i = 0; i < yylloc->first_column; i++) + for (int i = 0; i < yylloc->first_column; i++) ssUnderline << " "; ssUnderline << "^"; excEvent.data.compound["sourcemark"] = uscxml::Data(ssUnderline.str(), uscxml::Data::VERBATIM); @@ -196,7 +196,7 @@ void PromelaParserNode::push(PromelaParserNode* node) { operands.push_back(node); } -void PromelaParserNode::dump(int indent) { +void PromelaParserNode::dump(size_t indent) { std::string padding; for (size_t i = 0; i < indent; i++) { padding += " "; diff --git a/src/uscxml/plugins/datamodel/promela/PromelaParser.h b/src/uscxml/plugins/datamodel/promela/PromelaParser.h index 236233d..45ea341 100644 --- a/src/uscxml/plugins/datamodel/promela/PromelaParser.h +++ b/src/uscxml/plugins/datamodel/promela/PromelaParser.h @@ -48,7 +48,7 @@ public: void merge(PromelaParserNode* node); void push(PromelaParserNode* node); - void dump(int indent = 0); + void dump(size_t indent = 0); static std::string typeToDesc(int type); diff --git a/src/uscxml/plugins/invoker/CMakeLists.txt b/src/uscxml/plugins/invoker/CMakeLists.txt index 5500e3f..9f50684 100644 --- a/src/uscxml/plugins/invoker/CMakeLists.txt +++ b/src/uscxml/plugins/invoker/CMakeLists.txt @@ -6,7 +6,18 @@ if (WITH_INV_SCXML) file(GLOB_RECURSE USCXML_INVOKER scxml/*.cpp scxml/*.h) + if (BUILD_AS_PLUGINS) + source_group("" FILES ${USCXML_INVOKER}) + add_library(invoker_uscxml SHARED ${USCXML_INVOKER} "../Plugins.cpp") + target_link_libraries(invoker_uscxml + uscxml + ) + set_target_properties(invoker_uscxml PROPERTIES FOLDER "Plugins//Invoker") + set_target_properties(invoker_uscxml PROPERTIES COMPILE_FLAGS "-DPLUMA_EXPORTS") + set_target_properties(invoker_uscxml PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/plugins") + else() list (APPEND USCXML_FILES ${USCXML_INVOKER}) + endif() endif() # Directoy Monitor @@ -17,7 +28,18 @@ if (WITH_INV_DIRMON) file(GLOB_RECURSE DIRMON_INVOKER dirmon/*.cpp dirmon/*.h) + if (BUILD_AS_PLUGINS) + source_group("" FILES ${DIRMON_INVOKER}) + add_library(invoker_dirmon SHARED ${DIRMON_INVOKER} "../Plugins.cpp") + target_link_libraries(invoker_dirmon + uscxml + ) + set_target_properties(invoker_dirmon PROPERTIES FOLDER "Plugins//Invoker") + set_target_properties(invoker_dirmon PROPERTIES COMPILE_FLAGS "-DPLUMA_EXPORTS") + set_target_properties(invoker_dirmon PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/plugins") + else() list (APPEND USCXML_FILES ${DIRMON_INVOKER}) + endif() endif() set(USCXML_INCLUDE_DIRS ${USCXML_INCLUDE_DIRS} PARENT_SCOPE) diff --git a/src/uscxml/plugins/invoker/dirmon/DirMonInvoker.cpp b/src/uscxml/plugins/invoker/dirmon/DirMonInvoker.cpp index be13bf4..e9cf702 100644 --- a/src/uscxml/plugins/invoker/dirmon/DirMonInvoker.cpp +++ b/src/uscxml/plugins/invoker/dirmon/DirMonInvoker.cpp @@ -19,8 +19,6 @@ #include "DirMonInvoker.h" -#include "uscxml/config.h" - #ifdef BUILD_AS_PLUGINS #include #endif @@ -62,7 +60,7 @@ DirMonInvoker::~DirMonInvoker() { } if (_watcher) delete(_watcher); -}; +} std::shared_ptr DirMonInvoker::create(InvokerCallbacks* callbacks) { std::shared_ptr invoker(new DirMonInvoker()); diff --git a/src/uscxml/plugins/invoker/dirmon/DirMonInvoker.h b/src/uscxml/plugins/invoker/dirmon/DirMonInvoker.h index dffbe14..6d9911f 100644 --- a/src/uscxml/plugins/invoker/dirmon/DirMonInvoker.h +++ b/src/uscxml/plugins/invoker/dirmon/DirMonInvoker.h @@ -20,6 +20,7 @@ #ifndef DIRMONINVOKER_H_W09J90F0 #define DIRMONINVOKER_H_W09J90F0 +#include "uscxml/config.h" #include "uscxml/plugins/InvokerImpl.h" #include "uscxml/interpreter/Logging.h" @@ -139,7 +140,7 @@ protected: }; #ifdef BUILD_AS_PLUGINS -PLUMA_INHERIT_PROVIDER(DirMonInvoker, InvokerImpl); +PLUMA_INHERIT_PROVIDER(DirMonInvoker, InvokerImpl) #endif } diff --git a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp index b035993..d3bc5bf 100644 --- a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp +++ b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp @@ -19,8 +19,6 @@ #include "USCXMLInvoker.h" -#include "uscxml/config.h" - #ifdef BUILD_AS_PLUGINS #include #endif @@ -52,7 +50,7 @@ USCXMLInvoker::USCXMLInvoker() { USCXMLInvoker::~USCXMLInvoker() { stop(); -}; +} void USCXMLInvoker::start() { _isStarted = true; @@ -184,7 +182,7 @@ void USCXMLInvoker::invoke(const std::string& source, const Event& invokeEvent) InterpreterImpl* invoked = _invokedInterpreter.getImpl().get(); ActionLanguage al = _callbacks->getActionLanguage(); - // create new instances + // create new instances al.execContent = al.execContent.getImpl()->create(invoked); al.delayQueue = al.delayQueue.getImplDelayed()->create(invoked); al.internalQueue = al.internalQueue.getImplBase()->create(); diff --git a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h index d37d2af..61931c6 100644 --- a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h +++ b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h @@ -20,6 +20,7 @@ #ifndef USCXMLINVOKER_H_OQFA21IO #define USCXMLINVOKER_H_OQFA21IO +#include "uscxml/config.h" #include "uscxml/interpreter/InterpreterImpl.h" #include "uscxml/interpreter/BasicEventQueue.h" @@ -88,7 +89,7 @@ protected: }; #ifdef BUILD_AS_PLUGINS -PLUMA_INHERIT_PROVIDER(USCXMLInvoker, InvokerImpl); +PLUMA_INHERIT_PROVIDER(USCXMLInvoker, InvokerImpl) #endif } diff --git a/src/uscxml/plugins/ioprocessor/CMakeLists.txt b/src/uscxml/plugins/ioprocessor/CMakeLists.txt index 3505920..fb4315b 100644 --- a/src/uscxml/plugins/ioprocessor/CMakeLists.txt +++ b/src/uscxml/plugins/ioprocessor/CMakeLists.txt @@ -7,7 +7,18 @@ if (WITH_IOPROC_SCXML) scxml/*.cpp scxml/*.h ) - list (APPEND USCXML_FILES ${SCXML_IOPROCESSOR}) + if (BUILD_AS_PLUGINS) + source_group("" FILES ${SCXML_IOPROCESSOR}) + add_library(ioproc_scxml SHARED ${SCXML_IOPROCESSOR} "../Plugins.cpp") + target_link_libraries(ioproc_scxml + uscxml + ) + set_target_properties(ioproc_scxml PROPERTIES FOLDER "Plugins//IO Processors") + set_target_properties(ioproc_scxml PROPERTIES COMPILE_FLAGS "-DPLUMA_EXPORTS") + set_target_properties(ioproc_scxml PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/plugins") + else() + list (APPEND USCXML_FILES ${SCXML_IOPROCESSOR}) + endif() endif() OPTION(WITH_IOPROC_BASICHTTP "Build the basichttp i/o processor" ON) @@ -17,8 +28,18 @@ if (WITH_IOPROC_BASICHTTP) basichttp/*.cpp basichttp/*.h ) - list (APPEND BASICHTTP_IOPROCESSOR "") - list (APPEND USCXML_FILES ${BASICHTTP_IOPROCESSOR}) + if (BUILD_AS_PLUGINS) + source_group("" FILES ${BASICHTTP_IOPROCESSOR}) + add_library(ioproc_basichttp SHARED ${BASICHTTP_IOPROCESSOR} "../Plugins.cpp") + target_link_libraries(ioproc_basichttp + uscxml + ) + set_target_properties(ioproc_basichttp PROPERTIES FOLDER "Plugins//IO Processors") + set_target_properties(ioproc_basichttp PROPERTIES COMPILE_FLAGS "-DPLUMA_EXPORTS") + set_target_properties(ioproc_basichttp PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/plugins") + else() + list (APPEND USCXML_FILES ${BASICHTTP_IOPROCESSOR}) + endif() endif() set(USCXML_INCLUDE_DIRS ${USCXML_INCLUDE_DIRS} PARENT_SCOPE) diff --git a/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.h b/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.h index dec22fe..5ec66ec 100644 --- a/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.h +++ b/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.h @@ -20,6 +20,8 @@ #ifndef BASICHTTPIOPROCESSOR_H_2CUY93KU #define BASICHTTPIOPROCESSOR_H_2CUY93KU +#include "uscxml/config.h" + extern "C" { #include #include @@ -93,11 +95,8 @@ protected: std::map > _sendRequests; }; -// do not implement pluma plugins if we build an inherited plugin -#ifdef ioprocessor_basichttp_EXPORTS -# ifdef BUILD_AS_PLUGINS -PLUMA_INHERIT_PROVIDER(BasicHTTPIOProcessor, IOProcessorImpl); -# endif +#ifdef BUILD_AS_PLUGINS +PLUMA_INHERIT_PROVIDER(BasicHTTPIOProcessor, IOProcessorImpl) #endif } diff --git a/src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.cpp b/src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.cpp index 5a82860..33a725e 100644 --- a/src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.cpp +++ b/src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.cpp @@ -30,8 +30,20 @@ #include #endif +#ifdef BUILD_AS_PLUGINS +#include +#endif + namespace uscxml { +#ifdef BUILD_AS_PLUGINS +PLUMA_CONNECTOR +bool pluginConnect(pluma::Host& host) { + host.add( new SCXMLIOProcessorProvider() ); + return true; +} +#endif + // see http://www.w3.org/TR/scxml/#SCXMLEventProcessor SCXMLIOProcessor::SCXMLIOProcessor() { diff --git a/src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.h b/src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.h index 6494873..328e18e 100644 --- a/src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.h +++ b/src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.h @@ -20,8 +20,13 @@ #ifndef SCXMLIOProcessor_H_2CUY93KU #define SCXMLIOProcessor_H_2CUY93KU +#include "uscxml/config.h" #include "uscxml/plugins/IOProcessorImpl.h" +#ifdef BUILD_AS_PLUGINS +#include "uscxml/plugins/Plugins.h" +#endif + namespace uscxml { /** @@ -45,12 +50,10 @@ public: virtual bool isValidTarget(const std::string& target); Data getDataModelVariables(); -protected: - IOProcessorCallbacks* _callbacks; }; #ifdef BUILD_AS_PLUGINS -PLUMA_INHERIT_PROVIDER(SCXMLIOProcessor, IOProcessorImpl); +PLUMA_INHERIT_PROVIDER(SCXMLIOProcessor, IOProcessorImpl) #endif } diff --git a/src/uscxml/transform/ChartToC.cpp b/src/uscxml/transform/ChartToC.cpp index 932ac73..7deef17 100644 --- a/src/uscxml/transform/ChartToC.cpp +++ b/src/uscxml/transform/ChartToC.cpp @@ -309,7 +309,18 @@ void ChartToC::prepare() { } // set transitions' postfix order attribute - tmp = DOMUtils::inPostFixOrder({ XML_PREFIX(_scxml).str() + "transition" }, _scxml); +// tmp = DOMUtils::inPostFixOrder({ XML_PREFIX(_scxml).str() + "transition" }, _scxml); + + tmp = DOMUtils::inPostFixOrder({ + XML_PREFIX(_scxml).str() + "scxml", + XML_PREFIX(_scxml).str() + "state", + XML_PREFIX(_scxml).str() + "final", + XML_PREFIX(_scxml).str() + "history", + XML_PREFIX(_scxml).str() + "initial", + XML_PREFIX(_scxml).str() + "parallel" + }, _scxml); + tmp = DOMUtils::filterChildElements(XML_PREFIX(_scxml).str() + "transition", tmp); + _transitions.insert(_transitions.end(), tmp.begin(), tmp.end()); for (size_t i = 0; i < _transitions.size(); i++) { diff --git a/src/uscxml/transform/ChartToPromela.cpp b/src/uscxml/transform/ChartToPromela.cpp index ec11a76..7b1c327 100644 --- a/src/uscxml/transform/ChartToPromela.cpp +++ b/src/uscxml/transform/ChartToPromela.cpp @@ -816,7 +816,7 @@ void ChartToPromela::writeTransitions(std::ostream& stream) { if (HAS_ATTR(transition, "conflictBools")) { std::string conflicts = ATTR(transition, "conflictBools"); - for (auto j = 0; j < conflicts.size(); j++) { + for (size_t j = 0; j < conflicts.size(); j++) { if (conflicts[j] == '1') stream << " " << _prefix << "transitions[" << toStr(i) << "].conflicts[" << toStr(j) << "] = 1;" << std::endl; } @@ -824,7 +824,7 @@ void ChartToPromela::writeTransitions(std::ostream& stream) { if (HAS_ATTR(transition, "exitSetBools")) { std::string exitSet = ATTR(transition, "exitSetBools"); - for (auto j = 0; j < exitSet.size(); j++) { + for (size_t j = 0; j < exitSet.size(); j++) { if (exitSet[j] == '1') stream << " " << _prefix << "transitions[" << toStr(i) << "].exit_set[" << toStr(j) << "] = 1;" << std::endl; } @@ -848,7 +848,7 @@ void ChartToPromela::writeStates(std::ostream& stream) { if (HAS_ATTR(state, "childBools")) { std::string childs = ATTR(state, "childBools"); - for (auto j = 0; j < childs.size(); j++) { + for (size_t j = 0; j < childs.size(); j++) { if (childs[j] == '1') stream << " " << _prefix << "states[" << toStr(i) << "].children[" << toStr(j) << "] = 1;" << std::endl; } @@ -856,7 +856,7 @@ void ChartToPromela::writeStates(std::ostream& stream) { if (HAS_ATTR(state, "completionBools")) { std::string completions = ATTR(state, "completionBools"); - for (auto j = 0; j < completions.size(); j++) { + for (size_t j = 0; j < completions.size(); j++) { if (completions[j] == '1') stream << " " << _prefix << "states[" << toStr(i) << "].completion[" << toStr(j) << "] = 1;" << std::endl; } @@ -864,7 +864,7 @@ void ChartToPromela::writeStates(std::ostream& stream) { if (HAS_ATTR(state, "ancBools")) { std::string ancestors = ATTR(state, "ancBools"); - for (auto j = 0; j < ancestors.size(); j++) { + for (size_t j = 0; j < ancestors.size(); j++) { if (ancestors[j] == '1') stream << " " << _prefix << "states[" << toStr(i) << "].ancestors[" << toStr(j) << "] = 1;" << std::endl; } @@ -1849,7 +1849,7 @@ void ChartToPromela::writeFSMSelectTransitions(std::ostream& stream) { stream << " (false " << std::endl; - for (auto i = 0; i < _transitions.size(); i++) { + for (size_t i = 0; i < _transitions.size(); i++) { stream << " || (i == " << toStr(i); if (HAS_ATTR(_transitions[i], "event") && ATTR(_transitions[i], "event") != "*") { stream << " && (false"; @@ -2333,7 +2333,7 @@ void ChartToPromela::writeFSMExitStates(std::ostream& stream) { TRACE_EXECUTION_V("Exiting state %d", "i"); stream << " if" << std::endl; - for (auto i = 0; i < _states.size(); i++) { + for (size_t i = 0; i < _states.size(); i++) { std::list onexits = DOMUtils::filterChildElements(XML_PREFIX(_states[i]).str() + "onexit" , _states[i]); if (onexits.size() > 0) { stream << " :: i == " << toStr(i) << " -> {" << std::endl; @@ -2374,7 +2374,7 @@ void ChartToPromela::writeFSMTakeTransitions(std::ostream& stream) { TRACE_EXECUTION_V("Taking transition %d", "i"); stream << " if" << std::endl; - for (auto i = 0; i < _transitions.size(); i++) { + for (size_t i = 0; i < _transitions.size(); i++) { stream << " :: i == " << toStr(i) << " -> {" << std::endl; TRACE_EXECUTION_V("Processing executable content for transition %d", "i"); writeExecContent(stream, _transitions[i], 4); @@ -2428,7 +2428,7 @@ void ChartToPromela::writeFSMEnterStates(std::ostream& stream) { stream << " /* Process executable content for entering a state */" << std::endl; stream << " if" << std::endl; - for (auto i = 0; i < _states.size(); i++) { + for (size_t i = 0; i < _states.size(); i++) { std::list onentries = DOMUtils::filterChildElements(XML_PREFIX(_states[i]).str() + "onentry" , _states[i]); if (onentries.size() > 0) { stream << " :: i == " << toStr(i) << " -> {" << std::endl; @@ -2454,7 +2454,7 @@ void ChartToPromela::writeFSMEnterStates(std::ostream& stream) { stream << " " << _prefix << "states[" << _prefix << "transitions[j].source].parent == i) -> {" << std::endl; stream << " /* Call executable content in history or initial transition */" << std::endl; stream << " if" << std::endl; - for (auto i = 0; i < _transitions.size(); i++) { + for (size_t i = 0; i < _transitions.size(); i++) { stream << " :: j == " << toStr(i) << " -> {" << std::endl; TRACE_EXECUTION_V("Processing executable content for transition %d", "j"); @@ -2642,7 +2642,7 @@ void ChartToPromela::writeFSMTerminateMachine(std::ostream& stream) { stream << " :: " << _prefix << "config[i] && " << _prefix << "flags[USCXML_CTX_TOP_LEVEL_FINAL] -> {" << std::endl; stream << " /* call all on exit handlers */" << std::endl; stream << " if" << std::endl; - for (auto i = 0; i < _states.size(); i++) { + for (size_t i = 0; i < _states.size(); i++) { std::list onentries = DOMUtils::filterChildElements(XML_PREFIX(_states[i]).str() + "onexit" , _states[i]); if (onentries.size() > 0) { stream << " :: i == " << toStr(i) << " -> {" << std::endl; @@ -2884,7 +2884,7 @@ std::string ChartToPromela::declForRange(const std::string& identifier, long min } } -void ChartToPromela::writeDetermineShortestDelay(std::ostream& stream, int indent) { +void ChartToPromela::writeDetermineShortestDelay(std::ostream& stream, size_t indent) { std::string padding; for (size_t i = 0; i < indent; i++) { padding += " "; @@ -2905,7 +2905,7 @@ void ChartToPromela::writeDetermineShortestDelay(std::ostream& stream, int inden stream << padding << "}" << std::endl; } -void ChartToPromela::writeScheduleMachines(std::ostream& stream, int indent) { +void ChartToPromela::writeScheduleMachines(std::ostream& stream, size_t indent) { std::string padding; for (size_t i = 0; i < indent; i++) { padding += " "; @@ -2963,7 +2963,7 @@ void ChartToPromela::writeScheduleMachines(std::ostream& stream, int indent) { stream << padding << "}" << std::endl; } -void ChartToPromela::writeAdvanceTime(std::ostream& stream, int indent) { +void ChartToPromela::writeAdvanceTime(std::ostream& stream, size_t indent) { std::string padding; for (size_t i = 0; i < indent; i++) { padding += " "; @@ -2986,7 +2986,7 @@ void ChartToPromela::writeAdvanceTime(std::ostream& stream, int indent) { stream << padding << "}" << std::endl; } -void ChartToPromela::writeInsertWithDelay(std::ostream& stream, int indent) { +void ChartToPromela::writeInsertWithDelay(std::ostream& stream, size_t indent) { std::string padding; for (size_t i = 0; i < indent; i++) { padding += " "; @@ -3089,7 +3089,7 @@ void ChartToPromela::writeInsertWithDelay(std::ostream& stream, int indent) { stream << padding << "}" << std::endl; } -void ChartToPromela::writeRescheduleProcess(std::ostream& stream, int indent) { +void ChartToPromela::writeRescheduleProcess(std::ostream& stream, size_t indent) { std::string padding; for (size_t i = 0; i < indent; i++) { padding += " "; @@ -3133,7 +3133,7 @@ void ChartToPromela::writeRescheduleProcess(std::ostream& stream, int indent) { stream << padding << "}" << std::endl; } -void ChartToPromela::writeCancelEvents(std::ostream& stream, int indent) { +void ChartToPromela::writeCancelEvents(std::ostream& stream, size_t indent) { std::list queues; queues.push_back("eQ"); if (_allowEventInterleaving) @@ -3166,7 +3166,7 @@ void ChartToPromela::writeCancelEvents(std::ostream& stream, int indent) { stream << "}" << std::endl; } -void ChartToPromela::writeRemovePendingEventsFromInvoker(std::ostream& stream, int indent) { +void ChartToPromela::writeRemovePendingEventsFromInvoker(std::ostream& stream, size_t indent) { std::list queues; queues.push_back("eQ"); if (_allowEventInterleaving) diff --git a/src/uscxml/transform/ChartToPromela.h b/src/uscxml/transform/ChartToPromela.h index d846e03..ead0ef0 100644 --- a/src/uscxml/transform/ChartToPromela.h +++ b/src/uscxml/transform/ChartToPromela.h @@ -72,13 +72,13 @@ protected: void writeStrings(std::ostream& stream); - void writeCancelEvents(std::ostream& stream, int indent = 0); - void writeScheduleMachines(std::ostream& stream, int indent = 0); - void writeDetermineShortestDelay(std::ostream& stream, int indent = 0); - void writeRescheduleProcess(std::ostream& stream, int indent = 0); - void writeInsertWithDelay(std::ostream& stream, int indent = 0); - void writeAdvanceTime(std::ostream& stream, int indent = 0); - void writeRemovePendingEventsFromInvoker(std::ostream& stream, int indent = 0); + void writeCancelEvents(std::ostream& stream, size_t indent = 0); + void writeScheduleMachines(std::ostream& stream, size_t indent = 0); + void writeDetermineShortestDelay(std::ostream& stream, size_t indent = 0); + void writeRescheduleProcess(std::ostream& stream, size_t indent = 0); + void writeInsertWithDelay(std::ostream& stream, size_t indent = 0); + void writeAdvanceTime(std::ostream& stream, size_t indent = 0); + void writeRemovePendingEventsFromInvoker(std::ostream& stream, size_t indent = 0); void prepare(); diff --git a/src/uscxml/transform/ChartToVHDL.cpp b/src/uscxml/transform/ChartToVHDL.cpp index 0a344c8..578b310 100644 --- a/src/uscxml/transform/ChartToVHDL.cpp +++ b/src/uscxml/transform/ChartToVHDL.cpp @@ -766,13 +766,13 @@ void ChartToVHDL::writeEventController(std::ostream &stream) { stream << "signal event_bus : std_logic_vector( " << _eventBitSize << " downto 0);" << std::endl; stream << "signal event_we : std_logic;" << std::endl; - for (int i = 0; i < _execContent.size(); i++) { + for (size_t i = 0; i < _execContent.size(); i++) { stream << "signal done_" << toStr(i) << "_sig : std_logic;" << std::endl; stream << "signal start_" << toStr(i) << "_sig : std_logic;" << std::endl; } stream << "-- sequence input line" << std::endl; - for (int i = 0; i < _execContent.size(); i++) { + for (size_t i = 0; i < _execContent.size(); i++) { stream << "signal seq_" << toStr(i) << "_sig : std_logic;" << std::endl; } stream << std::endl; @@ -838,7 +838,7 @@ void ChartToVHDL::writeEventController(std::ostream &stream) { stream << "ex_content_block : process (clk, rst) " << std::endl; stream << "begin" << std::endl; stream << " if rst = '1' then" << std::endl; - for (int i = 0; i < _execContent.size(); i++) { + for (size_t i = 0; i < _execContent.size(); i++) { stream << " done_" << toStr(i) << "_sig <= '0';" << std::endl; } stream << " event_bus <= (others => '0');" << std::endl; @@ -981,7 +981,7 @@ void ChartToVHDL::writeConditionSolver(std::ostream &stream) { stream << "signal rst : std_logic;" << std::endl; stream << "signal micro_stepper_en : std_logic;" << std::endl; - for (int i = 0; i < _execContent.size(); i++) { + for (size_t i = 0; i < _execContent.size(); i++) { stream << "signal done_" << toStr(i) << "_sig : std_logic;" << std::endl; stream << "signal start_" << toStr(i) << "_sig : std_logic;" << std::endl; } diff --git a/src/uscxml/transform/Trie.cpp b/src/uscxml/transform/Trie.cpp index 8e3aff3..9966931 100644 --- a/src/uscxml/transform/Trie.cpp +++ b/src/uscxml/transform/Trie.cpp @@ -146,7 +146,7 @@ std::list Trie::getChildsWithWords(TrieNode* node) { return nodes; } -void TrieNode::dump(int indent) { +void TrieNode::dump(size_t indent) { std::string padding; for (size_t i = 0; i < indent; i++) { padding += " "; @@ -170,4 +170,4 @@ void Trie::dump() { root->dump(); } -} \ No newline at end of file +} diff --git a/src/uscxml/transform/Trie.h b/src/uscxml/transform/Trie.h index 73d75e7..2c7da8b 100644 --- a/src/uscxml/transform/Trie.h +++ b/src/uscxml/transform/Trie.h @@ -36,7 +36,7 @@ struct USCXML_API TrieNode { std::string identifier; std::string value; std::map childs; - void dump(int indent = 0); + void dump(size_t indent = 0); }; struct USCXML_API Trie { diff --git a/src/uscxml/transform/promela/PromelaCodeAnalyzer.h b/src/uscxml/transform/promela/PromelaCodeAnalyzer.h index 7f69ac9..2188ab1 100644 --- a/src/uscxml/transform/promela/PromelaCodeAnalyzer.h +++ b/src/uscxml/transform/promela/PromelaCodeAnalyzer.h @@ -38,8 +38,8 @@ public: std::string name; std::string type; size_t arraySize = 0; - size_t minValue = 0; - size_t maxValue = 0; + int minValue = 0; + int maxValue = 0; std::map types; std::set occurrences; diff --git a/src/uscxml/util/DOM.cpp b/src/uscxml/util/DOM.cpp index f661ebb..c21dee1 100644 --- a/src/uscxml/util/DOM.cpp +++ b/src/uscxml/util/DOM.cpp @@ -21,9 +21,7 @@ #include "uscxml/Common.h" #include "uscxml/util/Convenience.h" -//#include "uscxml/util/UUID.h" #include "uscxml/util/DOM.h" -//#include "uscxml/util/Convenience.h" #include #include @@ -31,9 +29,6 @@ #include "uscxml/interpreter/Logging.h" -//#include -//#include - namespace uscxml { using namespace XERCESC_NS; @@ -42,12 +37,16 @@ std::ostream& operator<< (std::ostream& os, const DOMNode& node) { DOMImplementation *implementation = DOMImplementationRegistry::getDOMImplementation(X("LS")); DOMLSSerializer *serializer = ((DOMImplementationLS*)implementation)->createLSSerializer(); + if (serializer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true)) serializer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true); - serializer->setNewLine(XMLString::transcode("\r\n")); - X output = serializer->writeToString(&node); - os << output; + serializer->setNewLine(X("\r\n")); + XMLCh* outString = serializer->writeToString(&node); + os << X(outString); + XMLString::release(&outString); + + delete (serializer); return os; } @@ -220,108 +219,142 @@ bool DOMUtils::isDescendant(const DOMNode* s1, return false; } -std::list DOMUtils::inPostFixOrder(const std::set& elements, - const DOMElement* root, - const bool includeEmbeddedDoc) { - std::list nodes; - inPostFixOrder(elements, root, includeEmbeddedDoc, nodes); - return nodes; -} +void DOMUtils::filterElementGeneric(const std::set& elements, + std::list& result, + const DOMElement* root, + const Order order, + const bool includeEmbeddedDoc, + const bool includeRoot) { -void DOMUtils::inPostFixOrder(const std::set& elements, - const DOMElement* root, - const bool includeEmbeddedDoc, - std::list& nodes) { - - if (root == NULL) + if (!root) return; - for (auto childElem = root->getFirstElementChild(); childElem; childElem = childElem->getNextElementSibling()) { - if (!includeEmbeddedDoc && LOCALNAME(childElem) == "scxml") - continue; - inPostFixOrder(elements, childElem, includeEmbeddedDoc, nodes); + if ((order == NO_RECURSE || order == DOCUMENT) && + includeRoot && + elements.find(TAGNAME(root)) != elements.end()) { + result.push_back((DOMElement*)root); } - for (auto childElem = root->getFirstElementChild(); childElem; childElem = childElem->getNextElementSibling()) { - if (!includeEmbeddedDoc && TAGNAME(childElem) == XML_PREFIX(root).str() + "scxml") - continue; - if (elements.find(TAGNAME(childElem)) != elements.end()) { - nodes.push_back((DOMElement*)childElem); + if (root->getNodeType() == DOMNode::ELEMENT_NODE && root->hasChildNodes()) { + DOMElement* currElement = root->getFirstElementChild(); + while (currElement) { + if (order == NO_RECURSE) { + if (elements.find(TAGNAME(currElement)) != elements.end()) { + result.push_back(currElement); + } + } else { + if (includeEmbeddedDoc || TAGNAME(currElement) != XML_PREFIX(root).str() + "scxml") { + filterElementGeneric(elements, result, currElement, order, includeEmbeddedDoc, true); + } + } + currElement = currElement->getNextElementSibling(); } } -} -//TODO: Unify recursive search in DOM + if (order == POSTFIX && + includeRoot && + elements.find(TAGNAME(root)) != elements.end()) { + result.push_back((DOMElement*)root); + } -std::list DOMUtils::inDocumentOrder(const std::set& elements, - const DOMElement* root, - const bool includeEmbeddedDoc) { - std::list nodes; - inDocumentOrder(elements, root, includeEmbeddedDoc, nodes); - return nodes; } -void DOMUtils::inDocumentOrder(const std::set& elements, - const DOMElement* root, - const bool includeEmbeddedDoc, - std::list& nodes) { - if (root == NULL) + +void DOMUtils::filterTypeGeneric(const std::set& types, + std::list& result, + const DOMElement* root, + const Order order, + const bool includeEmbeddedDoc, + const bool includeRoot) { + + if (!root) return; - if (elements.find(TAGNAME(root)) != elements.end()) { - nodes.push_back((DOMElement*)root); + if ((order == NO_RECURSE || order == DOCUMENT) && + includeRoot && + types.find(root->getNodeType()) != types.end()) { + result.push_back((DOMNode*)root); } - /// @todo: item from getChildNodes is O(N)! - DOMElement* child = root->getFirstElementChild(); - while(child) { - if (includeEmbeddedDoc || TAGNAME(child) != XML_PREFIX(root).str() + "scxml") { - inDocumentOrder(elements, child, includeEmbeddedDoc, nodes); + if (root->getNodeType() == DOMNode::ELEMENT_NODE && root->hasChildNodes()) { + DOMNode* currNode = root->getFirstChild(); + while (currNode) { + if (currNode->getNodeType() != DOMNode::ELEMENT_NODE) { + if (types.find(currNode->getNodeType()) != types.end()) { + result.push_back(currNode); + } + } else { + if (currNode->getNodeType() == DOMNode::ELEMENT_NODE) { + DOMElement* currElement = (DOMElement*)currNode; + if (includeEmbeddedDoc || TAGNAME(currElement) != XML_PREFIX(root).str() + "scxml") { + filterTypeGeneric(types, result, currElement, order, includeEmbeddedDoc, true); + } + } + } + currNode = currNode->getNextSibling(); } + } - child = child->getNextElementSibling(); + if (order == POSTFIX && + includeRoot && + types.find(root->getNodeType()) != types.end()) { + result.push_back((DOMNode*)root); } -} -std::list DOMUtils::getElementsByType(const DOMNode* root, - DOMNode::NodeType type) { - std::list result; - std::list stack; - std::list::iterator stackIter; +} - if (!root) - return result; - - stack.push_back((DOMNode*)root); - while(stack.size() > 0) { -// for(stackIter = stack.begin(); stackIter != stack.end(); stackIter++) { -// std::cout << stackIter->getNodeType() << " " << stackIter->getLocalName() << " " << stackIter->getNodeValue() << std::endl; -// } -// std::cout << std::endl; - - DOMNode* currNode = stack.back(); - if (currNode->hasChildNodes()) { - stack.push_back(currNode->getFirstChild()); - continue; - } +#if 1 +std::list DOMUtils::inPostFixOrder(const std::set& elements, + const DOMElement* root, + const bool includeEmbeddedDoc) { + std::list result; + filterElementGeneric(elements, result, root, POSTFIX, includeEmbeddedDoc, true); + return result; +} +#else +std::list DOMUtils::inPostFixOrder(const std::set& elements, + const DOMElement* root, + const bool includeEmbeddedDoc) { + std::list nodes; + inPostFixOrder(elements, root, includeEmbeddedDoc, nodes); + return nodes; +} +#endif - // roll back stack and pop everyone without next sibling - do { - currNode = stack.back(); - if (currNode->getNodeType() == type) - result.push_back(currNode); - stack.pop_back(); - if (currNode->getNextSibling()) { - stack.push_back(currNode->getNextSibling()); - break; - } - } while(stack.size() > 0); - } +#if 1 +std::list DOMUtils::inDocumentOrder(const std::set& elements, + const DOMElement* root, + const bool includeEmbeddedDoc) { + std::list result; + filterElementGeneric(elements, result, root, DOCUMENT, includeEmbeddedDoc, true); return result; } +#else +std::list DOMUtils::inDocumentOrder(const std::set& elements, + const DOMElement* root, + const bool includeEmbeddedDoc) { + std::list nodes; + inDocumentOrder(elements, root, includeEmbeddedDoc, nodes); + return nodes; +} +#endif +#if 1 +std::list DOMUtils::filterChildElements(const std::string& tagName, + const std::list& nodeSet, + bool recurse) { + std::list filteredChildElems; + std::list::const_iterator nodeIter = nodeSet.begin(); + while(nodeIter != nodeSet.end()) { + if ((*nodeIter)->getNodeType() == DOMNode::ELEMENT_NODE) + filterElementGeneric({ tagName }, filteredChildElems, (DOMElement*)(*nodeIter), (recurse ? DOCUMENT : NO_RECURSE), true, false); + nodeIter++; + } + return filteredChildElems; +} +#else std::list DOMUtils::filterChildElements(const std::string& tagName, const std::list& nodeSet, bool recurse) { @@ -335,7 +368,18 @@ std::list DOMUtils::filterChildElements(const std::string& tagName, } return filteredChildElems; } +#endif +#if 1 +std::list DOMUtils::filterChildElements(const std::string& tagName, + const DOMElement* node, + bool recurse) { + + std::list result; + filterElementGeneric({ tagName }, result, node, (recurse ? DOCUMENT : NO_RECURSE), true, false); + return result; +} +#else std::list DOMUtils::filterChildElements(const std::string& tagName, const DOMElement* node, bool recurse) { @@ -358,7 +402,22 @@ std::list DOMUtils::filterChildElements(const std::string& tagName, return filteredChildElems; } +#endif +#if 1 +std::list DOMUtils::filterChildType(const DOMNode::NodeType type, + const std::list& nodeSet, + bool recurse) { + std::list filteredChildType; + std::list::const_iterator nodeIter = nodeSet.begin(); + while(nodeIter != nodeSet.end()) { + if ((*nodeIter)->getNodeType() == DOMNode::ELEMENT_NODE) + filterTypeGeneric({ type }, filteredChildType, (DOMElement*)(*nodeIter), (recurse ? DOCUMENT : NO_RECURSE), true, false); + nodeIter++; + } + return filteredChildType; +} +#else std::list DOMUtils::filterChildType(const DOMNode::NodeType type, const std::list& nodeSet, bool recurse) { @@ -371,7 +430,21 @@ std::list DOMUtils::filterChildType(const DOMNode::NodeType type, } return filteredChildType; } +#endif +#if 1 +std::list DOMUtils::filterChildType(const DOMNode::NodeType type, + const DOMNode* node, + bool recurse) { + + std::list result; + if (node) { + assert(node->getNodeType() == DOMNode::ELEMENT_NODE); + } + filterTypeGeneric({ type }, result, (DOMElement*)node, (recurse ? DOCUMENT : NO_RECURSE), true, false); + return result; +} +#else std::list DOMUtils::filterChildType(const DOMNode::NodeType type, const DOMNode* node, bool recurse) { @@ -392,6 +465,53 @@ std::list DOMUtils::filterChildType(const DOMNode::NodeType type, } return filteredChildTypes; } +#endif + +#if 0 +void DOMUtils::inPostFixOrder(const std::set& elements, + const DOMElement* root, + const bool includeEmbeddedDoc, + std::list& nodes) { + + if (root == NULL) + return; + + for (auto childElem = root->getFirstElementChild(); childElem; childElem = childElem->getNextElementSibling()) { + if (!includeEmbeddedDoc && LOCALNAME(childElem) == "scxml") + continue; + inPostFixOrder(elements, childElem, includeEmbeddedDoc, nodes); + + } + for (auto childElem = root->getFirstElementChild(); childElem; childElem = childElem->getNextElementSibling()) { + if (!includeEmbeddedDoc && TAGNAME(childElem) == XML_PREFIX(root).str() + "scxml") + continue; + + if (elements.find(TAGNAME(childElem)) != elements.end()) { + nodes.push_back((DOMElement*)childElem); + } + } +} +void DOMUtils::inDocumentOrder(const std::set& elements, + const DOMElement* root, + const bool includeEmbeddedDoc, + std::list& nodes) { + if (root == NULL) + return; + + if (elements.find(TAGNAME(root)) != elements.end()) { + nodes.push_back((DOMElement*)root); + } + /// @todo: item from getChildNodes is O(N)! + DOMElement* child = root->getFirstElementChild(); + while(child) { + if (includeEmbeddedDoc || TAGNAME(child) != XML_PREFIX(root).str() + "scxml") { + inDocumentOrder(elements, child, includeEmbeddedDoc, nodes); + } + + child = child->getNextElementSibling(); + } +} +#endif } diff --git a/src/uscxml/util/DOM.h b/src/uscxml/util/DOM.h index 2b133d8..48ad321 100644 --- a/src/uscxml/util/DOM.h +++ b/src/uscxml/util/DOM.h @@ -57,9 +57,6 @@ public: const std::string& ns = ""); static std::string idForNode(const XERCESC_NS::DOMNode* node); - static std::list getElementsByType(const XERCESC_NS::DOMNode* root, - XERCESC_NS::DOMNode::NodeType type); - static std::list inPostFixOrder(const std::set& elements, const XERCESC_NS::DOMElement* root, const bool includeEmbeddedDoc = false); @@ -83,8 +80,28 @@ public: static std::list filterChildType(const XERCESC_NS::DOMNode::NodeType type, const std::list& nodeSet, bool recurse = false); - protected: + enum Order { + POSTFIX, + DOCUMENT, + NO_RECURSE + }; + + static void filterElementGeneric(const std::set& elements, + std::list& result, + const XERCESC_NS::DOMElement* root, + const Order order, + const bool includeEmbeddedDoc, + const bool includeRoot); + + static void filterTypeGeneric(const std::set& types, + std::list& result, + const XERCESC_NS::DOMElement* root, + const Order order, + const bool includeEmbeddedDoc, + const bool includeRoot); + +#if 0 static void inPostFixOrder(const std::set& elements, const XERCESC_NS::DOMElement* root, const bool includeEmbeddedDoc, @@ -94,7 +111,7 @@ protected: const XERCESC_NS::DOMElement* root, const bool includeEmbeddedDoc, std::list& nodes); - +#endif }; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index bc1c85a..2b90b97 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -39,25 +39,32 @@ function(USCXML_TEST_COMPILE) add_test(${USCXML_TEST_NAME} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${USCXML_TEST_NAME} ${USCXML_TEST_ARGS}) set_property(TEST ${USCXML_TEST_NAME} PROPERTY LABELS ${USCXML_TEST_LABEL}) set_property(TEST ${USCXML_TEST_NAME} PROPERTY TIMEOUT ${TEST_TIMEOUT}) + set_property(TEST ${USCXML_TEST_NAME} PROPERTY ENVIRONMENT "USCXML_PLUGIN_PATH=${CMAKE_BINARY_DIR}/lib/plugins") endif () set_target_properties(${USCXML_TEST_NAME} PROPERTIES FOLDER "Tests") endfunction() # simple one file tests +USCXML_TEST_COMPILE(NAME test-utils LABEL general/test-utils FILES src/test-utils.cpp) USCXML_TEST_COMPILE(NAME test-extensions LABEL general/test-extensions FILES src/test-extensions.cpp ../contrib/src/uscxml/PausableDelayedEventQueue.cpp) USCXML_TEST_COMPILE(NAME test-url LABEL general/test-url FILES src/test-url.cpp) USCXML_TEST_COMPILE(NAME test-lifecycle LABEL general/test-lifecycle FILES src/test-lifecycle.cpp) USCXML_TEST_COMPILE(NAME test-validating LABEL general/test-validating FILES src/test-validating.cpp) USCXML_TEST_COMPILE(NAME test-snippets LABEL general/test-snippets FILES src/test-snippets.cpp) -USCXML_TEST_COMPILE( - NAME test-serialization - LABEL general/test-serialization - FILES src/test-serialization.cpp ../contrib/src/uscxml/PausableDelayedEventQueue.cpp - ARGS ${CMAKE_CURRENT_SOURCE_DIR}/w3c/ecma) + +if (NOT BUILD_AS_PLUGINS) + USCXML_TEST_COMPILE( + NAME test-serialization + LABEL general/test-serialization + FILES src/test-serialization.cpp ../contrib/src/uscxml/PausableDelayedEventQueue.cpp + ARGS ${CMAKE_CURRENT_SOURCE_DIR}/w3c/ecma) +endif() # USCXML_TEST_COMPILE(NAME test-c89-parser LABEL general/test-c89-parser FILES src/test-c89-parser.cpp) # test-stress is not an automated test -USCXML_TEST_COMPILE(BUILD_ONLY NAME test-stress LABEL general/test-stress FILES src/test-stress.cpp) +if (NOT BUILD_AS_PLUGINS) + USCXML_TEST_COMPILE(BUILD_ONLY NAME test-stress LABEL general/test-stress FILES src/test-stress.cpp) +endif() file(GLOB_RECURSE USCXML_WRAPPERS ${PROJECT_SOURCE_DIR}/src/bindings/swig/wrapped/*.cpp @@ -91,6 +98,7 @@ foreach (USCXML_ISSUE ${USCXML_ISSUES}) if (ISSUE_TYPE STREQUAL ".scxml") add_test(issue/${ISSUE_NAME} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-state-pass ${USCXML_ISSUE}) set_property(TEST issue/${ISSUE_NAME} PROPERTY LABELS issue/${ISSUE_NAME}) + set_property(TEST issue/${ISSUE_NAME} PROPERTY ENVIRONMENT "USCXML_PLUGIN_PATH=${CMAKE_BINARY_DIR}/lib/plugins") else () USCXML_TEST_COMPILE(NAME ${ISSUE_NAME} LABEL issues/${ISSUE_NAME} FILES ${USCXML_ISSUE}) endif () @@ -130,6 +138,7 @@ foreach (USCXML_HEADER ${USCXML_PUBLIC_HEADERS}) -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} -P ${CMAKE_CURRENT_SOURCE_DIR}/ctest/scripts/run_header_compiles.cmake) set_property(TEST "header/${USCXML_REL_HEADER}" PROPERTY LABELS "header/${USCXML_REL_HEADER}") + set_property(TEST "header/${USCXML_REL_HEADER}" PROPERTY ENVIRONMENT "USCXML_PLUGIN_PATH=${CMAKE_BINARY_DIR}/lib/plugins") endforeach () @@ -142,7 +151,8 @@ if (PERL_BIN) WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/test/src ) set_property(TEST "general/test-debug-api" PROPERTY LABELS "general/test-debug-api") - set_tests_properties("general/test-debug-api" PROPERTIES DEPENDS uscxml-browser) + set_property(TEST "general/test-debug-api" PROPERTY DEPENDS uscxml-browser) + set_property(TEST "general/test-debug-api" PROPERTY ENVIRONMENT "USCXML_PLUGIN_PATH=${CMAKE_BINARY_DIR}/lib/plugins") endif () @@ -299,7 +309,7 @@ if (NOT BUILD_MINIMAL) -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} -DSCAFFOLDING_FOR_GENERATED_C:FILEPATH=${CMAKE_CURRENT_SOURCE_DIR}/src/test-gen-c.cpp -P ${CMAKE_CURRENT_SOURCE_DIR}/ctest/scripts/test_generated_${TEST_TARGET}.cmake) - set_tests_properties("${TEST_NAME}" PROPERTIES DEPENDS uscxml-transform) + set_property(TEST ${TEST_NAME} PROPERTY DEPENDS uscxml-transform) set(TEST_ADDED ON) endif() @@ -313,7 +323,7 @@ if (NOT BUILD_MINIMAL) -Dtest.file=${W3C_TEST} -Duscxml.jar=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/uscxml.jar WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/contrib/java/bindings) - set_tests_properties("${TEST_NAME}" PROPERTIES DEPENDS jar) + set_property(TEST ${TEST_NAME} PROPERTY DEPENDS jar) set(TEST_ADDED ON) endif () @@ -325,7 +335,8 @@ if (NOT BUILD_MINIMAL) ${W3C_TEST} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/contrib/python/bindings) - set_tests_properties("${TEST_NAME}" PROPERTIES ENVIRONMENT "USCXML_PYTHON_PATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}") + 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(TEST_ADDED ON) endif () @@ -343,8 +354,8 @@ if (NOT BUILD_MINIMAL) -DSPIN_BIN:FILEPATH=${SPIN_BIN} -DCC_BIN:FILEPATH=${CC_BIN} -P ${CMAKE_CURRENT_SOURCE_DIR}/ctest/scripts/run_promela_test.cmake) - set_tests_properties("${TEST_NAME}" PROPERTIES PASS_REGULAR_EXPRESSION "depth reached [0-9]+, errors: 0") - set_tests_properties("${TEST_NAME}" PROPERTIES FAIL_REGULAR_EXPRESSION "depth reached [0-9]+, errors: [1-9]+") + set_property(TEST ${TEST_NAME} PROPERTY PASS_REGULAR_EXPRESSION "depth reached [0-9]+, errors: 0") + set_property(TEST ${TEST_NAME} PROPERTY FAIL_REGULAR_EXPRESSION "depth reached [0-9]+, errors: [1-9]+") set(TEST_ADDED ON) elseif (TEST_TYPE MATCHES "^fsm.*") @@ -356,9 +367,10 @@ if (NOT BUILD_MINIMAL) if (TEST_ADDED) set_property(TEST ${TEST_NAME} PROPERTY LABELS ${TEST_NAME}) - set_tests_properties(${TEST_NAME} PROPERTIES TIMEOUT ${TEST_TIMEOUT}) + set_property(TEST ${TEST_NAME} PROPERTY TIMEOUT ${TEST_TIMEOUT}) + set_property(TEST ${TEST_NAME} APPEND PROPERTY ENVIRONMENT "USCXML_PLUGIN_PATH=${CMAKE_BINARY_DIR}/lib/plugins") if (IS_PERFORMANCE_TEST) - set_tests_properties("${TEST_NAME}" PROPERTIES ENVIRONMENT USCXML_BENCHMARK_ITERATIONS=${TEST_BENCHMARK_ITERATIONS}) + set_property(TEST ${TEST_NAME} APPEND PROPERTY ENVIRONMENT USCXML_BENCHMARK_ITERATIONS=${TEST_BENCHMARK_ITERATIONS}) endif () endif () diff --git a/test/ctest/scripts/test_generated_c.cmake b/test/ctest/scripts/test_generated_c.cmake index c170639..b130d29 100644 --- a/test/ctest/scripts/test_generated_c.cmake +++ b/test/ctest/scripts/test_generated_c.cmake @@ -15,36 +15,6 @@ if (CMD_RESULT) endif () message(STATUS "time for transforming to c machine") -# set(COMPILE_CMD_OBJ -# "-c" "${OUTDIR}/${TEST_FILE_NAME}.machine.c" -# "-o" "${OUTDIR}/${TEST_FILE_NAME}.machine.c.o" -# "-Ofast" "-ansi" "-m16") -# -# message(STATUS "${CC_BIN} ${COMPILE_CMD_OBJ}") -# execute_process( -# COMMAND time -p ${CC_BIN} ${COMPILE_CMD_OBJ} -# WORKING_DIRECTORY ${OUTDIR} RESULT_VARIABLE CMD_RESULT) -# if(CMD_RESULT) -# message(FATAL_ERROR "Error running gcc ${CC_BIN}: ${CMD_RESULT}") -# endif() -# file (SIZE "${OUTDIR}/${TEST_FILE_NAME}.machine.c.o" BINARY_SIZE) -# message("Size of compiled unit optimized for speed: ${BINARY_SIZE}") -# -# set(COMPILE_CMD_OBJ -# "-c" "${OUTDIR}/${TEST_FILE_NAME}.machine.c" -# "-o" "${OUTDIR}/${TEST_FILE_NAME}.machine.c.o" -# "-Os" "-ansi" "-m16") -# -# message(STATUS "${CC_BIN} ${COMPILE_CMD_OBJ}") -# execute_process( -# COMMAND time -p ${CC_BIN} ${COMPILE_CMD_OBJ} -# WORKING_DIRECTORY ${OUTDIR} RESULT_VARIABLE CMD_RESULT) -# if(CMD_RESULT) -# message(FATAL_ERROR "Error running gcc ${CC_BIN}: ${CMD_RESULT}") -# endif() -# file (SIZE "${OUTDIR}/${TEST_FILE_NAME}.machine.c.o" BINARY_SIZE) -# message("Size of compiled unit optimized for size: ${BINARY_SIZE}") - set(COMPILE_CMD_BIN "-O0" "-std=c++11" @@ -53,6 +23,7 @@ set(COMPILE_CMD_BIN "-o" "${OUTDIR}/${TEST_FILE_NAME}" "-L${CMAKE_LIBRARY_OUTPUT_DIRECTORY}" "-L${PROJECT_BINARY_DIR}/deps/xerces-c/lib" + "-L/opt/local/lib" "-luscxml" "-lxerces-c" "-include" "${OUTDIR}/${TEST_FILE_NAME}.machine.c" diff --git a/test/src/test-gen-c.cpp b/test/src/test-gen-c.cpp index 090b289..7af121c 100644 --- a/test/src/test-gen-c.cpp +++ b/test/src/test-gen-c.cpp @@ -18,9 +18,7 @@ #ifndef AUTOINCLUDE_TEST #include "test-c-machine.scxml.c" -//#include "/Users/sradomski/Documents/TK/Code/uscxml/build/cli/test/gen/c/ecma/test562.scxml.machine.c" -//#include "/Users/sradomski/Documents/TK/Code/uscxml/build/cli/test/gen/c/ecma/test558.scxml.machine.c" -// #include "/Users/sradomski/Documents/TK/Code/uscxml/build/cli/test/gen/c/lua/test530.scxml.machine.c" +//#include "/Users/sradomski/Documents/TK/Code/uscxml/build/cli/test/gen/c/ecma/test446.scxml.machine.c" #endif #include "uscxml/util/URL.h" diff --git a/test/src/test-utils.cpp b/test/src/test-utils.cpp new file mode 100644 index 0000000..474cf89 --- /dev/null +++ b/test/src/test-utils.cpp @@ -0,0 +1,74 @@ +/** + * This file contains all the snippets in the doxygen documentation. + * + * It is not actually a test as such, but makes sure that the snippets will + * actually compile and do what we claim they do. + */ +#define protected public + +#include "uscxml/config.h" +#include "uscxml/Common.h" +#include "uscxml/Interpreter.h" +#include "uscxml/interpreter/InterpreterImpl.h" +#include "uscxml/util/DOM.h" + +using namespace uscxml; +using namespace XERCESC_NS; + +void testDOMUtils() { + + const char* xml = + "" + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + ""; + + size_t index = 1; + + Interpreter interpreter = Interpreter::fromXML(xml, ""); + interpreter.step(); + XERCESC_NS::DOMElement* scxml = interpreter.getImpl()->_scxml; + + { + // postfix + std::list result; + DOMUtils::filterElementGeneric({ "state" }, result, scxml, DOMUtils::POSTFIX, true, true); + index = 1; + for (auto trans : result) { + assert(HAS_ATTR(trans, "post")); + std::cout << "post: " << ATTR(trans, "post") << std::endl; + assert(ATTR(trans, "post") == toStr(index)); + index++; + } + } + + { + // document + std::list result; + DOMUtils::filterElementGeneric({ "state" }, result, scxml, DOMUtils::DOCUMENT, true, true); + index = 1; + for (auto trans : result) { + assert(HAS_ATTR(trans, "doc")); + std::cout << "doc: " << ATTR(trans, "doc") << std::endl; + assert(ATTR(trans, "doc") == toStr(index)); + index++; + } + } + +} + +int main(int argc, char** argv) { + try { + testDOMUtils(); + } catch (ErrorEvent e) { + std::cout << e; + } +} diff --git a/test/src/test-validating.cpp b/test/src/test-validating.cpp index fa660b9..7e0cc31 100644 --- a/test/src/test-validating.cpp +++ b/test/src/test-validating.cpp @@ -5,6 +5,8 @@ #include "uscxml/interpreter/Logging.h" #include +uscxml::Factory* factory = NULL; + using namespace uscxml; std::set issueLocationsForXML(const std::string xml) { @@ -36,782 +38,865 @@ public: } }; -int main(int argc, char** argv) { - - using namespace XERCESC_NS; - - int iterations = 1; +bool endlessLoop() { - while(iterations--) { - - if (Factory::getInstance()->hasDataModel("ecmascript")) { - // Potential endless loop - - const char* xml = - "" - " " - " " - " " - " 0\" />" - " " - " " - " " - ""; + if (Factory::getInstance()->hasDataModel("ecmascript")) { + // Potential endless loop - IssueMonitor monitor; - Interpreter interpreter = Interpreter::fromXML(xml, ""); - interpreter.addMonitor(&monitor); + const char* xml = + "" + " " + " " + " " + " 0\" />" + " " + " " + " " + ""; - while(interpreter.step() > 0) {} + IssueMonitor monitor; + Interpreter interpreter = Interpreter::fromXML(xml, ""); + interpreter.addMonitor(&monitor); - // four identical configurations between macrosteps - assert(runtimeIssues == 4); - } + while(interpreter.step() > 0) {} - if (1) { - // Unreachable states 1 + // four identical configurations between macrosteps + assert(runtimeIssues == 4); + } + return true; +} - const char* xml = - "" - " " - " " - " " - " " - " " - " " - " " - " " - ""; +bool unreachableState() { + if (1) { + // Unreachable states 1 + + const char* xml = + "" + " " + " " + " " + " " + " " + " " + " " + " " + ""; + + std::set issueLocations = issueLocationsForXML(xml); + assert(issueLocations.find("//state[@id=\"bar\"]") != issueLocations.end()); + assert(issueLocations.size() == 1); + } + return true; +} - std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("//state[@id=\"bar\"]") != issueLocations.end()); - assert(issueLocations.size() == 1); - } +bool invalidParents() { + if (1) { + // Invalid parents + const char* xml = + "" + " " + " " + " " + ""; + + std::set issueLocations = issueLocationsForXML(xml); + assert(issueLocations.find("/scxml[1]/onentry[1]") != issueLocations.end()); + assert(issueLocations.size() == 1); + } + return true; +} - if (1) { - // Invalid parents - const char* xml = - "" - " " - " " - " " - ""; +bool noIdAttr() { + if (1) { + // State has no 'id' attribute + // *** This is not actually an error! *** + const char* xml = + "" + " " + " " + " " + ""; + + std::set issueLocations = issueLocationsForXML(xml); + assert(issueLocations.find("/scxml[1]/state[1]") != issueLocations.end()); + assert(issueLocations.size() == 1); + } - std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("/scxml[1]/onentry[1]") != issueLocations.end()); - assert(issueLocations.size() == 1); - } + return true; +} - if (1) { - // State has no 'id' attribute - // *** This is not actually an error! *** - const char* xml = - "" - " " - " " - " " - ""; +bool duplicateIdAttr() { + if (1) { + // Duplicate state with id + const char* xml = + "" + " " + " " + ""; + + std::set issueLocations = issueLocationsForXML(xml); + assert(issueLocations.find("//state[@id=\"start\"]") != issueLocations.end()); + assert(issueLocations.size() == 1); + } - std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("/scxml[1]/state[1]") != issueLocations.end()); - assert(issueLocations.size() == 1); - } + return true; +} - if (1) { - // Duplicate state with id - const char* xml = - "" - " " - " " - ""; +bool invalidTarget() { + if (1) { + // Transition has non-existant target state - std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("//state[@id=\"start\"]") != issueLocations.end()); - assert(issueLocations.size() == 1); - } + const char* xml = + "" + " " + " " + " " + ""; - if (1) { - // Transition has non-existant target state + std::set issueLocations = issueLocationsForXML(xml); + assert(issueLocations.find("//state[@id=\"start\"]/transition[1]") != issueLocations.end()); + assert(issueLocations.size() == 1); + } - const char* xml = - "" - " " - " " - " " - ""; + return true; +} - std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("//state[@id=\"start\"]/transition[1]") != issueLocations.end()); - assert(issueLocations.size() == 1); - } +bool uselessHistory1() { + if (1) { + // Useless history 1 + + const char* xml = + "" + " " + " " + " " + " " + " " + " " + " " + ""; + + std::set issueLocations = issueLocationsForXML(xml); + assert(issueLocations.find("//history[@id=\"bar\"]") != issueLocations.end()); + assert(issueLocations.size() == 1); + } - if (1) { - // Useless history 1 + return true; +} - const char* xml = - "" - " " - " " - " " - " " - " " - " " - " " - ""; +bool uselessHistory2() { + if (1) { + // Useless history 2 + + const char* xml = + "" + " " + " " + " " + " " + " " + " " + " " + " " + ""; + + std::set issueLocations = issueLocationsForXML(xml); + assert(issueLocations.find("//history[@id=\"bar\"]") != issueLocations.end()); + assert(issueLocations.size() == 1); + } + return true; +} - std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("//history[@id=\"bar\"]") != issueLocations.end()); - assert(issueLocations.size() == 1); - } +bool illegalCompletion() { + if (1) { + // No legal completion + + const char* xml = + "" + " " + " " + " " + " " + " " + ""; + + std::set issueLocations = issueLocationsForXML(xml); + assert(issueLocations.find("//state[@id=\"start\"]") != issueLocations.end()); + assert(issueLocations.find("//state[@id=\"start\"]/transition[1]") != issueLocations.end()); + assert(issueLocations.size() == 2); + } + return true; +} - if (1) { - // Useless history 2 +bool attributeConstraints() { + if (1) { + // attribute constraints + { + // initial attribute and child const char* xml = "" - " " - " " + " " + " " " " - " " - " " - " " - " " - " " - ""; - - std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("//history[@id=\"bar\"]") != issueLocations.end()); - assert(issueLocations.size() == 1); - } - - if (1) { - // No legal completion - - const char* xml = - "" - " " + " " " " - " " - " " " " ""; std::set issueLocations = issueLocationsForXML(xml); assert(issueLocations.find("//state[@id=\"start\"]") != issueLocations.end()); - assert(issueLocations.find("//state[@id=\"start\"]/transition[1]") != issueLocations.end()); - assert(issueLocations.size() == 2); - } - - if (1) { - // attribute constraints - - { - // initial attribute and child - const char* xml = - "" - " " - " " - " " - " " - " " - " " - ""; - - std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("//state[@id=\"start\"]") != issueLocations.end()); - assert(issueLocations.size() == 1); - } - - { - // initial attribute with atomic state - const char* xml = - "" - " " - ""; - - std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("//state[@id=\"start\"]") != issueLocations.end()); - assert(issueLocations.size() == 1); - } - - { - // initial child with atomic state - const char* xml = - "" - " " - " " - " " - " " - " " - ""; - - std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("//state[@id=\"start\"]") != issueLocations.end()); - assert(issueLocations.size() == 2); // also invalid non-child target state in initial - } - - // combinations of namelist, content and param - { - // send with content and namelist, not allowed - const char* xml = - "" - " " - " " - " " - " Foo!" - " " - " " - " " - ""; - - std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("//state[@id=\"start\"]/onentry[1]/send[1]") != issueLocations.end()); - assert(issueLocations.size() == 1); - } - - { - // send with content and params, not allowed - const char* xml = - "" - " " - " " - " " - " " - " Foo!" - " " - " " - " " - ""; - - std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("//state[@id=\"start\"]/onentry[1]/send[1]") != issueLocations.end()); - assert(issueLocations.size() == 1); - } - - { - // send with params and namelist, perfectly acceptable - const char* xml = - "" - " " - " " - " " - " " - " " - " " - " " - ""; - - std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.size() == 0); - } - - { - // invoke with content and src, not allowed - const char* xml = - "" - " " - " " - " Foo!" - " " - " " - ""; - - std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("//state[@id=\"start\"]/invoke[1]") != issueLocations.end()); - assert(issueLocations.size() == 1); - } - - { - // invoke with namelist and param, not allowed - const char* xml = - "" - " " - " " - " " - " " - " " - ""; - - std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("//state[@id=\"start\"]/invoke[1]") != issueLocations.end()); - assert(issueLocations.size() == 1); - } - - { - // invoke with param and content, perfectly acceptable - const char* xml = - "" - " " - " " - " " - " Foo!" - " " - " " - ""; - - std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.size() == 0); - } - - { - // invoke with namelist and content, perfectly acceptable - const char* xml = - "" - " " - " " - " Foo!" - " " - " " - ""; - - std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.size() == 0); - } - - { - // donedata with content and param, not allowed - const char* xml = - "" - " " - " " - " " - " Foo!" - " " - " " - ""; - - std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("//state[@id=\"start\"]/donedata[1]") != issueLocations.end()); - assert(issueLocations.size() == 1); - } - - - } - - if (1) { - // Transition can never be optimally enabled (conditionless, eventless) - - const char* xml = - "" - " " - " " - " " - " " - " " - ""; - - std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("//state[@id=\"start\"]/transition[2]") != issueLocations.end()); - assert(issueLocations.size() == 1); - } - if (1) { - // Transition can never be optimally enabled (conditionless, more events) - - const char* xml = - "" - " " - " " - " " - " " - " " - ""; - - std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("//state[@id=\"start\"]/transition[2]") != issueLocations.end()); - assert(issueLocations.size() == 1); - } - - - if (1) { - // Initial attribute has invalid target state - - const char* xml = - "" - ""; - - std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("/scxml[1]") != issueLocations.end()); assert(issueLocations.size() == 1); } - if (1) { - // Initial attribute with target outside of children - + { + // initial attribute with atomic state const char* xml = "" - " " - " " - " " - " " + " " ""; std::set issueLocations = issueLocationsForXML(xml); assert(issueLocations.find("//state[@id=\"start\"]") != issueLocations.end()); assert(issueLocations.size() == 1); } - if (1) { - // Initial transition with target outside of children + { + // initial child with atomic state const char* xml = "" " " " " - " " + " " " " - " " " " - " " ""; std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("//state[@id=\"start\"]/initial[1]/transition[1]") != issueLocations.end()); - assert(issueLocations.size() == 1); // there are actually two issues with the transition + assert(issueLocations.find("//state[@id=\"start\"]") != issueLocations.end()); + assert(issueLocations.size() == 2); // also invalid non-child target state in initial } - if (1) { - // Initial history transition with target outside of children + // combinations of namelist, content and param + { + // send with content and namelist, not allowed const char* xml = "" - " " - " " - " " - " " - " " - " " - " " - " " + " " + " " + " " + " Foo!" + " " + " " " " - " " ""; std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("//history[@id=\"bar\"]/transition[1]") != issueLocations.end()); + assert(issueLocations.find("//state[@id=\"start\"]/onentry[1]/send[1]") != issueLocations.end()); assert(issueLocations.size() == 1); } - if (1) { - // Initial transition with target outside of children + { + // send with content and params, not allowed const char* xml = "" " " - " " - " " - " " - " " + " " + " " + " " + " Foo!" + " " + " " " " - " " ""; std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("//state[@id=\"start\"]/initial[1]/transition[1]") != issueLocations.end()); + assert(issueLocations.find("//state[@id=\"start\"]/onentry[1]/send[1]") != issueLocations.end()); assert(issueLocations.size() == 1); } - if (1) { - // Initial transition with event + { + // send with params and namelist, perfectly acceptable const char* xml = "" " " - " " - " " - " " - " " - " " + " " + " " + " " + " " + " " " " - " " ""; std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("//state[@id=\"start\"]/initial[1]/transition[1]") != issueLocations.end()); - assert(issueLocations.size() == 1); + assert(issueLocations.size() == 0); } - if (1) { - // Initial transition with condition + { + // invoke with content and src, not allowed const char* xml = "" " " - " " - " " - " " - " " - " " + " " + " Foo!" + " " " " - " " ""; std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("//state[@id=\"start\"]/initial[1]/transition[1]") != issueLocations.end()); + assert(issueLocations.find("//state[@id=\"start\"]/invoke[1]") != issueLocations.end()); assert(issueLocations.size() == 1); } - if (1) { - // Initial with multiple transitions + { + // invoke with namelist and param, not allowed const char* xml = "" " " - " " - " " - " " - " " - " " - " " + " " + " " + " " " " - " " ""; std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("//state[@id=\"start\"]/initial[1]") != issueLocations.end()); + assert(issueLocations.find("//state[@id=\"start\"]/invoke[1]") != issueLocations.end()); assert(issueLocations.size() == 1); } - if (1) { - // Initial with no transitions + { + // invoke with param and content, perfectly acceptable const char* xml = "" " " - " " - " " - " " + " " + " " + " Foo!" + " " " " - " " ""; std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("//state[@id=\"foo\"]") != issueLocations.end()); // unreachable - assert(issueLocations.find("//state[@id=\"start\"]/initial[1]") != issueLocations.end()); - assert(issueLocations.size() == 2); + assert(issueLocations.size() == 0); } - if (1) { - // History transition with event + { + // invoke with namelist and content, perfectly acceptable const char* xml = "" - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " + " " + " " + " Foo!" + " " " " - " " ""; std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("//history[@id=\"bar\"]/transition[1]") != issueLocations.end()); - assert(issueLocations.size() == 1); + assert(issueLocations.size() == 0); } - if (1) { - // History transition with condition + { + // donedata with content and param, not allowed const char* xml = "" - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " + " " + " " + " " + " Foo!" + " " " " - " " ""; std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("//history[@id=\"bar\"]/transition[1]") != issueLocations.end()); + assert(issueLocations.find("//state[@id=\"start\"]/donedata[1]") != issueLocations.end()); assert(issueLocations.size() == 1); } + } + return true; +} - if (1) { - // Send to unknown IO Processor +bool optimallyEnabled() { + if (1) { + // Transition can never be optimally enabled (conditionless, eventless) + + const char* xml = + "" + " " + " " + " " + " " + " " + ""; + + std::set issueLocations = issueLocationsForXML(xml); + assert(issueLocations.find("//state[@id=\"start\"]/transition[2]") != issueLocations.end()); + assert(issueLocations.size() == 1); + } + if (1) { + // Transition can never be optimally enabled (conditionless, more events) + + const char* xml = + "" + " " + " " + " " + " " + " " + ""; + + std::set issueLocations = issueLocationsForXML(xml); + assert(issueLocations.find("//state[@id=\"start\"]/transition[2]") != issueLocations.end()); + assert(issueLocations.size() == 1); + } + return true; +} - const char* xml = - "" - " " - " " - " " - " " - " " - ""; +bool invalidInitial() { + if (1) { + // Initial attribute has invalid target state - std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("//state[@id=\"start\"]/onentry[1]/send[1]") != issueLocations.end()); - assert(issueLocations.size() == 1); - } + const char* xml = + "" + ""; - if (1) { - // SCXML document requires unknown datamodel + std::set issueLocations = issueLocationsForXML(xml); + assert(issueLocations.find("/scxml[1]") != issueLocations.end()); + assert(issueLocations.size() == 1); + } - const char* xml = - "" - ""; + if (1) { + // Initial attribute with target outside of children - std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("/scxml[1]") != issueLocations.end()); - assert(issueLocations.size() == 1); - } + const char* xml = + "" + " " + " " + " " + " " + ""; - if (1) { - // Unknown executable content element + std::set issueLocations = issueLocationsForXML(xml); + assert(issueLocations.find("//state[@id=\"start\"]") != issueLocations.end()); + assert(issueLocations.size() == 1); + } + if (1) { + // Initial transition with target outside of children + + const char* xml = + "" + " " + " " + " " + " " + " " + " " + " " + ""; + + std::set issueLocations = issueLocationsForXML(xml); + assert(issueLocations.find("//state[@id=\"start\"]/initial[1]/transition[1]") != issueLocations.end()); + assert(issueLocations.size() == 1); // there are actually two issues with the transition + } + if (1) { + // Initial history transition with target outside of children + + const char* xml = + "" + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + ""; + + std::set issueLocations = issueLocationsForXML(xml); + assert(issueLocations.find("//history[@id=\"bar\"]/transition[1]") != issueLocations.end()); + assert(issueLocations.size() == 1); + } + if (1) { + // Initial transition with target outside of children + + const char* xml = + "" + " " + " " + " " + " " + " " + " " + " " + ""; + + std::set issueLocations = issueLocationsForXML(xml); + assert(issueLocations.find("//state[@id=\"start\"]/initial[1]/transition[1]") != issueLocations.end()); + assert(issueLocations.size() == 1); + } - const char* xml = - "" - " " - " " - " " - " " - " " - ""; + if (1) { + // Initial transition with event + const char* xml = + "" + " " + " " + " " + " " + " " + " " + " " + " " + ""; + + std::set issueLocations = issueLocationsForXML(xml); + assert(issueLocations.find("//state[@id=\"start\"]/initial[1]/transition[1]") != issueLocations.end()); + assert(issueLocations.size() == 1); + } - std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("//state[@id=\"start\"]/onentry[1]/nonexistant[1]") != issueLocations.end()); - assert(issueLocations.size() == 1); - } + if (1) { + // Initial transition with condition + const char* xml = + "" + " " + " " + " " + " " + " " + " " + " " + " " + ""; + + std::set issueLocations = issueLocationsForXML(xml); + assert(issueLocations.find("//state[@id=\"start\"]/initial[1]/transition[1]") != issueLocations.end()); + assert(issueLocations.size() == 1); + } - if (Factory::getInstance()->hasDataModel("ecmascript")) { - // Syntax error in script + if (1) { + // Initial with multiple transitions + const char* xml = + "" + " " + " " + " " + " " + " " + " " + " " + " " + " " + ""; + + std::set issueLocations = issueLocationsForXML(xml); + assert(issueLocations.find("//state[@id=\"start\"]/initial[1]") != issueLocations.end()); + assert(issueLocations.size() == 1); + } - const char* xml = - "" - " " - ""; + if (1) { + // Initial with no transitions + const char* xml = + "" + " " + " " + " " + " " + " " + " " + ""; + + std::set issueLocations = issueLocationsForXML(xml); + assert(issueLocations.find("//state[@id=\"foo\"]") != issueLocations.end()); // unreachable + assert(issueLocations.find("//state[@id=\"start\"]/initial[1]") != issueLocations.end()); + assert(issueLocations.size() == 2); + } + return true; +} - std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("/scxml[1]/script[1]") != issueLocations.end()); - assert(issueLocations.size() == 1); - } +bool invalidHistory() { + if (1) { + // History transition with event + const char* xml = + "" + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + ""; + + std::set issueLocations = issueLocationsForXML(xml); + assert(issueLocations.find("//history[@id=\"bar\"]/transition[1]") != issueLocations.end()); + assert(issueLocations.size() == 1); + } - if (Factory::getInstance()->hasDataModel("ecmascript")) { - // Syntax error in cond attribute + if (1) { + // History transition with condition + const char* xml = + "" + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + ""; + + std::set issueLocations = issueLocationsForXML(xml); + assert(issueLocations.find("//history[@id=\"bar\"]/transition[1]") != issueLocations.end()); + assert(issueLocations.size() == 1); + } + return true; +} - const char* xml = - "" - " " - " " - " " - " " - " " - " " - " " - " " - ""; +bool unknownIOProc() { + if (1) { + // Send to unknown IO Processor + + const char* xml = + "" + " " + " " + " " + " " + " " + ""; + + std::set issueLocations = issueLocationsForXML(xml); + assert(issueLocations.find("//state[@id=\"start\"]/onentry[1]/send[1]") != issueLocations.end()); + assert(issueLocations.size() == 1); + } - std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("//state[@id=\"start\"]/transition[1]") != issueLocations.end()); - assert(issueLocations.find("//state[@id=\"start\"]/onentry[1]/if[1]") != issueLocations.end()); - assert(issueLocations.find("//state[@id=\"start\"]/onentry[1]/if[1]/elseif[1]") != issueLocations.end()); - assert(issueLocations.size() == 3); - } + return true; +} - if (Factory::getInstance()->hasDataModel("ecmascript")) { - // Syntax error in expr attribute +bool unknownDataModel() { + if (1) { + // SCXML document requires unknown datamodel - const char* xml = - "" - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - ""; + const char* xml = + "" + ""; - std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("//state[@id=\"start\"]/onentry[1]/log[1]") != issueLocations.end()); - assert(issueLocations.find("//data[@id=\"foo\"]") != issueLocations.end()); - assert(issueLocations.find("//state[@id=\"start\"]/onentry[1]/assign[1]") != issueLocations.end()); - assert(issueLocations.find("//state[@id=\"start\"]/onentry[1]/send[1]/param[1]") != issueLocations.end()); - assert(issueLocations.find("//state[@id=\"start\"]/onentry[1]/send[2]/content[1]") != issueLocations.end()); - assert(issueLocations.size() == 5); - } + std::set issueLocations = issueLocationsForXML(xml); + assert(issueLocations.find("/scxml[1]") != issueLocations.end()); + assert(issueLocations.size() == 1); + } - if (Factory::getInstance()->hasDataModel("ecmascript")) { - // Syntax error with foreach + return true; +} - const char* xml = - "" - " " - " " - " " - " " - " " - " " - ""; +bool unknownExecContent() { + if (1) { + // Unknown executable content element + + const char* xml = + "" + " " + " " + " " + " " + " " + ""; + + std::set issueLocations = issueLocationsForXML(xml); + assert(issueLocations.find("//state[@id=\"start\"]/onentry[1]/nonexistant[1]") != issueLocations.end()); + assert(issueLocations.size() == 1); + } - std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("//state[@id=\"start\"]/onentry[1]/foreach[1]") != issueLocations.end()); - assert(issueLocations.size() == 1); - } + return true; +} - if (Factory::getInstance()->hasDataModel("ecmascript")) { - // Syntax error with send +bool syntaxErrors() { + if (Factory::getInstance()->hasDataModel("ecmascript")) { + // Syntax error in script - const char* xml = - "" - " " - " " - " " - " " - " " - ""; + const char* xml = + "" + " " + ""; - std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("//state[@id=\"start\"]/onentry[1]/send[1]") != issueLocations.end()); - assert(issueLocations.size() == 1); - } + std::set issueLocations = issueLocationsForXML(xml); + assert(issueLocations.find("/scxml[1]/script[1]") != issueLocations.end()); + assert(issueLocations.size() == 1); + } - if (Factory::getInstance()->hasDataModel("ecmascript")) { - // Syntax error with invoke + if (Factory::getInstance()->hasDataModel("ecmascript")) { + // Syntax error in cond attribute + + const char* xml = + "" + " " + " " + " " + " " + " " + " " + " " + " " + ""; + + std::set issueLocations = issueLocationsForXML(xml); + assert(issueLocations.find("//state[@id=\"start\"]/transition[1]") != issueLocations.end()); + assert(issueLocations.find("//state[@id=\"start\"]/onentry[1]/if[1]") != issueLocations.end()); + assert(issueLocations.find("//state[@id=\"start\"]/onentry[1]/if[1]/elseif[1]") != issueLocations.end()); + assert(issueLocations.size() == 3); + } - const char* xml = - "" - " " - " " - " " - ""; + if (Factory::getInstance()->hasDataModel("ecmascript")) { + // Syntax error in expr attribute + + const char* xml = + "" + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + ""; + + std::set issueLocations = issueLocationsForXML(xml); + assert(issueLocations.find("//state[@id=\"start\"]/onentry[1]/log[1]") != issueLocations.end()); + assert(issueLocations.find("//data[@id=\"foo\"]") != issueLocations.end()); + assert(issueLocations.find("//state[@id=\"start\"]/onentry[1]/assign[1]") != issueLocations.end()); + assert(issueLocations.find("//state[@id=\"start\"]/onentry[1]/send[1]/param[1]") != issueLocations.end()); + assert(issueLocations.find("//state[@id=\"start\"]/onentry[1]/send[2]/content[1]") != issueLocations.end()); + assert(issueLocations.size() == 5); + } - std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("//state[@id=\"start\"]/invoke[1]") != issueLocations.end()); - assert(issueLocations.size() == 1); - } + if (Factory::getInstance()->hasDataModel("ecmascript")) { + // Syntax error with foreach + + const char* xml = + "" + " " + " " + " " + " " + " " + " " + ""; + + std::set issueLocations = issueLocationsForXML(xml); + assert(issueLocations.find("//state[@id=\"start\"]/onentry[1]/foreach[1]") != issueLocations.end()); + assert(issueLocations.size() == 1); + } - if (Factory::getInstance()->hasDataModel("ecmascript")) { - // Syntax error with cancel + if (Factory::getInstance()->hasDataModel("ecmascript")) { + // Syntax error with send + + const char* xml = + "" + " " + " " + " " + " " + " " + ""; + + std::set issueLocations = issueLocationsForXML(xml); + assert(issueLocations.find("//state[@id=\"start\"]/onentry[1]/send[1]") != issueLocations.end()); + assert(issueLocations.size() == 1); + } - const char* xml = - "" - " " - " " - " " - " " - " " - ""; + if (Factory::getInstance()->hasDataModel("ecmascript")) { + // Syntax error with invoke - std::set issueLocations = issueLocationsForXML(xml); - assert(issueLocations.find("//state[@id=\"start\"]/onentry[1]/cancel[1]") != issueLocations.end()); - assert(issueLocations.size() == 1); - } + const char* xml = + "" + " " + " " + " " + ""; + + std::set issueLocations = issueLocationsForXML(xml); + assert(issueLocations.find("//state[@id=\"start\"]/invoke[1]") != issueLocations.end()); + assert(issueLocations.size() == 1); + } + + if (Factory::getInstance()->hasDataModel("ecmascript")) { + // Syntax error with cancel + + const char* xml = + "" + " " + " " + " " + " " + " " + ""; + + std::set issueLocations = issueLocationsForXML(xml); + assert(issueLocations.find("//state[@id=\"start\"]/onentry[1]/cancel[1]") != issueLocations.end()); + assert(issueLocations.size() == 1); + } + + return true; +} + +int main(int argc, char** argv) { + + factory = Factory::getInstance(); + return EXIT_SUCCESS; + try { + using namespace XERCESC_NS; + + int iterations = 1; + + while(iterations--) { + + endlessLoop(); + unreachableState(); + invalidParents(); + noIdAttr(); + duplicateIdAttr(); + invalidTarget(); + uselessHistory1(); + uselessHistory2(); + illegalCompletion(); + attributeConstraints(); + optimallyEnabled(); + invalidInitial(); + invalidHistory(); + unknownIOProc(); + unknownDataModel(); + unknownExecContent(); + syntaxErrors(); + + } + } catch (ErrorEvent e) { + std::cout << e; + return EXIT_FAILURE; } return EXIT_SUCCESS; -- cgit v0.12