[PATCH 2.3.1 4/5] MAMA: Update gunittest for completed support of Vector Bool and Vectar Char.


Alireza Assadzadeh <Alireza.Assadzadeh@...>
 

Signed-off-by: Alireza Assadzadeh <Alireza.Assadzadeh@solacesystems.com>
---
.../gunittest/c/fieldcache/fieldcachefieldtest.cpp | 60 ++++++++++++++++
.../gunittest/c/mamamsg/msgfieldvectortests.cpp | 29 +++++---
.../src/gunittest/c/mamamsg/msgvectortests.cpp | 2 +-
.../src/gunittest/c/payload/fieldvectortests.cpp | 9 ++-
.../fieldcache/MamaFieldCacheFieldTypesTest.cpp | 80 ++++++++++++++++++++++
5 files changed, 168 insertions(+), 12 deletions(-)

diff --git a/mama/c_cpp/src/gunittest/c/fieldcache/fieldcachefieldtest.cpp b/mama/c_cpp/src/gunittest/c/fieldcache/fieldcachefieldtest.cpp
index 124c5b6..0b65f2b 100644
--- a/mama/c_cpp/src/gunittest/c/fieldcache/fieldcachefieldtest.cpp
+++ b/mama/c_cpp/src/gunittest/c/fieldcache/fieldcachefieldtest.cpp
@@ -662,6 +662,66 @@ TEST_F(MamaFieldCacheFieldTestC, testSetGetI8Vector)
DESTROY_FIELD
}

+TEST_F(MamaFieldCacheFieldTestC, testSetGetBoolVector)
+{
+ //TODO: AA: Change u8 test
+ const mama_u8_t* retValue = NULL;
+ mama_size_t retSize;
+ mama_u8_t dataVector[3] = { 1, 2, 3 };
+
+ CREATE_FIELD(1, MAMA_FIELD_TYPE_VECTOR_U8)
+
+ // Adding only 2 fields
+ ASSERT_EQ(MAMA_STATUS_OK, mamaFieldCacheField_setU8Vector(field, dataVector, 2));
+ ASSERT_EQ(MAMA_STATUS_OK, mamaFieldCacheField_getU8Vector(field, &retValue, &retSize));
+ ASSERT_EQ(2, retSize);
+ ASSERT_TRUE(retValue);
+ ASSERT_EQ(1, retValue[0]);
+ ASSERT_EQ(2, retValue[1]);
+
+ dataVector[0] = 10;
+ ASSERT_EQ(MAMA_STATUS_OK, mamaFieldCacheField_setU8Vector(field, dataVector, 3));
+ ASSERT_EQ(MAMA_STATUS_OK, mamaFieldCacheField_getU8Vector(field, &retValue, &retSize));
+
+ ASSERT_EQ(3, retSize);
+ ASSERT_TRUE(retValue);
+ ASSERT_EQ(10, retValue[0]);
+ ASSERT_EQ(2, retValue[1]);
+ ASSERT_EQ(3, retValue[2]);
+
+ DESTROY_FIELD
+}
+
+TEST_F(MamaFieldCacheFieldTestC, testSetGetCharVector)
+{
+ //TODO: AA: Change u8 test
+ const mama_u8_t* retValue = NULL;
+ mama_size_t retSize;
+ mama_u8_t dataVector[3] = { 1, 2, 3 };
+
+ CREATE_FIELD(1, MAMA_FIELD_TYPE_VECTOR_U8)
+
+ // Adding only 2 fields
+ ASSERT_EQ(MAMA_STATUS_OK, mamaFieldCacheField_setU8Vector(field, dataVector, 2));
+ ASSERT_EQ(MAMA_STATUS_OK, mamaFieldCacheField_getU8Vector(field, &retValue, &retSize));
+ ASSERT_EQ(2, retSize);
+ ASSERT_TRUE(retValue);
+ ASSERT_EQ(1, retValue[0]);
+ ASSERT_EQ(2, retValue[1]);
+
+ dataVector[0] = 10;
+ ASSERT_EQ(MAMA_STATUS_OK, mamaFieldCacheField_setU8Vector(field, dataVector, 3));
+ ASSERT_EQ(MAMA_STATUS_OK, mamaFieldCacheField_getU8Vector(field, &retValue, &retSize));
+
+ ASSERT_EQ(3, retSize);
+ ASSERT_TRUE(retValue);
+ ASSERT_EQ(10, retValue[0]);
+ ASSERT_EQ(2, retValue[1]);
+ ASSERT_EQ(3, retValue[2]);
+
+ DESTROY_FIELD
+}
+
TEST_F(MamaFieldCacheFieldTestC, testSetGetU8Vector)
{
const mama_u8_t* retValue = NULL;
diff --git a/mama/c_cpp/src/gunittest/c/mamamsg/msgfieldvectortests.cpp b/mama/c_cpp/src/gunittest/c/mamamsg/msgfieldvectortests.cpp
index 7d690e1..874bcd9 100644
--- a/mama/c_cpp/src/gunittest/c/mamamsg/msgfieldvectortests.cpp
+++ b/mama/c_cpp/src/gunittest/c/mamamsg/msgfieldvectortests.cpp
@@ -78,14 +78,16 @@ protected:
MsgFieldVectorBoolTests()
: mOut(NULL)
{
- mIn[0] = 1;
- mIn[1] = 2;
+ mIn[0] = 0;
+ mIn[1] = 1;
}

virtual void SetUp()
{
MsgFieldVectorTestsC::SetUp();

+ mamaMsg_addVectorBool (mMsg, NULL, 1, mIn, VECTOR_SIZE);
+
mOut = NULL;
}

@@ -100,21 +102,32 @@ protected:
* ****************************************************************************
*/

-TEST_F(MsgFieldVectorBoolTests, DISABLED_GetVectorBool)
+TEST_F(MsgFieldVectorBoolTests, GetVectorBool)
{
- /* getVectorBool is declared in msgfield.h but not defined */
+ mStatus = mamaMsg_getField (mMsg, NULL, 1, &mField);
+ ASSERT_EQ (mStatus, MAMA_STATUS_OK) << "Failed getting field";
+ mStatus = mamaMsgField_getVectorBool (mField, &mOut, &mSize);
+ ASSERT_EQ (mStatus, MAMA_STATUS_OK) << "Failed getting Vector Bool";
+ EXPECT_EQ (0, mOut[0]);
+ EXPECT_EQ (1, mOut[1]);
+ EXPECT_EQ (VECTOR_SIZE, mSize);
}

TEST_F(MsgFieldVectorBoolTests, DISABLED_GetVectorBoolNullField)
{
- /* getVectorBool is declared in msgfield.h but not defined */
+ mStatus = mamaMsgField_getVectorBool (NULL, &mOut, &mSize);
+ EXPECT_EQ (MAMA_STATUS_NULL_ARG, mStatus);
}

-TEST_F(MsgFieldVectorBoolTests, DISABLED_GetVectorBoolNullVector)
+TEST_F(MsgFieldVectorBoolTests, GetVectorBoolNullVector)
{
- /* getVectorBool is declared in msgfield.h but not defined */
+ mStatus = mamaMsg_getField (mMsg, NULL, 1, &mField);
+ ASSERT_EQ (MAMA_STATUS_OK, mStatus) << "Failed getting field";
+ mStatus = mamaMsgField_getVectorBool (mField, NULL, &mSize);
+ EXPECT_EQ (MAMA_STATUS_NULL_ARG, mStatus);
}

+
/*
* CHAR TEST SUITE
* ****************************************************************************
@@ -168,7 +181,7 @@ TEST_F(MsgFieldVectorCharTests, DISABLED_GetVectorCharNullField)
EXPECT_EQ (mStatus, MAMA_STATUS_NULL_ARG);
}

-TEST_F(MsgFieldVectorCharTests, DISABLED_GetVectorCharNullVector)
+TEST_F(MsgFieldVectorCharTests, GetVectorCharNullVector)
{
mamaMsg_getField (mMsg, NULL, 1, &mField);
mStatus = mamaMsgField_getVectorChar (mField, NULL, &mSize);
diff --git a/mama/c_cpp/src/gunittest/c/mamamsg/msgvectortests.cpp b/mama/c_cpp/src/gunittest/c/mamamsg/msgvectortests.cpp
index 8cd03b9..b72fa68 100644
--- a/mama/c_cpp/src/gunittest/c/mamamsg/msgvectortests.cpp
+++ b/mama/c_cpp/src/gunittest/c/mamamsg/msgvectortests.cpp
@@ -125,7 +125,7 @@ TEST_F(MsgVectorBoolTestsC, AddVectorBool)
&mOutSize);

EXPECT_EQ( mStatus, MAMA_STATUS_OK );
- // EXPECT_EQ( 0, ::memcmp( mIn, mOut, (sizeof(mama_bool_t) * VECTOR_SIZE) ) );
+ EXPECT_EQ( 0, ::memcmp( mIn, mOut, (sizeof(mama_bool_t) * VECTOR_SIZE) ) );
EXPECT_EQ( mOutSize, VECTOR_SIZE );
}

diff --git a/mama/c_cpp/src/gunittest/c/payload/fieldvectortests.cpp b/mama/c_cpp/src/gunittest/c/payload/fieldvectortests.cpp
index 9c701c8..4429347 100644
--- a/mama/c_cpp/src/gunittest/c/payload/fieldvectortests.cpp
+++ b/mama/c_cpp/src/gunittest/c/payload/fieldvectortests.cpp
@@ -118,19 +118,22 @@ TEST_F(FieldVectorBoolTests, GetVectorBool)
{
m_payloadBridge->msgPayloadGetField (m_msg, NULL, 1, &m_field);
m_status = m_payloadBridge->msgFieldPayloadGetVectorBool(m_field, &m_out, &m_size);
- ASSERT_EQ (MAMA_STATUS_NOT_IMPLEMENTED, m_status);
+ ASSERT_EQ (MAMA_STATUS_OK, m_status);
+ ASSERT_EQ (1, m_out[0]);
+ ASSERT_EQ (0, m_out[1]);
+ ASSERT_EQ ((mama_size_t) VECTOR_SIZE * sizeof(mama_bool_t), m_size);
}

TEST_F(FieldVectorBoolTests, GetVectorBoolNullOut)
{
m_status = m_payloadBridge->msgFieldPayloadGetVectorBool(m_field, NULL, &m_size);
- ASSERT_EQ (MAMA_STATUS_NOT_IMPLEMENTED, m_status);
+ ASSERT_EQ (MAMA_STATUS_NULL_ARG, m_status);
}

TEST_F(FieldVectorBoolTests, GetVectorBoolNullSize)
{
m_status = m_payloadBridge->msgFieldPayloadGetVectorBool(m_field, &m_out, NULL);
- ASSERT_EQ (MAMA_STATUS_NOT_IMPLEMENTED, m_status);
+ ASSERT_EQ (MAMA_STATUS_NULL_ARG, m_status);
}

/**
diff --git a/mama/c_cpp/src/gunittest/cpp/fieldcache/MamaFieldCacheFieldTypesTest.cpp b/mama/c_cpp/src/gunittest/cpp/fieldcache/MamaFieldCacheFieldTypesTest.cpp
index ee4c6b1..da62656 100644
--- a/mama/c_cpp/src/gunittest/cpp/fieldcache/MamaFieldCacheFieldTypesTest.cpp
+++ b/mama/c_cpp/src/gunittest/cpp/fieldcache/MamaFieldCacheFieldTypesTest.cpp
@@ -499,6 +499,86 @@ TEST_F(MamaFieldCacheFieldTypesTest, testDateTime)
ASSERT_DOUBLE_EQ(2500, value.getEpochTimeSeconds());
}

+TEST_F(MamaFieldCacheFieldTypesTest, testBoolVector)
+{
+ MamaFieldCacheField fieldBase;
+ fieldBase.create(1, MAMA_FIELD_TYPE_VECTOR_BOOL, "");
+ MamaFieldCacheFieldBoolVector field;
+
+ mama_bool_t values[5] = { 0, 1, 0, 1, 1 };
+ field.set(fieldBase, values, 5);
+ ASSERT_EQ(0, field.get(fieldBase, 0));
+ ASSERT_EQ(1, field.get(fieldBase, 1));
+ ASSERT_EQ(0, field.get(fieldBase, 2));
+ ASSERT_EQ(1, field.get(fieldBase, 3));
+ ASSERT_EQ(1, field.get(fieldBase, 4));
+
+ const mama_bool_t* result = NULL;
+ mama_size_t size;
+ field.get(fieldBase, result, size);
+ ASSERT_EQ(5, size);
+ ASSERT_EQ(0, result[0]);
+ ASSERT_EQ(1, result[1]);
+ ASSERT_EQ(0, result[2]);
+ ASSERT_EQ(1, result[3]);
+ ASSERT_EQ(1, result[4]);
+ getFieldValue(fieldBase, result, size);
+ ASSERT_EQ(5, size);
+ ASSERT_EQ(0, result[0]);
+ ASSERT_EQ(1, result[1]);
+ ASSERT_EQ(0, result[2]);
+ ASSERT_EQ(1, result[3]);
+ ASSERT_EQ(1, result[4]);
+
+ values[2] = 1;
+ setFieldValue(fieldBase, values, 5);
+ ASSERT_EQ(0, field.get(fieldBase, 0));
+ ASSERT_EQ(1, field.get(fieldBase, 1));
+ ASSERT_EQ(1, field.get(fieldBase, 2));
+ ASSERT_EQ(1, field.get(fieldBase, 3));
+ ASSERT_EQ(1, field.get(fieldBase, 4));
+}
+
+TEST_F(MamaFieldCacheFieldTypesTest, testCharVector)
+{
+ MamaFieldCacheField fieldBase;
+ fieldBase.create(1, MAMA_FIELD_TYPE_VECTOR_CHAR, "");
+ MamaFieldCacheFieldI8Vector field;
+
+ mama_i8_t values[5] = { 'E', 'F', 'V', 'H', 'I' };
+ field.set(fieldBase, values, 5);
+ ASSERT_EQ('E', field.get(fieldBase, 0));
+ ASSERT_EQ('F', field.get(fieldBase, 1));
+ ASSERT_EQ('V', field.get(fieldBase, 2));
+ ASSERT_EQ('H', field.get(fieldBase, 3));
+ ASSERT_EQ('I', field.get(fieldBase, 4));
+
+ const mama_i8_t* result = NULL;
+ mama_size_t size;
+ field.get(fieldBase, result, size);
+ ASSERT_EQ(5, size);
+ ASSERT_EQ('E', result[0]);
+ ASSERT_EQ('F', result[1]);
+ ASSERT_EQ('V', result[2]);
+ ASSERT_EQ('H', result[3]);
+ ASSERT_EQ('I', result[4]);
+ getFieldValue(fieldBase, result, size);
+ ASSERT_EQ(5, size);
+ ASSERT_EQ('E', result[0]);
+ ASSERT_EQ('F', result[1]);
+ ASSERT_EQ('V', result[2]);
+ ASSERT_EQ('H', result[3]);
+ ASSERT_EQ('I', result[4]);
+
+ values[2] = 'G';
+ setFieldValue(fieldBase, values, 5);
+ ASSERT_EQ('E', field.get(fieldBase, 0));
+ ASSERT_EQ('F', field.get(fieldBase, 1));
+ ASSERT_EQ('G', field.get(fieldBase, 2));
+ ASSERT_EQ('H', field.get(fieldBase, 3));
+ ASSERT_EQ('I', field.get(fieldBase, 4));
+}
+
TEST_F(MamaFieldCacheFieldTypesTest, testI8Vector)
{
MamaFieldCacheField fieldBase;
--
1.9.3