diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2012-07-16 06:48:11 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2012-07-16 06:48:11 +0000 |
commit | 574ccee478b9da9457cdf0e476b8df6eb584b580 (patch) | |
tree | 5a8166f47057ed322294db7816e2732d1d18f7bc /sca-cpp/trunk/modules/python/python-test.cpp | |
parent | 419f903ff44a22debba43976baae1e86c1e5d871 (diff) |
Minor memory management, performance, and tracing improvements.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1361917 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk/modules/python/python-test.cpp')
-rw-r--r-- | sca-cpp/trunk/modules/python/python-test.cpp | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/sca-cpp/trunk/modules/python/python-test.cpp b/sca-cpp/trunk/modules/python/python-test.cpp index bc275f27c7..29a66cc2e7 100644 --- a/sca-cpp/trunk/modules/python/python-test.cpp +++ b/sca-cpp/trunk/modules/python/python-test.cpp @@ -42,7 +42,7 @@ bool testEvalExpr() { PythonRuntime py; istringstream is(testPythonAdd); - failable<PyObject*> script = readScript("script", "script.py", is, py); + failable<PyObject*> script = readScript("script1", "script1.py", is, py); assert(hasContent(script)); const value exp = mklist<value>("add", 2, 3); @@ -54,6 +54,29 @@ bool testEvalExpr() { return true; } +const string testPythonMap = + "def addmap(x, y):\n" + " return tuple(map(lambda i: i + y, x))\n"; + +bool testEvalList() { + gc_scoped_pool pool; + PythonRuntime py; + + istringstream is(testPythonMap); + failable<PyObject*> script = readScript("script2", "script2.py", is, py); + assert(hasContent(script)); + + const value exp = mklist<value>("addmap", mklist<value>(1, 2, 3), 1); + const failable<value> r = evalScript(exp, content(script), py); + assert(hasContent(r)); + assert(car<value>(content(r)) == value(2)); + assert(cadr<value>(content(r)) == value(3)); + assert(caddr<value>(content(r)) == value(4)); + + releaseScript(content(script), py); + return true; +} + const value mult(const list<value>& args) { const double x = car(args); const double y = cadr(args); @@ -104,7 +127,7 @@ struct testEvalReadAdd { } const bool operator()() const { istringstream is(testPythonAdd); - failable<PyObject*> script = readScript("script", "script.py", is, py); + failable<PyObject*> script = readScript("script3", "script3.py", is, py); assert(hasContent(script)); const value exp = mklist<value>("add", 2, 3); @@ -139,7 +162,7 @@ bool testEvalPerf() { cout << "Python read + eval test " << time(erl, 5, 10000) << " ms" << endl; istringstream is(testPythonAdd); - failable<PyObject*> script = readScript("script", "script.py", is, py); + failable<PyObject*> script = readScript("script4", "script4.py", is, py); assert(hasContent(script)); const lambda<bool()> el = lambda<bool()>(testEvalAdd(content(script), py)); @@ -158,7 +181,7 @@ struct testReadEvalAddLoop { const bool operator()() const { for (int i = 0; i < 100; i++) { istringstream is(testPythonAdd); - failable<PyObject*> script = readScript("script", "script.py", is, py); + failable<PyObject*> script = readScript("script6", "script6.py", is, py); assert(hasContent(script)); const value exp = mklist<value>("add", 2, 3); @@ -247,7 +270,7 @@ bool testThreads() { cout << "Python eval + read thread test " << time(elr, 1, 1) / 10000.0 << " ms" << endl; istringstream is(testPythonAdd); - failable<PyObject*> script = readScript("script", "script.py", is, py); + failable<PyObject*> script = readScript("script7", "script7.py", is, py); assert(hasContent(script)); const lambda<bool()> el = lambda<bool()>(testEvalThreads(w, max, content(script), py)); @@ -263,9 +286,13 @@ bool testThreads() { } int main() { + tuscany::gc_scoped_pool p; tuscany::cout << "Testing..." << tuscany::endl; tuscany::python::testEvalExpr(); + tuscany::python::testEvalList(); + tuscany::python::testEvalLambda(); + tuscany::python::testEvalLambda(); tuscany::python::testEvalLambda(); tuscany::python::testEvalPerf(); #ifdef WANT_THREADS |