From d1404b669a00a6cff2ac35f09d0222c1d9ab4bff Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Fri, 2 Jun 2017 14:54:23 +0200 Subject: Added UTF8 tests --- CMakeLists.txt | 1 + src/uscxml/Interpreter.cpp | 12 +++--- src/uscxml/server/HTTPServer.cpp | 4 +- test/CMakeLists.txt | 1 + test/src/test-snippets.cpp | 3 +- test/src/test-utf8.cpp | 88 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 99 insertions(+), 10 deletions(-) create mode 100644 test/src/test-utf8.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 48c8133..5f1fecb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -390,6 +390,7 @@ find_package(SWIG) # JavaScriptCore +# https://github.com/Lichtso/JSC-Standalone OPTION(WITH_DM_ECMA_JSC "Do search for JavaScriptCore" ON) if (WITH_DM_ECMA_JSC) find_package(JSC) diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp index 0758cd1..59a5084 100644 --- a/src/uscxml/Interpreter.cpp +++ b/src/uscxml/Interpreter.cpp @@ -98,7 +98,7 @@ Interpreter Interpreter::fromXML(const std::string& xml, const std::string& base Interpreter Interpreter::fromElement(XERCESC_NS::DOMElement* scxml, const std::string& baseURL) { URL absUrl = normalizeURL(baseURL); - + std::shared_ptr interpreterImpl(new InterpreterImpl()); Interpreter interpreter(interpreterImpl); @@ -148,12 +148,12 @@ Interpreter Interpreter::fromURL(const std::string& url) { URL absUrl = normalizeURL(url); #ifdef _WIN32 - // Xercesc is hard to build with SSL on windows, whereas curl uses winssl - if (absUrl.scheme() == "https") { - return fromXML(absUrl.getInContent(), absUrl); - } + // Xercesc is hard to build with SSL on windows, whereas curl uses winssl + if (absUrl.scheme() == "https") { + return fromXML(absUrl.getInContent(), absUrl); + } #endif - + std::shared_ptr interpreterImpl(new InterpreterImpl()); Interpreter interpreter(interpreterImpl); diff --git a/src/uscxml/server/HTTPServer.cpp b/src/uscxml/server/HTTPServer.cpp index e9a1039..aa43002 100644 --- a/src/uscxml/server/HTTPServer.cpp +++ b/src/uscxml/server/HTTPServer.cpp @@ -129,7 +129,7 @@ HTTPServer::HTTPServer(unsigned short port, unsigned short wsPort, SSLConfig* ss SSL_library_init (); SSL_load_error_strings (); - ERR_load_crypto_strings(); + ERR_load_crypto_strings(); OpenSSL_add_all_algorithms (); SSL_CTX *ctx = SSL_CTX_new (SSLv23_server_method ()); @@ -144,7 +144,7 @@ HTTPServer::HTTPServer(unsigned short port, unsigned short wsPort, SSLConfig* ss goto FAIL_SSL_SETUP; } if (1 != SSL_CTX_set_tmp_ecdh (ctx, ecdh)) { - LOGD(USCXML_ERROR) << ("SSL_CTX_set_tmp_ecdh") << ERR_error_string(ERR_get_error(), NULL); + LOGD(USCXML_ERROR) << ("SSL_CTX_set_tmp_ecdh") << ERR_error_string(ERR_get_error(), NULL); goto FAIL_SSL_SETUP; } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e76e249..9e5b61f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -60,6 +60,7 @@ if(WITH_DM_LUA AND NOT BUILD_AS_PLUGINS) ../contrib/src/uscxml/CustomExecutableContent.cpp) endif() USCXML_TEST_COMPILE(NAME test-url LABEL general/test-url FILES src/test-url.cpp) +USCXML_TEST_COMPILE(NAME test-utf8 LABEL general/test-utf8 FILES src/test-utf8.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) diff --git a/test/src/test-snippets.cpp b/test/src/test-snippets.cpp index 581a258..f26b730 100644 --- a/test/src/test-snippets.cpp +++ b/test/src/test-snippets.cpp @@ -35,8 +35,7 @@ int main(int argc, char** argv) { try { Logger::getDefault().log(USCXML_FATAL) << "Foo!" << " BAR?" << std::endl; microstep_snippet(); - } - catch (...) { + } catch (...) { exit(EXIT_FAILURE); } } diff --git a/test/src/test-utf8.cpp b/test/src/test-utf8.cpp new file mode 100644 index 0000000..37aace0 --- /dev/null +++ b/test/src/test-utf8.cpp @@ -0,0 +1,88 @@ +#include "uscxml/config.h" +#include "uscxml/Interpreter.h" +#include "uscxml/plugins/Factory.h" +#include "uscxml/plugins/DataModelImpl.h" + +#include +#include + +/* +#define WITH_DM_ECMA_V8 +#define WITH_DM_ECMA_JSC +#define WITH_DM_LUA +#define WITH_DM_PYTHON +#define WITH_DM_C89 +#define WITH_DM_PROMELA +*/ + +using namespace uscxml; + +class TestDataModelCallbacks : public DataModelCallbacks { +public: + std::string _name = "name"; + std::string _sessionId = "sessionId"; + std::map _ioProcs; + std::map _invokers; + + const std::string& getName() { + return _name; + } + const std::string& getSessionId() { + return _sessionId; + } + const std::map& getIOProcessors() { + return _ioProcs; + } + virtual bool isInState(const std::string& stateId) { + return true; + } + XERCESC_NS::DOMDocument* getDocument() const { + return NULL; + } + const std::map& getInvokers() { + return _invokers; + } + Logger getLogger() { + return Logger::getDefault(); + } + +}; + +TestDataModelCallbacks dmCallbacks; +std::list datamodels; + +bool testSimpleJSON() { + for (auto dmName : datamodels) { + std::cout << "** " << dmName << ":" << std::endl; + DataModel dm = Factory::getInstance()->createDataModel(dmName, &dmCallbacks); + Data json = Data::fromJSON("{\"ü\": \"ä\"}"); + dm.init("foo", json); + Data json2 = dm.evalAsData("foo"); + std::cout << json << std::endl; + std::cout << json2 << std::endl; + assert(json == json2); + + dm.init("bar", Data("ö", Data::VERBATIM)); + bool cmp = dm.evalAsBool("bar == \"ö\""); + std::cout << dm.evalAsData("bar") << std::endl; + assert(cmp); + + } + return true; +} + + +int main(int argc, char** argv) { +#ifdef WITH_DM_LUA + datamodels.push_back("lua"); +#endif +#ifdef WITH_DM_PROMELA +// datamodels.push_back("promela"); +#endif +#if (defined WITH_DM_ECMA_V8 || defined WITH_DM_ECMA_JSC) + datamodels.push_back("ecmascript"); +#endif + + testSimpleJSON(); + return EXIT_SUCCESS; +} -- cgit v0.12