diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/CMakeLists.txt | 10 | ||||
-rw-r--r-- | test/samples/uscxml/test-jvoicexml.scxml | 57 | ||||
-rw-r--r-- | test/src/test-mmi.cpp | 4 | ||||
-rw-r--r-- | test/src/test-url.cpp | 358 |
4 files changed, 248 insertions, 181 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4f803e7..9bfe9da 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -58,10 +58,12 @@ target_link_libraries(test-url uscxml) add_test(test-url ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-url) set_target_properties(test-url PROPERTIES FOLDER "Tests") -add_executable(test-mmi src/test-mmi.cpp) -target_link_libraries(test-mmi uscxml) -add_test(test-url ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-mmi) -set_target_properties(test-mmi PROPERTIES FOLDER "Tests") +if (NOT WIN32) + add_executable(test-mmi src/test-mmi.cpp) + target_link_libraries(test-mmi uscxml) + add_test(test-url ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-mmi) + set_target_properties(test-mmi PROPERTIES FOLDER "Tests") +endif() add_executable(scxml-test-framework-client src/scxml-test-framework-client.cpp) diff --git a/test/samples/uscxml/test-jvoicexml.scxml b/test/samples/uscxml/test-jvoicexml.scxml new file mode 100644 index 0000000..691a951 --- /dev/null +++ b/test/samples/uscxml/test-jvoicexml.scxml @@ -0,0 +1,57 @@ +<scxml xmlns="http://www.w3.org/2005/07/scxml" + xmlns:vxml="http://www.w3.org/2001/vxml" + datamodel="ecmascript"> + <script src="http://uscxml.tk.informatik.tu-darmstadt.de/scripts/dump.js" /> + <state id="start"> + <invoke type="heartbeat"> + <param name="interval" expr="'4s'" /> + </invoke> + + <invoke type="vxml" id="vxml"> + <finalize> + <script> + dump(_event); + </script> + </finalize> + </invoke> + + <onentry> + <log expr="'Starting!!'" /> + </onentry> + + <state id="idle"> + <onentry> + <log expr="'Idling!'" /> + </onentry> + + <transition event="heartbeat.4s" target="vxmlHello"> + <log expr="'Foo!'" /> + </transition> + </state> + + <state id="vxmlHello"> + <onentry> + <send target="#_vxml"> + <content> + <vxml:vxml version="2.1" xml:lang="en" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schematicLocation="http://www.w3.org/2001/vxml http://www.w3.org/TR/voicexml20/vxml.xsd"> + <vxml:form id="say_hello"> + <vxml:block> + Hello World! + <vxml:goto next="#say_goodbye" /> + </vxml:block> + </vxml:form> + <vxml:form id="say_goodbye"> + <vxml:block> + <vxml:prompt>Goodbye!</vxml:prompt> + </vxml:block> + </vxml:form> + </vxml:vxml> + </content> + </send> + </onentry> + <transition target="idle" /> + </state> + </state> +</scxml>
\ No newline at end of file diff --git a/test/src/test-mmi.cpp b/test/src/test-mmi.cpp index 2b34a82..0b9f5f9 100644 --- a/test/src/test-mmi.cpp +++ b/test/src/test-mmi.cpp @@ -1,3 +1,6 @@ +#include <iostream> +#include <string> + #include "uscxml/plugins/ioprocessor/modality/MMIMessages.h" #include <SAX/helpers/InputSourceResolver.hpp> @@ -6,7 +9,6 @@ #include <assert.h> #include <boost/algorithm/string.hpp> -#include <iostream> using namespace uscxml; using namespace boost; diff --git a/test/src/test-url.cpp b/test/src/test-url.cpp index 19257d6..69951e4 100644 --- a/test/src/test-url.cpp +++ b/test/src/test-url.cpp @@ -1,177 +1,183 @@ -#include "uscxml/URL.h" -#include "uscxml/Message.h" -#include "uscxml/Interpreter.h" -#include "uscxml/server/HTTPServer.h" - -#include <SAX/helpers/InputSourceResolver.hpp> - -#include <assert.h> -#include <boost/algorithm/string.hpp> -#include <iostream> - -using namespace uscxml; -using namespace boost; - -class TestServlet : public HTTPServlet { -public: - TestServlet(bool adaptPath) : _canAdaptPath(adaptPath) {} - - void httpRecvRequest(const HTTPServer::Request& request) {}; - bool canAdaptPath() { - return _canAdaptPath; - } - void setURL(const std::string& url) { - _actualUrl = url; - } - - std::string _actualUrl; - bool _canAdaptPath; -}; - -bool canResolve(const std::string& url) { - Arabica::SAX::InputSource<std::string> is(url); - Arabica::SAX::InputSourceResolver res1(is, Arabica::default_string_adaptor<std::string>()); - if(res1.resolve()) { - std::cout << "good: " << url << std::endl; - return true; - } else { - std::cout << "bad: " << url << std::endl; - return false; - } -} - -int main(int argc, char** argv) { - - std::string exeName = argv[0]; - exeName = exeName.substr(exeName.find_last_of("\\/") + 1); - - { - Interpreter interpreter = Interpreter::fromURI("/Users/sradomski/Desktop/application_small.scxml"); - assert(interpreter); - std::vector<std::string> states; - states.push_back("b"); - interpreter.setConfiguration(states); - interpreter.interpret(); - } - - { - URL url(argv[0]); - assert(canResolve(argv[0])); - assert(canResolve(url.asString())); - - URL baseUrl = URL::asBaseURL(url); - URL exeUrl(exeName); - exeUrl.toAbsolute(baseUrl); - assert(canResolve(exeUrl.asString())); - } - - { - TestServlet* testServlet1 = new TestServlet(false); - TestServlet* testServlet2 = new TestServlet(false); - - assert(HTTPServer::registerServlet("/foo", testServlet1)); - assert(!HTTPServer::registerServlet("/foo", testServlet2)); - HTTPServer::unregisterServlet(testServlet1); - assert(HTTPServer::registerServlet("/foo", testServlet2)); - HTTPServer::unregisterServlet(testServlet1); - - assert(HTTPServer::registerServlet("/foo/bar/", testServlet1)); - assert(!HTTPServer::registerServlet("/foo/bar/", testServlet2)); - HTTPServer::unregisterServlet(testServlet1); - HTTPServer::unregisterServlet(testServlet2); - } - - { - TestServlet* testServlet1 = new TestServlet(true); - TestServlet* testServlet2 = new TestServlet(true); - TestServlet* testServlet3 = new TestServlet(true); - - assert(HTTPServer::registerServlet("/foo", testServlet1)); - assert(HTTPServer::registerServlet("/foo", testServlet2)); - assert(HTTPServer::registerServlet("/foo", testServlet3)); - assert(boost::ends_with(testServlet1->_actualUrl, "foo")); - assert(boost::ends_with(testServlet2->_actualUrl, "foo2")); - assert(boost::ends_with(testServlet3->_actualUrl, "foo3")); - - HTTPServer::unregisterServlet(testServlet1); - HTTPServer::unregisterServlet(testServlet2); - HTTPServer::unregisterServlet(testServlet3); - } - - { - Data data = Data::fromJSON("asdf"); - std::cout << data << std::endl; - } - { - Data data = Data::fromJSON("[ '1', '2', '3', '4' ]"); - std::cout << data << std::endl; - } - { - Data data = Data::fromJSON("{'foo1': 'bar2', 'foo3': { 'foo4': 'bar5' }, 'foo6': 'bar7', 'foo8': { 'foo9': 'foo10': { 'foo11': 'bar12' } } }"); - std::cout << data << std::endl; - } - { - Data data = Data::fromJSON("{\"firstName\": \"John\", \"lastName\": \"Smith\", \"age\": 25, \"address\": { \"streetAddress\": \"21 2nd Street\", \"city\": \"New York\",\"state\": \"NY\",\"postalCode\": 10021},\"phoneNumber\": [{\"type\": \"home\",\"number\": \"212 555-1234\"},{ \"type\": \"fax\",\"number\": \"646 555-4567\"}]}"); - std::cout << data << std::endl; - } - - { - URL url("http://www.heise.de/index.html"); - std::cout << url.asString() << std::endl; - assert(url.isAbsolute()); - assert(iequals(url.scheme(), "http")); - assert(iequals(url.host(), "www.heise.de")); - assert(iequals(url.port(), "80")); - assert(iequals(url.path(), "/index.html")); - assert(iequals(url.asString(), "http://www.heise.de/index.html")); - std::stringstream content; - content << url; - } - - { - URL url("https://raw.github.com/tklab-tud/uscxml/master/test/samples/uscxml/test-ecmascript.scxml"); - std::cout << url.asString() << std::endl; - assert(url.isAbsolute()); - assert(iequals(url.scheme(), "https")); - std::stringstream content; - content << url; - } - - { - URL url("file:Document/Text.foo"); - std::cout << url.asString() << std::endl; - assert(!url.isAbsolute()); - assert(iequals(url.scheme(), "file")); - assert(iequals(url.host(), "")); - assert(iequals(url.port(), "0")); - assert(iequals(url.path(), "Document/Text.foo")); - assert(iequals(url.asString(), "file:Document/Text.foo")); - } - { - URL url("test/index.html"); - assert(iequals(url.scheme(), "")); - url.toAbsoluteCwd(); - assert(iequals(url.scheme(), "file")); - std::cout << url.asString() << std::endl; - } - { - URL url("C:\\Document\\Some Spaces\\index.txt"); - assert(url.isAbsolute()); - assert(iequals(url.scheme(), "file")); - std::cout << url.asString() << std::endl; - } - { - URL url = URL::toLocalFile("this is quite some content!", "txt"); - std::cout << url.asLocalFile("txt"); - assert(url.isAbsolute()); - assert(iequals(url.scheme(), "file")); - } - { - URL url("C:\\Document\\Some Spaces\\index.txt"); - assert(iequals(url.pathComponents()[0], "C:")); - assert(iequals(url.pathComponents()[1], "Document")); - assert(iequals(url.pathComponents()[2], "Some Spaces")); - assert(iequals(url.pathComponents()[3], "index.txt")); - } - +#include "uscxml/URL.h"
+#include "uscxml/Message.h"
+#include "uscxml/Interpreter.h"
+#include "uscxml/server/HTTPServer.h"
+
+#include <SAX/helpers/InputSourceResolver.hpp>
+
+#include <assert.h>
+#include <boost/algorithm/string.hpp>
+#include <iostream>
+
+using namespace uscxml;
+using namespace boost;
+
+class TestServlet : public HTTPServlet {
+public:
+ TestServlet(bool adaptPath) : _canAdaptPath(adaptPath) {}
+
+ void httpRecvRequest(const HTTPServer::Request& request) {};
+ bool canAdaptPath() {
+ return _canAdaptPath;
+ }
+ void setURL(const std::string& url) {
+ _actualUrl = url;
+ }
+
+ std::string _actualUrl;
+ bool _canAdaptPath;
+};
+
+bool canResolve(const std::string& url) {
+ Arabica::SAX::InputSource<std::string> is(url);
+ Arabica::SAX::InputSourceResolver res1(is, Arabica::default_string_adaptor<std::string>());
+ if(res1.resolve()) {
+ std::cout << "good: " << url << std::endl;
+ return true;
+ } else {
+ std::cout << "bad: " << url << std::endl;
+ return false;
+ }
+}
+
+int main(int argc, char** argv) {
+#ifdef _WIN32
+ WSADATA wsaData;
+ WSAStartup(MAKEWORD(2, 2), &wsaData);
+#endif
+
+ std::string exeName = argv[0];
+ exeName = exeName.substr(exeName.find_last_of("\\/") + 1);
+
+#if 0
+ {
+ Interpreter interpreter = Interpreter::fromURI("/Users/sradomski/Desktop/application_small.scxml");
+ assert(interpreter);
+ std::vector<std::string> states;
+ states.push_back("b");
+ interpreter.setConfiguration(states);
+ interpreter.interpret();
+ }
+#endif
+
+ {
+ URL url(argv[0]);
+ assert(canResolve(argv[0]));
+ assert(canResolve(url.asString()));
+
+ URL baseUrl = URL::asBaseURL(url);
+ URL exeUrl(exeName);
+ exeUrl.toAbsolute(baseUrl);
+ assert(canResolve(exeUrl.asString()));
+ }
+
+ {
+ TestServlet* testServlet1 = new TestServlet(false);
+ TestServlet* testServlet2 = new TestServlet(false);
+
+ assert(HTTPServer::registerServlet("/foo", testServlet1));
+ assert(!HTTPServer::registerServlet("/foo", testServlet2));
+ HTTPServer::unregisterServlet(testServlet1);
+ assert(HTTPServer::registerServlet("/foo", testServlet2));
+ HTTPServer::unregisterServlet(testServlet1);
+
+ assert(HTTPServer::registerServlet("/foo/bar/", testServlet1));
+ assert(!HTTPServer::registerServlet("/foo/bar/", testServlet2));
+ HTTPServer::unregisterServlet(testServlet1);
+ HTTPServer::unregisterServlet(testServlet2);
+ }
+
+ {
+ TestServlet* testServlet1 = new TestServlet(true);
+ TestServlet* testServlet2 = new TestServlet(true);
+ TestServlet* testServlet3 = new TestServlet(true);
+
+ assert(HTTPServer::registerServlet("/foo", testServlet1));
+ assert(HTTPServer::registerServlet("/foo", testServlet2));
+ assert(HTTPServer::registerServlet("/foo", testServlet3));
+ assert(boost::ends_with(testServlet1->_actualUrl, "foo"));
+ assert(boost::ends_with(testServlet2->_actualUrl, "foo2"));
+ assert(boost::ends_with(testServlet3->_actualUrl, "foo3"));
+
+ HTTPServer::unregisterServlet(testServlet1);
+ HTTPServer::unregisterServlet(testServlet2);
+ HTTPServer::unregisterServlet(testServlet3);
+ }
+
+ {
+ Data data = Data::fromJSON("asdf");
+ std::cout << data << std::endl;
+ }
+ {
+ Data data = Data::fromJSON("[ '1', '2', '3', '4' ]");
+ std::cout << data << std::endl;
+ }
+ {
+ Data data = Data::fromJSON("{'foo1': 'bar2', 'foo3': { 'foo4': 'bar5' }, 'foo6': 'bar7', 'foo8': { 'foo9': 'foo10': { 'foo11': 'bar12' } } }");
+ std::cout << data << std::endl;
+ }
+ {
+ Data data = Data::fromJSON("{\"firstName\": \"John\", \"lastName\": \"Smith\", \"age\": 25, \"address\": { \"streetAddress\": \"21 2nd Street\", \"city\": \"New York\",\"state\": \"NY\",\"postalCode\": 10021},\"phoneNumber\": [{\"type\": \"home\",\"number\": \"212 555-1234\"},{ \"type\": \"fax\",\"number\": \"646 555-4567\"}]}");
+ std::cout << data << std::endl;
+ }
+
+ {
+ URL url("http://www.heise.de/index.html");
+ std::cout << url.asString() << std::endl;
+ assert(url.isAbsolute());
+ assert(iequals(url.scheme(), "http"));
+ assert(iequals(url.host(), "www.heise.de"));
+ assert(iequals(url.port(), "80"));
+ assert(iequals(url.path(), "/index.html"));
+ assert(iequals(url.asString(), "http://www.heise.de/index.html"));
+ std::stringstream content;
+ content << url;
+ }
+
+ {
+ URL url("https://raw.github.com/tklab-tud/uscxml/master/test/samples/uscxml/test-ecmascript.scxml");
+ std::cout << url.asString() << std::endl;
+ assert(url.isAbsolute());
+ assert(iequals(url.scheme(), "https"));
+ std::stringstream content;
+ content << url;
+ }
+
+ {
+ URL url("file:Document/Text.foo");
+ std::cout << url.asString() << std::endl;
+ assert(!url.isAbsolute());
+ assert(iequals(url.scheme(), "file"));
+ assert(iequals(url.host(), ""));
+ assert(iequals(url.port(), "0"));
+ assert(iequals(url.path(), "Document/Text.foo"));
+ assert(iequals(url.asString(), "file:Document/Text.foo"));
+ }
+ {
+ URL url("test/index.html");
+ assert(iequals(url.scheme(), ""));
+ url.toAbsoluteCwd();
+ assert(iequals(url.scheme(), "file"));
+ std::cout << url.asString() << std::endl;
+ }
+ {
+ URL url("C:\\Document\\Some Spaces\\index.txt");
+ assert(url.isAbsolute());
+ assert(iequals(url.scheme(), "file"));
+ std::cout << url.asString() << std::endl;
+ }
+ {
+ URL url = URL::toLocalFile("this is quite some content!", "txt");
+ std::cout << url.asLocalFile("txt");
+ assert(url.isAbsolute());
+ assert(iequals(url.scheme(), "file"));
+ }
+ {
+ URL url("C:\\Document\\Some Spaces\\index.txt");
+ assert(iequals(url.pathComponents()[0], "C:"));
+ assert(iequals(url.pathComponents()[1], "Document"));
+ assert(iequals(url.pathComponents()[2], "Some Spaces"));
+ assert(iequals(url.pathComponents()[3], "index.txt"));
+ }
+
}
\ No newline at end of file |