From f453584ae0a3ec04f1781fc35b7abe5d139c6679 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Sat, 26 Dec 2009 03:25:16 +0000 Subject: Added timing functions to measure performance, removed unused cache support, refactored and removed some obsolete tests and adjusted build. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@893937 13f79535-47bb-0310-9956-ffa450edef68 --- .../trunk/components/cache/mcache-client-test.cpp | 55 +++--- sca-cpp/trunk/components/cache/mcache-test.cpp | 40 ++-- sca-cpp/trunk/configure.ac | 9 +- sca-cpp/trunk/kernel/Makefile.am | 18 +- sca-cpp/trunk/kernel/cache-test.cpp | 79 -------- sca-cpp/trunk/kernel/cache.hpp | 160 ---------------- sca-cpp/trunk/kernel/diskcache-test | 27 --- sca-cpp/trunk/kernel/parallel-test.cpp | 151 +++++++++++++++ sca-cpp/trunk/kernel/perf.hpp | 68 +++++++ sca-cpp/trunk/kernel/xml-test.cpp | 165 +++++++++++++++++ sca-cpp/trunk/modules/http/curl-test.cpp | 40 ++-- sca-cpp/trunk/modules/server/Makefile.am | 9 +- sca-cpp/trunk/modules/server/client-test.cpp | 205 +++++++++++---------- sca-cpp/trunk/test/Makefile.am | 2 +- sca-cpp/trunk/test/store-function/Makefile.am | 28 --- sca-cpp/trunk/test/store-function/cart.hpp | 69 ------- sca-cpp/trunk/test/store-function/catalog.hpp | 54 ------ .../trunk/test/store-function/catalogs.composite | 43 ----- .../test/store-function/currency-composite.hpp | 37 ---- .../trunk/test/store-function/currency.composite | 32 ---- sca-cpp/trunk/test/store-function/currency.hpp | 59 ------ sca-cpp/trunk/test/store-function/item.hpp | 54 ------ sca-cpp/trunk/test/store-function/service.hpp | 35 ---- .../trunk/test/store-function/store-composite.hpp | 47 ----- .../test/store-function/store-function-test.cpp | 50 ----- .../trunk/test/store-function/store-solution.hpp | 41 ----- sca-cpp/trunk/test/store-function/store-ui.hpp | 64 ------- sca-cpp/trunk/test/store-function/store.composite | 64 ------- sca-cpp/trunk/test/store-object/Makefile.am | 28 --- sca-cpp/trunk/test/store-object/cart.hpp | 74 -------- sca-cpp/trunk/test/store-object/catalog.hpp | 65 ------- sca-cpp/trunk/test/store-object/catalogs.composite | 43 ----- .../trunk/test/store-object/currency-composite.hpp | 51 ----- sca-cpp/trunk/test/store-object/currency.composite | 32 ---- sca-cpp/trunk/test/store-object/currency.hpp | 60 ------ sca-cpp/trunk/test/store-object/item.hpp | 47 ----- .../trunk/test/store-object/store-composite.hpp | 68 ------- .../trunk/test/store-object/store-object-test.cpp | 52 ------ sca-cpp/trunk/test/store-object/store-solution.hpp | 62 ------- sca-cpp/trunk/test/store-object/store-ui.hpp | 72 -------- sca-cpp/trunk/test/store-object/store.composite | 64 ------- 41 files changed, 561 insertions(+), 1862 deletions(-) delete mode 100644 sca-cpp/trunk/kernel/cache-test.cpp delete mode 100644 sca-cpp/trunk/kernel/cache.hpp delete mode 100755 sca-cpp/trunk/kernel/diskcache-test create mode 100644 sca-cpp/trunk/kernel/parallel-test.cpp create mode 100644 sca-cpp/trunk/kernel/perf.hpp create mode 100644 sca-cpp/trunk/kernel/xml-test.cpp delete mode 100644 sca-cpp/trunk/test/store-function/Makefile.am delete mode 100644 sca-cpp/trunk/test/store-function/cart.hpp delete mode 100644 sca-cpp/trunk/test/store-function/catalog.hpp delete mode 100644 sca-cpp/trunk/test/store-function/catalogs.composite delete mode 100644 sca-cpp/trunk/test/store-function/currency-composite.hpp delete mode 100644 sca-cpp/trunk/test/store-function/currency.composite delete mode 100644 sca-cpp/trunk/test/store-function/currency.hpp delete mode 100644 sca-cpp/trunk/test/store-function/item.hpp delete mode 100644 sca-cpp/trunk/test/store-function/service.hpp delete mode 100644 sca-cpp/trunk/test/store-function/store-composite.hpp delete mode 100644 sca-cpp/trunk/test/store-function/store-function-test.cpp delete mode 100644 sca-cpp/trunk/test/store-function/store-solution.hpp delete mode 100644 sca-cpp/trunk/test/store-function/store-ui.hpp delete mode 100644 sca-cpp/trunk/test/store-function/store.composite delete mode 100644 sca-cpp/trunk/test/store-object/Makefile.am delete mode 100644 sca-cpp/trunk/test/store-object/cart.hpp delete mode 100644 sca-cpp/trunk/test/store-object/catalog.hpp delete mode 100644 sca-cpp/trunk/test/store-object/catalogs.composite delete mode 100644 sca-cpp/trunk/test/store-object/currency-composite.hpp delete mode 100644 sca-cpp/trunk/test/store-object/currency.composite delete mode 100644 sca-cpp/trunk/test/store-object/currency.hpp delete mode 100644 sca-cpp/trunk/test/store-object/item.hpp delete mode 100644 sca-cpp/trunk/test/store-object/store-composite.hpp delete mode 100644 sca-cpp/trunk/test/store-object/store-object-test.cpp delete mode 100644 sca-cpp/trunk/test/store-object/store-solution.hpp delete mode 100644 sca-cpp/trunk/test/store-object/store-ui.hpp delete mode 100644 sca-cpp/trunk/test/store-object/store.composite (limited to 'sca-cpp') diff --git a/sca-cpp/trunk/components/cache/mcache-client-test.cpp b/sca-cpp/trunk/components/cache/mcache-client-test.cpp index 0a560bc05f..2e444250c7 100644 --- a/sca-cpp/trunk/components/cache/mcache-client-test.cpp +++ b/sca-cpp/trunk/components/cache/mcache-client-test.cpp @@ -24,14 +24,13 @@ */ #include -#include -#include #include #include #include "list.hpp" #include "value.hpp" #include "monad.hpp" +#include "perf.hpp" #include "../../modules/http/curl.hpp" namespace tuscany { @@ -83,43 +82,33 @@ bool testCache() { return true; } -const double duration(struct timeval start, struct timeval end, int count) { - long t = (end.tv_sec * 1000 + end.tv_usec / 1000) - (start.tv_sec * 1000 + start.tv_usec / 1000); - return (double)t / (double)count; -} - -bool testGetLoop(const int count, const value& id, const value& entry, http::CURLSession& cs) { - if (count == 0) +struct getLoop { + const value id; + const value entry; + http::CURLSession cs; + getLoop(const value& id, const value& entry, http::CURLSession cs) : id(id), entry(entry), cs(cs) { + } + const bool operator()() const { + const failable val = http::get(url + "/" + std::string(id), cs); + assert(hasContent(val)); + assert(content(val) == entry); return true; - const failable val = http::get(url + "/" + std::string(id), cs); - assert(hasContent(val)); - assert(content(val) == entry); - return testGetLoop(count - 1, id, entry, cs); -} + } +}; bool testGetPerf() { - const int count = 50; - struct timeval start; - struct timeval end; - { - const list i = list() - << (list() << "name" << std::string("Apple")) - << (list() << "price" << std::string("$4.55")); - const list a = mklist(std::string("item"), std::string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i); - - http::CURLSession cs; - const failable id = http::post(a, url, cs); - assert(hasContent(id)); - - testGetLoop(5, content(id), a, cs); + const list i = list() + << (list() << "name" << std::string("Apple")) + << (list() << "price" << std::string("$4.55")); + const value a = mklist(std::string("item"), std::string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i); - gettimeofday(&start, NULL); + http::CURLSession cs; + const failable id = http::post(a, url, cs); + assert(hasContent(id)); - testGetLoop(count, content(id), a, cs); + const lambda gl = getLoop(content(id), a, cs); + std::cout << "Cache get test " << time(gl, 5, 200) << " ms" << std::endl; - gettimeofday(&end, NULL); - std::cout << "Cache get test " << duration(start, end, count) << " ms" << std::endl; - } return true; } diff --git a/sca-cpp/trunk/components/cache/mcache-test.cpp b/sca-cpp/trunk/components/cache/mcache-test.cpp index 78f0da0465..dc286687c0 100644 --- a/sca-cpp/trunk/components/cache/mcache-test.cpp +++ b/sca-cpp/trunk/components/cache/mcache-test.cpp @@ -24,11 +24,9 @@ */ #include -#include -#include #include #include -#include +#include "perf.hpp" #include "mcache.hpp" namespace tuscany { @@ -47,35 +45,23 @@ bool testMemCached() { return true; } -const double duration(struct timeval start, struct timeval end, int count) { - long t = (end.tv_sec * 1000 + end.tv_usec / 1000) - (start.tv_sec * 1000 + start.tv_usec / 1000); - return (double)t / (double)count; -} - -bool testGetLoop(const int count, MemCached& ch) { - if (count == 0) +struct getLoop { + MemCached& ch; + getLoop(MemCached& ch) : ch(ch) { + } + const bool operator()() const { + assert(get("c", ch) == value(std::string("CCC"))); return true; - assert(get("c", ch) == value(std::string("CCC"))); - return testGetLoop(count - 1, ch); -} + } +}; bool testGetPerf() { - const int count = 50; - struct timeval start; - struct timeval end; - { - MemCached ch; - assert(hasContent(post("c", std::string("CCC"), ch))); - - testGetLoop(5, ch); - - gettimeofday(&start, NULL); + MemCached ch; + assert(hasContent(post("c", std::string("CCC"), ch))); - testGetLoop(count, ch); + const lambda gl = getLoop(ch); + std::cout << "Memcached get test " << time(gl, 5, 200) << " ms" << std::endl; - gettimeofday(&end, NULL); - std::cout << "Memcached get test " << duration(start, end, count) << " ms" << std::endl; - } return true; } diff --git a/sca-cpp/trunk/configure.ac b/sca-cpp/trunk/configure.ac index ada22c92e7..1452d7164c 100644 --- a/sca-cpp/trunk/configure.ac +++ b/sca-cpp/trunk/configure.ac @@ -172,10 +172,11 @@ AC_ARG_ENABLE(maintainer-mode, [AS_HELP_STRING([--enable-maintainer-mode], [comp esac ], [ AC_MSG_RESULT(no)]) if test "$want_maintainer_mode" = "true"; then - AC_SUBST([CXXFLAGS], ["-D_DEBUG -O0 -g3 -pg -Wall -Wextra -Wno-ignored-qualifiers -Winit-self -Wmissing-include-dirs -Wcast-qual -Wcast-align -Wwrite-strings -Wpointer-arith -Wconversion -Waddress -Wlogical-op -Wredundant-decls -std=c++0x -fmessage-length=0"]) - AC_SUBST([LDFLAGS], ["${LDFLAGS} -pg"]) + AC_SUBST([CXXFLAGS], [" -D_REENTRANT -D_DEBUG -O0 -g3 -pg -Werror -Wall -Wextra -Wno-ignored-qualifiers -Winit-self -Wmissing-include-dirs -Wcast-qual -Wcast-align -Wwrite-strings -Wpointer-arith -Wconversion -Waddress -Wlogical-op -Wredundant-decls -std=c++0x -fmessage-length=0"]) + AC_SUBST([LDFLAGS], ["${LDFLAGS} -lpthread -pg"]) else - AC_SUBST([CXXFLAGS], ["-O3 -std=c++0x -fmessage-length=0"]) + AC_SUBST([CXXFLAGS], [" -D_REENTRANT -O3 -std=c++0x -fmessage-length=0"]) + AC_SUBST([LDFLAGS], ["${LDFLAGS} -lpthread -pg"]) fi # Configure exuberant ctags @@ -222,8 +223,6 @@ AC_CONFIG_FILES([Makefile components/store/Makefile samples/Makefile test/Makefile - test/store-object/Makefile - test/store-function/Makefile test/store-script/Makefile doc/Makefile doc/Doxyfile diff --git a/sca-cpp/trunk/kernel/Makefile.am b/sca-cpp/trunk/kernel/Makefile.am index bfaeb2ce9b..4dfc285e90 100644 --- a/sca-cpp/trunk/kernel/Makefile.am +++ b/sca-cpp/trunk/kernel/Makefile.am @@ -15,7 +15,7 @@ # specific language governing permissions and limitations # under the License. -noinst_PROGRAMS = kernel-test cache-test xsd-test +noinst_PROGRAMS = kernel-test parallel-test xml-test xsd-test testdir=$(prefix)/test test_LTLIBRARIES = libdynlib-test.la @@ -26,18 +26,18 @@ include_HEADERS = *.hpp INCLUDES = -I. -I$(top_builddir)/kernel -I${LIBXML2_INCLUDE} -I${APR_INCLUDE} kernel_test_SOURCES = kernel-test.cpp -kernel_test_CXXFLAGS = $(CXXFLAGS) -D_REENTRANT -kernel_test_LDADD = -lpthread -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1 +kernel_test_LDADD = -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1 libdynlib_test_la_SOURCES = dynlib-test.cpp -libdynlib_test_la_CXXFLAGS = $(CXXFLAGS) -D_REENTRANT -libdynlib_test_la_LIBADD = -lpthread -L${APR_LIB} -lapr-1 -laprutil-1 +libdynlib_test_la_LIBADD = -L${APR_LIB} -lapr-1 -laprutil-1 -cache_test_SOURCES = cache-test.cpp -cache_test_LDADD = -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1 +parallel_test_SOURCES = parallel-test.cpp +parallel_test_LDADD = -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1 + +xml_test_SOURCES = xml-test.cpp +xml_test_LDADD = -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1 xsd_test_SOURCES = xsd-test.cpp xsd_test_LDADD = -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1 -TESTS = kernel-test diskcache-test - +TESTS = kernel-test parallel-test xml-test diff --git a/sca-cpp/trunk/kernel/cache-test.cpp b/sca-cpp/trunk/kernel/cache-test.cpp deleted file mode 100644 index 5391d38cf6..0000000000 --- a/sca-cpp/trunk/kernel/cache-test.cpp +++ /dev/null @@ -1,79 +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 cache functions. - */ - -#include -#include -#include -#include -#include -#include -#include "slist.hpp" -#include "cache.hpp" - -namespace tuscany { - -const std::string fileRead(const std::string path) { - std::ifstream is(path); - return car(streamList(is)); -} - -bool testCache() { - const std::string p("tmp/test.txt"); - const lambda fr(fileRead); - const lambda ft(latestFileTime); - - const cached c(curry(fr, p), curry(ft, p)); - - { - std::ofstream os(p); - os << "initial"; - os.close(); - assert(content(latest(c)) == std::string("initial")); - } - - usleep(1000000); - - { - std::ofstream os(p); - os << "updated"; - os.close(); - assert(latest(c) != c); - assert(content(latest(c)) == std::string("updated")); - assert(latest(c) == latest(c)); - } - return true; -} - -} - -int main() { - std::cout << "Testing..." << std::endl; - - tuscany::testCache(); - - std::cout << "OK" << std::endl; - - return 0; -} diff --git a/sca-cpp/trunk/kernel/cache.hpp b/sca-cpp/trunk/kernel/cache.hpp deleted file mode 100644 index 4cab4e4e9b..0000000000 --- a/sca-cpp/trunk/kernel/cache.hpp +++ /dev/null @@ -1,160 +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$ */ - -#ifndef tuscany_cache_hpp -#define tuscany_cache_hpp - -/** - * Simple local cache monad implementation. - */ - -#ifdef _REENTRANT -#include -#endif -#include - -#include -#include "value.hpp" -#include "monad.hpp" - -namespace tuscany { - -/** - * Cached monad. Used to represent a value that can be cached. - * To get the value in the monad, just cast it to the value type. - */ -template class cached { -public: - cached() : mutex(mutex_init()), mtime(0) { - } - - cached(const lambda& lvalue, const lambda ltime) : mutex(mutex_init()), lvalue(lvalue), ltime(ltime), mtime(0) { - } - - cached(const lambda& lvalue, const lambda ltime, const unsigned long mtime, const V& v) : mutex(mutex_init()), lvalue(lvalue), ltime(ltime), mtime(mtime), v(v) { - } - - cached(const cached& c) : mutex(mutex_init()), lvalue(c.lvalue), ltime(c.ltime), mtime(c.mtime), v(c.v) { - } - - ~cached() { -#ifdef _REENTRANT - pthread_mutex_destroy(mutex); -#endif - } - - const cached& operator=(const cached& c) { - if(this == &c) - return *this; -#ifdef _REENTRANT - pthread_mutex_lock(mutex); -#endif - this->lvalue = c.lvalue; - this->ltime = c.ltime; - this->mtime = c.mtime; - this->v = c.v; -#ifdef _REENTRANT - pthread_mutex_unlock(mutex); -#endif - return *this; - } - - const bool operator!=(const cached& m) const { - return !this->operator==(m); - } - - const bool operator==(const cached& m) const { - if (this == &m) - return true; -#ifdef _REENTRANT - pthread_mutex_lock(mutex); -#endif - const bool r = mtime == m.mtime && v == m.v; -#ifdef _REENTRANT - pthread_mutex_unlock(mutex); -#endif - return r; - } - -private: -#ifdef _REENTRANT - pthread_mutex_t* mutex; - pthread_mutex_t* mutex_init() { - pthread_mutex_t* mx = new pthread_mutex_t(); - pthread_mutex_init(mx, NULL); - return mx; - } -#else - void* mutex; - void* mutex_init() { - return NULL; - } -#endif - - lambda lvalue; - lambda ltime; - unsigned long mtime; - V v; - - template friend const cached latest(const cached& c); - template friend const X content(const cached& c); - template friend std::ostream& operator<<(std::ostream& out, const cached& c); -}; - -/** - * Write a cached monad to a stream. - */ -template std::ostream& operator<<(std::ostream& out, const cached& c) { - out << c.v; - return out; -} - -/** - * Returns the latest value of a cached monad. - */ -template const cached latest(const cached& c) { - unsigned long nt = c.ltime(); - if (nt == c.mtime) - return c; - return cached(c.lvalue, c.ltime, nt, c.lvalue()); -} - -/** - * Returns the content of a cached monad. - */ -template const V content(const cached& c) { - return c.v; -} - -/** - * Returns the latest modification time of a file. - */ -const unsigned long latestFileTime(const std::string& path) { - struct stat st; - int rc = stat(path.c_str(), &st); - if (rc < 0) - return 0; - return st.st_mtim.tv_nsec; -} - -} - -#endif /* tuscany_cache_hpp */ diff --git a/sca-cpp/trunk/kernel/diskcache-test b/sca-cpp/trunk/kernel/diskcache-test deleted file mode 100755 index dfcc177496..0000000000 --- a/sca-cpp/trunk/kernel/diskcache-test +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh - -# 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. - -# Setup -mkdir -p tmp - -# Test -./cache-test -rc=$? - -return $rc diff --git a/sca-cpp/trunk/kernel/parallel-test.cpp b/sca-cpp/trunk/kernel/parallel-test.cpp new file mode 100644 index 0000000000..8ae2eeed2c --- /dev/null +++ b/sca-cpp/trunk/kernel/parallel-test.cpp @@ -0,0 +1,151 @@ +/* + * 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 parallel functions. + */ + +#include +#include +#include +#include "function.hpp" +#include "list.hpp" +#include "perf.hpp" +#include "parallel.hpp" + +namespace tuscany { + +int inci = 0; + +struct incPerf { + incPerf() { + } + const bool operator()() const { + inci = inci + 1; + return true; + } +}; + +int addi = 0; + +struct addAndFetchPerf { + addAndFetchPerf() { + } + const bool operator()() const { + __sync_add_and_fetch(&addi, 1); + return true; + } +}; + +int muxi = 0; + +struct mutexPerf { + pthread_mutex_t* mutex; + mutexPerf(pthread_mutex_t* mutex) : mutex(mutex) { + } + const bool operator()() const { + pthread_mutex_lock(mutex); + muxi = muxi + 1; + pthread_mutex_unlock(mutex); + return true; + } +}; + +__thread int tlsi = 0; + +struct tlsPerf { + tlsPerf() { + } + const bool operator()() const { + tlsi = tlsi + 1; + return true; + } +}; + +bool testAtomicPerf() { + const int count = 100000; + { + const lambda l = incPerf(); + std::cout << "Non-atomic inc test " << time(l, 1000, count) << " ms" << std::endl; + assert(inci == count + 1000); + } + { + const lambda l = addAndFetchPerf(); + std::cout << "Atomic inc test " << time(l, 1000, count) << " ms" << std::endl; + assert(addi == count + 1000); + } + { + pthread_mutex_t mutex; + pthread_mutex_init(&mutex, NULL); + const lambda l = mutexPerf(&mutex); + std::cout << "Locked inc test " << time(l, 1000, count) << " ms" << std::endl; + assert(muxi == count + 1000); + pthread_mutex_destroy(&mutex); + } + { + const lambda l = tlsPerf(); + std::cout << "Thread local inc test " << time(l, 1000, count) << " ms" << std::endl; + assert(tlsi == count + 1000); + } + return true; +} + +const int mtsquare(const int x) { + for(int i = 0; i < 10000000; i++) + ; + return x * x; +} + +bool testWorker() { + worker w(10); + { + const lambda func = curry(lambda (mtsquare), 2); + assert(submit(w, func) == 4); + } + { + const int max = 10; + + list > r; + for(int i = 0; i < max; i++) { + const lambda func = curry(lambda (mtsquare), i); + r = cons(submit(w, func), r); + } + for(int i = max - 1; i >= 0; i--) { + assert(car(r) == i * i); + r = cdr(r); + } + } + shutdown(w); + return true; +} + +} + +int main() { + std::cout << "Testing..." << std::endl; + + tuscany::testAtomicPerf(); + tuscany::testWorker(); + + std::cout << "OK" << std::endl; + + return 0; +} diff --git a/sca-cpp/trunk/kernel/perf.hpp b/sca-cpp/trunk/kernel/perf.hpp new file mode 100644 index 0000000000..f5004d015b --- /dev/null +++ b/sca-cpp/trunk/kernel/perf.hpp @@ -0,0 +1,68 @@ +/* + * 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$ */ + +#ifndef tuscany_perf_hpp +#define tuscany_perf_hpp + +/** + * Functions to help measure performance. + */ + +#include +#include + +#include "function.hpp" + +namespace tuscany +{ + +/** + * Measure the time required to perform a function in msec. + */ +struct timeLambda { + const lambda f; + timeLambda(const lambda& f) : f(f) { + } + bool operator()(const long count) const { + if (count == 0) + return true; + f(); + (*this)(count - 1); + return true; + } +}; + +const double time(const lambda& f, const long warmup, const long count) { + const lambda tl = timeLambda(f); + struct timeval start; + struct timeval end; + + tl(warmup); + gettimeofday(&start, NULL); + tl(count); + gettimeofday(&end, NULL); + + const long t = (end.tv_sec * 1000 + end.tv_usec / 1000) - (start.tv_sec * 1000 + start.tv_usec / 1000); + return (double)t / (double)count; +} + +} +#endif /* tuscany_perf_hpp */ diff --git a/sca-cpp/trunk/kernel/xml-test.cpp b/sca-cpp/trunk/kernel/xml-test.cpp new file mode 100644 index 0000000000..88c476ffef --- /dev/null +++ b/sca-cpp/trunk/kernel/xml-test.cpp @@ -0,0 +1,165 @@ +/* + * 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 XML handling functions. + */ + +#include +#include +#include +#include +#include "list.hpp" +#include "value.hpp" +#include "element.hpp" +#include "xml.hpp" + +namespace tuscany { + +const std::string currencyXML = +"\n" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"US" +"" +"" +"\n"; + +const std::string customerXML = +"\n" +"" +"jdoe" +"
san franciscoca
" +"12341000" +"67892000" +"45673000" +"
" +"\n"; + + +const bool isName(const value& token) { + return isTaggedList(token, attribute) && attributeName(token) == "name"; +} + +bool testReadXML() { + { + std::istringstream is(customerXML); + const list c = readXML(streamList(is)); + } + { + std::istringstream is(currencyXML); + const list c = readXML(streamList(is)); + + const value composite = car(c); + assert(isTaggedList(composite, element)); + assert(elementName(composite) == "composite"); + assert(attributeValue(car(filter(isName, elementChildren(composite)))) == std::string("currency")); + } + return true; +} + +std::ostringstream* xmlWriter(const std::string& s, std::ostringstream* os) { + (*os) << s; + return os; +} + +bool testWriteXML() { + { + std::istringstream is(customerXML); + const list c = readXML(streamList(is)); + std::ostringstream os; + writeXML(xmlWriter, &os, c); + assert(os.str() == customerXML); + } + { + std::istringstream is(currencyXML); + const list c = readXML(streamList(is)); + std::ostringstream os; + writeXML(xmlWriter, &os, c); + assert(os.str() == currencyXML); + } + return true; +} + +bool testElement() { + { + const list ad = mklist(mklist("city", std::string("san francisco")), mklist("state", std::string("ca"))); + const list ac1 = mklist(mklist("id", std::string("1234")), mklist("balance", 1000)); + const list ac2 = mklist(mklist("id", std::string("6789")), mklist("balance", 2000)); + const list ac3 = mklist(mklist("id", std::string("4567")), mklist("balance", 3000)); + { + const list c = mklist(mklist("customer", mklist("name", std::string("jdoe")), cons("address", ad), mklist("account", mklist(ac1, ac2, ac3)))); + const list e = valuesToElements(c); + const list v = elementsToValues(e); + assert(v == c); + + std::ostringstream os; + writeXML(xmlWriter, &os, e); + assert(os.str() == customerXML); + } + { + const list c = mklist(mklist("customer", mklist("name", std::string("jdoe")), cons("address", ad), cons("account", ac1), cons("account", ac2), cons("account", ac3))); + const list e = valuesToElements(c); + const list v = elementsToValues(e); + + std::ostringstream os; + writeXML(xmlWriter, &os, e); + assert(os.str() == customerXML); + } + } + { + std::istringstream is(customerXML); + const list c = readXML(streamList(is)); + const list v = elementsToValues(c); + const list e = valuesToElements(v); + std::ostringstream os; + writeXML(xmlWriter, &os, e); + assert(os.str() == customerXML); + } + return true; +} + +} + +int main() { + std::cout << "Testing..." << std::endl; + + tuscany::testReadXML(); + tuscany::testWriteXML(); + tuscany::testElement(); + + std::cout << "OK" << std::endl; + + return 0; +} diff --git a/sca-cpp/trunk/modules/http/curl-test.cpp b/sca-cpp/trunk/modules/http/curl-test.cpp index 59944546a1..01355dd429 100644 --- a/sca-cpp/trunk/modules/http/curl-test.cpp +++ b/sca-cpp/trunk/modules/http/curl-test.cpp @@ -24,12 +24,11 @@ */ #include -#include -#include #include #include #include #include "slist.hpp" +#include "perf.hpp" #include "curl.hpp" namespace tuscany { @@ -39,11 +38,6 @@ const bool contains(const std::string& str, const std::string& pattern) { return str.find(pattern) != str.npos; } -const double duration(struct timeval start, struct timeval end, int count) { - long t = (end.tv_sec * 1000 + end.tv_usec / 1000) - (start.tv_sec * 1000 + start.tv_usec / 1000); - return (double)t / (double)count; -} - std::ostringstream* curlWriter(const std::string& s, std::ostringstream* os) { (*os) << s; return os; @@ -66,30 +60,22 @@ const bool testGet() { return true; } -const bool testGetLoop(const int count, CURLSession& ch) { - if (count == 0) +struct getLoop { + CURLSession& ch; + getLoop(CURLSession& ch) : ch(ch) { + } + const bool operator()() const { + const failable r = get("http://localhost:8090", ch); + assert(hasContent(r)); + assert(contains(content(r), "It works")); return true; - const failable r = get("http://localhost:8090", ch); - assert(hasContent(r)); - assert(contains(content(r), "It works")); - return testGetLoop(count - 1, ch); -} + } +}; const bool testGetPerf() { - const int count = 50; CURLSession ch; - struct timeval start; - struct timeval end; - { - testGetLoop(5, ch); - - gettimeofday(&start, NULL); - - testGetLoop(count, ch); - - gettimeofday(&end, NULL); - std::cout << "Static GET test " << duration(start, end, count) << " ms" << std::endl; - } + lambda gl = getLoop(ch); + std::cout << "Static GET test " << time(gl, 5, 200) << " ms" << std::endl; return true; } diff --git a/sca-cpp/trunk/modules/server/Makefile.am b/sca-cpp/trunk/modules/server/Makefile.am index 0740790ad1..9e28d8602e 100644 --- a/sca-cpp/trunk/modules/server/Makefile.am +++ b/sca-cpp/trunk/modules/server/Makefile.am @@ -23,19 +23,16 @@ lib_LTLIBRARIES = libmod_tuscany_eval.la libmod_tuscany_wiring.la INCLUDES = -I. -I$(top_builddir)/kernel -I${LIBXML2_INCLUDE} -I${HTTPD_INCLUDE} -I${APR_INCLUDE} -I${JS_INCLUDE} -I${CURL_INCLUDE} libmod_tuscany_eval_la_SOURCES = mod-eval.cpp -libmod_tuscany_eval_la_CXXFLAGS = $(CXXFLAGS) -D_REENTRANT -libmod_tuscany_eval_la_LIBADD = -lpthread -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1 -L${CURL_LIB} -lcurl -L${JS_LIB} -lmozjs +libmod_tuscany_eval_la_LIBADD = -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1 -L${CURL_LIB} -lcurl -L${JS_LIB} -lmozjs libmod_tuscany_wiring_la_SOURCES = mod-wiring.cpp -libmod_tuscany_wiring_la_CXXFLAGS = $(CXXFLAGS) -D_REENTRANT -libmod_tuscany_wiring_la_LIBADD = -lpthread -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1 -L${CURL_LIB} -lcurl -L${JS_LIB} -lmozjs +libmod_tuscany_wiring_la_LIBADD = -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1 -L${CURL_LIB} -lcurl -L${JS_LIB} -lmozjs testdir=$(prefix)/test test_LTLIBRARIES = libimpl-test.la libimpl_test_la_SOURCES = impl-test.cpp -libimpl_test_la_CXXFLAGS = $(CXXFLAGS) -D_REENTRANT -libimpl_test_la_LIBADD = -lpthread -L${APR_LIB} -lapr-1 -laprutil-1 +libimpl_test_la_LIBADD = -L${APR_LIB} -lapr-1 -laprutil-1 client_test_SOURCES = client-test.cpp client_test_LDADD = -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1 -L${CURL_LIB} -lcurl -L${JS_LIB} -lmozjs diff --git a/sca-cpp/trunk/modules/server/client-test.cpp b/sca-cpp/trunk/modules/server/client-test.cpp index 5888c481e3..496d67f59c 100644 --- a/sca-cpp/trunk/modules/server/client-test.cpp +++ b/sca-cpp/trunk/modules/server/client-test.cpp @@ -24,12 +24,12 @@ */ #include -#include -#include #include #include #include #include "slist.hpp" +#include "parallel.hpp" +#include "perf.hpp" #include "../http/curl.hpp" namespace tuscany { @@ -39,11 +39,6 @@ const bool contains(const std::string& str, const std::string& pattern) { return str.find(pattern) != str.npos; } -const double duration(struct timeval start, struct timeval end, int count) { - long t = (end.tv_sec * 1000 + end.tv_usec / 1000) - (start.tv_sec * 1000 + start.tv_usec / 1000); - return (double)t / (double)count; -} - std::ostringstream* curlWriter(const std::string& s, std::ostringstream* os) { (*os) << s; return os; @@ -66,27 +61,22 @@ const bool testGet() { return true; } -const bool testGetLoop(const int count, http::CURLSession& ch) { - if (count == 0) +struct getLoop { + http::CURLSession ch; + getLoop(http::CURLSession& ch) : ch(ch) { + } + const bool operator()() const { + const failable r = get("http://localhost:8090", ch); + assert(hasContent(r)); + assert(contains(content(r), "It works")); return true; - const failable r = get("http://localhost:8090", ch); - assert(hasContent(r)); - assert(contains(content(r), "It works")); - return testGetLoop(count - 1, ch); -} + } +}; const bool testGetPerf() { - const int count = 50; http::CURLSession ch; - struct timeval start; - struct timeval end; - { - testGetLoop(5, ch); - gettimeofday(&start, NULL); - testGetLoop(count, ch); - gettimeofday(&end, NULL); - std::cout << "Static GET test " << duration(start, end, count) << " ms" << std::endl; - } + const lambda gl = getLoop(ch); + std::cout << "Static GET test " << time(gl, 5, 200) << " ms" << std::endl; return true; } @@ -97,48 +87,37 @@ const bool testEval() { return true; } -const bool testEvalLoop(const int count, http::CURLSession& ch) { - if (count == 0) +struct evalLoop { + http::CURLSession ch; + evalLoop(http::CURLSession& ch) : ch(ch) { + } + const bool operator()() const { + const value val = content(http::evalExpr(mklist(std::string("echo"), std::string("Hello")), "http://localhost:8090/test", ch)); + assert(val == std::string("Hello")); return true; - const value val = content(http::evalExpr(mklist(std::string("echo"), std::string("Hello")), "http://localhost:8090/test", ch)); - assert(val == std::string("Hello")); - return testEvalLoop(count - 1, ch); -} + } +}; const value blob(std::string(3000, 'A')); const list blobs = mklist(blob, blob, blob, blob, blob); -const bool testBlobEvalLoop(const int count, http::CURLSession& ch) { - if (count == 0) - return true; - const value val = content(http::evalExpr(mklist(std::string("echo"), blobs), "http://localhost:8090/test", ch)); - assert(val == blobs); - return testBlobEvalLoop(count - 1, ch); -} - -const bool testEvalPerf() { - const int count = 50; +struct blobEvalLoop { http::CURLSession ch; - struct timeval start; - struct timeval end; - { - testEvalLoop(5, ch); - gettimeofday(&start, NULL); - testEvalLoop(count, ch); - gettimeofday(&end, NULL); - std::cout << "JSON-RPC eval echo test " << duration(start, end, count) << " ms" << std::endl; + blobEvalLoop(http::CURLSession& ch) : ch(ch) { } - { - testBlobEvalLoop(5, ch); - gettimeofday(&start, NULL); - testBlobEvalLoop(count, ch); - gettimeofday(&end, NULL); - std::cout << "JSON-RPC eval blob test " << duration(start, end, count) << " ms" << std::endl; + const bool operator()() const { + const value val = content(http::evalExpr(mklist(std::string("echo"), blobs), "http://localhost:8090/test", ch)); + assert(val == blobs); + return true; } - return true; -} +}; -const bool testFeed() { +const bool testEvalPerf() { + http::CURLSession ch; + const lambda el = evalLoop(ch); + std::cout << "JSON-RPC eval echo test " << time(el, 5, 200) << " ms" << std::endl; + const lambda bel = blobEvalLoop(ch); + std::cout << "JSON-RPC eval blob test " << time(bel, 5, 200) << " ms" << std::endl; return true; } @@ -153,29 +132,27 @@ bool testPost() { return true; } -const bool testPostLoop(const int count, const value& val, http::CURLSession& ch) { - if (count == 0) +struct postLoop { + const value val; + http::CURLSession ch; + postLoop(const value& val, http::CURLSession& ch) : val(val), ch(ch) { + } + const bool operator()() const { + const failable id = http::post(val, "http://localhost:8090/test", ch); + assert(hasContent(id)); return true; - const failable id = http::post(val, "http://localhost:8090/test", ch); - assert(hasContent(id)); - return testPostLoop(count - 1, val, ch); -} + } +}; const bool testPostPerf() { - const int count = 50; http::CURLSession ch; - struct timeval start; - struct timeval end; { const list i = list() << (list() << "name" << std::string("Apple")) << (list() << "price" << std::string("$2.99")); const list val = mklist(std::string("item"), std::string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i); - testPostLoop(5, val, ch); - gettimeofday(&start, NULL); - testPostLoop(count, val, ch); - gettimeofday(&end, NULL); - std::cout << "ATOMPub POST small test " << duration(start, end, count) << " ms" << std::endl; + const lambda pl = postLoop(val, ch); + std::cout << "ATOMPub POST small test " << time(pl, 5, 200) << " ms" << std::endl; } { const list i = list() @@ -187,12 +164,59 @@ const bool testPostPerf() { << (list() << "blob5" << blob) << (list() << "price" << std::string("$2.99")); const list val = mklist(std::string("item"), std::string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i); - testPostLoop(5, val, ch); - gettimeofday(&start, NULL); - testPostLoop(count, val, ch); - gettimeofday(&end, NULL); - std::cout << "ATOMPub POST blob test " << duration(start, end, count) << " ms" << std::endl; + const lambda pl = postLoop(val, ch); + std::cout << "ATOMPub POST blob test " << time(pl, 5, 200) << " ms" << std::endl; + } + return true; +} + +const bool postThread(const int count, const value& val) { + http::CURLSession ch; + const lambda pl = postLoop(val, ch); + time(pl, 0, count); + return true; +} + +const list > startPost(worker& w, const int threads, const lambda& l) { + if (threads == 0) + return list >(); + return cons(submit(w, l), startPost(w, threads - 1, l)); +} + +const bool checkPost(const list >& r) { + if (isNil(r)) + return true; + assert(car(r) == true); + return checkPost(cdr(r)); +} + +struct postThreadLoop { + const lambda l; + const int threads; + const gc_ptr w; + postThreadLoop(const lambda& l, const int threads) : l(l), threads(threads), w(new worker(threads)) { + } + const bool operator()() const { + list > r = startPost(*w, threads, l); + checkPost(r); + return true; } +}; + +const bool testPostThreadPerf() { + const int count = 50; + const int threads = 10; + + const list i = list() + << (list() << "name" << std::string("Apple")) + << (list() << "price" << std::string("$2.99")); + const value val = mklist(std::string("item"), std::string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i); + + const lambda pl= curry(lambda(postThread), count, val); + const lambda ptl = postThreadLoop(pl, threads); + double t = time(ptl, 0, 1) / (threads * count); + std::cout << "ATOMPub POST thread test " << t << " ms" << std::endl; + return true; } @@ -221,26 +245,21 @@ const bool testEvalCpp() { return true; } -const bool testEvalCppLoop(const int count, http::CURLSession& ch) { - if (count == 0) +struct evalCppLoop { + http::CURLSession ch; + evalCppLoop(http::CURLSession& ch) : ch(ch) { + } + const bool operator()() const { + const value val = content(http::evalExpr(mklist(std::string("hello"), std::string("world")), "http://localhost:8090/cpp", ch)); + assert(val == std::string("hello world")); return true; - const value val = content(http::evalExpr(mklist(std::string("hello"), std::string("world")), "http://localhost:8090/cpp", ch)); - assert(val == std::string("hello world")); - return testEvalCppLoop(count - 1, ch); -} + } +}; const bool testEvalCppPerf() { - const int count = 50; http::CURLSession ch; - struct timeval start; - struct timeval end; - { - testEvalCppLoop(5, ch); - gettimeofday(&start, NULL); - testEvalCppLoop(count, ch); - gettimeofday(&end, NULL); - std::cout << "JSON-RPC C++ eval test " << duration(start, end, count) << " ms" << std::endl; - } + const lambda el = evalCppLoop(ch); + std::cout << "JSON-RPC C++ eval test " << time(el, 5, 200) << " ms" << std::endl; return true; } @@ -254,9 +273,9 @@ int main() { tuscany::server::testGetPerf(); tuscany::server::testPost(); tuscany::server::testPostPerf(); + tuscany::server::testPostThreadPerf(); tuscany::server::testEval(); tuscany::server::testEvalPerf(); - tuscany::server::testFeed(); tuscany::server::testPut(); tuscany::server::testDel(); tuscany::server::testEvalCpp(); diff --git a/sca-cpp/trunk/test/Makefile.am b/sca-cpp/trunk/test/Makefile.am index 4a20e27139..521bf3becf 100644 --- a/sca-cpp/trunk/test/Makefile.am +++ b/sca-cpp/trunk/test/Makefile.am @@ -15,5 +15,5 @@ # specific language governing permissions and limitations # under the License. -SUBDIRS = store-object store-function store-script +SUBDIRS = store-script diff --git a/sca-cpp/trunk/test/store-function/Makefile.am b/sca-cpp/trunk/test/store-function/Makefile.am deleted file mode 100644 index 7645db2273..0000000000 --- a/sca-cpp/trunk/test/store-function/Makefile.am +++ /dev/null @@ -1,28 +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. - -noinst_PROGRAMS = store-function-test - -noinst_HEADERS = *.hpp - -INCLUDES = -I. -I$(top_builddir)/kernel -I${LIBXML2_INCLUDE} -I${APR_INCLUDE} - -store_function_test_SOURCES = store-function-test.cpp -store_function_test_LDADD = -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1 - -TESTS = store-function-test - diff --git a/sca-cpp/trunk/test/store-function/cart.hpp b/sca-cpp/trunk/test/store-function/cart.hpp deleted file mode 100644 index 9ed6474985..0000000000 --- a/sca-cpp/trunk/test/store-function/cart.hpp +++ /dev/null @@ -1,69 +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$ */ - -#ifndef tuscany_cart_hpp -#define tuscany_cart_hpp - -#include -#include "service.hpp" -#include "item.hpp" - -namespace store -{ - -const double accumTotal(const double total, const ItemType& item) { - return total + itemPrice(item); -} - -tuscany::list cart; - -const tuscany::list shoppingCart_getAll() { - return cart; -} - -const bool shoppingCart_post(const ItemType& item) { - cart = cons(item, cart); - return true; -} - -const bool shoppingCart_deleteAll() { - cart = tuscany::list(); - return true; -} - -const double shoppingCart_getTotal() { - return tuscany::reduce(accumTotal, 0.0, cart); -} - -const tuscany::value shoppingCart_service(const tuscany::list& args) { - if (car(args) == "getAll") - return shoppingCart_getAll(); - if (car(args) == "post") - return shoppingCart_post(cadr(args)); - if (car(args) == "deleteAll") - return shoppingCart_deleteAll(); - if (car(args) == "getTotal") - return shoppingCart_getTotal(); - return tuscany::value(); -} - -} -#endif /* tuscany_cart_hpp */ diff --git a/sca-cpp/trunk/test/store-function/catalog.hpp b/sca-cpp/trunk/test/store-function/catalog.hpp deleted file mode 100644 index c49ebc8fa3..0000000000 --- a/sca-cpp/trunk/test/store-function/catalog.hpp +++ /dev/null @@ -1,54 +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$ */ - -#ifndef tuscany_catalog_hpp -#define tuscany_catalog_hpp - -#include -#include "service.hpp" -#include "currency.hpp" -#include "item.hpp" - -namespace store -{ - -std::string catalog_currencyCode = "USD"; - -double catalog_convert(const service& currencyConverter, const double price) { - return currencyConverter(tuscany::mklist("convert", "USD", catalog_currencyCode, price)); -} - -const tuscany::list catalog_get(const service& currencyConverter) { - const std::string currencySymbol = currencyConverter_service(tuscany::mklist("getSymbol", catalog_currencyCode)); - return tuscany::mklist( - item("Apple", catalog_currencyCode, currencySymbol, catalog_convert(currencyConverter, 2.99)), - item("Orange", catalog_currencyCode, currencySymbol, catalog_convert(currencyConverter, 3.55)), - item("Pear", catalog_currencyCode, currencySymbol, catalog_convert(currencyConverter, 1.55))); -} - -const tuscany::value catalog_service(const service& currencyConverter, const tuscany::list& args) { - if (car(args) == "get") - return catalog_get(currencyConverter); - return tuscany::value(); -} - -} -#endif /* tuscany_catalog_hpp */ diff --git a/sca-cpp/trunk/test/store-function/catalogs.composite b/sca-cpp/trunk/test/store-function/catalogs.composite deleted file mode 100644 index 1638ed0a05..0000000000 --- a/sca-cpp/trunk/test/store-function/catalogs.composite +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - USD - - - - - - - - - - - - - diff --git a/sca-cpp/trunk/test/store-function/currency-composite.hpp b/sca-cpp/trunk/test/store-function/currency-composite.hpp deleted file mode 100644 index ae28471538..0000000000 --- a/sca-cpp/trunk/test/store-function/currency-composite.hpp +++ /dev/null @@ -1,37 +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$ */ - -#ifndef tuscany_currencycomposite_hpp -#define tuscany_currencycomposite_hpp - -#include -#include "service.hpp" -#include "currency.hpp" - -namespace store -{ - -const tuscany::value currency_service(const tuscany::list& args) { - return currencyConverter_service(args); -} - -} -#endif /* tuscany_currencycomposite_hpp */ diff --git a/sca-cpp/trunk/test/store-function/currency.composite b/sca-cpp/trunk/test/store-function/currency.composite deleted file mode 100644 index aefd474f1f..0000000000 --- a/sca-cpp/trunk/test/store-function/currency.composite +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - diff --git a/sca-cpp/trunk/test/store-function/currency.hpp b/sca-cpp/trunk/test/store-function/currency.hpp deleted file mode 100644 index ca4376d2c7..0000000000 --- a/sca-cpp/trunk/test/store-function/currency.hpp +++ /dev/null @@ -1,59 +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$ */ - -#ifndef tuscany_currency_hpp -#define tuscany_currency_hpp - -#include -#include -#include "debug.hpp" -#include "service.hpp" -#include "item.hpp" - -namespace store -{ - -const double currencyConverter_convert(unused const std::string& fromCurrencyCode, const std::string& toCurrencyCode, const double amount) { - if(toCurrencyCode == "USD") - return amount; - if(toCurrencyCode == "EUR") - return round(amount * 0.7256 * 100) / 100; - return amount; -} - -const std::string currencyConverter_getSymbol(const std::string& currencyCode) { - if(currencyCode == "USD") - return "$"; - if(currencyCode == "EUR") - return "E"; - return "?"; -} - -const tuscany::value currencyConverter_service(const tuscany::list& args) { - if (car(args) == "convert") - return currencyConverter_convert(cadr(args), car(cdr(cdr(args))), car(cdr(cdr(cdr(args))))); - if (car(args) == "getSymbol") - return currencyConverter_getSymbol(cadr(args)); - return tuscany::value(); -} - -} -#endif /* tuscany_currency_hpp */ diff --git a/sca-cpp/trunk/test/store-function/item.hpp b/sca-cpp/trunk/test/store-function/item.hpp deleted file mode 100644 index fbe29915dc..0000000000 --- a/sca-cpp/trunk/test/store-function/item.hpp +++ /dev/null @@ -1,54 +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$ */ - -#ifndef tuscany_item_hpp -#define tuscany_item_hpp - -#include -#include "service.hpp" - -namespace store -{ - -typedef tuscany::value ItemType; - -const ItemType item(const std::string& name, const std::string& currencyCode, const std::string& currencySymbol, const double price) { - return tuscany::mklist(name, currencyCode, currencySymbol, price); -} - -const std::string itemName(const ItemType& item) { - return car((tuscany::list)item); -} - -const std::string itemCurrencyCode(const ItemType& item) { - return car(cdr((tuscany::list)item)); -} - -const std::string itemCurrencySymbol(const ItemType& item) { - return car(cdr(cdr((tuscany::list)item))); -} - -const double itemPrice(const ItemType& item) { - return car(cdr(cdr(cdr((tuscany::list)item)))); -} - -} -#endif /* tuscany_item_hpp */ diff --git a/sca-cpp/trunk/test/store-function/service.hpp b/sca-cpp/trunk/test/store-function/service.hpp deleted file mode 100644 index b764e87d1a..0000000000 --- a/sca-cpp/trunk/test/store-function/service.hpp +++ /dev/null @@ -1,35 +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$ */ - -#ifndef tuscany_service_hpp -#define tuscany_service_hpp - -#include "function.hpp" -#include "list.hpp" -#include "value.hpp" - -namespace store -{ - -typedef tuscany::lambda)> service; - -} -#endif /* tuscany_service_hpp */ diff --git a/sca-cpp/trunk/test/store-function/store-composite.hpp b/sca-cpp/trunk/test/store-function/store-composite.hpp deleted file mode 100644 index 351c905eae..0000000000 --- a/sca-cpp/trunk/test/store-function/store-composite.hpp +++ /dev/null @@ -1,47 +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$ */ - -#ifndef tuscany_storecomposite_hpp -#define tuscany_storecomposite_hpp - -#include -#include "service.hpp" -#include "currency.hpp" -#include "currency-composite.hpp" -#include "item.hpp" -#include "catalog.hpp" -#include "cart.hpp" -#include "store-ui.hpp" - -namespace store -{ - -const tuscany::value store_service(const service& currency, const tuscany::list& args) { - const tuscany::lambda)> catalogService(catalog_service); - const service catalog(curry(catalogService, currency)); - const service cart(shoppingCart_service); - const tuscany::lambda)> storeUIService(storeUI_service); - const service configuredStoreUIService(curry(storeUIService, catalog, cart)); - return configuredStoreUIService(args); -} - -} -#endif /* tuscany_storecomposite_hpp */ diff --git a/sca-cpp/trunk/test/store-function/store-function-test.cpp b/sca-cpp/trunk/test/store-function/store-function-test.cpp deleted file mode 100644 index 8a6a86eb8a..0000000000 --- a/sca-cpp/trunk/test/store-function/store-function-test.cpp +++ /dev/null @@ -1,50 +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$ */ - -/** - * Store Test case. - */ - -#include -#include -#include -#include "store-solution.hpp" - -namespace store -{ - -bool testComponentAssembly() { - const service store(storeSolution_service); - assert(length((tuscany::list)store(tuscany::mklist("getCatalog"))) == 3); - return true; -} - -} - -int main() { - - std::cout << "Testing..." << std::endl; - - store::testComponentAssembly(); - std::cout << "OK" << std::endl; - - return 0; -} diff --git a/sca-cpp/trunk/test/store-function/store-solution.hpp b/sca-cpp/trunk/test/store-function/store-solution.hpp deleted file mode 100644 index e0addcba12..0000000000 --- a/sca-cpp/trunk/test/store-function/store-solution.hpp +++ /dev/null @@ -1,41 +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$ */ - -#ifndef tuscany_storesolution_hpp -#define tuscany_storesolution_hpp - -#include -#include "service.hpp" -#include "store-composite.hpp" -#include "currency-composite.hpp" - -namespace store -{ - -const tuscany::value storeSolution_service(const tuscany::list& args) { - const service currency(currency_service); - const tuscany::lambda)> storeService(store_service); - const service configuredStoreService(curry(storeService, currency)); - return configuredStoreService(args); -} - -} -#endif /* tuscany_storesolution_hpp */ diff --git a/sca-cpp/trunk/test/store-function/store-ui.hpp b/sca-cpp/trunk/test/store-function/store-ui.hpp deleted file mode 100644 index 12b28d6a92..0000000000 --- a/sca-cpp/trunk/test/store-function/store-ui.hpp +++ /dev/null @@ -1,64 +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$ */ - -#ifndef tuscany_storeui_hpp -#define tuscany_storeui_hpp - -#include -#include "service.hpp" -#include "currency.hpp" -#include "item.hpp" -#include "catalog.hpp" -#include "cart.hpp" - -namespace store -{ - -const tuscany::list storeUI_getCatalog(const service& catalog) { - return catalog(tuscany::mklist("get")); -} - -const tuscany::list storeUI_getCart(const service& cart) { - return cart(tuscany::mklist("getAll")); -} - -const double storeUI_getTotal(const service& cart) { - return cart(tuscany::mklist("getTotal")); -} - -const bool storeUI_post(const service& cart, const ItemType& item) { - return cart(tuscany::mklist("post", item)); -} - -const tuscany::value storeUI_service(const service& catalog, const service& cart, const tuscany::list& args) { - if (car(args) == "getCatalog") - return storeUI_getCatalog(catalog); - if (car(args) == "getCart") - return storeUI_getCart(cart); - if (car(args) == "getTotal") - return storeUI_getTotal(cart); - if (car(args) == "post") - return storeUI_post(cart, cadr(args)); - return tuscany::value(); -} - -} -#endif /* STOREUI_HPP_ */ diff --git a/sca-cpp/trunk/test/store-function/store.composite b/sca-cpp/trunk/test/store-function/store.composite deleted file mode 100644 index 124adff853..0000000000 --- a/sca-cpp/trunk/test/store-function/store.composite +++ /dev/null @@ -1,64 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - USD - - - - - - - - - - - - - - - - - - - - - diff --git a/sca-cpp/trunk/test/store-object/Makefile.am b/sca-cpp/trunk/test/store-object/Makefile.am deleted file mode 100644 index 83b8bc7d4e..0000000000 --- a/sca-cpp/trunk/test/store-object/Makefile.am +++ /dev/null @@ -1,28 +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. - -noinst_PROGRAMS = store-object-test - -noinst_HEADERS = *.hpp - -INCLUDES = -I. -I$(top_builddir)/kernel -I${LIBXML2_INCLUDE} -I${APR_INCLUDE} - -store_object_test_SOURCES = store-object-test.cpp -store_object_test_LDADD = -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1 - -TESTS = store-object-test - diff --git a/sca-cpp/trunk/test/store-object/cart.hpp b/sca-cpp/trunk/test/store-object/cart.hpp deleted file mode 100644 index f35a5c4527..0000000000 --- a/sca-cpp/trunk/test/store-object/cart.hpp +++ /dev/null @@ -1,74 +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$ */ - -#ifndef store_cart_hpp -#define store_cart_hpp - -#include -#include "function.hpp" -#include "list.hpp" -#include "currency.hpp" -#include "item.hpp" -#include "catalog.hpp" - -namespace store -{ - -const double accum(const double total, const Item& item) { - return total + item.price; -} - -class ShoppingCart { -public: - virtual const tuscany::list getAll() const = 0; - - virtual const bool post(const Item& item) = 0; - - virtual const bool deleteAll() = 0; - - virtual const double getTotal() const = 0; -}; - -class ShoppingCartImpl : public ShoppingCart { -public: - tuscany::list cart; - - virtual const tuscany::list getAll() const { - return cart; - } - - virtual const bool post(const Item& item) { - cart = cons(item, cart); - return true; - } - - virtual const bool deleteAll() { - cart = tuscany::list(); - return true; - } - - virtual const double getTotal() const { - return tuscany::reduce(accum, 0.0, cart); - } -}; - -} -#endif /* store_cart_hpp */ diff --git a/sca-cpp/trunk/test/store-object/catalog.hpp b/sca-cpp/trunk/test/store-object/catalog.hpp deleted file mode 100644 index fab013cf8e..0000000000 --- a/sca-cpp/trunk/test/store-object/catalog.hpp +++ /dev/null @@ -1,65 +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$ */ - -#ifndef store_catalog_hpp -#define store_catalog_hpp - -#include -#include "list.hpp" -#include "currency.hpp" -#include "item.hpp" - -namespace store -{ - -class Catalog { -public: - - virtual const double convert(const double price) const = 0; - - virtual const tuscany::list get() const = 0; -}; - -class CatalogImpl : public Catalog { -public: - - const std::string currencyCode; - const CurrencyConverter& currencyConverter; - - CatalogImpl(const CurrencyConverter& currencyConverter) : - currencyCode("USD"), currencyConverter(currencyConverter) { - } - - virtual const double convert(const double price) const { - return currencyConverter.convert("USD", currencyCode, price); - } - - virtual const tuscany::list get() const { - const std::string currencySymbol = currencyConverter.getSymbol(currencyCode); - return tuscany::mklist( - Item("Apple", currencyCode, currencySymbol, convert(2.99)), - Item("Orange", currencyCode, currencySymbol, convert(3.55)), - Item("Pear", currencyCode, currencySymbol, convert(1.55))); - } -}; - -} -#endif /* store_catalog_hpp */ diff --git a/sca-cpp/trunk/test/store-object/catalogs.composite b/sca-cpp/trunk/test/store-object/catalogs.composite deleted file mode 100644 index 1638ed0a05..0000000000 --- a/sca-cpp/trunk/test/store-object/catalogs.composite +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - USD - - - - - - - - - - - - - diff --git a/sca-cpp/trunk/test/store-object/currency-composite.hpp b/sca-cpp/trunk/test/store-object/currency-composite.hpp deleted file mode 100644 index 94b52b461e..0000000000 --- a/sca-cpp/trunk/test/store-object/currency-composite.hpp +++ /dev/null @@ -1,51 +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$ */ - -#ifndef store_currencycomposite_hpp -#define store_currencycomposite_hpp - -#include -#include "currency.hpp" - -namespace store -{ - -class Currency : public CurrencyConverter { -}; - -class CurrencyImpl : public Currency { -public: - const CurrencyConverterImpl currencyConverter; - - CurrencyImpl() : currencyConverter(CurrencyConverterImpl()) { - } - - virtual const double convert(const std::string& fromCurrencyCode, const std::string& toCurrencyCode, const double amount) const { - return currencyConverter.convert(fromCurrencyCode, toCurrencyCode, amount); - } - - virtual const std::string getSymbol(const std::string& currencyCode) const { - return currencyConverter.getSymbol(currencyCode); - } -}; - -} -#endif /* store_currencycomposite_hpp */ diff --git a/sca-cpp/trunk/test/store-object/currency.composite b/sca-cpp/trunk/test/store-object/currency.composite deleted file mode 100644 index aefd474f1f..0000000000 --- a/sca-cpp/trunk/test/store-object/currency.composite +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - diff --git a/sca-cpp/trunk/test/store-object/currency.hpp b/sca-cpp/trunk/test/store-object/currency.hpp deleted file mode 100644 index 921c0efb3b..0000000000 --- a/sca-cpp/trunk/test/store-object/currency.hpp +++ /dev/null @@ -1,60 +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$ */ - -#ifndef store_currency_hpp -#define store_currency_hpp - -#include -#include -#include "debug.hpp" - -namespace store -{ - -class CurrencyConverter { -public: - - virtual const double convert(const std::string& fromCurrencyCode, const std::string& toCurrencyCode, const double amount) const = 0; - virtual const std::string getSymbol(const std::string& currencyCode) const = 0; -}; - -class CurrencyConverterImpl : public CurrencyConverter { -public: - - virtual const double convert(unused const std::string& fromCurrencyCode, const std::string& toCurrencyCode, const double amount) const { - if(toCurrencyCode == "USD") - return amount; - if(toCurrencyCode == "EUR") - return round(amount * 0.7256 * 100) / 100; - return amount; - } - - virtual const std::string getSymbol(const std::string& currencyCode) const { - if(currencyCode == "USD") - return "$"; - if(currencyCode == "EUR") - return "E"; - return "?"; - } -}; - -} -#endif /* store_currency_hpp */ diff --git a/sca-cpp/trunk/test/store-object/item.hpp b/sca-cpp/trunk/test/store-object/item.hpp deleted file mode 100644 index ab8e52769b..0000000000 --- a/sca-cpp/trunk/test/store-object/item.hpp +++ /dev/null @@ -1,47 +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$ */ - -#ifndef store_item_hpp -#define store_item_hpp - -#include - -namespace store -{ - -class Item { -public: - std::string name; - double price; - std::string currencyCode; - std::string currencySymbol; - - Item() { - } - - Item(const std::string& name, const std::string& currencyCode, const std::string& currencySymbol, const double price) : - name(name), price(price), currencyCode(currencyCode), currencySymbol(currencySymbol) { - } - -}; - -} -#endif /* store_item_hpp */ diff --git a/sca-cpp/trunk/test/store-object/store-composite.hpp b/sca-cpp/trunk/test/store-object/store-composite.hpp deleted file mode 100644 index 8cee5a943f..0000000000 --- a/sca-cpp/trunk/test/store-object/store-composite.hpp +++ /dev/null @@ -1,68 +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$ */ - -#ifndef store_storecomposite_hpp -#define store_storecomposite_hpp - -#include "list.hpp" -#include "currency.hpp" -#include "currency-composite.hpp" -#include "item.hpp" -#include "catalog.hpp" -#include "cart.hpp" -#include "store-ui.hpp" - -namespace store -{ - -class Store : public StoreUI { -}; - -class StoreImpl : public Store { -public: - const CatalogImpl catalog; - ShoppingCartImpl cart; - StoreUIImpl storeUI; - - StoreImpl(const Currency& currency) : - catalog(CatalogImpl(currency)), cart(ShoppingCartImpl()), storeUI(StoreUIImpl(catalog, cart)) { - } - - virtual const tuscany::list getCatalog() const { - return storeUI.getCatalog(); - } - - virtual const tuscany::list getCart() const { - return storeUI.getCart(); - } - - virtual const double getTotal() const { - return storeUI.getTotal(); - } - - virtual const bool post(const Item& item) { - return storeUI.post(item); - } - -}; - -} -#endif /* store_storecomposite_hpp */ diff --git a/sca-cpp/trunk/test/store-object/store-object-test.cpp b/sca-cpp/trunk/test/store-object/store-object-test.cpp deleted file mode 100644 index bfbf5459ac..0000000000 --- a/sca-cpp/trunk/test/store-object/store-object-test.cpp +++ /dev/null @@ -1,52 +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$ */ - -/** - * Store Test case. - */ - -#include -#include -#include "store-solution.hpp" - -namespace store -{ - -bool testComponentAssembly() { - StoreSolutionImpl store = StoreSolutionImpl(); - assert(length(store.getCatalog()) == 3); - assert(store.post(car(store.getCatalog())) == true); - assert(store.post(cadr(store.getCatalog())) == true); - assert(length(store.getCart()) == 2); - assert(store.getTotal() == 6.54); - return true; -} - -} - -int main() { - std::cout << "Testing..." << std::endl; - - store::testComponentAssembly(); - std::cout << "OK" << std::endl; - - return 0; -} diff --git a/sca-cpp/trunk/test/store-object/store-solution.hpp b/sca-cpp/trunk/test/store-object/store-solution.hpp deleted file mode 100644 index ecabb18f1c..0000000000 --- a/sca-cpp/trunk/test/store-object/store-solution.hpp +++ /dev/null @@ -1,62 +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$ */ - -#ifndef store_storesolution_hpp -#define store_storesolution_hpp - -#include "list.hpp" -#include "store-composite.hpp" -#include "currency-composite.hpp" - -namespace store -{ - -class StoreSolution : public Store { -}; - -class StoreSolutionImpl : public StoreSolution { -public: - const CurrencyImpl currency; - StoreImpl store; - - StoreSolutionImpl() : - currency(CurrencyImpl()), store(StoreImpl(currency)) { - } - - virtual const tuscany::list getCatalog() const { - return store.getCatalog(); - } - - virtual const tuscany::list getCart() const { - return store.getCart(); - } - - virtual const double getTotal() const { - return store.getTotal(); - } - - virtual const bool post(const Item& item) { - return store.post(item); - } -}; - -} -#endif /* store_storesolution_hpp */ diff --git a/sca-cpp/trunk/test/store-object/store-ui.hpp b/sca-cpp/trunk/test/store-object/store-ui.hpp deleted file mode 100644 index c9d0f4330b..0000000000 --- a/sca-cpp/trunk/test/store-object/store-ui.hpp +++ /dev/null @@ -1,72 +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$ */ - -#ifndef store_storeui_hpp -#define store_storeui_hpp - -#include "list.hpp" -#include "currency.hpp" -#include "item.hpp" -#include "catalog.hpp" -#include "cart.hpp" - -namespace store -{ - -class StoreUI { -public: - - virtual const tuscany::list getCatalog() const =0; - - virtual const tuscany::list getCart() const = 0; - - virtual const double getTotal() const =0; - - virtual const bool post(const Item& item) = 0; -}; - -class StoreUIImpl : public StoreUI { -public: - const Catalog& catalog; - ShoppingCart& cart; - - StoreUIImpl(const Catalog& catalog, ShoppingCart& cart) : catalog(catalog), cart(cart) { - } - - virtual const tuscany::list getCatalog() const { - return catalog.get(); - } - - virtual const tuscany::list getCart() const { - return cart.getAll(); - } - - virtual const double getTotal() const { - return cart.getTotal(); - } - - virtual const bool post(const Item& item) { - return cart.post(item); - } -}; - -} -#endif /* store_storeui_hpp */ diff --git a/sca-cpp/trunk/test/store-object/store.composite b/sca-cpp/trunk/test/store-object/store.composite deleted file mode 100644 index 124adff853..0000000000 --- a/sca-cpp/trunk/test/store-object/store.composite +++ /dev/null @@ -1,64 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - USD - - - - - - - - - - - - - - - - - - - - - -- cgit v1.2.3