From 3479cfa1585b752df58873b941b5bfd06a879b04 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Mon, 20 Feb 2012 07:20:27 +0000 Subject: Rename some of the utility programs and add them to the install target. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1291135 13f79535-47bb-0310-9956-ffa450edef68 --- sca-cpp/trunk/.gitignore | 8 +- sca-cpp/trunk/modules/java/Makefile.am | 3 +- sca-cpp/trunk/modules/js/Makefile.am | 7 +- sca-cpp/trunk/modules/js/js-eval.cpp | 55 ------ sca-cpp/trunk/modules/js/js-shell.cpp | 55 ++++++ sca-cpp/trunk/modules/js/util-test | 2 +- sca-cpp/trunk/modules/opencl/Makefile.am | 3 +- sca-cpp/trunk/modules/python/Makefile.am | 3 +- sca-cpp/trunk/modules/scheme/Makefile.am | 11 +- sca-cpp/trunk/modules/scheme/eval-shell.cpp | 36 ---- sca-cpp/trunk/modules/scheme/eval-test.cpp | 241 -------------------------- sca-cpp/trunk/modules/scheme/scheme-shell.cpp | 36 ++++ sca-cpp/trunk/modules/scheme/scheme-test.cpp | 241 ++++++++++++++++++++++++++ 13 files changed, 355 insertions(+), 346 deletions(-) delete mode 100644 sca-cpp/trunk/modules/js/js-eval.cpp create mode 100644 sca-cpp/trunk/modules/js/js-shell.cpp delete mode 100644 sca-cpp/trunk/modules/scheme/eval-shell.cpp delete mode 100644 sca-cpp/trunk/modules/scheme/eval-test.cpp create mode 100644 sca-cpp/trunk/modules/scheme/scheme-shell.cpp create mode 100644 sca-cpp/trunk/modules/scheme/scheme-test.cpp (limited to 'sca-cpp') diff --git a/sca-cpp/trunk/.gitignore b/sca-cpp/trunk/.gitignore index 8d56a49c91..1a45e7cdbd 100644 --- a/sca-cpp/trunk/.gitignore +++ b/sca-cpp/trunk/.gitignore @@ -108,8 +108,8 @@ parallel-test xml-test xsd-test atom-test -eval-test -eval-shell +scheme-test +scheme-shell json-test client-test memcache-test @@ -133,7 +133,7 @@ curl-connect rss-test scribe-cat js-test -js-eval +js-shell file-test test-start* test-stop* @@ -143,6 +143,8 @@ json-value value-json element-value value-element +hosting/server/nuvem +hosting/server/lib hosting/server/data/apps/*/nuvem hosting/server/data/apps/*/lib chat-send diff --git a/sca-cpp/trunk/modules/java/Makefile.am b/sca-cpp/trunk/modules/java/Makefile.am index 5242349319..8b80276d15 100644 --- a/sca-cpp/trunk/modules/java/Makefile.am +++ b/sca-cpp/trunk/modules/java/Makefile.am @@ -63,7 +63,8 @@ client_test_SOURCES = client-test.cpp client_test_LDFLAGS = -lxml2 -lcurl -lmozjs dist_noinst_SCRIPTS = server-test wiring-test -noinst_PROGRAMS = jni-test java-test java-shell client-test +noinst_PROGRAMS = jni-test java-test client-test +mod_PROGRAMS = java-shell TESTS = jni-test java-test server-test endif diff --git a/sca-cpp/trunk/modules/js/Makefile.am b/sca-cpp/trunk/modules/js/Makefile.am index 5b8e36a5cf..833a764230 100644 --- a/sca-cpp/trunk/modules/js/Makefile.am +++ b/sca-cpp/trunk/modules/js/Makefile.am @@ -37,9 +37,10 @@ EXTRA_DIST = htdocs/*.js htdocs/*.css htdocs/all.js js_test_SOURCES = js-test.cpp js_test_LDFLAGS = -lmozjs -js_eval_SOURCES = js-eval.cpp -js_eval_LDFLAGS = -lmozjs +js_shell_SOURCES = js-shell.cpp +js_shell_LDFLAGS = -lmozjs -noinst_PROGRAMS = js-test js-eval +noinst_PROGRAMS = js-test +mod_PROGRAMS = js-shell dist_noinst_SCRIPTS = util-test TESTS = js-test util-test diff --git a/sca-cpp/trunk/modules/js/js-eval.cpp b/sca-cpp/trunk/modules/js/js-eval.cpp deleted file mode 100644 index ee0fa89b31..0000000000 --- a/sca-cpp/trunk/modules/js/js-eval.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/* $Rev$ $Date$ */ - -/** - * Evaluate a JavaScript script. - */ - -#include -#include "stream.hpp" -#include "fstream.hpp" -#include "string.hpp" -#include "eval.hpp" - -namespace tuscany { -namespace js { - -bool eval() { - ostringstream os; - for(;;) { - int c = cin.get(); - if (c == -1) - break; - os << (char)c; - } - failable v = evalScript(str(os)); - assert(hasContent(v)); - cout << v; - return true; -} - -} -} - -int main() { - tuscany::js::eval(); - return 0; -} diff --git a/sca-cpp/trunk/modules/js/js-shell.cpp b/sca-cpp/trunk/modules/js/js-shell.cpp new file mode 100644 index 0000000000..ee0fa89b31 --- /dev/null +++ b/sca-cpp/trunk/modules/js/js-shell.cpp @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +/** + * Evaluate a JavaScript script. + */ + +#include +#include "stream.hpp" +#include "fstream.hpp" +#include "string.hpp" +#include "eval.hpp" + +namespace tuscany { +namespace js { + +bool eval() { + ostringstream os; + for(;;) { + int c = cin.get(); + if (c == -1) + break; + os << (char)c; + } + failable v = evalScript(str(os)); + assert(hasContent(v)); + cout << v; + return true; +} + +} +} + +int main() { + tuscany::js::eval(); + return 0; +} diff --git a/sca-cpp/trunk/modules/js/util-test b/sca-cpp/trunk/modules/js/util-test index 08407ea2d1..c69f46c67c 100755 --- a/sca-cpp/trunk/modules/js/util-test +++ b/sca-cpp/trunk/modules/js/util-test @@ -21,7 +21,7 @@ here=`echo "import os; print os.path.realpath('$0')" | python`; here=`dirname $here` echo "Testing..." -cat htdocs/util.js htdocs/elemutil.js htdocs/jsonutil.js json-test.js | ./js-eval 2>/dev/null 1>&2 +cat htdocs/util.js htdocs/elemutil.js htdocs/jsonutil.js json-test.js | ./js-shell 2>/dev/null 1>&2 rc=$? if [ "$rc" = "0" ]; then echo "OK" diff --git a/sca-cpp/trunk/modules/opencl/Makefile.am b/sca-cpp/trunk/modules/opencl/Makefile.am index 95e30d20b1..3e76a435c8 100644 --- a/sca-cpp/trunk/modules/opencl/Makefile.am +++ b/sca-cpp/trunk/modules/opencl/Makefile.am @@ -51,7 +51,8 @@ client_test_SOURCES = client-test.cpp client_test_LDFLAGS = -lxml2 -lcurl -lmozjs dist_noinst_SCRIPTS = server-test -noinst_PROGRAMS = opencl-test opencl-shell client-test +noinst_PROGRAMS = opencl-test client-test +mod_PROGRAMS = opencl-shell TESTS = opencl-test endif diff --git a/sca-cpp/trunk/modules/python/Makefile.am b/sca-cpp/trunk/modules/python/Makefile.am index d24913665e..80c3097b48 100644 --- a/sca-cpp/trunk/modules/python/Makefile.am +++ b/sca-cpp/trunk/modules/python/Makefile.am @@ -50,7 +50,8 @@ client_test_SOURCES = client-test.cpp client_test_LDFLAGS = -lxml2 -lcurl -lmozjs dist_noinst_SCRIPTS = server-test wiring-test -noinst_PROGRAMS = python-test python-shell client-test +noinst_PROGRAMS = python-test client-test +mod_PROGRAMS = python-shell TESTS = python-test server-test endif diff --git a/sca-cpp/trunk/modules/scheme/Makefile.am b/sca-cpp/trunk/modules/scheme/Makefile.am index 8e2141e724..130fe14303 100644 --- a/sca-cpp/trunk/modules/scheme/Makefile.am +++ b/sca-cpp/trunk/modules/scheme/Makefile.am @@ -18,9 +18,11 @@ incl_HEADERS = *.hpp incldir = $(prefix)/include/modules/scheme -eval_test_SOURCES = eval-test.cpp +moddir = $(prefix)/modules/scheme -eval_shell_SOURCES = eval-shell.cpp +scheme_test_SOURCES = scheme-test.cpp + +scheme_shell_SOURCES = scheme-shell.cpp value_element_SOURCES = value-element.cpp value_element_LDFLAGS = @@ -40,5 +42,6 @@ json_value_LDFLAGS = -lmozjs value_json_SOURCES = value-json.cpp value_json_LDFLAGS = -lmozjs -noinst_PROGRAMS = eval-test eval-shell element-value value-element xml-value value-xml json-value value-json -TESTS = eval-test +noinst_PROGRAMS = scheme-test +mod_PROGRAMS = scheme-shell element-value value-element xml-value value-xml json-value value-json +TESTS = scheme-test diff --git a/sca-cpp/trunk/modules/scheme/eval-shell.cpp b/sca-cpp/trunk/modules/scheme/eval-shell.cpp deleted file mode 100644 index 4aa67c2375..0000000000 --- a/sca-cpp/trunk/modules/scheme/eval-shell.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/* $Rev$ $Date$ */ - -/** - * Script evaluator shell, used for interactive testing of scripts. - */ - -#include -#include "gc.hpp" -#include "stream.hpp" -#include "string.hpp" -#include "driver.hpp" - -int main() { - tuscany::gc_scoped_pool pool; - tuscany::scheme::evalDriverRun(tuscany::cin, tuscany::cout); - return 0; -} diff --git a/sca-cpp/trunk/modules/scheme/eval-test.cpp b/sca-cpp/trunk/modules/scheme/eval-test.cpp deleted file mode 100644 index dd97bc358d..0000000000 --- a/sca-cpp/trunk/modules/scheme/eval-test.cpp +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/* $Rev$ $Date$ */ - -/** - * Test script evaluator. - */ - -#include -#include "stream.hpp" -#include "string.hpp" -#include "driver.hpp" - -namespace tuscany { -namespace scheme { - -bool testEnv() { - gc_scoped_pool pool; - Env globalEnv = list(); - Env env = extendEnvironment(mklist("a"), mklist(1), globalEnv); - defineVariable("x", env, env); - assert(lookupVariableValue(value("x"), env) == env); - assert(lookupVariableValue("a", env) == value(1)); - return true; -} - -bool testEnvGC() { - resetLambdaCounters(); - resetListCounters(); - resetValueCounters(); - testEnv(); - assert(checkValueCounters()); - assert(checkLambdaCounters()); - assert(checkListCounters()); - return true; -} - -bool testRead() { - istringstream is("abcd"); - assert(readValue(is) == "abcd"); - - istringstream is2("123"); - assert(readValue(is2) == value(123)); - - istringstream is3("(abcd)"); - assert(readValue(is3) == mklist(value("abcd"))); - - istringstream is4("(abcd xyz)"); - assert(readValue(is4) == mklist("abcd", "xyz")); - - istringstream is5("(abcd (xyz tuv))"); - assert(readValue(is5) == mklist("abcd", mklist("xyz", "tuv"))); - - return true; -} - -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 a = cons("Feed", cons("feed-1234", i)); - ostringstream os; - writeValue(a, os); - istringstream is(str(os)); - assert(readValue(is) == a); - } - { - const list i = mklist("x", value()); - const list a = mklist(i); - ostringstream os; - writeValue(a, os); - istringstream is(str(os)); - assert(readValue(is) == a); - } - return true; -} - -const string testSchemeNumber( - "(define (testNumber) (if (= 1 1) (display \"testNumber ok\") (error \"testNumber\"))) " - "(testNumber)"); - -const string testSchemeString( - "(define (testString) (if (= \"abc\" \"abc\") (display \"testString ok\") (error \"testString\"))) " - "(testString)"); - -const string testSchemeDefinition( - "(define a \"abc\") (define (testDefinition) (if (= a \"abc\") (display \"testDefinition ok\") (error \"testDefinition\"))) " - "(testDefinition)"); - -const string testSchemeIf( - "(define (testIf) (if (= \"abc\" \"abc\") (if (= \"xyz\" \"xyz\") (display \"testIf ok\") (error \"testNestedIf\")) (error \"testIf\"))) " - "(testIf)"); - -const string testSchemeCond( - "(define (testCond) (cond ((= \"abc\" \"abc\") (display \"testCond ok\")) (else (error \"testIf\"))))" - "(testCond)"); - -const string testSchemeBegin( - "(define (testBegin) " - "(begin " - "(define a \"abc\") " - "(if (= a \"abc\") (display \"testBegin1 ok\") (error \"testBegin\")) " - "(define x \"xyz\") " - "(if (= x \"xyz\") (display \"testBegin2 ok\") (error \"testBegin\")) " - ") " - ") " - "(testBegin)"); - -const string testSchemeLambda( - "(define sqrt (lambda (x) (* x x))) " - "(define (testLambda) (if (= 4 (sqrt 2)) (display \"testLambda ok\") (error \"testLambda\"))) " - "(testLambda)"); - -const string testSchemeForward( - "(define (testLambda) (if (= 4 (sqrt 2)) (display \"testForward ok\") (error \"testForward\"))) " - "(define sqrt (lambda (x) (* x x))) " - "(testLambda)"); - -const string evalOutput(const string& scm) { - istringstream is(scm); - ostringstream os; - evalDriverRun(is, os); - return str(os); -} - -bool testEval() { - gc_scoped_pool pool; - assert(contains(evalOutput(testSchemeNumber), "testNumber ok")); - assert(contains(evalOutput(testSchemeString), "testString ok")); - assert(contains(evalOutput(testSchemeDefinition), "testDefinition ok")); - assert(contains(evalOutput(testSchemeIf), "testIf ok")); - assert(contains(evalOutput(testSchemeCond), "testCond ok")); - assert(contains(evalOutput(testSchemeBegin), "testBegin1 ok")); - assert(contains(evalOutput(testSchemeBegin), "testBegin2 ok")); - assert(contains(evalOutput(testSchemeLambda), "testLambda ok")); - assert(contains(evalOutput(testSchemeForward), "testForward ok")); - return true; -} - -bool testEvalExpr() { - gc_scoped_pool pool; - const value exp = mklist("+", 2, 3); - Env env = setupEnvironment(); - const value r = evalExpr(exp, env); - assert(r == value(5)); - return true; -} - -bool testEvalRun() { - gc_scoped_pool pool; - evalDriverRun(cin, cout); - return true; -} - -const value mult(const list& args) { - const double x = car(args); - const double y = cadr(args); - return x * y; -} - -const string testReturnLambda( - "(define (testReturnLambda) * )"); - -const string testCallLambda( - "(define (testCallLambda l x y) (l x y))"); - -bool testEvalLambda() { - gc_scoped_pool pool; - Env env = setupEnvironment(); - - const value trl = mklist("testReturnLambda"); - istringstream trlis(testReturnLambda); - const value trlv = evalScript(trl, trlis, env); - - istringstream tclis(testCallLambda); - const value tcl = cons("testCallLambda", quotedParameters(mklist(trlv, 2, 3))); - const value tclv = evalScript(tcl, tclis, env); - assert(tclv == value(6)); - - istringstream tcelis(testCallLambda); - const value tcel = cons("testCallLambda", quotedParameters(mklist(primitiveProcedure(mult), 3, 4))); - const value tcelv = evalScript(tcel, tcelis, env); - assert(tcelv == value(12)); - return true; -} - -bool testEvalGC() { - resetLambdaCounters(); - resetListCounters(); - resetValueCounters(); - testEval(); - testEvalExpr(); - testEvalLambda(); - assert(checkValueCounters()); - assert(checkLambdaCounters()); - assert(checkListCounters()); - return true; -} - -} -} - -int main() { - tuscany::cout << "Testing..." << tuscany::endl; - - tuscany::scheme::testEnv(); - tuscany::scheme::testEnvGC(); - tuscany::scheme::testRead(); - tuscany::scheme::testWrite(); - tuscany::scheme::testEval(); - tuscany::scheme::testEvalExpr(); - tuscany::scheme::testEvalLambda(); - tuscany::scheme::testEvalGC(); - - tuscany::cout << "OK" << tuscany::endl; - return 0; -} diff --git a/sca-cpp/trunk/modules/scheme/scheme-shell.cpp b/sca-cpp/trunk/modules/scheme/scheme-shell.cpp new file mode 100644 index 0000000000..4aa67c2375 --- /dev/null +++ b/sca-cpp/trunk/modules/scheme/scheme-shell.cpp @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +/** + * Script evaluator shell, used for interactive testing of scripts. + */ + +#include +#include "gc.hpp" +#include "stream.hpp" +#include "string.hpp" +#include "driver.hpp" + +int main() { + tuscany::gc_scoped_pool pool; + tuscany::scheme::evalDriverRun(tuscany::cin, tuscany::cout); + return 0; +} diff --git a/sca-cpp/trunk/modules/scheme/scheme-test.cpp b/sca-cpp/trunk/modules/scheme/scheme-test.cpp new file mode 100644 index 0000000000..dd97bc358d --- /dev/null +++ b/sca-cpp/trunk/modules/scheme/scheme-test.cpp @@ -0,0 +1,241 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +/** + * Test script evaluator. + */ + +#include +#include "stream.hpp" +#include "string.hpp" +#include "driver.hpp" + +namespace tuscany { +namespace scheme { + +bool testEnv() { + gc_scoped_pool pool; + Env globalEnv = list(); + Env env = extendEnvironment(mklist("a"), mklist(1), globalEnv); + defineVariable("x", env, env); + assert(lookupVariableValue(value("x"), env) == env); + assert(lookupVariableValue("a", env) == value(1)); + return true; +} + +bool testEnvGC() { + resetLambdaCounters(); + resetListCounters(); + resetValueCounters(); + testEnv(); + assert(checkValueCounters()); + assert(checkLambdaCounters()); + assert(checkListCounters()); + return true; +} + +bool testRead() { + istringstream is("abcd"); + assert(readValue(is) == "abcd"); + + istringstream is2("123"); + assert(readValue(is2) == value(123)); + + istringstream is3("(abcd)"); + assert(readValue(is3) == mklist(value("abcd"))); + + istringstream is4("(abcd xyz)"); + assert(readValue(is4) == mklist("abcd", "xyz")); + + istringstream is5("(abcd (xyz tuv))"); + assert(readValue(is5) == mklist("abcd", mklist("xyz", "tuv"))); + + return true; +} + +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 a = cons("Feed", cons("feed-1234", i)); + ostringstream os; + writeValue(a, os); + istringstream is(str(os)); + assert(readValue(is) == a); + } + { + const list i = mklist("x", value()); + const list a = mklist(i); + ostringstream os; + writeValue(a, os); + istringstream is(str(os)); + assert(readValue(is) == a); + } + return true; +} + +const string testSchemeNumber( + "(define (testNumber) (if (= 1 1) (display \"testNumber ok\") (error \"testNumber\"))) " + "(testNumber)"); + +const string testSchemeString( + "(define (testString) (if (= \"abc\" \"abc\") (display \"testString ok\") (error \"testString\"))) " + "(testString)"); + +const string testSchemeDefinition( + "(define a \"abc\") (define (testDefinition) (if (= a \"abc\") (display \"testDefinition ok\") (error \"testDefinition\"))) " + "(testDefinition)"); + +const string testSchemeIf( + "(define (testIf) (if (= \"abc\" \"abc\") (if (= \"xyz\" \"xyz\") (display \"testIf ok\") (error \"testNestedIf\")) (error \"testIf\"))) " + "(testIf)"); + +const string testSchemeCond( + "(define (testCond) (cond ((= \"abc\" \"abc\") (display \"testCond ok\")) (else (error \"testIf\"))))" + "(testCond)"); + +const string testSchemeBegin( + "(define (testBegin) " + "(begin " + "(define a \"abc\") " + "(if (= a \"abc\") (display \"testBegin1 ok\") (error \"testBegin\")) " + "(define x \"xyz\") " + "(if (= x \"xyz\") (display \"testBegin2 ok\") (error \"testBegin\")) " + ") " + ") " + "(testBegin)"); + +const string testSchemeLambda( + "(define sqrt (lambda (x) (* x x))) " + "(define (testLambda) (if (= 4 (sqrt 2)) (display \"testLambda ok\") (error \"testLambda\"))) " + "(testLambda)"); + +const string testSchemeForward( + "(define (testLambda) (if (= 4 (sqrt 2)) (display \"testForward ok\") (error \"testForward\"))) " + "(define sqrt (lambda (x) (* x x))) " + "(testLambda)"); + +const string evalOutput(const string& scm) { + istringstream is(scm); + ostringstream os; + evalDriverRun(is, os); + return str(os); +} + +bool testEval() { + gc_scoped_pool pool; + assert(contains(evalOutput(testSchemeNumber), "testNumber ok")); + assert(contains(evalOutput(testSchemeString), "testString ok")); + assert(contains(evalOutput(testSchemeDefinition), "testDefinition ok")); + assert(contains(evalOutput(testSchemeIf), "testIf ok")); + assert(contains(evalOutput(testSchemeCond), "testCond ok")); + assert(contains(evalOutput(testSchemeBegin), "testBegin1 ok")); + assert(contains(evalOutput(testSchemeBegin), "testBegin2 ok")); + assert(contains(evalOutput(testSchemeLambda), "testLambda ok")); + assert(contains(evalOutput(testSchemeForward), "testForward ok")); + return true; +} + +bool testEvalExpr() { + gc_scoped_pool pool; + const value exp = mklist("+", 2, 3); + Env env = setupEnvironment(); + const value r = evalExpr(exp, env); + assert(r == value(5)); + return true; +} + +bool testEvalRun() { + gc_scoped_pool pool; + evalDriverRun(cin, cout); + return true; +} + +const value mult(const list& args) { + const double x = car(args); + const double y = cadr(args); + return x * y; +} + +const string testReturnLambda( + "(define (testReturnLambda) * )"); + +const string testCallLambda( + "(define (testCallLambda l x y) (l x y))"); + +bool testEvalLambda() { + gc_scoped_pool pool; + Env env = setupEnvironment(); + + const value trl = mklist("testReturnLambda"); + istringstream trlis(testReturnLambda); + const value trlv = evalScript(trl, trlis, env); + + istringstream tclis(testCallLambda); + const value tcl = cons("testCallLambda", quotedParameters(mklist(trlv, 2, 3))); + const value tclv = evalScript(tcl, tclis, env); + assert(tclv == value(6)); + + istringstream tcelis(testCallLambda); + const value tcel = cons("testCallLambda", quotedParameters(mklist(primitiveProcedure(mult), 3, 4))); + const value tcelv = evalScript(tcel, tcelis, env); + assert(tcelv == value(12)); + return true; +} + +bool testEvalGC() { + resetLambdaCounters(); + resetListCounters(); + resetValueCounters(); + testEval(); + testEvalExpr(); + testEvalLambda(); + assert(checkValueCounters()); + assert(checkLambdaCounters()); + assert(checkListCounters()); + return true; +} + +} +} + +int main() { + tuscany::cout << "Testing..." << tuscany::endl; + + tuscany::scheme::testEnv(); + tuscany::scheme::testEnvGC(); + tuscany::scheme::testRead(); + tuscany::scheme::testWrite(); + tuscany::scheme::testEval(); + tuscany::scheme::testEvalExpr(); + tuscany::scheme::testEvalLambda(); + tuscany::scheme::testEvalGC(); + + tuscany::cout << "OK" << tuscany::endl; + return 0; +} -- cgit v1.2.3