FYI erroneous log messages
William Henry <whenry@...>
Hi, Got some time today to look through the avis bridge code to try and understand the flow more. Not a biggie: I found that avisBridgeMamaTransport_destroy() logs two avisBridgeMamaTransport_create traces. William |
|
Re: General MAMA feature / project questions
Mike Schonberg <mschonberg@...>
On Wed, 9 May 2012, Noah Zucker wrote:
Greetings all. I'm getting started with OpenMAMA here at NYSE and had themama_open() by default attempts to load properties from $WOMBAT_PATH/mama.properties. mama_openWithProperties(path, filename) initializes OpenMAMA reading the properties from path/filename rather than $WOMBAT_PATH/mama.properties. mama_getProperty(const char* name) returns the property value given the property name. mama_setProperty(...) alows applications to set/modify properties prgramatically. mama_setPropertiesFromFile(path, filename) loads additional properties from the specfied file. common/c_cpp/src/c/property.h defines the low level interface for manipulating property files. It uses the flex grammar defined in common/.../c/properties.l to parse properties files. Bridges should use mama_getProperty() to access properties. Bridges should prefix all properties with "mama.<bridge_name>". The canonical form is "mama.<bridge_name>.<category>.[<name>].property". The optional name allows for multiple "named" configurations. For example, mama.some_middleware.transport.my_transport.broker_address=127.0.0.1 defines the broker address for a transported named "my_transport" on some_middleware. 1c) Do I have to parse the strings myself, or can I provide just theThe properties parser only knows how to parse the file into name value pairs so bridges need to interpret the resulting value strings. There are a few helper functions like strtobool() in common/.../c/wombat/strutils.h; however it might be nice to start building a well defined library of property parsers/validators standard types (IP addresses, integers, comma delimited lists, etc.). 1d) How / where do I define the configuration parameters that are settable inI suggest that you create properties.h file for your bridge with macros for all your properties and a properties.c file with functions to read and interpret them. Currently the Avis message payload is the only open source payload. Since payloads are not dependent on middleware, it should be possible to use the Avis payload with other middleware bridges. We are currently investigating other potential FOSS payload implementations. One interesting possibility is Google Protocol Buffers. MAMA currently contains default implementations for queues and timers. I would like to see a default implemenatation for IO Events as well. Since most applications do not use IO Events, implementing them is optional. "make clean" should get rid of most of them. I also find "git clean -d -f" useful (WARNING: THIS WILL DELETE ALL UNTRACKED FILES SO MAKE SURE THAT YOU HAVE STASHED, OR ADDED ALL NEW SOURCE FILES FIRST). We should also get out of tree builds working as this minimizing the noise in the source directory. Configure.ac takes care of this. In general you run "configure --with-<middlware_name>" to indicate which bridge(s) you want to build. In the future, I would like to add an option that builds all middlewares for which configure can locate valid libraries. You can configure with --without-middleware-bridge and no bridge will be built. Likewise you can specify --without-payload-bridge to build without a payload bridge. Regards, -Mike Please consider the environment before printing this email. Visit our website at http://www.nyse.com **************************************************** Note: The information contained in this message and any attachment to it is privileged, confidential and protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify the sender immediately by replying to the message, and please delete it from your system. Thank you. NYSE Euronext. |
|
General MAMA feature / project questions
Noah Zucker <NZucker@...>
Greetings all. I'm getting started with OpenMAMA here at NYSE and had the below questions. Mike suggested that I send them to this list for the benefit of anyone else who had similar questions:
1) mama.properties 1a) What component / function provides the parsed values from mama.properties? 1b) How does my bridge access configuration in mama.properties? 1c) Do I have to parse the strings myself, or can I provide just the components I need such as the final token that identifies the actual setting I need? 1d) How / where do I define the configuration parameters that are settable in mama.properties? 2) Message Format / Encoding 2a) Does OpenMAMA come with an out-of-the-box encoding for message payload, or is this supposed to be provided by the bridge? 2b) If it comes with payload encoding(s), what are the format(s)? 3) MAMA engine 3a) Does OpenMAMA come with the messaging engine that manages the event loop, queues, queue monitoring, quality of service detection, etc. or does that all (or some of it) have to be provided by the bridge implementation? 4) Build 4a) How do I clean the build? I noticed that there are object files all over the place next to my source files. How do I get rid of these? (Perhaps this is a n00bish question since I'm new to automake). 4b) Have we considered separating bridges from the OpenMAMA project? Related: how do we configure OpenMAMA to build with multiple bridges, or one bridge but not another? Regards, Noah Zucker NYSE Technologies Please consider the environment before printing this email. Visit our website at http://www.nyse.com **************************************************** Note: The information contained in this message and any attachment to it is privileged, confidential and protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify the sender immediately by replying to the message, and please delete it from your system. Thank you. NYSE Euronext. |
|
Re: Why are bridges in the general build
Pavel Patarinski
I can build all of the projects under OpenMAMA 2.1 solution (Windows
7, VS 2010).
toggle quoted message
Show quoted text
Requirements:  1. flex - http://gnuwin32.sourceforge.net/packages/flex.htm  2. avis-client - http://avis.sourceforge.net/downloads.html Environment variables:  1. add AVIS_HOME variable with path to avis-client as value.  2. append path to flex executable to system "Path" variable Fix paths in solution:  1. for all of the projects which depends on avis-client lib, remove Debug after AVIS_HOME. Regards Pavel On 5.05.2012 21:05, Leslie Spiro wrote:
|
|
Why are bridges in the general build
Leslie Spiro <lspiro@...>
Reading the difficulties that William is having getting the Avis bridge to build, wouldn't it make sense to split the build into open mama core (possibly including a null bridge as an example for bridge and payload writers), and then have separate bridge builds ? Also as the number of bridges increase we don't want to keep changing the build as each new bridge is released. Les Spiro Tick42 |
|
Re: Why are bridges in the general build
Michael Schonberg
On Sat, May 5, 2012 at 11:05 AM, Leslie Spiro <lspiro@...> wrote:
Les, You can configure with --without-middleware-bridge and no bridge will be built. Likewise you can specify --without-payload-bridge to build without a payload bridge. I definitely like the idea of a NULL bridge for testing and as a documented template for writing new bridges. I am not sure that separate bridge builds make sense. When I download source, I expect to run configure, make, make install and build something useful. I prefer to make the configure scripts smart enough to build build painlessly. One option is for the default behavior to automatically build bridges if all the required packages (middleware, tools, etc.) are found in the default locations. Updating configure.ac can be painful, but you usually only have to do it once. Currently, I think we need to make the avis configuration more sophisticated. Regards, -Mike Also as the number of bridges increase we don't want to keep changing the |
|
Re: Fedora build issues
Mike Schonberg <mschonberg@...>
toggle quoted message
Show quoted text
-----Original Message-----This file needs to be copied over manually. I believe the README file documents this. We usually download the Avis archives rather than pulling from SVN. It is possible that the SVN version is different. -Mike Please consider the environment before printing this email. Visit our website at http://www.nyse.com **************************************************** Note: The information contained in this message and any attachment to it is privileged, confidential and protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify the sender immediately by replying to the message, and please delete it from your system. Thank you. NYSE Euronext. |
|
Re: Fedora build issues
William Henry <whenry@...>
Okay so here's what's wrong now and what I did to get to wrong and what I'm doing to fix it.
toggle quoted message
Show quoted text
The ./configure flags the avis_client_config.h file. So after svn co the avis source. I copied this file (well one of them - there are four but no "linux") to /usr/local/include/avis. That got me by the ./configure However it seems that more .h files are needed in this directory for the build. So I'll copy them over one by one. Later: actually I just copied the entire directory over. Now I'm getting: bridge.c: In function 'avisBridge_getVersion': bridge.c:65:30: error: 'VERSION' undeclared (first use in this function) bridge.c:65:30: note: each undeclared identifier is reported only once for each function it appears in bridge.c:66:1: warning: control reaches end of non-void function [-Wreturn-type] make[5]: *** [bridge.lo] Error 1 make[5]: Leaving directory `/home/whenry/os/openmamam/OpenMAMA-1.1/mama/c_cpp/src/c/bridge/avis' make[4]: *** [install-recursive] Error 1 make[4]: Leaving directory `/home/whenry/os/openmamam/OpenMAMA-1.1/mama/c_cpp/src/c/bridge' make[3]: *** [install-recursive] Error 1 make[3]: Leaving directory `/home/whenry/os/openmamam/OpenMAMA-1.1/mama/c_cpp/src/c' make[2]: *** [install-recursive] Error 1 make[2]: Leaving directory `/home/whenry/os/openmamam/OpenMAMA-1.1/mama/c_cpp/src' make[1]: *** [install-recursive] Error 1 make[1]: Leaving directory `/home/whenry/os/openmamam/OpenMAMA-1.1/mama/c_cpp' I wonder if I have the correct .h file versions. William ----- Original Message -----
Got the build at least going now with the avis stuff installed. |
|
Re: Fedora build issues
William Henry <whenry@...>
Got the build at least going now with the avis stuff installed.
toggle quoted message
Show quoted text
But I'm hitting: bridge.c:22:24: fatal error: avis/elvin.h: No such file or directory compilation terminated. make[5]: *** [bridge.lo] Error 1 make[5]: Leaving directory `/home/whenry/os/openmamam/OpenMAMA-1.1/mama/c_cpp/src/c/bridge/avis' make[4]: *** [install-recursive] Error 1 make[4]: Leaving directory `/home/whenry/os/openmamam/OpenMAMA-1.1/mama/c_cpp/src/c/bridge' make[3]: *** [install-recursive] Error 1 make[3]: Leaving directory `/home/whenry/os/openmamam/OpenMAMA-1.1/mama/c_cpp/src/c' make[2]: *** [install-recursive] Error 1 make[2]: Leaving directory `/home/whenry/os/openmamam/OpenMAMA-1.1/mama/c_cpp/src' make[1]: *** [install-recursive] Error 1 make[1]: Leaving directory `/home/whenry/os/openmamam/OpenMAMA-1.1/mama/c_cpp' William ----- Original Message -----
I've attached the output from ./configure |
|
Re: Fedora build issues
William Henry <whenry@...>
I've attached the output from ./configure
toggle quoted message
Show quoted text
I wonder if now my only issue is having avis installed. William. ----- Original Message -----
-----Original Message-----I also see this error. It occurs because we search librt but not |
|
Re: OpenMAMA 2.1 - configure: WARNING: unrecognized options: --with-avis
Mike Schonberg <mschonberg@...>
Mark,  The current top level configure script is fairly simplistic and passes all of the configure arguments to all the lower level configure scripts. If the option is not supported by the lower level configure, it emits a warning. These are, as you mention, harmless. At some point we should make the higher level script more sophisticated. It might make sense to even use autoconf rather than a simple shell script.  At the moment this is fairly low priority, but we should get to it when we have time.  Regards, -Mike  From:
openmama-dev-bounces@...
[mailto:openmama-dev-bounces@...] On Behalf Of Mark
Spielman  I’ve cloned the OpenMAMA 2.1 release git repository. When I try to configure the environment with --wIth-avis, the output from the configure script has a bunch of warnings of the following:  configure: WARNING: unrecognized options: --with-avis  After debugging, these seem to be benign. Can the build environment be enhanced to remove these warnings?  Cheers, Mark   Mark Spielman Development Lead, Solace Systems Professional Services   Please consider the environment before printing this email. Visit our website at http://www.nyse.com |
|
[PATCH] [mamda] Add patch for -lmama for news and orderbook examples
Michael Schonberg <mschonberg@...>
From: Mike Schonberg <mschonberg@...>
The news and orderbook examples were not building because the linker could not find libmama. This patch adjusts the link flags to include the path to the mama c libraries. Signed-off-by: Mike Schonberg <mschonberg@...> --- mamda/c_cpp/src/examples/news/Makefile.am | 1 + mamda/c_cpp/src/examples/orderbooks/Makefile.am | 1 + 2 files changed, 2 insertions(+), 0 deletions(-) diff --git a/mamda/c_cpp/src/examples/news/Makefile.am b/mamda/c_cpp/src/examples/news/Makefile.am index 5cf0964..751cedf 100644 --- a/mamda/c_cpp/src/examples/news/Makefile.am +++ b/mamda/c_cpp/src/examples/news/Makefile.am @@ -33,6 +33,7 @@ CPPFLAGS +=-I$(srcdir)/../../cpp \ LDFLAGS += -L${srcdir}/../../cpp \ -L$(srcdir)/../../cpp/news \ + -L$(srcdir)/../../../../../mama/c_cpp/src/c \ -L$(srcdir)/../../../../../mama/c_cpp/src/cpp LIBS += -lmamdanews -lmamda -lmamacpp -lmama -lpthread -lnsl -ldl -lm diff --git a/mamda/c_cpp/src/examples/orderbooks/Makefile.am b/mamda/c_cpp/src/examples/orderbooks/Makefile.am index 92568b1..36685d6 100644 --- a/mamda/c_cpp/src/examples/orderbooks/Makefile.am +++ b/mamda/c_cpp/src/examples/orderbooks/Makefile.am @@ -35,6 +35,7 @@ CPPFLAGS += -I$(srcdir)/../../cpp \ LDFLAGS += -L${srcdir}/../../cpp \ -L$(srcdir)/../../cpp/orderbooks \ + -L$(srcdir)/../../../../../mama/c_cpp/src/c \ -L$(srcdir)/../../../../../mama/c_cpp/src/cpp if USE_GCC_FLAGS -- 1.7.7.6 |
|
[PATCH] [mama] Add libpthread to library list for sem_timedwait
Michael Schonberg <mschonberg@...>
From: Mike Schonberg <mschonberg@...>
configure.ac needs to search for sem_timedwait in both librt and libpthread. On OS's like certain Solaris versions that do not support sem_timedwait(), OpenMAMA provides an implentation. Signed-off-by: Mike Schonberg <mschonberg@...> --- mama/c_cpp/configure.ac | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/mama/c_cpp/configure.ac b/mama/c_cpp/configure.ac index e70e918..0ff4380 100644 --- a/mama/c_cpp/configure.ac +++ b/mama/c_cpp/configure.ac @@ -106,7 +106,7 @@ AC_CHECK_LIB(socket,socket) AC_CHECK_LIB(nsl,gethostbyname) # SOLARIS 8 does not have sem_timedwait -AC_SEARCH_LIBS(sem_timedwait, rt, +AC_SEARCH_LIBS(sem_timedwait, rt pthread, [ echo "Found sem_timedwait()." ], -- 1.7.7.6 |
|
Re: Fedora build issues
Mike Schonberg <mschonberg@...>
toggle quoted message
Show quoted text
-----Original Message-----I also see this error. It occurs because we search librt but not libpthread. I will post a patch shortly. The following results in a clean build for me with the current code: git clean -d -f ./generateBuildFiles.sh export JAVA_HOME=/home/mike/JDK-6/jdk1.6.0_30/ ./configure --with-avis=/usr/local --prefix=`pwd`/dist make install Could you post the output from your configure script? Thanks, -Mike Please consider the environment before printing this email. Visit our website at http://www.nyse.com **************************************************** Note: The information contained in this message and any attachment to it is privileged, confidential and protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify the sender immediately by replying to the message, and please delete it from your system. Thank you. NYSE Euronext. |
|
Re: Bridge devel process
Mike Schonberg <mschonberg@...>
toggle quoted message
Show quoted text
-----Original Message-----The current bridge documentation, which we will post soon, does not include a "dummies guide". We want to add a "getting started" guide before sending it out for review. In the mean time, we will post a summary of first steps for writing a bridge to help you get started. I also think it makes sense to write a well documented NULL template bridge to facilitate testing and bridge development. Regards, -Mike Please consider the environment before printing this email. Visit our website at http://www.nyse.com **************************************************** Note: The information contained in this message and any attachment to it is privileged, confidential and protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify the sender immediately by replying to the message, and please delete it from your system. Thank you. NYSE Euronext. |
|
Fedora build issues
William Henry <whenry@...>
Hi,
I see configure fail because it can't find sem_timedwait(): checking for library containing sem_timedwait... no Failed to find sem_timedwait(). This appears to be the cause of no makefile being build in mama/c_cpp and so that never builds. William |
|
OpenMAMA 2.1 - configure: WARNING: unrecognized options: --with-avis
Mark Spielman
I’ve cloned the OpenMAMA 2.1 release git repository. When I try to configure the environment with --wIth-avis, the output from the configure script has a bunch of warnings of the following:  configure: WARNING: unrecognized options: --with-avis  After debugging, these seem to be benign. Can the build environment be enhanced to remove these warnings?  Cheers, Mark   Mark Spielman Development Lead, Solace Systems Professional Services   |
|
Bridge devel process
William Henry <whenry@...>
Mike or someone,
Would you mind posting a link to the "dummies guide" to OpenMAMA bridge development? Best William |
|
[PATCH 50/50] [unittest] Adding C Unit Tests
Michael Schonberg <mschonberg@...>
From: Mike Schonberg <mschonberg@...>
Signed-off-by: Mike Schonberg <mschonberg@...> --- mama/c_cpp/src/gunittest/c/Makefile.am | 10 +- mama/c_cpp/src/gunittest/c/datetimetest.cpp | 133 ++++++++++ mama/c_cpp/src/gunittest/c/openclose.c | 51 ---- mama/c_cpp/src/gunittest/c/openclosetest.cpp | 152 ++++++++++++ mama/c_cpp/src/gunittest/c/pricetest.cpp | 295 +++++++++++++++++++++++ mama/c_cpp/src/gunittest/c/subscriptiontest.cpp | 181 ++++++++++++++ mama/c_cpp/src/gunittest/c/timertest.cpp | 258 ++++++++++++++++++++ 7 files changed, 1027 insertions(+), 53 deletions(-) create mode 100644 mama/c_cpp/src/gunittest/c/datetimetest.cpp delete mode 100644 mama/c_cpp/src/gunittest/c/openclose.c create mode 100644 mama/c_cpp/src/gunittest/c/openclosetest.cpp create mode 100644 mama/c_cpp/src/gunittest/c/pricetest.cpp create mode 100644 mama/c_cpp/src/gunittest/c/subscriptiontest.cpp create mode 100644 mama/c_cpp/src/gunittest/c/timertest.cpp diff --git a/mama/c_cpp/src/gunittest/c/Makefile.am b/mama/c_cpp/src/gunittest/c/Makefile.am index 13b5915..e968bce 100644 --- a/mama/c_cpp/src/gunittest/c/Makefile.am +++ b/mama/c_cpp/src/gunittest/c/Makefile.am @@ -1,4 +1,4 @@ -# $Id: Makefile.am,v 1.2.4.1.16.5 2011/09/13 16:01:26 ianbell Exp $ +# $Id$ # # OpenMAMA: The open middleware agnostic messaging API # Copyright (C) 2011 NYSE Inc. @@ -39,10 +39,16 @@ LDFLAGS += -L${srcdir}/../../c \ -L${srcdir}/../../../../../common/c_cpp/src/c LIBS = -lmama -lwombatcommon -lgtest +LDADD = -lgtest_main -ldl bin_PROGRAMS = MainUnitTestC nodist_MainUnitTestC_SOURCES = MainUnitTestC.cpp \ msgtests.cpp \ - iteration.cpp + iteration.cpp \ + openclosetest.cpp \ + datetimetest.cpp \ + subscriptiontest.cpp \ + pricetest.cpp \ + timertest.cpp diff --git a/mama/c_cpp/src/gunittest/c/datetimetest.cpp b/mama/c_cpp/src/gunittest/c/datetimetest.cpp new file mode 100644 index 0000000..a3c7393 --- /dev/null +++ b/mama/c_cpp/src/gunittest/c/datetimetest.cpp @@ -0,0 +1,133 @@ +/* Text editors: this is -*-C-*- code. */ +/*---------------------------------------------------------------------------- + * + * $Id$ + * + * Copyright (c) 1999-2007 Wombat Financial Software Inc., of Incline + * Village, NV. All rights reserved. + * + * This software and documentation constitute an unpublished work and + * contain valuable trade secrets and proprietary information belonging + * to Wombat. None of this material may be copied, duplicated or + * disclosed without the express written permission of Wombat. + * + * WOMBAT EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES CONCERNING THIS + * SOFTWARE AND DOCUMENTATION, INCLUDING ANY WARRANTIES OF + * MERCHANTABILITY AND/OR FITNESS FOR ANY PARTICULAR PURPOSE, AND + * WARRANTIES OF PERFORMANCE, AND ANY WARRANTY THAT MIGHT OTHERWISE ARISE + * FROM COURSE OF DEALING OR USAGE OF TRADE. NO WARRANTY IS EITHER + * EXPRESS OR IMPLIED WITH RESPECT TO THE USE OF THE SOFTWARE OR + * DOCUMENTATION. + * + * Under no circumstances shall Wombat be liable for incidental, special, + * indirect, direct or consequential damages or loss of profits, + * interruption of business, or related expenses which may arise from use + * of software or documentation, including but not limited to those + * resulting from defects in software and/or documentation, or loss or + * inaccuracy of data of any kind. + * + *--------------------------------------------------------------------------*/ + +#include "gtest/gtest.h" +#include "mama/mama.h" +#include "mama/status.h" +#include "MainUnitTestC.h" +#include "mama/types.h" +#include "mama/datetime.h" + +class MamaDateTimeTestC : public ::testing::Test +{ +protected: + // This C date time will be used for testing + mamaDateTime m_DateTime; + + /* Work around for problem in gtest where the this pointer can't be accessed + * from a test fixture. + */ + MamaDateTimeTestC *m_this; + + MamaDateTimeTestC(void); + virtual ~MamaDateTimeTestC(void); + + virtual void SetUp(void); + virtual void TearDown(void); + +}; + +MamaDateTimeTestC::MamaDateTimeTestC(void) +{ + m_DateTime = NULL; +} + +MamaDateTimeTestC::~MamaDateTimeTestC(void) +{ +} + +void MamaDateTimeTestC::SetUp(void) +{ + ASSERT_EQ(mamaDateTime_create(&m_DateTime), MAMA_STATUS_OK); +} + +void MamaDateTimeTestC::TearDown(void) +{ + ASSERT_EQ(mamaDateTime_destroy(m_DateTime), MAMA_STATUS_OK); +} + +/* ************************************************************************* */ +/* Test Functions */ +/* ************************************************************************* */ + +TEST_F(MamaDateTimeTestC, NullArguments) +{ + // Call with a NULL date time + mama_f64_t seconds = 0; + ASSERT_EQ(mamaDateTime_getEpochTimeSecondsWithCheck(NULL, &seconds), MAMA_STATUS_NULL_ARG); + + // NULL seconds + ASSERT_EQ(mamaDateTime_getEpochTimeSecondsWithCheck(m_DateTime, NULL), MAMA_STATUS_NULL_ARG); + + // NULL for both + ASSERT_EQ(mamaDateTime_getEpochTimeSecondsWithCheck(NULL, NULL), MAMA_STATUS_NULL_ARG); +} + +TEST_F(MamaDateTimeTestC, CompareDates) +{ + // Get todays date in a date time + mamaDateTime today = NULL; + + ASSERT_EQ(mamaDateTime_create(&today), MAMA_STATUS_OK); + ASSERT_EQ(mamaDateTime_setToNow(today), MAMA_STATUS_OK); + + // Get the string representation of the data + char stringDate[100] = ""; + ASSERT_EQ(mamaDateTime_getAsFormattedString(today, stringDate, 100, "%Y-%m-%d"), MAMA_STATUS_OK); + + // Destroy the date + ASSERT_EQ(mamaDateTime_destroy(today), MAMA_STATUS_OK); + + // Format a string using today's date and a time, this should be as "2010-07-04 10:00:00.000" + const char *time = "10:00:00.000000"; + char completeDateTime[100] = ""; + mamaDateTime m_cDateTime; + sprintf(completeDateTime, "%s %s", stringDate, time); + + // Set the date from this string + ASSERT_EQ(mamaDateTime_setFromString(m_cDateTime, completeDateTime), MAMA_STATUS_OK); + + // Get the number of seconds + mama_f64_t completeDateSeconds = 0; + ASSERT_EQ(mamaDateTime_getEpochTimeSecondsWithCheck(m_cDateTime, &completeDateSeconds), MAMA_STATUS_OK); + + // Set the date using just the time string + ASSERT_EQ(mamaDateTime_clear(m_cDateTime), MAMA_STATUS_OK); + + ASSERT_EQ(mamaDateTime_setFromString(m_cDateTime, time), MAMA_STATUS_OK); + + // Get the number of seconds from this + mama_f64_t timeSeconds = 0; + ASSERT_EQ(mamaDateTime_getEpochTimeSecondsWithCheck(m_cDateTime, &timeSeconds), MAMA_STATUS_OK); + + // These must be the same + ASSERT_EQ(completeDateSeconds, timeSeconds); +} + diff --git a/mama/c_cpp/src/gunittest/c/openclose.c b/mama/c_cpp/src/gunittest/c/openclose.c deleted file mode 100644 index 23adcef..0000000 --- a/mama/c_cpp/src/gunittest/c/openclose.c +++ /dev/null @@ -1,51 +0,0 @@ -/* $Id: openclose.c,v 1.2.22.2 2011/08/10 14:53:30 nicholasmarriott Exp $ - * - * OpenMAMA: The open middleware agnostic messaging API - * Copyright (C) 2011 NYSE Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -#include <gtest/gtest.h> -#include <sys/types.h> -#include <unistd.h> - - - -TEST(ExampleTest, LogicExampleHello) { - printf("simple example test\n"); -} - - -TEST(ExampleTest, LogicExampleHello2) { - printf("simple example test 2\n"); - -} - - -/** - * *VERY* Simple example - -TEST(OpenCloseTest, BasicOpenClose) { - printf("BasicOpenClose test\n"); -} - - -TEST(OpenCloseTest, RepeatedOpenClose) { - printf("RepeatedOpenClose\n"); - -} -*/ diff --git a/mama/c_cpp/src/gunittest/c/openclosetest.cpp b/mama/c_cpp/src/gunittest/c/openclosetest.cpp new file mode 100644 index 0000000..25e51b3 --- /dev/null +++ b/mama/c_cpp/src/gunittest/c/openclosetest.cpp @@ -0,0 +1,152 @@ +/* $Id$ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include <gtest/gtest.h> +#include "mama/mama.h" +#include "mama/status.h" +#include "MainUnitTestC.h" + +class MamaOpenCloseTestC : public ::testing::Test +{ +protected: + + /* Work around for problem in gtest where the this pointer can't be accessed + * from a test fixture. + */ + MamaOpenCloseTestC *m_this; + + MamaOpenCloseTestC(void); + virtual ~MamaOpenCloseTestC(void); + + virtual void SetUp(void); + virtual void TearDown(void); + + +}; + +MamaOpenCloseTestC::MamaOpenCloseTestC(void) +{ +} + +MamaOpenCloseTestC::~MamaOpenCloseTestC(void) +{ +} + +void MamaOpenCloseTestC::SetUp(void) +{ + m_this = this; +} + +void MamaOpenCloseTestC::TearDown(void) +{ + m_this = NULL; +} + +static void MAMACALLTYPE startCallback(mama_status status) +{ + printf("In start in background callback\n"); +} + + +/* ************************************************************************* */ +/* Tests */ +/* ************************************************************************* */ +TEST_F(MamaOpenCloseTestC, OpenClose) +{ + mamaBridge mBridge; + mama_loadBridge(&mBridge, getMiddleware()); + + mama_open(); + + mama_close(); +} + +TEST_F(MamaOpenCloseTestC, NestedOpenClose) +{ + mamaBridge mBridge; + mama_loadBridge(&mBridge, getMiddleware()); + + printf("Attempt first open\n"); + mama_open(); + + printf("Attempt second open\n"); + mama_open(); + + printf("Attempt first close\n"); + mama_close(); + + printf("Attempt second close\n"); + mama_close(); + + printf("Finished nested testing\n"); +} + +TEST_F(MamaOpenCloseTestC, OpenCloseReopenSameBridge) +{ + mamaBridge mBridge; + mama_loadBridge(&mBridge, getMiddleware()); + + mama_open(); + + mama_close(); + + ASSERT_EQ(MAMA_STATUS_OK, mama_open()); + + return; + + // If we get here there is a problem + ASSERT_TRUE(1); +} + +TEST_F(MamaOpenCloseTestC, OpenCloseReopenNewBridge) +{ + mamaBridge mBridge; + mama_loadBridge(&mBridge, "wmw"); + + mama_open(); + + mama_close(); + + mama_loadBridge(&mBridge, "lbm"); + + mama_open(); + + mama_close(); +} + +TEST_F(MamaOpenCloseTestC, StartStopDifferentThreads) +{ + mamaBridge mBridge; + mama_loadBridge(&mBridge, getMiddleware()); + + mama_open(); + + // Start mama in the background so it uses a different thread + ASSERT_EQ(MAMA_STATUS_OK, mama_startBackground(mBridge, startCallback)); + + // Sleep to allow the other thread to complete startup + sleep(2); + + mama_stop(mBridge); + + mama_close(); +} + diff --git a/mama/c_cpp/src/gunittest/c/pricetest.cpp b/mama/c_cpp/src/gunittest/c/pricetest.cpp new file mode 100644 index 0000000..8bcc7c8 --- /dev/null +++ b/mama/c_cpp/src/gunittest/c/pricetest.cpp @@ -0,0 +1,295 @@ +/* $Id$ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +/* + * Description : This test will check the mamaPrice type to ensure that the + * setting the precision will not cause the price value to be + * truncated. + */ + +#include "gtest/gtest.h" +#include "MainUnitTestC.h" +#include "mama/price.h" + +#ifdef WIN32 +#define WMPRICE_LARGE_INT32_FORMAT_SPECIFIER "%I32d" +#define WMPRICE_LARGE_INT64_FORMAT_SPECIFIER "%I64d" +#else +#define WMPRICE_LARGE_INT32_FORMAT_SPECIFIER "%ld" +#define WMPRICE_LARGE_INT64_FORMAT_SPECIFIER "%lld" +#endif + +class MamaPriceTestC : public ::testing::Test +{ +protected: + + mamaPrice m_price; + +protected: + + MamaPriceTestC(void); + virtual ~MamaPriceTestC(void); + + virtual void SetUp(void); + virtual void TearDown(void); +}; + + +MamaPriceTestC::MamaPriceTestC(void) +{ + m_price = NULL; +} + +MamaPriceTestC::~MamaPriceTestC(void) +{ +} + + +void MamaPriceTestC::SetUp(void) +{ + // Create a new mama price + ASSERT_EQ(mamaPrice_create(&m_price), MAMA_STATUS_OK); + + // Set the value of the price + ASSERT_EQ(mamaPrice_setValue(m_price, 4000000000), MAMA_STATUS_OK); +} + +void MamaPriceTestC::TearDown(void) +{ + // Delete the price + if(m_price != NULL) + { + ASSERT_EQ(mamaPrice_destroy(m_price), MAMA_STATUS_OK); + } +} + +/* ************************************************************************* */ +/* Test Functions */ +/* ************************************************************************* +*/ +TEST_F(MamaPriceTestC, SetPrecisionInt) +{ + // Set the precision + ASSERT_EQ(mamaPrice_setPrecision(m_price, MAMA_PRICE_PREC_INT), MAMA_STATUS_OK); + + // Get the value as a double + double doubleValue = 0; + ASSERT_EQ(mamaPrice_getValue(m_price, &doubleValue), MAMA_STATUS_OK); + + // Format the double value as a string using an integer flag + char doubleString[20] = ""; + sprintf(doubleString, WMPRICE_LARGE_INT64_FORMAT_SPECIFIER, (int64_t)doubleValue); + + // Get the value as a string + char stringValue[20] = ""; + ASSERT_EQ(mamaPrice_getAsString(m_price, stringValue, 19), MAMA_STATUS_OK); + + // Compare the strings + ASSERT_STREQ(stringValue, doubleString); +} + +TEST_F(MamaPriceTestC, SetPrecisionDiv2) +{ + // Set the precision + ASSERT_EQ(mamaPrice_setPrecision(m_price, MAMA_PRICE_PREC_DIV_2), MAMA_STATUS_OK); + + // Get the value as a double + double doubleValue = 0; + ASSERT_EQ(mamaPrice_getValue(m_price, &doubleValue), MAMA_STATUS_OK); + + // Format the double value as a string using an integer flag + char doubleString[20] = ""; + sprintf(doubleString, WMPRICE_LARGE_INT64_FORMAT_SPECIFIER, (int64_t)doubleValue); + + // Get the value as a string + char stringValue[20] = ""; + ASSERT_EQ(mamaPrice_getAsString(m_price, stringValue, 19), MAMA_STATUS_OK); + + // Compare the strings + ASSERT_STREQ(stringValue, doubleString); +} + +TEST_F(MamaPriceTestC, SetPrecisionDiv4) +{ + // Set the precision + ASSERT_EQ(mamaPrice_setPrecision(m_price, MAMA_PRICE_PREC_DIV_4), MAMA_STATUS_OK); + + // Get the value as a double + double doubleValue = 0; + ASSERT_EQ(mamaPrice_getValue(m_price, &doubleValue), MAMA_STATUS_OK); + + // Format the double value as a string using an integer flag + char doubleString[20] = ""; + sprintf(doubleString, WMPRICE_LARGE_INT64_FORMAT_SPECIFIER, (int64_t)doubleValue); + + // Get the value as a string + char stringValue[20] = ""; + ASSERT_EQ(mamaPrice_getAsString(m_price, stringValue, 19), MAMA_STATUS_OK); + + // Compare the strings + ASSERT_STREQ(stringValue, doubleString); +} + +TEST_F(MamaPriceTestC, SetPrecisionDiv8) +{ + // Set the precision + ASSERT_EQ(mamaPrice_setPrecision(m_price, MAMA_PRICE_PREC_DIV_8), MAMA_STATUS_OK); + + // Get the value as a double + double doubleValue = 0; + ASSERT_EQ(mamaPrice_getValue(m_price, &doubleValue), MAMA_STATUS_OK); + + // Format the double value as a string using an integer flag + char doubleString[20] = ""; + sprintf(doubleString, WMPRICE_LARGE_INT64_FORMAT_SPECIFIER, (int64_t)doubleValue); + + // Get the value as a string + char stringValue[20] = ""; + ASSERT_EQ(mamaPrice_getAsString(m_price, stringValue, 19), MAMA_STATUS_OK); + + // Compare the strings + ASSERT_STREQ(stringValue, doubleString); +} + +TEST_F(MamaPriceTestC, SetPrecisionDiv16) +{ + // Set the precision + ASSERT_EQ(mamaPrice_setPrecision(m_price, MAMA_PRICE_PREC_DIV_16), MAMA_STATUS_OK); + + // Get the value as a double + double doubleValue = 0; + ASSERT_EQ(mamaPrice_getValue(m_price, &doubleValue), MAMA_STATUS_OK); + + // Format the double value as a string using an integer flag + char doubleString[20] = ""; + sprintf(doubleString, WMPRICE_LARGE_INT64_FORMAT_SPECIFIER, (int64_t)doubleValue); + + // Get the value as a string + char stringValue[20] = ""; + ASSERT_EQ(mamaPrice_getAsString(m_price, stringValue, 19), MAMA_STATUS_OK); + + // Compare the strings + ASSERT_STREQ(stringValue, doubleString); +} + +TEST_F(MamaPriceTestC, SetPrecisionDiv32) +{ + // Set the precision + ASSERT_EQ(mamaPrice_setPrecision(m_price, MAMA_PRICE_PREC_DIV_32), MAMA_STATUS_OK); + + // Get the value as a double + double doubleValue = 0; + ASSERT_EQ(mamaPrice_getValue(m_price, &doubleValue), MAMA_STATUS_OK); + + // Format the double value as a string using an integer flag + char doubleString[20] = ""; + sprintf(doubleString, WMPRICE_LARGE_INT64_FORMAT_SPECIFIER, (int64_t)doubleValue); + + // Get the value as a string + char stringValue[20] = ""; + ASSERT_EQ(mamaPrice_getAsString(m_price, stringValue, 19), MAMA_STATUS_OK); + + // Compare the strings + ASSERT_STREQ(stringValue, doubleString); +} + +TEST_F(MamaPriceTestC, SetPrecisionDiv64) +{ + // Set the precision + ASSERT_EQ(mamaPrice_setPrecision(m_price, MAMA_PRICE_PREC_DIV_64), MAMA_STATUS_OK); + + // Get the value as a double + double doubleValue = 0; + ASSERT_EQ(mamaPrice_getValue(m_price, &doubleValue), MAMA_STATUS_OK); + + // Format the double value as a string using an integer flag + char doubleString[20] = ""; + sprintf(doubleString, WMPRICE_LARGE_INT64_FORMAT_SPECIFIER, (int64_t)doubleValue); + + // Get the value as a string + char stringValue[20] = ""; + ASSERT_EQ(mamaPrice_getAsString(m_price, stringValue, 19), MAMA_STATUS_OK); + + // Compare the strings + ASSERT_STREQ(stringValue, doubleString); +} + +TEST_F(MamaPriceTestC, SetPrecisionDiv128) +{ + // Set the precision + ASSERT_EQ(mamaPrice_setPrecision(m_price, MAMA_PRICE_PREC_DIV_128), MAMA_STATUS_OK); + + // Get the value as a double + double doubleValue = 0; + ASSERT_EQ(mamaPrice_getValue(m_price, &doubleValue), MAMA_STATUS_OK); + + // Format the double value as a string using an integer flag + char doubleString[20] = ""; + sprintf(doubleString, WMPRICE_LARGE_INT64_FORMAT_SPECIFIER, (int64_t)doubleValue); + + // Get the value as a string + char stringValue[20] = ""; + ASSERT_EQ(mamaPrice_getAsString(m_price, stringValue, 19), MAMA_STATUS_OK); + + // Compare the strings + ASSERT_STREQ(stringValue, doubleString); +} + +TEST_F(MamaPriceTestC, SetPrecisionDiv256) +{ + // Set the precision + ASSERT_EQ(mamaPrice_setPrecision(m_price, MAMA_PRICE_PREC_DIV_256), MAMA_STATUS_OK); + + // Get the value as a double + double doubleValue = 0; + ASSERT_EQ(mamaPrice_getValue(m_price, &doubleValue), MAMA_STATUS_OK); + + // Format the double value as a string using an integer flag + char doubleString[20] = ""; + sprintf(doubleString, WMPRICE_LARGE_INT64_FORMAT_SPECIFIER, (int64_t)doubleValue); + + // Get the value as a string + char stringValue[20] = ""; + ASSERT_EQ(mamaPrice_getAsString(m_price, stringValue, 19), MAMA_STATUS_OK); + + // Compare the strings + ASSERT_STREQ(stringValue, doubleString); +} + +TEST_F(MamaPriceTestC, SetPrecisionDiv512) +{ + // Set the precision + ASSERT_EQ(mamaPrice_setPrecision(m_price, MAMA_PRICE_PREC_DIV_512), MAMA_STATUS_OK); + + // Get the value as a double + double doubleValue = 0; + ASSERT_EQ(mamaPrice_getValue(m_price, &doubleValue), MAMA_STATUS_OK); + + // Format the double value as a string using an integer flag + char doubleString[20] = ""; + sprintf(doubleString, WMPRICE_LARGE_INT64_FORMAT_SPECIFIER, (int64_t)doubleValue); + + // Get the value as a string + char stringValue[20] = ""; + ASSERT_EQ(mamaPrice_getAsString(m_price, stringValue, 19), MAMA_STATUS_OK); + + // Compare the strings + ASSERT_STREQ(stringValue, doubleString); +} diff --git a/mama/c_cpp/src/gunittest/c/subscriptiontest.cpp b/mama/c_cpp/src/gunittest/c/subscriptiontest.cpp new file mode 100644 index 0000000..ea631dc --- /dev/null +++ b/mama/c_cpp/src/gunittest/c/subscriptiontest.cpp @@ -0,0 +1,181 @@ +/*---------------------------------------------------------------------------- + * + * $Id$ + * + * Copyright (c) 1999-2007 Wombat Financial Software Inc., of Incline + * Village, NV. All rights reserved. + * + * This software and documentation constitute an unpublished work and + * contain valuable trade secrets and proprietary information belonging + * to Wombat. None of this material may be copied, duplicated or + * disclosed without the express written permission of Wombat. + * + * WOMBAT EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES CONCERNING THIS + * SOFTWARE AND DOCUMENTATION, INCLUDING ANY WARRANTIES OF + * MERCHANTABILITY AND/OR FITNESS FOR ANY PARTICULAR PURPOSE, AND + * WARRANTIES OF PERFORMANCE, AND ANY WARRANTY THAT MIGHT OTHERWISE ARISE + * FROM COURSE OF DEALING OR USAGE OF TRADE. NO WARRANTY IS EITHER + * EXPRESS OR IMPLIED WITH RESPECT TO THE USE OF THE SOFTWARE OR + * DOCUMENTATION. + * + * Under no circumstances shall Wombat be liable for incidental, special, + * indirect, direct or consequential damages or loss of profits, + * interruption of business, or related expenses which may arise from use + * of software or documentation, including but not limited to those + * resulting from defects in software and/or documentation, or loss or + * inaccuracy of data of any kind. + * + *--------------------------------------------------------------------------*/ + +#include "gtest/gtest.h" +#include "mama/mama.h" +#include "MainUnitTestC.h" +#include "mama/subscription.h" +#include "mama/source.h" +#include "mama/types.h" + +//using namespace Wombat; + +class MamaSubscriptionTest : public ::testing::Test +{ +public: + mamaBridge m_bridge; +protected: + + /* Work around for problem in gtest where the this pointer can't be accessed + * from a test fixture. + */ + MamaSubscriptionTest *m_this; + + mamaQueue m_defaultQueue; + + mamaMsgCallbacks simpleCallback; + + mamaSubscription subscription; + + mamaTransport m_transport; + char transportName[10]; + +protected: + + MamaSubscriptionTest(void); + virtual ~MamaSubscriptionTest(void); + + virtual void SetUp(void); + virtual void TearDown(void); +}; + +static void MAMACALLTYPE onSimpleCallbackCreate(mamaSubscription sub, void* closure) +{ +} + +static void MAMACALLTYPE onSimpleCallbackDestroy(mamaSubscription sub, void* closure) +{ + MamaSubscriptionTest* mamaSubscriptionTest = (MamaSubscriptionTest*) closure; + mama_stop(mamaSubscriptionTest->m_bridge); +} + +static void MAMACALLTYPE onSimpleCallbackMsg(mamaSubscription sub, mamaMsg msg, void* closure, void* itemClosure) +{ + MamaSubscriptionTest* mamaSubscriptionTest = (MamaSubscriptionTest*) closure; + mama_stop(mamaSubscriptionTest->m_bridge); +} + +static void MAMACALLTYPE onSimpleCallbackRecapRequest(mamaSubscription sub, void* closure) +{ +} + +static void MAMACALLTYPE onSimpleCallbackQuality(mamaSubscription sub, mamaQuality quality, const char* symbol, short cause, const void* platformInfo, void* closure) +{ +} + +static void MAMACALLTYPE onSimpleCallbackGap(mamaSubscription sub, void* closure) +{ +} + +MamaSubscriptionTest::MamaSubscriptionTest(void) +{ + m_bridge = NULL; + m_transport = NULL; + m_defaultQueue = NULL; + + memset(&simpleCallback, 0, sizeof(simpleCallback)); + simpleCallback.onCreate = onSimpleCallbackCreate; + simpleCallback.onDestroy = onSimpleCallbackDestroy; + simpleCallback.onMsg = onSimpleCallbackMsg; + simpleCallback.onQuality = onSimpleCallbackQuality; + simpleCallback.onGap = onSimpleCallbackGap; + simpleCallback.onRecapRequest = onSimpleCallbackRecapRequest; + + subscription = NULL; + + //recreateOnMsgCallback = ; + //recreateOnDestroyCallback = NULL; +} + +MamaSubscriptionTest::~MamaSubscriptionTest(void) +{ +} + + +void MamaSubscriptionTest::SetUp(void) +{ + // Save the this pointer in the member variable to get around gtest problems + m_this = this; + + mama_loadBridge(&m_bridge, getMiddleware()); + + mama_open(); + + transportName[0] = '\0'; + strncat(transportName, "sub_", 5); + strncat(transportName, getMiddleware(), 4); + + mamaTransport_allocate(&m_transport); + mamaTransport_create(m_transport, transportName, m_bridge); +} + +void MamaSubscriptionTest::TearDown(void) +{ + m_transport = NULL; + + mama_close(); + + m_this = NULL; +} + + + +/* ************************************************************************* */ +/* Test Functions - Basic Subscription */ +/* ************************************************************************* */ + +TEST_F(MamaSubscriptionTest, BasicSubscription) +{ + ASSERT_EQ(MAMA_STATUS_OK, mamaSubscription_allocate(&subscription)); + if(NULL != subscription) + { + // Get the default queue + mama_getDefaultEventQueue(m_bridge, &m_defaultQueue); + + //create a test source + mamaSource testSource = NULL; + mamaSource_create(&testSource); + mamaSource_setId(testSource, "TestSource"); + mamaSource_setTransport(testSource, m_transport); + mamaSource_setSymbolNamespace(testSource, "WOMBAT"); + printf("Note: as there is no real source, this test should hang\n"); + + // Create the subscription + ASSERT_EQ( MAMA_STATUS_OK, + mamaSubscription_create(subscription, m_defaultQueue, &simpleCallback, testSource, "TEST_SYMBOL", m_this)); + + mama_start(m_bridge); + + // Destroy the subscription + ASSERT_EQ(MAMA_STATUS_OK, mamaSubscription_destroy(subscription)); + + // Delete the basic subscription + ASSERT_EQ(MAMA_STATUS_OK, mamaSubscription_deallocate(subscription)); + } +} diff --git a/mama/c_cpp/src/gunittest/c/timertest.cpp b/mama/c_cpp/src/gunittest/c/timertest.cpp new file mode 100644 index 0000000..2604fe7 --- /dev/null +++ b/mama/c_cpp/src/gunittest/c/timertest.cpp @@ -0,0 +1,258 @@ +/* $Id$ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +/* + * Description : This test harness will cover MAMA issue 3418 which includes + * several timer tests. See the function header for each + * fixture for more information. Note that this test should + * be run against different versions of LBM including 3.5.2 + * and an earlier version. + */ + +#include <gtest/gtest.h> +#include "MainUnitTestC.h" +#include "wombat/wConfig.h" +#include "mama/types.h" +#include "mama/timer.h" +#include "mama/queue.h" +#include <cstring> +#include <cstdio> +#include <cstdlib> + + +class MamaTimerTestC : public ::testing::Test +{ +protected: + MamaTimerTestC(); + virtual ~MamaTimerTestC(); + + virtual void SetUp(); + virtual void TearDown (); +public: + // Initialise all member variables + int m_numberForCallbacks; + int m_numberForTimers; + int m_numberRecursiveCallbacks; + double m_timerInterval; + mamaBridge m_bridge; + mamaQueue m_defaultQueue; + mamaTransport m_transport; + + mamaTimer mtarray[1000]; + + MamaTimerTestC *m_this; + char transportName[10]; + + mamaTimer shortTimer; + mamaTimer longTimer; + mamaTimer stopperTimer; + mamaTimer recursiveTimer; + + mamaTimerCb m_TickCallback; + mamaTimerCb m_DestroyCallback; + +}; + +MamaTimerTestC::MamaTimerTestC() +{ + m_numberForCallbacks = 0; + m_numberForTimers = 10; + m_numberRecursiveCallbacks = 0; + m_timerInterval = 0.0001; + m_bridge = NULL; + m_defaultQueue = NULL; + m_transport = NULL; + shortTimer = NULL; + longTimer = NULL; + stopperTimer = NULL; + recursiveTimer = NULL; + + m_TickCallback = NULL; + m_DestroyCallback = NULL; + m_this = NULL; +} + +MamaTimerTestC::~MamaTimerTestC() +{ +} + +void MamaTimerTestC::SetUp(void) +{ + // Save the this pointer in the member variable to get around gtest problems + m_this = this; + + mama_loadBridge(&m_bridge, getMiddleware()); + + mama_open(); + + mama_getDefaultEventQueue(m_bridge, &m_defaultQueue); + + transportName[0] = '\0'; + strncat(transportName, "sub_", 5); + strncat(transportName, getMiddleware(), 4); + + mamaTransport_allocate(&m_transport); + mamaTransport_create(m_transport, transportName, m_bridge); +} + +void MamaTimerTestC::TearDown(void) +{ + m_this = NULL; +} + +static void MAMACALLTYPE onTimerTick(mamaTimer timer, void* closure) +{ + printf("Timer ticking....\n"); + mamaTimer_destroy(timer); +} + +static void MAMACALLTYPE onTimerDestroy(mamaTimer timer, void* closure) +{ + printf("Timer destroying...\n"); + MamaTimerTestC *fixture = (MamaTimerTestC *)closure; + fixture->m_numberForCallbacks ++; + printf("m_numberForCallbacks = %i\n", fixture->m_numberForCallbacks); + + // If all the timers have been destroyed then quit out + if(fixture->m_numberForCallbacks == fixture->m_numberForTimers) + { + printf("Stopping timer\n"); + mama_stop(fixture->m_bridge); + } +} + +static void MAMACALLTYPE onStopDispatchingTimerTick(mamaTimer timer, void* closure) +{ + mamaTimer_destroy(timer); +} + +static void MAMACALLTYPE onStopDispatchingTimerDestroy(mamaTimer timer, void* closure) +{ + printf("Stopping Two Timers ticking\n"); + MamaTimerTestC* fixture = (MamaTimerTestC *)closure; + mama_stop(fixture->m_bridge); + + mamaTimer_destroy(fixture->shortTimer); + mamaTimer_destroy(fixture->longTimer); +} + + +static void MAMACALLTYPE onRecursiveTimerTick(mamaTimer timer, void* closure) +{ + MamaTimerTestC *fixture = (MamaTimerTestC*) closure; + EXPECT_EQ(mamaTimer_destroy(timer), MAMA_STATUS_OK); + fixture->recursiveTimer = NULL; +} + + +static void MAMACALLTYPE onRecursiveTimerDestroy(mamaTimer timer, void* closure) +{ + // Cast the closure to a test fixture + printf("in recursive onDestroy\n"); + MamaTimerTestC *fixture = (MamaTimerTestC *)closure; + + // Increment the number of times this function has been called + fixture->m_numberRecursiveCallbacks ++; + + // If this is the 10th pass then quit out + if(fixture->m_numberRecursiveCallbacks == 10) + { + //EXPECT_EQ(mama_stop(fixture->m_init->bridge), MAMA_STATUS_OK); + mama_stop(fixture->m_bridge); + } + else + { + mamaTimer_create2(&fixture->recursiveTimer, fixture->m_defaultQueue, onRecursiveTimerTick, onRecursiveTimerDestroy, fixture->m_timerInterval, fixture->m_this); + } +} + + +static void MAMACALLTYPE onTwoTimerTick(mamaTimer timer, void* closure) +{ + printf("In TwoTimer Tick\n"); + +} + +static void MAMACALLTYPE onTwoTimerDestroy(mamaTimer timer, void * closure) +{ + // Cast the closure to a test fixture + printf("In TwoTimer Destroy\n"); +} +/* ************************************************************************* */ +/* Test Functions */ +/* ************************************************************************* */ + +/* Description : This test will create a large number of timers in a for loop, each one will + * be freed in its callback function. + */ +TEST_F(MamaTimerTestC, ForTimer) +{ + // Create a whole lot of timers + for(int counter=0; counter<m_numberForTimers; counter++) + { + printf("Creating new timer\n"); + m_timerInterval = (counter + 1)/100; + mamaTimer_create2(&mtarray[counter], m_defaultQueue, onTimerTick, onTimerDestroy, m_timerInterval, m_this); + } + + ASSERT_EQ(MAMA_STATUS_OK, mama_start(m_bridge)); + +} + + +/* Description : This function will create a timer which will create another timer + * in its callback function, (the first timer will be destroyed). + */ + +TEST_F(MamaTimerTestC, RecursiveTimer) +{ + //Store the call + mamaTimer_create2(&recursiveTimer, m_defaultQueue, onRecursiveTimerTick, onRecursiveTimerDestroy, m_timerInterval, m_this); + + // Start processing messages, after 10 timers have been created this will stop blocking + mama_start(m_bridge); +} + + +/* Description : This test will create 2 timers, the first will constantly reset itself + * while the second will continue to reset the first timer as well. + * The whole test will run for 3 seconds. + */ +TEST_F(MamaTimerTestC, TwoTimer) +{ + + double interval = 0.1; + double testDuration = 3.0; + + mamaTimer_create2(&shortTimer, m_defaultQueue, onTwoTimerTick, onTwoTimerDestroy, interval, m_this); + mamaTimer_create2(&longTimer, m_defaultQueue, onTwoTimerTick, onTwoTimerDestroy, interval*2.0, m_this); //use same callback + + mamaTimer_create2( &stopperTimer, + m_defaultQueue, + onStopDispatchingTimerTick, + onStopDispatchingTimerDestroy, + testDuration, + m_this); + + mama_start(m_bridge); + +} + -- 1.7.7.6 |
|
[PATCH 49/50] [common] More Win32 Support
Michael Schonberg <mschonberg@...>
From: Mike Schonberg <mschonberg@...>
wUuid.c for uuid support and strpcasecmp and strptime implementations. Signed-off-by: Mike Schonberg <mschonberg@...> --- common/c_cpp/src/c/windows/strpcasecmp.c | 88 +++++++ common/c_cpp/src/c/windows/strptime.c | 376 ++++++++++++++++++++++++++++++ common/c_cpp/src/c/windows/wUuid.c | 69 ++++++ 3 files changed, 533 insertions(+), 0 deletions(-) create mode 100644 common/c_cpp/src/c/windows/strpcasecmp.c create mode 100644 common/c_cpp/src/c/windows/strptime.c create mode 100644 common/c_cpp/src/c/windows/wUuid.c diff --git a/common/c_cpp/src/c/windows/strpcasecmp.c b/common/c_cpp/src/c/windows/strpcasecmp.c new file mode 100644 index 0000000..5483fa8 --- /dev/null +++ b/common/c_cpp/src/c/windows/strpcasecmp.c @@ -0,0 +1,88 @@ +// +// strcasecmp.cc +// +// strcasecmp: replacement of the strcasecmp functions for architectures that do +// not have it. +// +// Part of the ht://Dig package <http://www.htdig.org/> +// Copyright (c) 1999-2004 The ht://Dig Group +// For copyright details, see the file COPYING in your distribution +// or the GNU Library General Public License (LGPL) version 2 or later +// <http://www.gnu.org/copyleft/lgpl.html> +// +// $Id: strpcasecmp.c,v 1.1.2.1 2012/03/15 11:02:57 evinkeating Exp $ +// + +//#ifdef HAVE_CONFIG_H +//#include "htconfig.h" +//#endif /* HAVE_CONFIG_H */ + +//#include "lib.h" +#include <ctype.h> + +//***************************************************************************** +// +int strcasecmp(const char *str1, const char *str2) +{ + if (!str1 && !str2) + return 0; + if (!str1) + return 1; + if (!str2) + return -1; + while (*str1 && + *str2 && + tolower((unsigned char)*str1) == tolower((unsigned char)*str2)) + { + str1++; + str2++; + } + + return tolower((unsigned char)*str1) - tolower((unsigned char)*str2); +} + + +//#define tolower(ch) (isupper(ch) ? (ch) + 'a' - 'A' : (ch)) +//***************************************************************************** +// +int strncasecmp(const char *str1, const char *str2, int n) +{ + if (!str1 && !str2) + return 0; + if (!str1) + return 1; + if (!str2) + return -1; + if (n < 0) + return 0; + while (n && + *str1 && + *str2 && + tolower((unsigned char)*str1) == tolower((unsigned char)*str2)) + { + str1++; + str2++; + n--; + } + + return n == 0 ? 0 : + tolower((unsigned char)*str1) - tolower((unsigned char)*str2); +} + + +//***************************************************************************** +// char *mystrcasestr(const char *s, const char *pattern) +// +const char * +mystrcasestr(const char *s, const char *pattern) +{ + int length = strlen(pattern); + + while (*s) + { + if (strncasecmp(s, pattern, length) == 0) + return s; + s++; + } + return 0; +} \ No newline at end of file diff --git a/common/c_cpp/src/c/windows/strptime.c b/common/c_cpp/src/c/windows/strptime.c new file mode 100644 index 0000000..88035e0 --- /dev/null +++ b/common/c_cpp/src/c/windows/strptime.c @@ -0,0 +1,376 @@ +// Part of the ht://Dig package <http://www.htdig.org/> +// Copyright (c) 1999-2004 The ht://Dig Group +// For copyright details, see the file COPYING in your distribution +// or the GNU Library General Public License (LGPL) version 2 or later +// <http://www.gnu.org/copyleft/lgpl.html> +// + +/* + * Copyright (c) 1994 Powerdog Industries. All rights reserved. + * + * Redistribution and use in source and binary forms, without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgement: + * This product includes software developed by Powerdog Industries. + * 4. The name of Powerdog Industries may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY POWERDOG INDUSTRIES ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE POWERDOG INDUSTRIES BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef lint +/* +static char copyright[] = +"@(#) Copyright (c) 1994 Powerdog Industries. All rights reserved."; +static char sccsid[] = "@(#)strptime.c 1.0 (Powerdog) 94/03/27"; +*/ +#endif /* not lint */ + +//#include <lib.h> + +#include <time.h> +#include <ctype.h> +#include <locale.h> +#include <string.h> + +#define asizeof(a) ((int)(sizeof (a) / sizeof ((a)[0]))) + +struct mydtconv { + char *abbrev_month_names[12]; + char *month_names[12]; + char *abbrev_weekday_names[7]; + char *weekday_names[7]; + char *time_format; + char *sdate_format; + char *dtime_format; + char *am_string; + char *pm_string; + char *ldate_format; +}; + +static struct mydtconv En_US = { + { "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }, + { "January", "February", "March", "April", + "May", "June", "July", "August", + "September", "October", "November", "December" }, + { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }, + { "Sunday", "Monday", "Tuesday", "Wednesday", + "Thursday", "Friday", "Saturday" }, + "%H:%M:%S", + "%m/%d/%y", + "%a %b %e %T %Z %Y", + "AM", + "PM", + "%A, %B, %e, %Y" +}; + +char * +strptime(const char *buf, const char *fmt, struct tm *tm) +{ + char c; + const char *ptr; + int i, len = 0; + + ptr = fmt; + while (*ptr != 0) + { + if (*buf == 0) + break; + + c = *ptr++; + + if (c != '%') + { + if (isspace(c)) + while (*buf != 0 && isspace(*buf)) + buf++; + else if (c != *buf++) + return 0; + continue; + } + + c = *ptr++; + switch (c) + { + case 0: + case '%': + if (*buf++ != '%') + return 0; + break; + + case 'C': + buf = strptime(buf, En_US.ldate_format, tm); + if (buf == 0) + return 0; + break; + + case 'c': + buf = strptime(buf, "%x %X", tm); + if (buf == 0) + return 0; + break; + + case 'D': + buf = strptime(buf, "%m/%d/%y", tm); + if (buf == 0) + return 0; + break; + + case 'R': + buf = strptime(buf, "%H:%M", tm); + if (buf == 0) + return 0; + break; + + case 'r': + buf = strptime(buf, "%I:%M:%S %p", tm); + if (buf == 0) + return 0; + break; + + case 'T': + buf = strptime(buf, "%H:%M:%S", tm); + if (buf == 0) + return 0; + break; + + case 'X': + buf = strptime(buf, En_US.time_format, tm); + if (buf == 0) + return 0; + break; + + case 'x': + buf = strptime(buf, En_US.sdate_format, tm); + if (buf == 0) + return 0; + break; + + case 'j': + if (!isdigit(*buf)) + return 0; + + for (i = 0; *buf != 0 && isdigit(*buf); buf++) + { + i *= 10; + i += *buf - '0'; + } + if (i > 365) + return 0; + + tm->tm_yday = i; + break; + + case 'M': + case 'S': + if (*buf == 0 || isspace(*buf)) + break; + + if (!isdigit(*buf)) + return 0; + + for (i = 0; *buf != 0 && isdigit(*buf); buf++) + { + i *= 10; + i += *buf - '0'; + } + if (i > 59) + return 0; + + if (c == 'M') + tm->tm_min = i; + else + tm->tm_sec = i; + + if (*buf != 0 && isspace(*buf)) + while (*ptr != 0 && !isspace(*ptr)) + ptr++; + break; + + case 'H': + case 'I': + case 'k': + case 'l': + if (!isdigit(*buf)) + return 0; + + for (i = 0; *buf != 0 && isdigit(*buf); buf++) + { + i *= 10; + i += *buf - '0'; + } + if (c == 'H' || c == 'k') { + if (i > 23) + return 0; + } else if (i > 11) + return 0; + + tm->tm_hour = i; + + if (*buf != 0 && isspace(*buf)) + while (*ptr != 0 && !isspace(*ptr)) + ptr++; + break; + + case 'p': + len = strlen(En_US.am_string); + if (strncasecmp(buf, En_US.am_string, len) == 0) + { + if (tm->tm_hour > 12) + return 0; + if (tm->tm_hour == 12) + tm->tm_hour = 0; + buf += len; + break; + } + + len = strlen(En_US.pm_string); + if (strncasecmp(buf, En_US.pm_string, len) == 0) + { + if (tm->tm_hour > 12) + return 0; + if (tm->tm_hour != 12) + tm->tm_hour += 12; + buf += len; + break; + } + + return 0; + + case 'A': + case 'a': + for (i = 0; i < asizeof(En_US.weekday_names); i++) + { + len = strlen(En_US.weekday_names[i]); + if (strncasecmp(buf, + En_US.weekday_names[i], + len) == 0) + break; + + len = strlen(En_US.abbrev_weekday_names[i]); + if (strncasecmp(buf, + En_US.abbrev_weekday_names[i], + len) == 0) + break; + } + if (i == asizeof(En_US.weekday_names)) + return 0; + + tm->tm_wday = i; + buf += len; + break; + + case 'd': + case 'e': + if (!isdigit(*buf)) + return 0; + + for (i = 0; *buf != 0 && isdigit(*buf); buf++) + { + i *= 10; + i += *buf - '0'; + } + if (i > 31) + return 0; + + tm->tm_mday = i; + + if (*buf != 0 && isspace(*buf)) + while (*ptr != 0 && !isspace(*ptr)) + ptr++; + break; + + case 'B': + case 'b': + case 'h': + for (i = 0; i < asizeof(En_US.month_names); i++) + { + len = strlen(En_US.month_names[i]); + if (strncasecmp(buf, + En_US.month_names[i], + len) == 0) + break; + + len = strlen(En_US.abbrev_month_names[i]); + if (strncasecmp(buf, + En_US.abbrev_month_names[i], + len) == 0) + break; + } + if (i == asizeof(En_US.month_names)) + return 0; + + tm->tm_mon = i; + buf += len; + break; + + case 'm': + if (!isdigit(*buf)) + return 0; + + for (i = 0; *buf != 0 && isdigit(*buf); buf++) + { + i *= 10; + i += *buf - '0'; + } + if (i < 1 || i > 12) + return 0; + + tm->tm_mon = i - 1; + + if (*buf != 0 && isspace(*buf)) + while (*ptr != 0 && !isspace(*ptr)) + ptr++; + break; + + case 'Y': + case 'y': + if (*buf == 0 || isspace(*buf)) + break; + + if (!isdigit(*buf)) + return 0; + + for (i = 0; *buf != 0 && isdigit(*buf); buf++) + { + i *= 10; + i += *buf - '0'; + } + if (c == 'y' && i < 69) /* Unix Epoch pivot year */ + i += 100; + if (c == 'Y') + i -= 1900; + if (i < 0) + return 0; + + tm->tm_year = i; + + if (*buf != 0 && isspace(*buf)) + while (*ptr != 0 && !isspace(*ptr)) + ptr++; + break; + } + } + + return (char *) buf; +} \ No newline at end of file diff --git a/common/c_cpp/src/c/windows/wUuid.c b/common/c_cpp/src/c/windows/wUuid.c new file mode 100644 index 0000000..54124ec --- /dev/null +++ b/common/c_cpp/src/c/windows/wUuid.c @@ -0,0 +1,69 @@ +/* $Id: wUuid.c,v 1.1.2.3 2012/04/05 09:33:15 evinkeating Exp $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + + +#include <time.h> +#include <stdio.h> +#include <stdlib.h> +#include "wombat/wUuid.h" + +static uint64_t gRoot = 0; +static uint16_t gGotroot = 0; + +#ifndef HOST_NAME_MAX +# define HOST_NAME_MAX 255 +#endif + +void wUuid_generate_time (wUuid myUuid) +{ +} + +void wUuid_unparse (wUuid myUuid, char* out) +{ + if (!gGotroot) + { + char hostname[HOST_NAME_MAX+1]; + if (gethostname (hostname, HOST_NAME_MAX) == 0) + { + struct in_addr addr; + struct hostent* host = gethostbyname (hostname); + if ((host != NULL) && (host->h_addrtype == AF_INET)) + { + /* Found host by name - we just look at the first entry. + * Maybe we should look at all of the entries (these are not + * aliases though). */ + addr = *(struct in_addr*)(host->h_addr_list[0]); + } + else + addr.s_addr=INADDR_NONE; + + gRoot = (((uint64_t)addr.s_addr) << 32) + getpid(); + } + else + { + gRoot = getpid(); + } + gGotroot = 1; + } + + srand (time (NULL)); + snprintf (out, 49, "%d%d", gRoot, rand() % 10000); +} -- 1.7.7.6 |
|