[PATCH 04/14] AVIS: Added several value validation steps that unit tests require


Frank Quinn <fquinn.ni@...>
 

Several unit tests expect MAMA bridges to return standard error
codes in various scenarios. This set of updates should bring avis
into line with these expectations.

Signed-off-by: Frank Quinn <fquinn.ni@...>
---
 mama/c_cpp/src/c/bridge/avis/msg.c             |  4 +++-
 mama/c_cpp/src/c/bridge/avis/sub.c             |  1 +
 mama/c_cpp/src/c/bridge/avis/transportbridge.c |  8 +++----
 mama/c_cpp/src/c/payload/avismsg/avismsgimpl.c | 22 ++++++++++--------
 mama/c_cpp/src/c/payload/avismsg/avispayload.c | 32 +++++++++++++++++++++-----
 5 files changed, 46 insertions(+), 21 deletions(-)

diff --git a/mama/c_cpp/src/c/bridge/avis/msg.c b/mama/c_cpp/src/c/bridge/avis/msg.c
index 5e02673..9840cf6 100644
--- a/mama/c_cpp/src/c/bridge/avis/msg.c
+++ b/mama/c_cpp/src/c/bridge/avis/msg.c
@@ -55,7 +55,7 @@ mama_status
 avisBridgeMamaMsg_create (msgBridge* msg, mamaMsg parent)
 {
     avisMsgImpl* impl;
-    if (avisMsg(msg) == NULL) return MAMA_STATUS_NULL_ARG;
+    if (avisMsg(msg) == NULL || parent == NULL) return MAMA_STATUS_NULL_ARG;
     *msg = NULL;
 
     impl = (avisMsgImpl*) calloc(1, sizeof(avisMsgImpl));
@@ -144,6 +144,7 @@ avisBridgeMamaMsg_isFromInbox (msgBridge msg)
 {
     const char* dummy;
 
+    if (NULL == msg) return -1;
     CHECK_MSG(msg);
 
     return (MAMA_STATUS_OK == avismsgPayload_getString(
@@ -213,6 +214,7 @@ mama_status
 avisBridgeMamaMsg_destroyReplyHandle (void* result)
 {
     char* replyAddr = (char*) result;
+    if (NULL == result) return MAMA_STATUS_NULL_ARG;
     free(replyAddr);
     return MAMA_STATUS_OK;
 }
diff --git a/mama/c_cpp/src/c/bridge/avis/sub.c b/mama/c_cpp/src/c/bridge/avis/sub.c
index 4a3a60d..0418634 100644
--- a/mama/c_cpp/src/c/bridge/avis/sub.c
+++ b/mama/c_cpp/src/c/bridge/avis/sub.c
@@ -446,6 +446,7 @@ mama_status
 avisBridgeMamaSubscription_getPlatformError (subscriptionBridge subscriber,
                                              void**             error)
 {
+    if (NULL == error) return MAMA_STATUS_NULL_ARG;
     CHECK_SUBSCRIBER(subscriber);
     *error = &(avisSub(subscriber)->mAvis->error);
     return MAMA_STATUS_OK;
diff --git a/mama/c_cpp/src/c/bridge/avis/transportbridge.c b/mama/c_cpp/src/c/bridge/avis/transportbridge.c
index f456f7e..3289189 100644
--- a/mama/c_cpp/src/c/bridge/avis/transportbridge.c
+++ b/mama/c_cpp/src/c/bridge/avis/transportbridge.c
@@ -251,7 +251,7 @@ avisBridgeMamaTransport_getNumLoadBalanceAttributes (
                                           const char* name,
                                           int*        numLoadBalanceAttributes)
 {
-    if (!numLoadBalanceAttributes) return MAMA_STATUS_NULL_ARG;
+    if (!numLoadBalanceAttributes || !name) return MAMA_STATUS_NULL_ARG;
     *numLoadBalanceAttributes = 0;
     return MAMA_STATUS_OK;
 }
@@ -261,7 +261,7 @@ avisBridgeMamaTransport_getLoadBalanceSharedObjectName (
                                       const char*  name,
                                       const char** loadBalanceSharedObjectName)
 {
-    if (!loadBalanceSharedObjectName) return MAMA_STATUS_NULL_ARG;
+    if (!loadBalanceSharedObjectName || !name) return MAMA_STATUS_NULL_ARG;
     *loadBalanceSharedObjectName = NULL;
     return MAMA_STATUS_OK;
 }
@@ -271,7 +271,7 @@ avisBridgeMamaTransport_getLoadBalanceScheme (
                                     const char*    name,
                                     tportLbScheme* scheme)
 {
-    if (!scheme) return MAMA_STATUS_NULL_ARG;
+    if (!scheme || !name) return MAMA_STATUS_NULL_ARG;
     *scheme = TPORT_LB_SCHEME_STATIC;
     return MAMA_STATUS_OK;
 }
@@ -287,7 +287,7 @@ avisBridgeMamaTransport_create (transportBridge* result,
     mamaBridgeImpl*      bridgeImpl = NULL;
     const char*          url        = NULL;
 
-    if (!result || !name) return MAMA_STATUS_NULL_ARG;
+    if (!result || !name || !mamaTport) return MAMA_STATUS_NULL_ARG;
    
     transport = (avisTransportBridge*)calloc( 1, sizeof( avisTransportBridge ) );
     if (transport == NULL)
diff --git a/mama/c_cpp/src/c/payload/avismsg/avismsgimpl.c b/mama/c_cpp/src/c/payload/avismsg/avismsgimpl.c
index 0664c4b..b179dbf 100644
--- a/mama/c_cpp/src/c/payload/avismsg/avismsgimpl.c
+++ b/mama/c_cpp/src/c/payload/avismsg/avismsgimpl.c
@@ -952,17 +952,19 @@ avisMsg_getDateTime(
         mama_fid_t     fid,
         mamaDateTime   result)
 {
-    char tempName[64];
-    Value* pValue = NULL;
-    if(fid != 0)
-    {
-        snprintf (tempName, 63, "%d", fid);
-        pValue = attributes_get(attributes, tempName);
-    }
+    char tempName[64];
+    Value* pValue = NULL;
+    if (NULL == result)
+        return MAMA_STATUS_NULL_ARG;
+    if(fid != 0)
+    {
+        snprintf (tempName, 63, "%d", fid);
+        pValue = attributes_get(attributes, tempName);
+    }
     if ((!pValue) && (name))
-        pValue = attributes_get(attributes, name);
+        pValue = attributes_get(attributes, name);
     if (!pValue)
-      return MAMA_STATUS_NOT_FOUND;
+        return MAMA_STATUS_NOT_FOUND;
     return avisValue_getDateTime(pValue, result);
 }
 
@@ -1064,7 +1066,7 @@ mama_status avisValue_getPrice(const Value* pValue, mamaPrice result)
           return MAMA_STATUS_WRONG_FIELD_TYPE;
 
     mamaPrice_setWithHints (result, pValue->value.real64, MAMA_PRICE_HINTS_NONE);
-    return MAMA_STATUS_NOT_IMPLEMENTED;
+    return MAMA_STATUS_OK;
 }
 
 
diff --git a/mama/c_cpp/src/c/payload/avismsg/avispayload.c b/mama/c_cpp/src/c/payload/avismsg/avispayload.c
index f02920e..0089fdc 100644
--- a/mama/c_cpp/src/c/payload/avismsg/avispayload.c
+++ b/mama/c_cpp/src/c/payload/avismsg/avispayload.c
@@ -52,7 +52,7 @@
 #define CHECK_NAME(name,fid) \
         do {  \
            if ((fid == 0) && (name == 0)) return MAMA_STATUS_NULL_ARG; \
-           if ((fid == 0) && (strlen(name)== 0)) return MAMA_STATUS_INVALID_ARG; \
+           if ((fid == 0) && (strlen(name) == 0)) return MAMA_STATUS_INVALID_ARG; \
          } while(0)
 
 #define CHECK_ITER(iter) \
@@ -165,8 +165,8 @@ mama_status
 avismsgPayload_createFromByteBuffer(msgPayload* msg, mamaPayloadBridge bridge, const void* buffer, mama_size_t bufferLength)
 {
     CHECK_NULL(msg);
-    CHECK_NULL(bridge);
     CHECK_NULL(buffer);
+    if (0 == bufferLength) return MAMA_STATUS_INVALID_ARG;
    
     avisPayloadImpl* newPayload = (avisPayloadImpl*)calloc (1, sizeof(avisPayloadImpl));
 
@@ -226,12 +226,12 @@ avismsgPayload_setParent (msgPayload          msg,
 
 mama_status
 avismsgPayload_getByteSize       (const msgPayload    msg,
-                                mama_size_t*        size)
+                                  mama_size_t*        size)
 {
+    const void* buffer = NULL;
     CHECK_PAYLOAD(msg);
     CHECK_NULL(size);
-    *size = 0;
-    return MAMA_STATUS_NOT_IMPLEMENTED;
+    return avismsgPayload_serialize (msg, &buffer, size);
 }
 
 mama_status
@@ -251,6 +251,7 @@ avismsgPayload_unSerialize (const msgPayload    msg,
 
     CHECK_PAYLOAD (msg);
     CHECK_NULL(buffer);
+    CHECK_NULL(bufferLength);
 
     if (!impl->mAvisMsg)
         impl->mAvisMsg = attributes_create();
@@ -462,6 +463,8 @@ avismsgPayload_setByteBuffer     (const msgPayload    msg,
 {
     avisPayloadImpl* impl = (avisPayloadImpl*)msg;
     CHECK_PAYLOAD(msg);
+    CHECK_NULL(buffer);
+    CHECK_NULL(bufferLength);
 
     impl->mAvisMsg=(Attributes*) buffer;
 
@@ -568,6 +571,11 @@ avismsgPayload_iterateFields (const msgPayload        msg,
     mama_status status = MAMA_STATUS_OK;
     avisFieldPayload* currField = NULL;
 
+    if (!parent || !cb || !field)
+    {
+        return MAMA_STATUS_NULL_ARG;
+    }
+
     if (!impl->mIterator)
     {
         status = avismsgPayloadIter_create((msgPayloadIter*) &impl->mIterator, msg);
@@ -604,7 +612,9 @@ avismsgPayload_getFieldAsString  (const msgPayload    msg,
                                 mama_size_t         len)
 {
     CHECK_PAYLOAD(msg);
+    CHECK_NULL(buf);
     CHECK_NAME(name, fid);
+    if (0 == len) return MAMA_STATUS_INVALID_ARG;
     return avisMsg_getFieldAsString(avisPayload(msg), name, fid, buf, len);
 }
 
@@ -857,6 +867,7 @@ avismsgPayload_addDateTime       (msgPayload          msg,
 {
     CHECK_PAYLOAD(msg);
     CHECK_NAME(name,fid);
+    CHECK_NULL(value);
     return avisMsg_setDateTime(avisPayload(msg), name, fid, value);
 }
 
@@ -868,6 +879,7 @@ avismsgPayload_addPrice          (msgPayload          msg,
 {
     CHECK_PAYLOAD(msg);
     CHECK_NAME(name,fid);
+    CHECK_NULL(value);
     return avisMsg_setPrice(avisPayload(msg), name, fid, value);
 }
 
@@ -1246,6 +1258,7 @@ avismsgPayload_updateDateTime    (msgPayload          msg,
 {
     CHECK_PAYLOAD(msg);
     CHECK_NAME(name,fid);
+    CHECK_NULL(value);
     return avisMsg_setDateTime(avisPayload(msg), name, fid, value);
 }
 
@@ -1257,6 +1270,7 @@ avismsgPayload_updatePrice       (msgPayload          msg,
 {
     CHECK_PAYLOAD(msg);
     CHECK_NAME(name,fid);
+    CHECK_NULL(value);
     return avisMsg_setPrice(avisPayload(msg), name, fid, value);
 }
 
@@ -1688,6 +1702,7 @@ avismsgPayload_getDateTime       (const msgPayload    msg,
 {
     CHECK_PAYLOAD(msg);
     CHECK_NAME(name,fid);
+    CHECK_NULL(result);
     return avisMsg_getDateTime(avisPayload(msg), name, fid, result);
 }
 
@@ -1699,6 +1714,7 @@ avismsgPayload_getPrice          (const msgPayload    msg,
 {
     CHECK_PAYLOAD(msg);
     CHECK_NAME(name,fid);
+    CHECK_NULL(result);
     return avisMsg_getPrice(avisPayload(msg), name, fid, result);
 }
 
@@ -1991,7 +2007,7 @@ avismsgPayloadIter_hasNext       (msgPayloadIter iter,
                                 msgPayload     msg)
 {
     avisIterator* impl = (avisIterator*) iter;
-    if (!impl) return false;
+    if (!impl || !msg) return false;
 
     return attributes_iter_has_next(impl->mMsgIterator);
 }
@@ -2485,6 +2501,7 @@ avismsgFieldPayload_getDateTime  (const msgFieldPayload   field,
                                 mamaDateTime            result)
 {
     CHECK_FIELD(field);
+    CHECK_NULL(result);
     return avisValue_getDateTime(avisField(field)->mValue, result);
 }
 
@@ -2493,6 +2510,7 @@ avismsgFieldPayload_getPrice     (const msgFieldPayload   field,
                                 mamaPrice               result)
 {
     CHECK_FIELD(field);
+    CHECK_NULL(result);
     return avisValue_getPrice(avisField(field)->mValue, result);
 }
 
@@ -2642,5 +2660,7 @@ avismsgFieldPayload_getAsString (
     char*         buf,
     mama_size_t   len)
 {
+    CHECK_NULL(buf);
+    CHECK_NULL(len);
     return avisValue_getFieldAsString(avisField(field)->mValue, avisField(field)->mName, 0, buf, len);
 }
--
2.4.3