diff options
author | Stefan Radomski <github@mintwerk.de> | 2017-01-08 21:59:18 (GMT) |
---|---|---|
committer | Stefan Radomski <github@mintwerk.de> | 2017-01-08 21:59:18 (GMT) |
commit | 030f3b483f54dbef6e164194a1771ef5b346312b (patch) | |
tree | 3f5b949b5ffed83d0b41a95d9fd3cfafd17cab2d /test/src | |
parent | 1ab8b9a0dcaa131b8cccc735a1794ce39b351715 (diff) | |
download | uscxml-030f3b483f54dbef6e164194a1771ef5b346312b.zip uscxml-030f3b483f54dbef6e164194a1771ef5b346312b.tar.gz uscxml-030f3b483f54dbef6e164194a1771ef5b346312b.tar.bz2 |
Support for caching values on filesystem
Use USCXML_NOCACHE_FILES=YES to prevent, I will make this a build flag
Diffstat (limited to 'test/src')
-rw-r--r-- | test/src/test-extensions.cpp | 10 | ||||
-rwxr-xr-x | test/src/test-http-debugger.pl | 118 | ||||
-rw-r--r-- | test/src/test-url.cpp | 216 |
3 files changed, 187 insertions, 157 deletions
diff --git a/test/src/test-extensions.cpp b/test/src/test-extensions.cpp index d73065c..e3dfbb6 100644 --- a/test/src/test-extensions.cpp +++ b/test/src/test-extensions.cpp @@ -54,9 +54,9 @@ std::shared_ptr<PausableDelayedEventQueue> nestedDelayQueue; class PausableDelayedEventQueue : public BasicDelayedEventQueue { public: PausableDelayedEventQueue(DelayedEventQueueCallbacks* callbacks) : BasicDelayedEventQueue(callbacks) { - _pausedAt.tv_sec = 0; - _pausedAt.tv_usec = 0; - } + _pausedAt.tv_sec = 0; + _pausedAt.tv_usec = 0; + } std::shared_ptr<DelayedEventQueueImpl> create(DelayedEventQueueCallbacks* callbacks) { // remember as nestedDelayQueue in global scope @@ -100,8 +100,8 @@ public: evutil_gettimeofday(&now, NULL); evutil_timersub(&now, &_pausedAt, &pausedFor); - _pausedAt.tv_sec = 0; - _pausedAt.tv_usec = 0; + _pausedAt.tv_sec = 0; + _pausedAt.tv_usec = 0; for(auto& callbackData : _callbackData) { // add the time we were paused to all due times diff --git a/test/src/test-http-debugger.pl b/test/src/test-http-debugger.pl index 14b2468..a7a1d0a 100755 --- a/test/src/test-http-debugger.pl +++ b/test/src/test-http-debugger.pl @@ -39,6 +39,42 @@ sub assertSuccess { from_json($response->content())->{'status'} eq "success" or die($message); } +sub prepareSession { + my $xml = shift; + + ### Get a session + my $request = GET $baseURL.'/connect'; + $response = $ua->request($request); + assertSuccess($response, "Could not connect"); + + my $session = from_json($response->content())->{'session'}; + die("Cannot acquire session from server") if (!$session); + + ### Prepare an SCXML interpreter + $request = POST $baseURL.'/prepare', + [ + 'session' => $session, + 'url' => 'http://localhost/anonymous.scxml', + 'xml' => $xml + ]; + $response = $ua->request($request); + assertSuccess($response, "Could not prepare SCXML"); + + return $session; +} + +sub finishSession { + my $session = shift; + + ### Prepare an SCXML interpreter + $request = POST $baseURL.'/disconnect', + [ + 'session' => $session, + ]; + $response = $ua->request($request); + assertSuccess($response, "Could not disconnect session"); +} + sub popAndCompare { my $qualified = shift; my $bp = shift(@breakpointSeq); @@ -97,24 +133,8 @@ END_SCXML ); - ### Get a session - $request = GET $baseURL.'/connect'; - $response = $ua->request($request); - assertSuccess($response, "Could not connect"); - - my $session = from_json($response->content())->{'session'}; - die("Cannot acquire session from server") if (!$session); - - ### Prepare an SCXML interpreter - $request = POST $baseURL.'/prepare', - [ - 'session' => $session, - 'url' => 'http://localhost/test152.scxml', - 'xml' => $xml - ]; - $response = $ua->request($request); - assertSuccess($response, "Could not prepare SCXML"); - + my $session = &prepareSession($xml); + while(@breakpointSeq > 0) { ### Take a step $request = POST $baseURL.'/step', ['session' => $session]; @@ -145,6 +165,7 @@ END_SCXML $data = from_json($response->content()); die("Machine not yet finished") if ($data->{'replyType'} ne "finished"); + &finishSession($session); } sub testBreakpoint { @@ -163,23 +184,7 @@ sub testBreakpoint { </scxml> END_SCXML - ### Get a session - $request = GET $baseURL.'/connect'; - $response = $ua->request($request); - assertSuccess($response, "Could not connect"); - - my $session = from_json($response->content())->{'session'}; - die("Cannot acquire session from server") if (!$session); - - ### Prepare an SCXML interpreter - $request = POST $baseURL.'/prepare', - [ - 'session' => $session, - 'url' => 'http://localhost/test154.scxml', - 'xml' => $xml - ]; - $response = $ua->request($request); - assertSuccess($response, "Could not prepare SCXML"); + my $session = prepareSession($xml); ### Skip to breakpoint $request = POST $baseURL.'/breakpoint/skipto', @@ -200,9 +205,50 @@ END_SCXML $data = from_json($response->content()); print Dumper($data); + + &finishSession($session); +} + +sub testIssueReporting { + my $xml = << 'END_SCXML'; + <scxml> + <state id='s1'> + <onentry> + <log label="'foo'" /> + </onentry> + <transition target='s2' /> + </state> + <state id='s2'> + <transition target='pass' /> + </state> + <state id='s3'> + <onentry> + <log label="'Unreachable!'" /> + </onentry> + </state> + <final id='pass' /> + </scxml> +END_SCXML + + my $session = prepareSession($xml); + + ### Get a list of issues + $request = POST $baseURL.'/issues', + [ + 'session' => $session + ]; + $response = $ua->request($request); + assertSuccess($response, "Could not get issues for prepared SCXML document"); + + $data = from_json($response->content()); + print Dumper($data); + + &finishSession($session); + } -# &testSimpleStepping(); +&testSimpleStepping(); &testBreakpoint(); +&testIssueReporting(); kill('TERM', $pid);
\ No newline at end of file diff --git a/test/src/test-url.cpp b/test/src/test-url.cpp index 4d6cee8..c1a840f 100644 --- a/test/src/test-url.cpp +++ b/test/src/test-url.cpp @@ -9,6 +9,9 @@ #include <assert.h>
#include <iostream>
+#include <sys/types.h>
+#include <sys/stat.h>
+
using namespace uscxml;
using namespace XERCESC_NS;
@@ -46,6 +49,29 @@ bool canResolve(const std::string& url) { }
}
+bool dirExists(const std::string& path) {
+#ifdef _WIN32
+ DWORD ftyp = GetFileAttributesA(dirName_in.c_str());
+ if (ftyp == INVALID_FILE_ATTRIBUTES)
+ return false; //something is wrong with your path!
+
+ if (ftyp & FILE_ATTRIBUTE_DIRECTORY)
+ return true; // this is a directory!
+
+ return false; // this is not a directory!
+#else
+ struct stat info;
+
+ if(stat( path.c_str(), &info ) != 0) {
+ return false;
+ } else if(info.st_mode & S_IFDIR) {
+ return true;
+ } else {
+ return false;
+ }
+#endif
+}
+
void testFileURLs() {
// absolute
@@ -125,33 +151,47 @@ void testFileURLs() { }
-int main(int argc, char** argv) {
-#ifdef _WIN32
- WSADATA wsaData;
- WSAStartup(MAKEWORD(2, 2), &wsaData);
-#endif
-
- // some URLs from http://www-archive.mozilla.org/quality/networking/testing/filetests.html
-
-// URL foo("file:/");
-// assert(foo.isAbsolute());
-
+void testData() {
+ {
+ Data data = Data::fromJSON("{\"shiftKey\":false,\"toElement\":{\"id\":\"\",\"localName\":\"body\"},\"clientY\":38,\"y\":38,\"x\":66,\"ctrlKey\":false,\"relatedTarget\":{\"id\":\"\",\"localName\":\"body\"},\"clientX\":66,\"screenY\":288,\"metaKey\":false,\"offsetX\":58,\"altKey\":false,\"offsetY\":30,\"fromElement\":{\"id\":\"foo\",\"localName\":\"div\"},\"screenX\":-1691,\"dataTransfer\":null,\"button\":0,\"pageY\":38,\"layerY\":38,\"pageX\":66,\"charCode\":0,\"which\":0,\"keyCode\":0,\"detail\":0,\"layerX\":66,\"returnValue\":true,\"timeStamp\":1371223991895,\"eventPhase\":2,\"target\":{\"id\":\"foo\",\"localName\":\"div\"},\"defaultPrevented\":false,\"srcElement\":{\"id\":\"foo\",\"localName\":\"div\"},\"type\":\"mouseout\",\"cancelable\":true,\"currentTarget\":{\"id\":\"foo\",\"localName\":\"div\"},\"bubbles\":true,\"cancelBubble\":false}");
+ std::cout << data << std::endl;
+ }
- HTTPServer::getInstance(8199, 8200);
+ {
+ 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;
+ }
- std::string exeName = argv[0];
- exeName = exeName.substr(exeName.find_last_of("\\/") + 1);
+}
- try {
- testFileURLs();
- } catch (Event e) {
- LOGD(USCXML_ERROR) << e;
- exit(EXIT_FAILURE);
+void testHTTPURLs() {
+ {
+ URL url("http://www.heise.de/de/index.html");
+ std::cout << std::string(url) << std::endl;
+ assert(url.isAbsolute());
+ assert(iequals(std::string(url), "http://www.heise.de/de/index.html"));
+ assert(iequals(url.scheme(), "http"));
+ assert(iequals(url.host(), "www.heise.de"));
+ assert(iequals(url.path(), "/de/index.html"));
+ url.download();
}
{
try {
URL url("http://asdfasdfasdfasdf.wgferg");
+ std::cout << std::string(url) << std::endl;
url.download(true);
assert(false);
} catch (Event e) {
@@ -161,6 +201,7 @@ int main(int argc, char** argv) { {
try {
URL url("http://uscxml.tk.informatik.tu-darmstadt.de/foobarfoo.html");
+ std::cout << std::string(url) << std::endl;
url.download(true);
assert(false);
} catch (Event e) {
@@ -168,40 +209,20 @@ int main(int argc, char** argv) { }
}
-#if 0
+#ifndef _WIN32
+ // no SSL support on windows
{
- Interpreter interpreter = Interpreter::fromURI("/Users/sradomski/Desktop/application_small.scxml");
- assert(interpreter);
- std::list<std::string> states;
- states.push_back("b");
- interpreter.setConfiguration(states);
- interpreter.interpret();
+ URL url("https://raw.github.com/tklab-tud/uscxml/master/test/samples/uscxml/test-ecmascript.scxml");
+ std::cout << std::string(url) << std::endl;
+ assert(url.isAbsolute());
+ assert(iequals(url.scheme(), "https"));
+ url.download();
}
#endif
-#if 0
- {
- try {
-
- URL url(argv[0]);
- assert(url.isAbsolute());
- assert(canResolve(argv[0]));
- assert(canResolve(url.asString()));
-
- URL baseUrl = URL::asBaseURL(url);
- URL exeUrl(exeName);
- exeUrl.toAbsolute(baseUrl);
- assert(canResolve(exeUrl.asString()));
- std::cout << exeUrl.asString() << std::endl;
- exeUrl.download(true);
- assert(exeUrl.getInContent().length() > 0);
-
- } catch (Event e) {
- std::cout << e << std::endl;
- }
- }
-#endif
+}
+void testServlets() {
{
TestServlet* testServlet1 = new TestServlet(false);
TestServlet* testServlet2 = new TestServlet(false);
@@ -218,81 +239,44 @@ int main(int argc, char** argv) { HTTPServer::unregisterServlet(testServlet2);
}
-#if 0
- {
- 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"));
+void testPaths() {
+ std::string resourceDir = URL::getResourceDir();
+ std::cout << resourceDir << std::endl;
+ assert(dirExists(resourceDir));
- HTTPServer::unregisterServlet(testServlet1);
- HTTPServer::unregisterServlet(testServlet2);
- HTTPServer::unregisterServlet(testServlet3);
- }
+ std::string tmpPrivateDir = URL::getTempDir(false);
+ std::cout << tmpPrivateDir << std::endl;
+ assert(dirExists(tmpPrivateDir));
+
+ std::string tmpSharedDir = URL::getTempDir(true);
+ std::cout << tmpSharedDir << std::endl;
+ assert(dirExists(tmpSharedDir));
+}
+
+int main(int argc, char** argv) {
+#ifdef _WIN32
+ WSADATA wsaData;
+ WSAStartup(MAKEWORD(2, 2), &wsaData);
#endif
- {
- Data data = Data::fromJSON("{\"shiftKey\":false,\"toElement\":{\"id\":\"\",\"localName\":\"body\"},\"clientY\":38,\"y\":38,\"x\":66,\"ctrlKey\":false,\"relatedTarget\":{\"id\":\"\",\"localName\":\"body\"},\"clientX\":66,\"screenY\":288,\"metaKey\":false,\"offsetX\":58,\"altKey\":false,\"offsetY\":30,\"fromElement\":{\"id\":\"foo\",\"localName\":\"div\"},\"screenX\":-1691,\"dataTransfer\":null,\"button\":0,\"pageY\":38,\"layerY\":38,\"pageX\":66,\"charCode\":0,\"which\":0,\"keyCode\":0,\"detail\":0,\"layerX\":66,\"returnValue\":true,\"timeStamp\":1371223991895,\"eventPhase\":2,\"target\":{\"id\":\"foo\",\"localName\":\"div\"},\"defaultPrevented\":false,\"srcElement\":{\"id\":\"foo\",\"localName\":\"div\"},\"type\":\"mouseout\",\"cancelable\":true,\"currentTarget\":{\"id\":\"foo\",\"localName\":\"div\"},\"bubbles\":true,\"cancelBubble\":false}");
- std::cout << data << std::endl;
- }
- {
- 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;
- }
+ // some URLs from http://www-archive.mozilla.org/quality/networking/testing/filetests.html
- {
- URL url("http://www.heise.de/de/index.html");
- std::cout << std::string(url) << std::endl;
- assert(url.isAbsolute());
- assert(iequals(std::string(url), "http://www.heise.de/de/index.html"));
- assert(iequals(url.scheme(), "http"));
- assert(iequals(url.host(), "www.heise.de"));
- assert(iequals(url.path(), "/de/index.html"));
- url.download();
- }
+ HTTPServer::getInstance(8199, 8200);
-#ifndef _WIN32
- {
- URL url("https://raw.github.com/tklab-tud/uscxml/master/test/samples/uscxml/test-ecmascript.scxml");
- std::cout << std::string(url) << std::endl;
- assert(url.isAbsolute());
- assert(iequals(url.scheme(), "https"));
- url.download();
+ try {
+ testPaths();
+ testFileURLs();
+ testHTTPURLs();
+ testData();
+ testServlets();
+ } catch (Event e) {
+ LOGD(USCXML_ERROR) << e;
+ exit(EXIT_FAILURE);
}
-#endif
-#if 0
- {
- URL url("test/index.html");
- assert(iequals(url.scheme(), ""));
- url.toAbsoluteCwd();
- assert(iequals(url.scheme(), "file"));
- std::cout << std::string(url) << 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"));
- }
-#endif
+
+
}
|