diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-01 05:24:54 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-01 05:24:54 +0000 |
commit | 9f187b46ae761e8275362d6c1533e9fe79028c7b (patch) | |
tree | e2625f63e0c84f172c877e1fe2cbe75adf678208 /cpp/sca/test/store-script | |
parent | 24021bd09a0d5c9664565a244c24e0bdef0908b8 (diff) |
Improved memory management using APR memory pools, changed frame allocation in eval library to support forward references and fixed memory leak in XML parsing code. Also simplified a bit the printing of lists to make them easier to read.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@831639 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r-- | cpp/sca/test/store-script/Makefile.am | 6 | ||||
-rw-r--r-- | cpp/sca/test/store-script/store-script-test.cpp | 34 |
2 files changed, 24 insertions, 16 deletions
diff --git a/cpp/sca/test/store-script/Makefile.am b/cpp/sca/test/store-script/Makefile.am index 2bd969b5ba..d5c4a8c0eb 100644 --- a/cpp/sca/test/store-script/Makefile.am +++ b/cpp/sca/test/store-script/Makefile.am @@ -18,13 +18,13 @@ store_script_PROGRAMS = store-script-test store_scriptdir=$(prefix)/test/store-script/deploy -INCLUDES = -I. -I$(top_builddir)/kernel -I$(top_builddir)/modules/eval -I${LIBXML2_INCLUDE} -I${LIBMOZJS_INCLUDE} +INCLUDES = -I. -I$(top_builddir)/kernel -I$(top_builddir)/modules/eval -I${LIBXML2_INCLUDE} -I${APR_INCLUDE} -I${LIBMOZJS_INCLUDE} store_script_test_SOURCES = store-script-test.cpp -store_script_test_LDADD = -L${LIBXML2_LIB} -lxml2 -lpthread -L${LIBMOZJS_LIB} -lmozjs +store_script_test_LDADD = -lpthread -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1 -L${LIBMOZJS_LIB} -lmozjs EXTRA_DIST = *.composite store_script_DATA = *.composite -TESTS = store-script-test +TESTS = store-script-test store-http-test diff --git a/cpp/sca/test/store-script/store-script-test.cpp b/cpp/sca/test/store-script/store-script-test.cpp index 2d1891dd14..5808bd889e 100644 --- a/cpp/sca/test/store-script/store-script-test.cpp +++ b/cpp/sca/test/store-script/store-script-test.cpp @@ -24,6 +24,7 @@ */ #include <assert.h> +#include <regex.h> #include <iostream> #include <fstream> #include <string> @@ -38,23 +39,27 @@ namespace store { using namespace tuscany; bool contains(const std::string& str, const std::string& pattern) { - return str.find(pattern) != str.npos; + return str.find(pattern) != std::string::npos; } bool testScript() { std::ifstream is("store.scm", std::ios_base::in); std::ostringstream os; eval::evalDriverRun(is, os); - assert(contains(os.str(), "(string::\"Sample Feed\", string::\"123\", (string::\"Item\", string::\"123456789\", ((symbol::javaClass, string::\"services.Item\"), (symbol::name, string::\"Orange\"), (symbol::currency, string::\"USD\"), (symbol::symbol, string::\"$\"), (symbol::price, number::3.55))), (string::\"Item\", string::\"123456789\", ((symbol::javaClass, string::\"services.Item\"), (symbol::name, string::\"Apple\"), (symbol::currency, string::\"USD\"), (symbol::symbol, string::\"$\"), (symbol::price, number::2.99))))")); + + assert(contains(os.str(), "(\"Sample Feed\" \"")); + assert(contains(os.str(), "\" (\"Item\" \"")); + assert(contains(os.str(), "\" ((javaClass \"services.Item\") (name \"Orange\") (currency \"USD\") (symbol \"$\") (price 3.55))) (\"Item\" \"")); + assert(contains(os.str(), "\" ((javaClass \"services.Item\") (name \"Apple\") (currency \"USD\") (symbol \"$\") (price 2.99))))")); return true; } -const value evalLoop(std::istream& is, const value& req, eval::Env& globalEnv) { +const value evalLoop(std::istream& is, const value& req, eval::Env& globalEnv, const gc_pool& pool) { value in = eval::read(is); if(isNil(in)) - return eval::evalApply(req, globalEnv); - eval::evalApply(in, globalEnv); - return evalLoop(is, req, globalEnv); + return eval::evalExpr(req, globalEnv, pool); + eval::evalExpr(in, globalEnv, pool); + return evalLoop(is, req, globalEnv, pool); } bool testEval() { @@ -62,29 +67,32 @@ bool testEval() { std::ifstream is("store.scm", std::ios_base::in); std::ostringstream os; eval::setupEvalOut(os); - eval::Env globalEnv = eval::setupEnvironment(); + gc_pool pool; + eval::Env globalEnv = eval::setupEnvironment(pool); const value req(mklist<value>("storeui_service", std::string("getcatalog"))); - const value val = evalLoop(is, req, globalEnv); + const value val = evalLoop(is, req, globalEnv, pool); + eval::cleanupEnvironment(globalEnv); std::ostringstream vs; vs << val; - assert(contains(vs.str(),"(((symbol::javaClass, string::\"services.Item\"), (symbol::name, string::\"Apple\"), (symbol::currency, string::\"USD\"), (symbol::symbol, string::\"$\"), (symbol::price, number::2.99)), ((symbol::javaClass, string::\"services.Item\"), (symbol::name, string::\"Orange\"), (symbol::currency, string::\"USD\"), (symbol::symbol, string::\"$\"), (symbol::price, number::3.55)), ((symbol::javaClass, string::\"services.Item\"), (symbol::name, string::\"Pear\"), (symbol::currency, string::\"USD\"), (symbol::symbol, string::\"$\"), (symbol::price, number::1.55)))")); + assert(contains(vs.str(), "(((javaClass \"services.Item\") (name \"Apple\") (currency \"USD\") (symbol \"$\") (price 2.99)) ((javaClass \"services.Item\") (name \"Orange\") (currency \"USD\") (symbol \"$\") (price 3.55)) ((javaClass \"services.Item\") (name \"Pear\") (currency \"USD\") (symbol \"$\") (price 1.55)))")); } { std::ifstream is("store.scm", std::ios_base::in); std::ostringstream os; - eval::setupEvalOut(os); - eval::Env globalEnv = eval::setupEnvironment(); + gc_pool pool; + eval::Env globalEnv = eval::setupEnvironment(pool); const value req(mklist<value>("storeui_service", std::string("gettotal"))); - const value res = evalLoop(is, req, globalEnv); + const value res = evalLoop(is, req, globalEnv, pool); + eval::cleanupEnvironment(globalEnv); std::ostringstream rs; rs << res; - assert(contains(rs.str(), "number::10")); + assert(contains(rs.str(), "10")); } return true; } |