[PATCH 2/2] UNITTEST: Add roundtrip serialization payload test and fix byte buffer and destroy calls.


Lee Skillen <lskillen@...>
 

- The roundtrip serialization unit test constructs a reasonably
representative payload with most of the payload types - It then
serialises and unserialises this into a second payload and then
extracts the field data for comparison against the egress payload.

- The wrong destroy function was being called in UpdateBoolInValid.

- Some of the unit tests that utilised setByteBuffer() were passing the
buffer in incorrectly (probably caused by the signature requiring a
const void** instead of a const void* which it should be).

- The setByteBuffer() call in SetByteBufferValid was passing address-of
testPayload instead of the testPayload itself.

Signed-off-by: Lee Skillen <lskillen@...>
---
.../src/gunittest/c/payload/fieldatomictests.cpp | 2 +-
.../gunittest/c/payload/payloadgeneraltests.cpp | 230 ++++++++++++++++++++-
2 files changed, 222 insertions(+), 10 deletions(-)

diff --git a/mama/c_cpp/src/gunittest/c/payload/fieldatomictests.cpp b/mama/c_cpp/src/gunittest/c/payload/fieldatomictests.cpp
index 933524a..22ea59b 100644
--- a/mama/c_cpp/src/gunittest/c/payload/fieldatomictests.cpp
+++ b/mama/c_cpp/src/gunittest/c/payload/fieldatomictests.cpp
@@ -126,7 +126,7 @@ TEST_F(FieldBoolTests, UpdateBoolInValid)
ret = aBridge->msgFieldPayloadUpdateBool(field, msg, m_update);
ASSERT_EQ (MAMA_STATUS_NULL_ARG, ret);

- ret = aBridge->msgPayloadDestroy(field);
+ ret = aBridge->msgFieldPayloadDestroy(field);
ASSERT_EQ (MAMA_STATUS_OK, ret);
}

diff --git a/mama/c_cpp/src/gunittest/c/payload/payloadgeneraltests.cpp b/mama/c_cpp/src/gunittest/c/payload/payloadgeneraltests.cpp
index ccaa470..c6780b2 100644
--- a/mama/c_cpp/src/gunittest/c/payload/payloadgeneraltests.cpp
+++ b/mama/c_cpp/src/gunittest/c/payload/payloadgeneraltests.cpp
@@ -25,6 +25,7 @@
#include "payloadbridge.h"
#include "msgimpl.h"
#include <set>
+#include <limits>
using std::cout;
using std::endl;

@@ -88,6 +89,217 @@ TEST_F(PayloadGeneralTests, CreateInValid)
EXPECT_EQ (MAMA_STATUS_NULL_ARG, result);
}

+TEST_F(PayloadGeneralTests, SerializeRoundtrip)
+{
+ msgPayload testPayload = NULL;
+ result = aBridge->msgPayloadCreate (&testPayload);
+ EXPECT_EQ (MAMA_STATUS_OK, result);
+
+ mama_bool_t b = 1;
+ char ch = 'V';
+ char chVector [] = {'A', 'B', 'C'};
+ mama_size_t chVectorSize = sizeof(chVector)/sizeof(chVector[0]);
+ const char* str = "LONG TEST STRING";
+ std::string s = "TEST";
+ mamaDateTime dt;
+ mamaPrice prc;
+ ASSERT_EQ (MAMA_STATUS_OK, mamaDateTime_create (&dt));
+ ASSERT_EQ (MAMA_STATUS_OK, mamaDateTime_setToNow (dt));
+ ASSERT_EQ (MAMA_STATUS_OK, mamaPrice_create (&prc));
+ ASSERT_EQ (MAMA_STATUS_OK, mamaPrice_setValue (prc, 17.79));
+
+ mama_fid_t orig_fid = 100;
+ mama_fid_t fid = orig_fid;
+ mama_status ret = MAMA_STATUS_OK;
+ ret = aBridge->msgPayloadAddBool (testPayload, "FirstNameOnly", ++fid, b);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ ret = aBridge->msgPayloadAddChar (testPayload, NULL, ++fid, ch);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ ret = aBridge->msgPayloadAddI8 (testPayload, NULL, ++fid, std::numeric_limits<mama_i8_t>::min ());
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ ret = aBridge->msgPayloadAddU8 (testPayload, NULL, ++fid, std::numeric_limits<mama_u8_t>::max ());
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ ret = aBridge->msgPayloadAddI16 (testPayload, NULL, ++fid, std::numeric_limits<mama_i16_t>::min ());
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ ret = aBridge->msgPayloadAddU16 (testPayload, NULL, ++fid, std::numeric_limits<mama_u16_t>::max ());
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ ret = aBridge->msgPayloadAddI32 (testPayload, NULL, ++fid, std::numeric_limits<mama_i32_t>::min ());
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ ret = aBridge->msgPayloadAddU32 (testPayload, NULL, ++fid, std::numeric_limits<mama_u32_t>::max ());
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ ret = aBridge->msgPayloadAddI64 (testPayload, NULL, ++fid, std::numeric_limits<mama_i64_t>::min ());
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ ret = aBridge->msgPayloadAddU64 (testPayload, NULL, ++fid, std::numeric_limits<mama_u64_t>::max ());
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ ret = aBridge->msgPayloadAddF32 (testPayload, NULL, ++fid, std::numeric_limits<mama_f32_t>::max ());
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ ret = aBridge->msgPayloadAddF64 (testPayload, NULL, ++fid, std::numeric_limits<mama_f64_t>::max ());
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ ret = aBridge->msgPayloadAddString (testPayload, NULL, ++fid, str);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ ret = aBridge->msgPayloadAddOpaque (testPayload, NULL, ++fid, (void*)s.data(), s.size());
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ ret = aBridge->msgPayloadAddDateTime (testPayload, NULL, ++fid, dt);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ ret = aBridge->msgPayloadAddPrice (testPayload, NULL, ++fid, prc);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ ret = aBridge->msgPayloadAddVectorChar (testPayload, NULL, ++fid, chVector,
+ chVectorSize);
+
+ bool hasVectors = (MAMA_STATUS_NOT_IMPLEMENTED != ret);
+ if (hasVectors)
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ else
+ --fid;
+
+ ret = aBridge->msgPayloadAddMsg (testPayload, NULL, ++fid, testPayload);
+
+ bool hasSubMessages = (MAMA_STATUS_NOT_IMPLEMENTED != ret);
+ if (hasSubMessages)
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ else
+ --fid;
+
+ mama_size_t numFieldsOut = 0;
+ ret = aBridge->msgPayloadGetNumFields (testPayload, &numFieldsOut);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (fid-orig_fid, numFieldsOut);
+
+ const void* buf = NULL;
+ mama_size_t bufSize = 0;
+ ret = aBridge->msgPayloadSerialize (testPayload, &buf, &bufSize);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_NE ((void*)NULL, buf);
+ EXPECT_NE (0, bufSize);
+
+ msgPayload testPayloadIn = NULL;
+ result = aBridge->msgPayloadCreate (&testPayloadIn);
+ EXPECT_EQ (MAMA_STATUS_OK, result);
+
+ ret = aBridge->msgPayloadUnSerialize (testPayloadIn, (const void**)buf, bufSize);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+
+ mama_size_t bs = 0;
+ ret = aBridge->msgPayloadGetByteSize (testPayloadIn, &bs);
+ if (ret != MAMA_STATUS_NOT_IMPLEMENTED)
+ {
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (bufSize, bs);
+ }
+
+ mama_size_t numFieldsIn = 0;
+ ret = aBridge->msgPayloadGetNumFields (testPayloadIn, &numFieldsIn);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (numFieldsOut, numFieldsIn);
+
+ mama_bool_t bIn = 0;
+ char chIn = '\0';
+ mama_i8_t i8In = 0;
+ mama_u8_t u8In = 0;
+ mama_i16_t i16In = 0;
+ mama_u16_t u16In = 0;
+ mama_i32_t i32In = 0;
+ mama_u32_t u32In = 0;
+ mama_i64_t i64In = 0;
+ mama_u64_t u64In = 0;
+ mama_f32_t f32In = 0;
+ mama_f64_t f64In = 0;
+ const char* strIn = "";
+ void* bufIn = NULL;
+ mama_size_t bufInSize = 0;
+ mamaDateTime dtIn;
+ mamaPrice prcIn;
+ ASSERT_EQ (MAMA_STATUS_OK, mamaDateTime_create (&dtIn));
+ ASSERT_EQ (MAMA_STATUS_OK, mamaPrice_create (&prcIn));
+
+ fid = orig_fid;
+ ret = aBridge->msgPayloadGetBool (testPayloadIn, NULL, ++fid, &bIn);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (b, bIn);
+ ret = aBridge->msgPayloadGetChar (testPayloadIn, NULL, ++fid, &chIn);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (ch, chIn);
+ ret = aBridge->msgPayloadGetI8 (testPayloadIn, NULL, ++fid, &i8In);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (std::numeric_limits<mama_i8_t>::min (), i8In);
+ ret = aBridge->msgPayloadGetU8 (testPayloadIn, NULL, ++fid, &u8In);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (std::numeric_limits<mama_u8_t>::max (), u8In);
+ ret = aBridge->msgPayloadGetI16 (testPayloadIn, NULL, ++fid, &i16In);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (std::numeric_limits<mama_i16_t>::min (), i16In);
+ ret = aBridge->msgPayloadGetU16 (testPayloadIn, NULL, ++fid, &u16In);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (std::numeric_limits<mama_u16_t>::max (), u16In);
+ ret = aBridge->msgPayloadGetI32 (testPayloadIn, NULL, ++fid, &i32In);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (std::numeric_limits<mama_i32_t>::min (), i32In);
+ ret = aBridge->msgPayloadGetU32 (testPayloadIn, NULL, ++fid, &u32In);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (std::numeric_limits<mama_u32_t>::max (), u32In);
+ ret = aBridge->msgPayloadGetI64 (testPayloadIn, NULL, ++fid, &i64In);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (std::numeric_limits<mama_i64_t>::min (), i64In);
+ ret = aBridge->msgPayloadGetU64 (testPayloadIn, NULL, ++fid, &u64In);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (std::numeric_limits<mama_u64_t>::max (), u64In);
+ ret = aBridge->msgPayloadGetF32 (testPayloadIn, NULL, ++fid, &f32In);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (std::numeric_limits<mama_f32_t>::max (), f32In);
+ ret = aBridge->msgPayloadGetF64 (testPayloadIn, NULL, ++fid, &f64In);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (std::numeric_limits<mama_f64_t>::max (), f64In);
+ ret = aBridge->msgPayloadGetString (testPayloadIn, NULL, ++fid, &strIn);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_STREQ (str, strIn);
+ ret = aBridge->msgPayloadGetOpaque (testPayloadIn, NULL, ++fid, (const void**)&bufIn, &bufInSize);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (0, memcmp (s.data(), bufIn, bufInSize));
+ EXPECT_EQ (s.size(), bufInSize);
+ ret = aBridge->msgPayloadGetDateTime (testPayload, NULL, ++fid, dtIn);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (1, mamaDateTime_equal (dt, dtIn));
+ ret = aBridge->msgPayloadGetPrice (testPayloadIn, NULL, ++fid, prcIn);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (1, mamaPrice_equal (prc, prcIn));
+
+ if (hasVectors)
+ {
+ const char* chVectorIn = NULL;
+ mama_size_t chVectorInSize = 0;
+ ret = aBridge->msgPayloadGetVectorChar (testPayloadIn, NULL, ++fid, &chVectorIn,
+ &chVectorInSize);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (chVectorSize, chVectorInSize);
+ for (mama_size_t k = 0; k < chVectorInSize; ++k)
+ {
+ EXPECT_EQ (chVector[k], chVectorIn[k]);
+ }
+ }
+
+ if (hasSubMessages)
+ {
+ msgPayload testPayloadInSub = NULL;
+ ret = aBridge->msgPayloadGetMsg (testPayloadIn, NULL, ++fid, &testPayloadInSub);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+
+ mama_size_t numFieldsInSub = 0;
+ ret = aBridge->msgPayloadGetNumFields (testPayloadInSub, &numFieldsInSub);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (fid-orig_fid-1, numFieldsInSub);
+
+ EXPECT_EQ (MAMA_STATUS_OK, aBridge->msgPayloadDestroy (testPayloadInSub));
+ }
+
+ EXPECT_EQ (MAMA_STATUS_OK, mamaDateTime_destroy (dt));
+ EXPECT_EQ (MAMA_STATUS_OK, mamaDateTime_destroy (dtIn));
+ EXPECT_EQ (MAMA_STATUS_OK, mamaPrice_destroy (prc));
+ EXPECT_EQ (MAMA_STATUS_OK, mamaPrice_destroy (prcIn));
+
+ EXPECT_EQ (MAMA_STATUS_OK, aBridge->msgPayloadDestroy (testPayload));
+ EXPECT_EQ (MAMA_STATUS_OK, aBridge->msgPayloadDestroy (testPayloadIn));
+}
+
/* OPTIONAL TEST:
* Since a large proportion of middlewares don't use templates, this functionality
* isn't required.
@@ -504,7 +716,7 @@ TEST_F(PayloadGeneralTests, SerializeValid)
TEST_F(PayloadGeneralTests, SerializeInValidPayLoad)
{
msgPayload testPayload = NULL;
- char* testBuffer;
+ char* testBuffer = NULL;
mama_size_t testBufferLength = 0;

result = aBridge->msgPayloadCreate(&testPayload);
@@ -679,7 +891,7 @@ TEST_F(PayloadGeneralTests, GetByteBufferInValidBufferLength)
TEST_F(PayloadGeneralTests, SetByteBufferValid)
{
msgPayload testPayload = NULL;
- const char* testBuffer;
+ const char* testBuffer = NULL;
mama_size_t testBufferLength = 100;

result = aBridge->msgPayloadCreate(&testPayload);
@@ -696,27 +908,27 @@ TEST_F(PayloadGeneralTests, SetByteBufferValid)
result = aBridge->msgPayloadCreateFromByteBuffer(&testPayload, aBridge, (const void*)testBuffer, testBufferLength);
EXPECT_EQ (MAMA_STATUS_OK, result);

- result = aBridge->msgPayloadSetByteBuffer(&testPayload, aBridge, &testBuffer, testBufferLength);
+ result = aBridge->msgPayloadSetByteBuffer(testPayload, aBridge, (const void**)testBuffer, testBufferLength);
EXPECT_EQ (MAMA_STATUS_OK, result);
}

TEST_F(PayloadGeneralTests, SetByteBufferInValidPayload)
{
msgPayload testPayload = NULL;
- const char* testBuffer;
+ const char* testBuffer = NULL;
mama_size_t testBufferLength = 0;

result = aBridge->msgPayloadCreate(&testPayload);
EXPECT_EQ (MAMA_STATUS_OK, result);

- result = aBridge->msgPayloadSetByteBuffer(NULL, aBridge, &testBuffer, testBufferLength);
+ result = aBridge->msgPayloadSetByteBuffer(NULL, aBridge, (const void**)testBuffer, testBufferLength);
EXPECT_EQ (MAMA_STATUS_NULL_ARG, result);
}

TEST_F(PayloadGeneralTests, SetByteBufferInValidBridge)
{
msgPayload testPayload = NULL;
- const char* testBuffer;
+ const char* testBuffer = NULL;
mama_size_t testBufferLength = 0;

result = aBridge->msgPayloadCreate(&testPayload);
@@ -727,7 +939,7 @@ TEST_F(PayloadGeneralTests, SetByteBufferInValidBridge)
aBridge->msgPayloadAddString (testPayload, "name4", 104, "Is");
aBridge->msgPayloadAddString (testPayload, "name5", 105, "Fun");

- result = aBridge->msgPayloadSetByteBuffer(&testPayload, NULL, &testBuffer, testBufferLength);
+ result = aBridge->msgPayloadSetByteBuffer(&testPayload, NULL, (const void**)testBuffer, testBufferLength);
EXPECT_EQ (MAMA_STATUS_NULL_ARG, result);
}

@@ -746,7 +958,7 @@ TEST_F(PayloadGeneralTests, SetByteBufferInValidBuffer)
TEST_F(PayloadGeneralTests, SetByteBufferInValidBufferLength)
{
msgPayload testPayload = NULL;
- const char* testBuffer;
+ const char* testBuffer = NULL;

result = aBridge->msgPayloadCreate(&testPayload);
EXPECT_EQ (MAMA_STATUS_OK, result);
@@ -756,7 +968,7 @@ TEST_F(PayloadGeneralTests, SetByteBufferInValidBufferLength)
aBridge->msgPayloadAddString (testPayload, "name4", 101, "Is");
aBridge->msgPayloadAddString (testPayload, "name5", 101, "Fun");

- result = aBridge->msgPayloadSetByteBuffer(&testPayload, aBridge, &testBuffer, 0);
+ result = aBridge->msgPayloadSetByteBuffer(&testPayload, aBridge, (const void**)testBuffer, 0);
EXPECT_EQ (MAMA_STATUS_NULL_ARG, result);
}

--
1.9.0


Damian Maguire <DMaguire@...>
 

Hey Lee,

I've raised this to Bugzilla for tracking. Ticket Number:
http://bugs.openmama.org/show_bug.cgi?id=74

Cheers,

Damian



On 3/5/14 4:45 PM, "Lee Skillen" <lskillen@...> wrote:

- The roundtrip serialization unit test constructs a reasonably
representative payload with most of the payload types - It then
serialises and unserialises this into a second payload and then
extracts the field data for comparison against the egress payload.

- The wrong destroy function was being called in UpdateBoolInValid.

- Some of the unit tests that utilised setByteBuffer() were passing the
buffer in incorrectly (probably caused by the signature requiring a
const void** instead of a const void* which it should be).

- The setByteBuffer() call in SetByteBufferValid was passing address-of
testPayload instead of the testPayload itself.

Signed-off-by: Lee Skillen <lskillen@...>
---
.../src/gunittest/c/payload/fieldatomictests.cpp | 2 +-
.../gunittest/c/payload/payloadgeneraltests.cpp | 230
++++++++++++++++++++-
2 files changed, 222 insertions(+), 10 deletions(-)

diff --git a/mama/c_cpp/src/gunittest/c/payload/fieldatomictests.cpp
b/mama/c_cpp/src/gunittest/c/payload/fieldatomictests.cpp
index 933524a..22ea59b 100644
--- a/mama/c_cpp/src/gunittest/c/payload/fieldatomictests.cpp
+++ b/mama/c_cpp/src/gunittest/c/payload/fieldatomictests.cpp
@@ -126,7 +126,7 @@ TEST_F(FieldBoolTests, UpdateBoolInValid)
ret = aBridge->msgFieldPayloadUpdateBool(field, msg, m_update);
ASSERT_EQ (MAMA_STATUS_NULL_ARG, ret);

- ret = aBridge->msgPayloadDestroy(field);
+ ret = aBridge->msgFieldPayloadDestroy(field);
ASSERT_EQ (MAMA_STATUS_OK, ret);
}

diff --git a/mama/c_cpp/src/gunittest/c/payload/payloadgeneraltests.cpp
b/mama/c_cpp/src/gunittest/c/payload/payloadgeneraltests.cpp
index ccaa470..c6780b2 100644
--- a/mama/c_cpp/src/gunittest/c/payload/payloadgeneraltests.cpp
+++ b/mama/c_cpp/src/gunittest/c/payload/payloadgeneraltests.cpp
@@ -25,6 +25,7 @@
#include "payloadbridge.h"
#include "msgimpl.h"
#include <set>
+#include <limits>
using std::cout;
using std::endl;

@@ -88,6 +89,217 @@ TEST_F(PayloadGeneralTests, CreateInValid)
EXPECT_EQ (MAMA_STATUS_NULL_ARG, result);
}

+TEST_F(PayloadGeneralTests, SerializeRoundtrip)
+{
+ msgPayload testPayload = NULL;
+ result = aBridge->msgPayloadCreate (&testPayload);
+ EXPECT_EQ (MAMA_STATUS_OK, result);
+
+ mama_bool_t b = 1;
+ char ch = 'V';
+ char chVector [] = {'A', 'B', 'C'};
+ mama_size_t chVectorSize = sizeof(chVector)/sizeof(chVector[0]);
+ const char* str = "LONG TEST STRING";
+ std::string s = "TEST";
+ mamaDateTime dt;
+ mamaPrice prc;
+ ASSERT_EQ (MAMA_STATUS_OK, mamaDateTime_create (&dt));
+ ASSERT_EQ (MAMA_STATUS_OK, mamaDateTime_setToNow (dt));
+ ASSERT_EQ (MAMA_STATUS_OK, mamaPrice_create (&prc));
+ ASSERT_EQ (MAMA_STATUS_OK, mamaPrice_setValue (prc, 17.79));
+
+ mama_fid_t orig_fid = 100;
+ mama_fid_t fid = orig_fid;
+ mama_status ret = MAMA_STATUS_OK;
+ ret = aBridge->msgPayloadAddBool (testPayload, "FirstNameOnly",
++fid, b);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ ret = aBridge->msgPayloadAddChar (testPayload, NULL, ++fid, ch);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ ret = aBridge->msgPayloadAddI8 (testPayload, NULL, ++fid,
std::numeric_limits<mama_i8_t>::min ());
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ ret = aBridge->msgPayloadAddU8 (testPayload, NULL, ++fid,
std::numeric_limits<mama_u8_t>::max ());
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ ret = aBridge->msgPayloadAddI16 (testPayload, NULL, ++fid,
std::numeric_limits<mama_i16_t>::min ());
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ ret = aBridge->msgPayloadAddU16 (testPayload, NULL, ++fid,
std::numeric_limits<mama_u16_t>::max ());
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ ret = aBridge->msgPayloadAddI32 (testPayload, NULL, ++fid,
std::numeric_limits<mama_i32_t>::min ());
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ ret = aBridge->msgPayloadAddU32 (testPayload, NULL, ++fid,
std::numeric_limits<mama_u32_t>::max ());
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ ret = aBridge->msgPayloadAddI64 (testPayload, NULL, ++fid,
std::numeric_limits<mama_i64_t>::min ());
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ ret = aBridge->msgPayloadAddU64 (testPayload, NULL, ++fid,
std::numeric_limits<mama_u64_t>::max ());
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ ret = aBridge->msgPayloadAddF32 (testPayload, NULL, ++fid,
std::numeric_limits<mama_f32_t>::max ());
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ ret = aBridge->msgPayloadAddF64 (testPayload, NULL, ++fid,
std::numeric_limits<mama_f64_t>::max ());
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ ret = aBridge->msgPayloadAddString (testPayload, NULL, ++fid, str);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ ret = aBridge->msgPayloadAddOpaque (testPayload, NULL, ++fid,
(void*)s.data(), s.size());
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ ret = aBridge->msgPayloadAddDateTime (testPayload, NULL, ++fid, dt);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ ret = aBridge->msgPayloadAddPrice (testPayload, NULL, ++fid, prc);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ ret = aBridge->msgPayloadAddVectorChar (testPayload, NULL, ++fid,
chVector,
+ chVectorSize);
+
+ bool hasVectors = (MAMA_STATUS_NOT_IMPLEMENTED != ret);
+ if (hasVectors)
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ else
+ --fid;
+
+ ret = aBridge->msgPayloadAddMsg (testPayload, NULL, ++fid,
testPayload);
+
+ bool hasSubMessages = (MAMA_STATUS_NOT_IMPLEMENTED != ret);
+ if (hasSubMessages)
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ else
+ --fid;
+
+ mama_size_t numFieldsOut = 0;
+ ret = aBridge->msgPayloadGetNumFields (testPayload, &numFieldsOut);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (fid-orig_fid, numFieldsOut);
+
+ const void* buf = NULL;
+ mama_size_t bufSize = 0;
+ ret = aBridge->msgPayloadSerialize (testPayload, &buf, &bufSize);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_NE ((void*)NULL, buf);
+ EXPECT_NE (0, bufSize);
+
+ msgPayload testPayloadIn = NULL;
+ result = aBridge->msgPayloadCreate (&testPayloadIn);
+ EXPECT_EQ (MAMA_STATUS_OK, result);
+
+ ret = aBridge->msgPayloadUnSerialize (testPayloadIn, (const
void**)buf, bufSize);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+
+ mama_size_t bs = 0;
+ ret = aBridge->msgPayloadGetByteSize (testPayloadIn, &bs);
+ if (ret != MAMA_STATUS_NOT_IMPLEMENTED)
+ {
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (bufSize, bs);
+ }
+
+ mama_size_t numFieldsIn = 0;
+ ret = aBridge->msgPayloadGetNumFields (testPayloadIn, &numFieldsIn);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (numFieldsOut, numFieldsIn);
+
+ mama_bool_t bIn = 0;
+ char chIn = '\0';
+ mama_i8_t i8In = 0;
+ mama_u8_t u8In = 0;
+ mama_i16_t i16In = 0;
+ mama_u16_t u16In = 0;
+ mama_i32_t i32In = 0;
+ mama_u32_t u32In = 0;
+ mama_i64_t i64In = 0;
+ mama_u64_t u64In = 0;
+ mama_f32_t f32In = 0;
+ mama_f64_t f64In = 0;
+ const char* strIn = "";
+ void* bufIn = NULL;
+ mama_size_t bufInSize = 0;
+ mamaDateTime dtIn;
+ mamaPrice prcIn;
+ ASSERT_EQ (MAMA_STATUS_OK, mamaDateTime_create (&dtIn));
+ ASSERT_EQ (MAMA_STATUS_OK, mamaPrice_create (&prcIn));
+
+ fid = orig_fid;
+ ret = aBridge->msgPayloadGetBool (testPayloadIn, NULL, ++fid, &bIn);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (b, bIn);
+ ret = aBridge->msgPayloadGetChar (testPayloadIn, NULL, ++fid, &chIn);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (ch, chIn);
+ ret = aBridge->msgPayloadGetI8 (testPayloadIn, NULL, ++fid, &i8In);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (std::numeric_limits<mama_i8_t>::min (), i8In);
+ ret = aBridge->msgPayloadGetU8 (testPayloadIn, NULL, ++fid, &u8In);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (std::numeric_limits<mama_u8_t>::max (), u8In);
+ ret = aBridge->msgPayloadGetI16 (testPayloadIn, NULL, ++fid, &i16In);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (std::numeric_limits<mama_i16_t>::min (), i16In);
+ ret = aBridge->msgPayloadGetU16 (testPayloadIn, NULL, ++fid, &u16In);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (std::numeric_limits<mama_u16_t>::max (), u16In);
+ ret = aBridge->msgPayloadGetI32 (testPayloadIn, NULL, ++fid, &i32In);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (std::numeric_limits<mama_i32_t>::min (), i32In);
+ ret = aBridge->msgPayloadGetU32 (testPayloadIn, NULL, ++fid, &u32In);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (std::numeric_limits<mama_u32_t>::max (), u32In);
+ ret = aBridge->msgPayloadGetI64 (testPayloadIn, NULL, ++fid, &i64In);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (std::numeric_limits<mama_i64_t>::min (), i64In);
+ ret = aBridge->msgPayloadGetU64 (testPayloadIn, NULL, ++fid, &u64In);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (std::numeric_limits<mama_u64_t>::max (), u64In);
+ ret = aBridge->msgPayloadGetF32 (testPayloadIn, NULL, ++fid, &f32In);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (std::numeric_limits<mama_f32_t>::max (), f32In);
+ ret = aBridge->msgPayloadGetF64 (testPayloadIn, NULL, ++fid, &f64In);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (std::numeric_limits<mama_f64_t>::max (), f64In);
+ ret = aBridge->msgPayloadGetString (testPayloadIn, NULL, ++fid,
&strIn);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_STREQ (str, strIn);
+ ret = aBridge->msgPayloadGetOpaque (testPayloadIn, NULL, ++fid,
(const void**)&bufIn, &bufInSize);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (0, memcmp (s.data(), bufIn, bufInSize));
+ EXPECT_EQ (s.size(), bufInSize);
+ ret = aBridge->msgPayloadGetDateTime (testPayload, NULL, ++fid,
dtIn);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (1, mamaDateTime_equal (dt, dtIn));
+ ret = aBridge->msgPayloadGetPrice (testPayloadIn, NULL, ++fid,
prcIn);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (1, mamaPrice_equal (prc, prcIn));
+
+ if (hasVectors)
+ {
+ const char* chVectorIn = NULL;
+ mama_size_t chVectorInSize = 0;
+ ret = aBridge->msgPayloadGetVectorChar (testPayloadIn, NULL,
++fid, &chVectorIn,
+ &chVectorInSize);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (chVectorSize, chVectorInSize);
+ for (mama_size_t k = 0; k < chVectorInSize; ++k)
+ {
+ EXPECT_EQ (chVector[k], chVectorIn[k]);
+ }
+ }
+
+ if (hasSubMessages)
+ {
+ msgPayload testPayloadInSub = NULL;
+ ret = aBridge->msgPayloadGetMsg (testPayloadIn, NULL, ++fid,
&testPayloadInSub);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+
+ mama_size_t numFieldsInSub = 0;
+ ret = aBridge->msgPayloadGetNumFields (testPayloadInSub,
&numFieldsInSub);
+ EXPECT_EQ (MAMA_STATUS_OK, ret);
+ EXPECT_EQ (fid-orig_fid-1, numFieldsInSub);
+
+ EXPECT_EQ (MAMA_STATUS_OK, aBridge->msgPayloadDestroy
(testPayloadInSub));
+ }
+
+ EXPECT_EQ (MAMA_STATUS_OK, mamaDateTime_destroy (dt));
+ EXPECT_EQ (MAMA_STATUS_OK, mamaDateTime_destroy (dtIn));
+ EXPECT_EQ (MAMA_STATUS_OK, mamaPrice_destroy (prc));
+ EXPECT_EQ (MAMA_STATUS_OK, mamaPrice_destroy (prcIn));
+
+ EXPECT_EQ (MAMA_STATUS_OK, aBridge->msgPayloadDestroy (testPayload));
+ EXPECT_EQ (MAMA_STATUS_OK, aBridge->msgPayloadDestroy
(testPayloadIn));
+}
+
/* OPTIONAL TEST:
* Since a large proportion of middlewares don't use templates, this
functionality
* isn't required.
@@ -504,7 +716,7 @@ TEST_F(PayloadGeneralTests, SerializeValid)
TEST_F(PayloadGeneralTests, SerializeInValidPayLoad)
{
msgPayload testPayload = NULL;
- char* testBuffer;
+ char* testBuffer = NULL;
mama_size_t testBufferLength = 0;

result = aBridge->msgPayloadCreate(&testPayload);
@@ -679,7 +891,7 @@ TEST_F(PayloadGeneralTests,
GetByteBufferInValidBufferLength)
TEST_F(PayloadGeneralTests, SetByteBufferValid)
{
msgPayload testPayload = NULL;
- const char* testBuffer;
+ const char* testBuffer = NULL;
mama_size_t testBufferLength = 100;

result = aBridge->msgPayloadCreate(&testPayload);
@@ -696,27 +908,27 @@ TEST_F(PayloadGeneralTests, SetByteBufferValid)
result = aBridge->msgPayloadCreateFromByteBuffer(&testPayload, aBridge,
(const void*)testBuffer, testBufferLength);
EXPECT_EQ (MAMA_STATUS_OK, result);

- result = aBridge->msgPayloadSetByteBuffer(&testPayload, aBridge,
&testBuffer, testBufferLength);
+ result = aBridge->msgPayloadSetByteBuffer(testPayload, aBridge,
(const void**)testBuffer, testBufferLength);
EXPECT_EQ (MAMA_STATUS_OK, result);
}

TEST_F(PayloadGeneralTests, SetByteBufferInValidPayload)
{
msgPayload testPayload = NULL;
- const char* testBuffer;
+ const char* testBuffer = NULL;
mama_size_t testBufferLength = 0;

result = aBridge->msgPayloadCreate(&testPayload);
EXPECT_EQ (MAMA_STATUS_OK, result);

- result = aBridge->msgPayloadSetByteBuffer(NULL, aBridge,
&testBuffer, testBufferLength);
+ result = aBridge->msgPayloadSetByteBuffer(NULL, aBridge, (const
void**)testBuffer, testBufferLength);
EXPECT_EQ (MAMA_STATUS_NULL_ARG, result);
}

TEST_F(PayloadGeneralTests, SetByteBufferInValidBridge)
{
msgPayload testPayload = NULL;
- const char* testBuffer;
+ const char* testBuffer = NULL;
mama_size_t testBufferLength = 0;

result = aBridge->msgPayloadCreate(&testPayload);
@@ -727,7 +939,7 @@ TEST_F(PayloadGeneralTests,
SetByteBufferInValidBridge)
aBridge->msgPayloadAddString (testPayload, "name4", 104, "Is");
aBridge->msgPayloadAddString (testPayload, "name5", 105, "Fun");

- result = aBridge->msgPayloadSetByteBuffer(&testPayload, NULL,
&testBuffer, testBufferLength);
+ result = aBridge->msgPayloadSetByteBuffer(&testPayload, NULL, (const
void**)testBuffer, testBufferLength);
EXPECT_EQ (MAMA_STATUS_NULL_ARG, result);
}

@@ -746,7 +958,7 @@ TEST_F(PayloadGeneralTests,
SetByteBufferInValidBuffer)
TEST_F(PayloadGeneralTests, SetByteBufferInValidBufferLength)
{
msgPayload testPayload = NULL;
- const char* testBuffer;
+ const char* testBuffer = NULL;

result = aBridge->msgPayloadCreate(&testPayload);
EXPECT_EQ (MAMA_STATUS_OK, result);
@@ -756,7 +968,7 @@ TEST_F(PayloadGeneralTests,
SetByteBufferInValidBufferLength)
aBridge->msgPayloadAddString (testPayload, "name4", 101, "Is");
aBridge->msgPayloadAddString (testPayload, "name5", 101, "Fun");

- result = aBridge->msgPayloadSetByteBuffer(&testPayload, aBridge,
&testBuffer, 0);
+ result = aBridge->msgPayloadSetByteBuffer(&testPayload, aBridge,
(const void**)testBuffer, 0);
EXPECT_EQ (MAMA_STATUS_NULL_ARG, result);
}

--
1.9.0
________________________________________________________

This message may contain confidential information and is intended for specific recipients unless explicitly noted otherwise. If you have reason to believe you are not an intended recipient of this message, please delete it and notify the sender. This message may not represent the opinion of IntercontinentalExchange Group, Inc. (ICE), NYSE Euronext or any of their subsidiaries or affiliates, and does not constitute a contract or guarantee. Unencrypted electronic mail is not secure and the recipient of this message is expected to provide safeguards from viruses and pursue alternate means of communication where privacy or a binding message is desired.
________________________________________________________