diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/CMakeLists.txt | 1 | ||||
-rw-r--r-- | test/src/test-snippets.cpp | 3 | ||||
-rw-r--r-- | test/src/test-utf8.cpp | 88 |
3 files changed, 90 insertions, 2 deletions
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 <iostream> +#include <cassert> + +/* +#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<std::string, IOProcessor> _ioProcs; + std::map<std::string, Invoker> _invokers; + + const std::string& getName() { + return _name; + } + const std::string& getSessionId() { + return _sessionId; + } + const std::map<std::string, IOProcessor>& getIOProcessors() { + return _ioProcs; + } + virtual bool isInState(const std::string& stateId) { + return true; + } + XERCESC_NS::DOMDocument* getDocument() const { + return NULL; + } + const std::map<std::string, Invoker>& getInvokers() { + return _invokers; + } + Logger getLogger() { + return Logger::getDefault(); + } + +}; + +TestDataModelCallbacks dmCallbacks; +std::list<std::string> 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; +} |