[PATCH 50/50] [unittest] Adding C Unit Tests


Michael Schonberg <mschonberg@...>
 

From: Mike Schonberg <mschonberg@nyx.com>


Signed-off-by: Mike Schonberg <mschonberg@nyx.com>
---
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