summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt1
-rw-r--r--src/uscxml/Interpreter.cpp11
-rw-r--r--src/uscxml/Interpreter.h5
-rw-r--r--src/uscxml/Message.cpp4
-rw-r--r--src/uscxml/Message.h2
-rw-r--r--src/uscxml/datamodel/ecmascript/v8/V8DataModel.cpp9
-rw-r--r--test/CMakeLists.txt8
-rw-r--r--test/src/test-apache-commons.cpp4
-rw-r--r--test/src/test-ecmascript-v8.cpp27
-rw-r--r--test/src/test-execution.cpp2
-rw-r--r--test/src/test-predicates.cpp2
11 files changed, 31 insertions, 44 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index dcbdc1b..fe9d754 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 2.8.4)
project(uscxml)
+enable_testing()
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/contrib/cmake)
diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp
index b1c504c..f965e1e 100644
--- a/src/uscxml/Interpreter.cpp
+++ b/src/uscxml/Interpreter.cpp
@@ -250,9 +250,15 @@ void Interpreter::initializeData(const Arabica::DOM::Node<std::string>& data) {
_dataModel->assign(ATTR(data, "id"), value);
} else if (data.hasChildNodes()) {
// search for the text node with the actual script
- Data value = Data(data);
+ NodeList<std::string> dataChilds = data.getChildNodes();
+ for (int i = 0; i < dataChilds.getLength(); i++) {
+ if (dataChilds.item(i).getNodeType() == Node_base::TEXT_NODE) {
+ Data value = Data(dataChilds.item(i), Data::INTERPRETED);
+ _dataModel->assign(ATTR(data, "id"), value);
+ break;
+ }
+ }
// std::cout << value << std::endl;
- _dataModel->assign(ATTR(data, "id"), value);
}
} catch (Event e) {
@@ -1406,6 +1412,7 @@ Arabica::DOM::Node<std::string> Interpreter::findLCCA(const Arabica::XPath::Node
Arabica::DOM::Node<std::string> Interpreter::getState(const std::string& stateId) {
// first try atomic and compund states
+ std::cout << _nsPrefix << stateId << std::endl;
NodeSet<std::string> target = _xpath.evaluate("//" + _nsPrefix + "state[@id='" + stateId + "']", _doc).asNodeSet();
if (target.size() > 0)
goto FOUND;
diff --git a/src/uscxml/Interpreter.h b/src/uscxml/Interpreter.h
index 9447498..cad8ee8 100644
--- a/src/uscxml/Interpreter.h
+++ b/src/uscxml/Interpreter.h
@@ -30,11 +30,6 @@ namespace uscxml {
LATE = 1
};
- struct SendData {
- Interpreter* interpreter;
- uscxml::SendRequest req;
- };
-
virtual ~Interpreter();
static Interpreter* fromDOM(const Arabica::DOM::Node<std::string>& node);
diff --git a/src/uscxml/Message.cpp b/src/uscxml/Message.cpp
index 9b713ca..a2990b9 100644
--- a/src/uscxml/Message.cpp
+++ b/src/uscxml/Message.cpp
@@ -7,7 +7,7 @@ namespace uscxml {
static int _dataIndentation = 1;
-Data::Data(const Arabica::DOM::Node<std::string>& dom) {
+Data::Data(const Arabica::DOM::Node<std::string>& dom, Type type) {
// we may need to convert some keys to arrays if we have the same name as an element
std::map<std::string, std::list<Data> > arrays;
// Interpreter::dump(dom);
@@ -54,7 +54,7 @@ Data::Data(const Arabica::DOM::Node<std::string>& dom) {
}
} else {
atom = dom.getNodeValue();
- type = VERBATIM;
+ this->type = type;
}
std::map<std::string, std::list<Data> >::iterator arrayIter = arrays.begin();
diff --git a/src/uscxml/Message.h b/src/uscxml/Message.h
index 34b85e1..be7747d 100644
--- a/src/uscxml/Message.h
+++ b/src/uscxml/Message.h
@@ -24,7 +24,7 @@ public:
Data() {}
Data(const std::string& atom_, Type type_ = INTERPRETED) : atom(atom_), type(type_) {}
- Data(const Arabica::DOM::Node<std::string>& dom);
+ Data(const Arabica::DOM::Node<std::string>& dom, Type type = VERBATIM);
virtual ~Data() {}
static Data fromXML(const std::string& xmlString);
diff --git a/src/uscxml/datamodel/ecmascript/v8/V8DataModel.cpp b/src/uscxml/datamodel/ecmascript/v8/V8DataModel.cpp
index 2dfc72f..52c7ad7 100644
--- a/src/uscxml/datamodel/ecmascript/v8/V8DataModel.cpp
+++ b/src/uscxml/datamodel/ecmascript/v8/V8DataModel.cpp
@@ -14,10 +14,13 @@ DataModel* V8DataModel::create(Interpreter* interpreter) {
v8::HandleScope scope;
// see http://stackoverflow.com/questions/3171418/v8-functiontemplate-class-instance
- dm->_globalTemplate = v8::Persistent<v8::ObjectTemplate>(v8::ObjectTemplate::New());
- dm->_globalTemplate->Set(v8::String::New("In"), v8::FunctionTemplate::New(jsIn, v8::External::New(reinterpret_cast<void*>(this))));
+// dm->_globalTemplate = v8::Persistent<v8::ObjectTemplate>(v8::ObjectTemplate::New());
+// dm->_globalTemplate->Set(v8::String::New("In"), v8::FunctionTemplate::New(jsIn, v8::External::New(reinterpret_cast<void*>(this))));
+
+ v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
+ global->Set(v8::String::New("In"), v8::FunctionTemplate::New(jsIn, v8::External::New(reinterpret_cast<void*>(dm))));
- dm->_contexts.push_back(v8::Context::New(0, _globalTemplate));
+ dm->_contexts.push_back(v8::Context::New(NULL, global));
dm->setName(interpreter->getName());
dm->setSessionId(interpreter->getSessionId());
dm->eval("_ioprocessors = {};");
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index bea3b53..0abcafa 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -1,21 +1,21 @@
add_executable(test-predicates src/test-predicates.cpp)
target_link_libraries(test-predicates uscxml)
-add_test(test-predicates ${CMAKE_SOURCE_DIR}/test/src/test-predicates.scxml)
+add_test(test-predicates ${CURRENT_BINARY_DIR}/test-predicates ${CMAKE_SOURCE_DIR}/test/src/test-predicates.scxml)
set_target_properties(test-predicates PROPERTIES FOLDER "Tests")
add_executable(test-execution src/test-execution.cpp)
target_link_libraries(test-execution uscxml)
-add_test(test-execution ${CMAKE_SOURCE_DIR}/test/src/test-execution.scxml)
+add_test(test-execution ${CURRENT_BINARY_DIR}/test-execution ${CMAKE_SOURCE_DIR}/test/src/test-execution.scxml)
set_target_properties(test-execution PROPERTIES FOLDER "Tests")
add_executable(test-apache-commons src/test-apache-commons.cpp)
target_link_libraries(test-apache-commons uscxml)
-add_test(test-apache-commons ${CMAKE_SOURCE_DIR}/test/apache)
+add_test(test-apache-commons ${CURRENT_BINARY_DIR}/test-apache-commons ${CMAKE_SOURCE_DIR}/test/samples/apache)
set_target_properties(test-apache-commons PROPERTIES FOLDER "Tests")
add_executable(test-ecmascript-v8 src/test-ecmascript-v8.cpp)
target_link_libraries(test-ecmascript-v8 uscxml)
-add_test(test-ecmascript-v8 test-ecmascript-v8)
+add_test(test-ecmascript-v8 ${CURRENT_BINARY_DIR}/test-ecmascript-v8 ${CMAKE_SOURCE_DIR}/test/src/test-ecmascript.scxml)
set_target_properties(test-ecmascript-v8 PROPERTIES FOLDER "Tests")
add_executable(test-communication src/test-communication.cpp)
diff --git a/test/src/test-apache-commons.cpp b/test/src/test-apache-commons.cpp
index 51c275d..3bfbfed 100644
--- a/test/src/test-apache-commons.cpp
+++ b/test/src/test-apache-commons.cpp
@@ -9,7 +9,7 @@ static std::string path;
bool testEvents1() {
LOG(INFO) << "---- testEvent1 ";
- Interpreter* interpreter = new Interpreter(path + "/eventdata-01.xml");
+ Interpreter* interpreter = Interpreter::fromURI(path + "/eventdata-01.xml");
interpreter->start();
interpreter->waitForStabilization();
assert(interpreter->getConfiguration().size() == 1);
@@ -42,7 +42,7 @@ bool testEvents1() {
bool testEvents2() {
LOG(INFO) << "---- testEvent2 ";
- Interpreter* interpreter = new Interpreter(path + "/eventdata-02.xml");
+ Interpreter* interpreter = Interpreter::fromURI(path + "/eventdata-02.xml");
interpreter->start();
interpreter->waitForStabilization();
assert(interpreter->getConfiguration().size() == 1);
diff --git a/test/src/test-ecmascript-v8.cpp b/test/src/test-ecmascript-v8.cpp
index d0b69ba..d11fc61 100644
--- a/test/src/test-ecmascript-v8.cpp
+++ b/test/src/test-ecmascript-v8.cpp
@@ -10,25 +10,8 @@ int main(int argc, char** argv) {
using namespace uscxml;
using namespace Arabica::DOM;
using namespace Arabica::XPath;
-
-// class SCXMLRunner : public Thread {
-// public:
-// SCXMLRunner(Runtime* runtime) : _runtime(runtime) {}
-// void run() {
-// _runtime->interpret();
-// }
-//
-// Runtime* _runtime;
-// };
-
-// boost::shared_ptr<V8DataModel> v8 = boost::static_pointer_cast<V8DataModel>(Factory::create("datamodel:ecmascript", Arabica::DOM::Node<std::string>()));
-// v8->eval("var x = 4;");
-// assert(v8->evalAsBool("x == 4"));
-// assert(!v8->evalAsBool("x == 5"));
-
- Interpreter* scxml = new Interpreter(argv[1]);
- scxml->dump();
-// scxml->interpret();
+
+ Interpreter* scxml = Interpreter::fromURI(argv[1]);
scxml->start();
scxml->waitForStabilization();
@@ -36,9 +19,7 @@ int main(int argc, char** argv) {
event1.name = "event1";
scxml->receive(event1);
scxml->waitForStabilization();
- tthread::this_thread::sleep_for(tthread::chrono::milliseconds(200));
-
-// SCXMLRunner* scxmlRun = new SCXMLRunner(scxmlRuntime);
-// scxmlRun->start();
+ while(true)
+ tthread::this_thread::sleep_for(tthread::chrono::milliseconds(200));
} \ No newline at end of file
diff --git a/test/src/test-execution.cpp b/test/src/test-execution.cpp
index e484eb4..cea89b5 100644
--- a/test/src/test-execution.cpp
+++ b/test/src/test-execution.cpp
@@ -10,7 +10,7 @@ int main(int argc, char** argv) {
using namespace Arabica::DOM;
using namespace Arabica::XPath;
- Interpreter* interpreter = new Interpreter(argv[1]);
+ Interpreter* interpreter = Interpreter::fromURI(argv[1]);
interpreter->dump();
interpreter->interpret();
} \ No newline at end of file
diff --git a/test/src/test-predicates.cpp b/test/src/test-predicates.cpp
index 73c37dc..0494c24 100644
--- a/test/src/test-predicates.cpp
+++ b/test/src/test-predicates.cpp
@@ -12,7 +12,7 @@ int main(int argc, char** argv) {
using namespace Arabica::DOM;
using namespace Arabica::XPath;
- Interpreter* interpreter = new Interpreter(argv[1]);
+ Interpreter* interpreter = Interpreter::fromURI(argv[1]);
Node<std::string> atomicState = interpreter->getState("atomic");
assert(Interpreter::isAtomic(atomicState));