From ae0b7c0063db6236be2d7cf01ddbf2159f77c98c Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Tue, 11 Dec 2012 03:51:03 +0000 Subject: Port kernel to C++11 and refactor some of the core modules. Convert functors to lambdas, and add C++ const, noexcept and inline annotations to get more efficient generated code. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1419985 13f79535-47bb-0310-9956-ffa450edef68 --- sca-cpp/trunk/modules/scheme/scheme-test.cpp | 126 ++++++++++++++++++++------- 1 file changed, 93 insertions(+), 33 deletions(-) (limited to 'sca-cpp/trunk/modules/scheme/scheme-test.cpp') diff --git a/sca-cpp/trunk/modules/scheme/scheme-test.cpp b/sca-cpp/trunk/modules/scheme/scheme-test.cpp index 5b69b8e588..e83f99456f 100644 --- a/sca-cpp/trunk/modules/scheme/scheme-test.cpp +++ b/sca-cpp/trunk/modules/scheme/scheme-test.cpp @@ -26,14 +26,16 @@ #include #include "stream.hpp" #include "string.hpp" +#include "perf.hpp" #include "driver.hpp" +#include "scheme-test.hpp" namespace tuscany { namespace scheme { -bool testEnv() { - gc_scoped_pool pool; - Env globalEnv = list(); +const bool testEnv() { + const gc_scoped_pool pool; + Env globalEnv = nilListValue; Env env = extendEnvironment(mklist("a"), mklist(1), globalEnv); defineVariable("x", env, env); assert(lookupVariableValue(value("x"), env) == env); @@ -41,7 +43,7 @@ bool testEnv() { return true; } -bool testEnvGC() { +const bool testEnvGC() { resetLambdaCounters(); resetListCounters(); resetValueCounters(); @@ -52,49 +54,49 @@ bool testEnvGC() { return true; } -bool testRead() { +const bool testRead() { istringstream is("abcd"); - assert(readValue(is) == "abcd"); + assert(content(readValue(is)) == "abcd"); istringstream is2("123"); - assert(readValue(is2) == value(123)); + assert(content(readValue(is2)) == value(123)); istringstream is3("(abcd)"); - assert(readValue(is3) == mklist(value("abcd"))); + assert(content(readValue(is3)) == mklist(value("abcd"))); istringstream is4("(abcd xyz)"); - assert(readValue(is4) == mklist("abcd", "xyz")); + assert(content(readValue(is4)) == mklist("abcd", "xyz")); istringstream is5("(abcd (xyz tuv))"); - assert(readValue(is5) == mklist("abcd", mklist("xyz", "tuv"))); + assert(content(readValue(is5)) == mklist("abcd", mklist("xyz", "tuv"))); return true; } -bool testWrite() { +const bool testWrite() { { - const list i = list() - + (list() + "item" + "cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b" - + (list() + "item" - + (list() + "name" + "Apple") - + (list() + "price" + "$2.99"))) - + (list() + "item" + "cart-53d67a61-aa5e-4e5e-8401-39edeba8b83c" - + (list() + "item" - + (list() + "name" + "Orange") - + (list() + "price" + "$3.55"))); + const list i = nilListValue + + (nilListValue + "item" + "cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b" + + (nilListValue + "item" + + (nilListValue + "name" + "Apple") + + (nilListValue + "price" + "$2.99"))) + + (nilListValue + "item" + "cart-53d67a61-aa5e-4e5e-8401-39edeba8b83c" + + (nilListValue + "item" + + (nilListValue + "name" + "Orange") + + (nilListValue + "price" + "$3.55"))); const list a = cons("Feed", cons("feed-1234", i)); ostringstream os; writeValue(a, os); istringstream is(str(os)); - assert(readValue(is) == a); + assert(content(readValue(is)) == a); } { - const list i = mklist("x", value()); + const list i = mklist("x", nilValue); const list a = mklist(i); ostringstream os; writeValue(a, os); istringstream is(str(os)); - assert(readValue(is) == a); + assert(content(readValue(is)) == a); } return true; } @@ -147,8 +149,8 @@ const string evalOutput(const string& scm) { return str(os); } -bool testEval() { - gc_scoped_pool pool; +const bool testEval() { + const gc_scoped_pool pool; assert(contains(evalOutput(testSchemeNumber), "testNumber ok")); assert(contains(evalOutput(testSchemeString), "testString ok")); assert(contains(evalOutput(testSchemeDefinition), "testDefinition ok")); @@ -161,8 +163,8 @@ bool testEval() { return true; } -bool testEvalExpr() { - gc_scoped_pool pool; +const bool testEvalExpr() { + const gc_scoped_pool pool; const value exp = mklist("+", 2, 3); Env env = setupEnvironment(); const value r = evalExpr(exp, env); @@ -170,8 +172,8 @@ bool testEvalExpr() { return true; } -bool testEvalRun() { - gc_scoped_pool pool; +const bool testEvalRun() { + const gc_scoped_pool pool; evalDriverRun(cin, cout); return true; } @@ -188,8 +190,8 @@ const string testReturnLambda( const string testCallLambda( "(define (testCallLambda l x y) (l x y))"); -bool testEvalLambda() { - gc_scoped_pool pool; +const bool testEvalLambda() { + const gc_scoped_pool pool; Env env = setupEnvironment(); const value trl = mklist("testReturnLambda"); @@ -208,7 +210,18 @@ bool testEvalLambda() { return true; } -bool testEvalGC() { +const bool testEvalScript() { + const gc_scoped_pool pool; + Env env = setupEnvironment(); + ifstream is("test.scm"); + const value script = readScript(is); + const value expr = mklist("echo", string("x")); + const value res = evalScript(expr, script, env); + assert(res == string("x")); + return true; +} + +const bool testEvalGC() { resetLambdaCounters(); resetListCounters(); resetValueCounters(); @@ -221,11 +234,55 @@ bool testEvalGC() { return true; } +const string testCustomer = "((customer (@name \"jdoe\") (account (id \"1234\") (@balance 1000)) (address (@city \"san francisco\") (@state \"ca\"))))"; + +const bool testReadWrite() { + const gc_scoped_pool pool; + + istringstream is(testCustomer); + const value r = content(readValue(is)); + + ostringstream os; + writeValue(r, os); + //assert(str(os) == testCustomer); + return true; +} + +const bool testReadWritePerf() { + const gc_scoped_pool pool; + + const blambda rwl = blambda(testReadWrite); + cout << "Scheme read + write test " << time(rwl, 5, 200) << " ms" << endl; + + return true; +} + +const bool testReadWriteBigDoc() { + const gc_scoped_pool pool; + + istringstream is(testBigDoc); + const value r = content(readValue(is)); + + ostringstream os; + writeValue(r, os); + //assert(str(os) == testBigDoc); + return true; +} + +const bool testReadWriteBigDocPerf() { + const gc_scoped_pool pool; + + const blambda rwl = blambda(testReadWriteBigDoc); + cout << "Scheme big doc read + write test " << time(rwl, 5, 200) << " ms" << endl; + + return true; +} + } } int main() { - tuscany::gc_scoped_pool p; + const tuscany::gc_scoped_pool p; tuscany::cout << "Testing..." << tuscany::endl; tuscany::scheme::testEnv(); @@ -235,7 +292,10 @@ int main() { tuscany::scheme::testEval(); tuscany::scheme::testEvalExpr(); tuscany::scheme::testEvalLambda(); + tuscany::scheme::testEvalScript(); tuscany::scheme::testEvalGC(); + tuscany::scheme::testReadWritePerf(); + tuscany::scheme::testReadWriteBigDocPerf(); tuscany::cout << "OK" << tuscany::endl; return 0; -- cgit v1.2.3