summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk
diff options
context:
space:
mode:
Diffstat (limited to 'sca-cpp/trunk')
-rw-r--r--sca-cpp/trunk/etc/git-exclude4
-rw-r--r--sca-cpp/trunk/modules/json/json.hpp12
-rw-r--r--sca-cpp/trunk/modules/python/eval.hpp2
-rw-r--r--sca-cpp/trunk/modules/server/client-test.cpp30
-rw-r--r--sca-cpp/trunk/modules/server/mod-eval.cpp4
-rw-r--r--sca-cpp/trunk/modules/server/server-test.py10
-rw-r--r--sca-cpp/trunk/test/store-python/Makefile.am2
-rw-r--r--sca-cpp/trunk/test/store-python/currency-converter.py10
-rw-r--r--sca-cpp/trunk/test/store-python/fruits-catalog.py10
-rw-r--r--sca-cpp/trunk/test/store-python/htdocs/store.html4
-rwxr-xr-xsca-cpp/trunk/test/store-python/server-test (renamed from sca-cpp/trunk/test/store-python/store-composite-test)0
-rw-r--r--sca-cpp/trunk/test/store-python/shopping-cart.py88
-rw-r--r--sca-cpp/trunk/test/store-python/store.py7
-rw-r--r--sca-cpp/trunk/test/store-scheme/Makefile.am10
-rw-r--r--sca-cpp/trunk/test/store-scheme/fruits-catalog.scm3
-rw-r--r--sca-cpp/trunk/test/store-scheme/htdocs/store.html4
-rw-r--r--sca-cpp/trunk/test/store-scheme/script-test.cpp (renamed from sca-cpp/trunk/test/store-scheme/store-script-test.cpp)6
-rw-r--r--sca-cpp/trunk/test/store-scheme/script-test.scm (renamed from sca-cpp/trunk/test/store-scheme/store-script-test.scm)26
-rwxr-xr-xsca-cpp/trunk/test/store-scheme/server-test (renamed from sca-cpp/trunk/test/store-scheme/store-composite-test)0
-rw-r--r--sca-cpp/trunk/test/store-scheme/shopping-cart.scm3
-rw-r--r--sca-cpp/trunk/test/store-scheme/store.scm4
21 files changed, 105 insertions, 134 deletions
diff --git a/sca-cpp/trunk/etc/git-exclude b/sca-cpp/trunk/etc/git-exclude
index d71d8e428b..aa44227d1b 100644
--- a/sca-cpp/trunk/etc/git-exclude
+++ b/sca-cpp/trunk/etc/git-exclude
@@ -75,7 +75,5 @@ mcache-test
mcache-client-test
curl-test
scdl-test
-store-function-test
-store-object-test
-store-script-test
+script-test
diff --git a/sca-cpp/trunk/modules/json/json.hpp b/sca-cpp/trunk/modules/json/json.hpp
index e2f036541a..fc5e512d5e 100644
--- a/sca-cpp/trunk/modules/json/json.hpp
+++ b/sca-cpp/trunk/modules/json/json.hpp
@@ -381,6 +381,18 @@ const failable<list<string> > jsonResult(const value& id, const value& val, JSON
return writeJSON(valuesToElements(mklist<value>(mklist<value>("id", id), mklist<value>("result", val))), cx);
}
+/**
+ * Return a portable function name from a JSON-RPC function name.
+ * Strip the "system." and "Service." prefixes added by some JSON-RPC clients.
+ */
+const string funcName(const string& f) {
+ if (length(f) > 7 && find(f, "system.", 0) == 0)
+ return c_str(f) + 7;
+ if (length(f) > 8 && find(f, "Service.", 0) == 0)
+ return c_str(f) + 8;
+ return f;
+}
+
}
}
diff --git a/sca-cpp/trunk/modules/python/eval.hpp b/sca-cpp/trunk/modules/python/eval.hpp
index b0d793418a..cb6cdea3e2 100644
--- a/sca-cpp/trunk/modules/python/eval.hpp
+++ b/sca-cpp/trunk/modules/python/eval.hpp
@@ -152,7 +152,7 @@ PyObject* valueToPyObject(const value& v) {
case value::Bool:
return (bool)v? Py_True : Py_False;
default:
- return NULL;
+ return Py_None;
}
}
diff --git a/sca-cpp/trunk/modules/server/client-test.cpp b/sca-cpp/trunk/modules/server/client-test.cpp
index d037aabbf9..f46cba5068 100644
--- a/sca-cpp/trunk/modules/server/client-test.cpp
+++ b/sca-cpp/trunk/modules/server/client-test.cpp
@@ -86,7 +86,7 @@ const bool testEval(const string& uri) {
const bool testEval() {
testEval("http://localhost:8090/test");
- //testEval("http://localhost:8090/cpp");
+ testEval("http://localhost:8090/cpp");
testEval("http://localhost:8090/python");
return true;
}
@@ -129,7 +129,7 @@ const bool testEvalPerf(const string& type, const string& uri) {
const bool testEvalPerf() {
testEvalPerf("Scheme", "http://localhost:8090/test");
- //testEvalPerf("C++", "http://localhost:8090/cpp");
+ testEvalPerf("C++", "http://localhost:8090/cpp");
testEvalPerf("Python", "http://localhost:8090/python");
return true;
}
@@ -147,7 +147,7 @@ bool testPost(const string& uri) {
const bool testPost() {
testPost("http://localhost:8090/test");
- //testPost("http://localhost:8090/cpp");
+ testPost("http://localhost:8090/cpp");
testPost("http://localhost:8090/python");
return true;
}
@@ -193,7 +193,7 @@ const bool testPostPerf(const string& type, const string& uri) {
const bool testPostPerf() {
testPostPerf("Scheme", "http://localhost:8090/test");
- //testPostPerf("C++", "http://localhost:8090/cpp");
+ testPostPerf("C++", "http://localhost:8090/cpp");
testPostPerf("Python", "http://localhost:8090/python");
return true;
}
@@ -252,16 +252,16 @@ const bool testPostThreadPerf(const string& type, const string& uri) {
const bool testPostThreadPerf() {
testPostThreadPerf("Scheme", "http://localhost:8090/test");
- //testPostThreadPerf("C++", "http://localhost:8090/cpp");
- //testPostThreadPerf("Python", "http://localhost:8090/python");
+ testPostThreadPerf("C++", "http://localhost:8090/cpp");
+ testPostThreadPerf("Python", "http://localhost:8090/python");
return true;
}
#else
-const bool postProc(const int count, const value& val) {
+const bool postProc(const string& uri, const int count, const value& val) {
http::CURLSession ch;
- const lambda<bool()> pl = postLoop(val, ch);
+ const lambda<bool()> pl = postLoop(uri, val, ch);
time(pl, 0, count);
return true;
}
@@ -316,9 +316,9 @@ const bool testPostForkPerf(const string& type, const string& uri) {
}
const bool testPostForkPerf() {
- testPostThreadPerf("Scheme", "http://localhost:8090/test");
- //testPostThreadPerf("C++", "http://localhost:8090/cpp");
- testPostThreadPerf("Python", "http://localhost:8090/python");
+ testPostForkPerf("Scheme", "http://localhost:8090/test");
+ //testPostForkPerf("C++", "http://localhost:8090/cpp");
+ testPostForkPerf("Python", "http://localhost:8090/python");
return true;
}
@@ -363,18 +363,18 @@ int main() {
tuscany::cout << "Testing..." << tuscany::endl;
tuscany::server::testGet();
- tuscany::server::testGetPerf();
tuscany::server::testPost();
+ tuscany::server::testPut();
+ tuscany::server::testDel();
+ tuscany::server::testEval();
+ tuscany::server::testGetPerf();
tuscany::server::testPostPerf();
#ifdef _REENTRANT
tuscany::server::testPostThreadPerf();
#else
tuscany::server::testPostForkPerf();
#endif
- tuscany::server::testEval();
tuscany::server::testEvalPerf();
- tuscany::server::testPut();
- tuscany::server::testDel();
tuscany::cout << "OK" << tuscany::endl;
diff --git a/sca-cpp/trunk/modules/server/mod-eval.cpp b/sca-cpp/trunk/modules/server/mod-eval.cpp
index 34c1f00cba..23454e3ceb 100644
--- a/sca-cpp/trunk/modules/server/mod-eval.cpp
+++ b/sca-cpp/trunk/modules/server/mod-eval.cpp
@@ -100,7 +100,7 @@ const failable<int> get(request_rec* r, const lambda<value(const list<value>&)>&
// Extract the request id, method and params
const value id = cadr(ia);
- const value func = c_str(string(cadr(ma)));
+ const value func = c_str(json::funcName(string(cadr(ma))));
// Apply the requested function
const failable<value> val = failableResult(impl(cons(func, httpd::queryParams(args))));
@@ -145,7 +145,7 @@ const failable<int> post(request_rec* r, const lambda<value(const list<value>&)>
// Extract the request id, method and params
const value id = cadr(assoc(value("id"), args));
- const value func = c_str(cadr(assoc(value("method"), args)));
+ const value func = c_str(json::funcName(cadr(assoc(value("method"), args))));
const list<value> params = (list<value>)cadr(assoc(value("params"), args));
// Evaluate the request expression
diff --git a/sca-cpp/trunk/modules/server/server-test.py b/sca-cpp/trunk/modules/server/server-test.py
index c80d800eff..cdef94e116 100644
--- a/sca-cpp/trunk/modules/server/server-test.py
+++ b/sca-cpp/trunk/modules/server/server-test.py
@@ -5,6 +5,16 @@ def echo(x):
# ATOMPub test case
+def getall():
+ return ("Sample Feed", "123456789",
+ ("Item", "111", (("'javaClass", "services.Item"), ("'name", "Apple"), ("'currencyCode", "USD"), ("'currencySymbol", "$"), ("'price", 2.99))),
+ ("Item", "222", (("'javaClass", "services.Item"), ("'name", "Orange"), ("'currencyCode", "USD"), ("'currencySymbol", "$"), ("'price", 3.55))),
+ ("Item", "333", (("'javaClass", "services.Item"), ("name", "Pear"), ("'currencyCode", "USD"), ("'currencySymbol", "$"), ("'price", 1.55))))
+
+def get(id):
+ entry = (("'javaClass", "services.Item"), ("'name", "Apple"), ("'currencyCode", "USD"), ("'currencySymbol", "$"), ("'price", 2.99))
+ return ("Item", id, entry)
+
def post(entry):
return "123456789"
diff --git a/sca-cpp/trunk/test/store-python/Makefile.am b/sca-cpp/trunk/test/store-python/Makefile.am
index daefd9a405..345e58d544 100644
--- a/sca-cpp/trunk/test/store-python/Makefile.am
+++ b/sca-cpp/trunk/test/store-python/Makefile.am
@@ -15,5 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-TESTS = store-composite-test
+TESTS = server-test
diff --git a/sca-cpp/trunk/test/store-python/currency-converter.py b/sca-cpp/trunk/test/store-python/currency-converter.py
index 1ee39b63f3..61d3ae42ac 100644
--- a/sca-cpp/trunk/test/store-python/currency-converter.py
+++ b/sca-cpp/trunk/test/store-python/currency-converter.py
@@ -1,14 +1,12 @@
# Currency converter implementation
def convert(fr, to, amount):
- if (to == "EUR")
+ if to == "EUR":
return amount * 0.70
- else
- return amount
+ return amount
def symbol(currency):
- if (currency == "EUR")
+ if currency == "EUR":
return "E"
- else
- return "$"
+ return "$"
diff --git a/sca-cpp/trunk/test/store-python/fruits-catalog.py b/sca-cpp/trunk/test/store-python/fruits-catalog.py
index 5fcb9216c2..ea71e93b22 100644
--- a/sca-cpp/trunk/test/store-python/fruits-catalog.py
+++ b/sca-cpp/trunk/test/store-python/fruits-catalog.py
@@ -3,17 +3,15 @@
def get(converter):
def convert(price):
return converter("convert", "USD", "USD", price)
- code = "USD")
+ code = "USD"
symbol = converter("symbol", code)
return (
(("'javaClass", "services.Item"), ("'name", "Apple"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(2.99))),
(("'javaClass", "services.Item"), ("'name", "Orange"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(3.55))),
- (("'javaClass", "services.Item"), ("'name", "Pear"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price" convert(1.55)))
+ (("'javaClass", "services.Item"), ("'name", "Pear"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(1.55)))
)
# TODO remove these JSON-RPC specific functions
-def system.listMethods(converter):
- return ("Service.get")
-
-Service.get = get
+def listMethods(converter):
+ return ("Service.get",)
diff --git a/sca-cpp/trunk/test/store-python/htdocs/store.html b/sca-cpp/trunk/test/store-python/htdocs/store.html
index f8c6027abe..21eabca7a7 100644
--- a/sca-cpp/trunk/test/store-python/htdocs/store.html
+++ b/sca-cpp/trunk/test/store-python/htdocs/store.html
@@ -51,7 +51,7 @@
catalogItems = items;
// TEMP
- shoppingTotal.getTotal(shoppingTotal_getTotalResponse);
+ shoppingTotal.gettotal(shoppingTotal_getTotalResponse);
}
function shoppingCart_getResponse(feed) {
@@ -68,7 +68,7 @@
if (entries.length != 0) {
try {
- shoppingTotal.getTotal(shoppingTotal_getTotalResponse);
+ shoppingTotal.gettotal(shoppingTotal_getTotalResponse);
}
catch(e){
alert(e);
diff --git a/sca-cpp/trunk/test/store-python/store-composite-test b/sca-cpp/trunk/test/store-python/server-test
index b41c4e5393..b41c4e5393 100755
--- a/sca-cpp/trunk/test/store-python/store-composite-test
+++ b/sca-cpp/trunk/test/store-python/server-test
diff --git a/sca-cpp/trunk/test/store-python/shopping-cart.py b/sca-cpp/trunk/test/store-python/shopping-cart.py
index cc89bb6c99..317038d93f 100644
--- a/sca-cpp/trunk/test/store-python/shopping-cart.py
+++ b/sca-cpp/trunk/test/store-python/shopping-cart.py
@@ -1,77 +1,65 @@
# Shopping cart implementation
+import uuid
+import sys
cartId = "1234"
-#TODO finish conversion from scheme to python
-
# Get the shopping cart from the cache
# Return an empty cart if not found
-(define (getcart id cache)
- (define cart (cache "get" id))
- (if (nul cart)
- (list)
- cart)
-)
+def getcart(id, cache):
+ cart = cache("get", id)
+ if cart is None:
+ return ()
+ return cart
# Post a new item to the cart, create a new cart if necessary
-(define (post item cache)
- (define id (uuid))
- (define newItem (list (car item) id (caddr item)))
- (define cart (cons newItem (getcart cartId cache)))
- (cache "put" cartId cart)
- id
-)
+def post(item, cache):
+ id = str(uuid.uuid1())
+ cart = ((item[0], id, item[2]),) + getcart(cartId, cache)
+ cache("put", cartId, cart)
+ return id
# Return the content of the cart
-(define (getall cache)
- (cons "Your Cart" (cons cartId (getcart cartId cache)))
-)
+def getall(cache):
+ return ("Your Cart", cartId) + getcart(cartId, cache)
# Find an item in the cart
-(define (find id cart)
- (if (nul cart)
- (cons "Item" (list "0" (list)))
- (if (= id (cadr (car cart)))
- (car cart)
- (find id (cdr cart))))
-)
+def find(id, cart):
+ if cart == ():
+ return ("Item", "0", ())
+ elif id == cart[0][1]:
+ return cart[0]
+ else:
+ return find(id, cart[1:])
# Get an item from the cart
-(define (get id cache)
- (find id (getcart cartId cache))
-)
+def get(id, cache):
+ return find(id, getcart(cartId, cache))
# Delete the whole cart
-(define (deleteall cache)
- (cache "delete" cartId)
-)
+def deleteall(cache):
+ return cache("delete", cartId)
# Delete an item from the cart
-(define (delete id cache)
- true
-)
+def delete(id, cache):
+ return true
# Return the price of an item
-(define (price item)
- (cadr (assoc 'price (caddr item)))
-)
+def price(item):
+ return float(filter(lambda x: x[0] == "'price", item[2])[0][1])
# Sum the prices of a list of items
-(define (sum items)
- (if (nul items)
- 0
- (+ (price (car items)) (sum (cdr items))))
-)
+def sum(items):
+ if items == ():
+ return 0
+ return price(items[0]) + sum(items[1:])
# Return the total price of the items in the cart
-(define (gettotal cache)
- (define cart (getcart cartId cache))
- (sum cart)
-)
+def gettotal(cache):
+ cart = getcart(cartId, cache)
+ return sum(cart)
# TODO remove these JSON-RPC specific functions
-def system.listMethods(cache):
- return ("Service.getTotal")
-
-Service.getTotal = gettotal
+def listMethods(cache):
+ return ("Service.gettotal",)
diff --git a/sca-cpp/trunk/test/store-python/store.py b/sca-cpp/trunk/test/store-python/store.py
index 942544a3b2..54fd315fea 100644
--- a/sca-cpp/trunk/test/store-python/store.py
+++ b/sca-cpp/trunk/test/store-python/store.py
@@ -22,9 +22,6 @@ def delete(id, catalog, shoppingCart, shoppingTotal):
return shoppingCart("delete", id)
# TODO remove these JSON-RPC specific functions
-def system.listMethods(catalog, shoppingCart, shoppingTotal):
- return ("Service.get", "Service.getTotal")
-
-Service.getCatalog = getcatalog
-Service.getTotal = gettotal
+def listMethods(catalog, shoppingCart, shoppingTotal):
+ return ("Service.get", "Service.gettotal")
diff --git a/sca-cpp/trunk/test/store-scheme/Makefile.am b/sca-cpp/trunk/test/store-scheme/Makefile.am
index fc6a1f88fb..19b2640f3b 100644
--- a/sca-cpp/trunk/test/store-scheme/Makefile.am
+++ b/sca-cpp/trunk/test/store-scheme/Makefile.am
@@ -15,12 +15,12 @@
# specific language governing permissions and limitations
# under the License.
-noinst_PROGRAMS = store-script-test
+noinst_PROGRAMS = script-test
INCLUDES = -I. -I$(top_builddir)/kernel -I${LIBXML2_INCLUDE} -I${APR_INCLUDE} -I${JS_INCLUDE}
-store_script_test_SOURCES = store-script-test.cpp
-store_script_test_LDADD = -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1 -L${JS_LIB} -lmozjs
-
-TESTS = store-script-test store-composite-test
+script_test_SOURCES = script-test.cpp
+script_test_LDADD = -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1 -L${JS_LIB} -lmozjs
+
+TESTS = script-test server-test
diff --git a/sca-cpp/trunk/test/store-scheme/fruits-catalog.scm b/sca-cpp/trunk/test/store-scheme/fruits-catalog.scm
index 18128f0137..173bcbe9c0 100644
--- a/sca-cpp/trunk/test/store-scheme/fruits-catalog.scm
+++ b/sca-cpp/trunk/test/store-scheme/fruits-catalog.scm
@@ -12,6 +12,5 @@
)
; TODO remove these JSON-RPC specific functions
-(define (system.listMethods converter) (list "Service.get"))
-(define Service.get get)
+(define (listMethods converter) (list "Service.get"))
diff --git a/sca-cpp/trunk/test/store-scheme/htdocs/store.html b/sca-cpp/trunk/test/store-scheme/htdocs/store.html
index f8c6027abe..21eabca7a7 100644
--- a/sca-cpp/trunk/test/store-scheme/htdocs/store.html
+++ b/sca-cpp/trunk/test/store-scheme/htdocs/store.html
@@ -51,7 +51,7 @@
catalogItems = items;
// TEMP
- shoppingTotal.getTotal(shoppingTotal_getTotalResponse);
+ shoppingTotal.gettotal(shoppingTotal_getTotalResponse);
}
function shoppingCart_getResponse(feed) {
@@ -68,7 +68,7 @@
if (entries.length != 0) {
try {
- shoppingTotal.getTotal(shoppingTotal_getTotalResponse);
+ shoppingTotal.gettotal(shoppingTotal_getTotalResponse);
}
catch(e){
alert(e);
diff --git a/sca-cpp/trunk/test/store-scheme/store-script-test.cpp b/sca-cpp/trunk/test/store-scheme/script-test.cpp
index fe2a64e57f..c8eecb65c3 100644
--- a/sca-cpp/trunk/test/store-scheme/store-script-test.cpp
+++ b/sca-cpp/trunk/test/store-scheme/script-test.cpp
@@ -39,7 +39,7 @@ using namespace tuscany;
bool testScript() {
gc_scoped_pool pool;
- ifstream is("store-script-test.scm");
+ ifstream is("script-test.scm");
ostringstream os;
scheme::evalDriverRun(is, os);
assert(contains(str(os), "(\"Sample Feed\" \""));
@@ -52,7 +52,7 @@ bool testScript() {
bool testEval() {
{
gc_scoped_pool pool;
- ifstream is("store-script-test.scm");
+ ifstream is("script-test.scm");
ostringstream os;
scheme::setupDisplay(os);
scheme::Env globalEnv = scheme::setupEnvironment();
@@ -66,7 +66,7 @@ bool testEval() {
{
gc_scoped_pool pool;
- ifstream is("store-script-test.scm");
+ ifstream is("script-test.scm");
ostringstream os;
scheme::setupDisplay(os);
diff --git a/sca-cpp/trunk/test/store-scheme/store-script-test.scm b/sca-cpp/trunk/test/store-scheme/script-test.scm
index 30c10d8184..711656019a 100644
--- a/sca-cpp/trunk/test/store-scheme/store-script-test.scm
+++ b/sca-cpp/trunk/test/store-scheme/script-test.scm
@@ -121,29 +121,3 @@
(display (storeui_service "getall" added2))
(display (storeui_service "gettotal"))
-; Store UI JSON-RPC interop test case
-
-(define (system.listMethods) (list "Service.get" "Service.getTotal"))
-
-(define (Service.get) (storeui_service "getcatalog"))
-
-(define (.get) (storeui_service "getcatalog"))
-
-(define (Service.getTotal) (storeui_service "gettotal"))
-
-; Store UI ATOMPub interop test case
-
-(define (getall) (storeui_service "getall" added2))
-
-(define (get id) (storeui_service "getentry" id))
-
-(define (post entry)
- (display entry)
- (uuid)
-)
-
-(define (delete id)
- (display id)
- true
-)
-
diff --git a/sca-cpp/trunk/test/store-scheme/store-composite-test b/sca-cpp/trunk/test/store-scheme/server-test
index b41c4e5393..b41c4e5393 100755
--- a/sca-cpp/trunk/test/store-scheme/store-composite-test
+++ b/sca-cpp/trunk/test/store-scheme/server-test
diff --git a/sca-cpp/trunk/test/store-scheme/shopping-cart.scm b/sca-cpp/trunk/test/store-scheme/shopping-cart.scm
index 60981411c7..77a98c9fd7 100644
--- a/sca-cpp/trunk/test/store-scheme/shopping-cart.scm
+++ b/sca-cpp/trunk/test/store-scheme/shopping-cart.scm
@@ -68,6 +68,5 @@
)
; TODO remove these JSON-RPC specific functions
-(define (system.listMethods cache) (list "Service.getTotal"))
-(define Service.getTotal gettotal)
+(define (listMethods cache) (list "Service.gettotal"))
diff --git a/sca-cpp/trunk/test/store-scheme/store.scm b/sca-cpp/trunk/test/store-scheme/store.scm
index e325a65d74..0091af542d 100644
--- a/sca-cpp/trunk/test/store-scheme/store.scm
+++ b/sca-cpp/trunk/test/store-scheme/store.scm
@@ -29,7 +29,5 @@
)
; TODO remove these JSON-RPC specific functions
-(define (system.listMethods catalog shoppingCart shoppingTotal) (list "Service.get" "Service.getTotal"))
-(define Service.getCatalog getcatalog)
-(define Service.getTotal gettotal)
+(define (listMethods catalog shoppingCart shoppingTotal) (list "Service.getcatalog" "Service.gettotal"))