Ejemplo n.º 1
1
TEST_F(MamaFieldCacheTestC, getFullMsg1)
{
    mamaFieldCache fieldCache = NULL;
    mama_status ret = mamaFieldCache_create(&fieldCache);

    mamaFieldCacheField field = NULL;
    mamaFieldCacheField_create(&field, 10, MAMA_FIELD_TYPE_BOOL, NULL);
    mamaFieldCacheField_setBool(field, 1);
    mamaFieldCache_applyField(fieldCache, field);

    /* This field must never be published */
    mamaFieldCacheField_create(&field, 25, MAMA_FIELD_TYPE_F64, NULL);
    mamaFieldCacheField_setF64(field, 3.1);
    mamaFieldCacheField_setPublish(field, 0);
    mamaFieldCache_applyField(fieldCache, field);

    mamaFieldCacheField_create(&field, 66, MAMA_FIELD_TYPE_I32, NULL);
    mamaFieldCacheField_setI32(field, -100);
    mamaFieldCache_applyField(fieldCache, field);

    // Creating a string field without a value. Even if this field is added to the
    // cache, it will not be added to the message because we cannot add a NULL
    // string to a mama message
    mamaFieldCacheField_create(&field, 110, MAMA_FIELD_TYPE_STRING, NULL);
    mamaFieldCache_applyField(fieldCache, field);

    mamaFieldCacheField_create(&field, 90, MAMA_FIELD_TYPE_STRING, NULL);
    mamaFieldCacheField_setString(field, "hello world", 0);
    mamaFieldCache_applyField(fieldCache, field);

    mamaMsg message;
    mamaMsg_create(&message);

    // should use add* methods to populate the message because the message is empty
    mamaFieldCache_getFullMessage(fieldCache, message);

    mama_bool_t resultBool = 0;
    ret = mamaMsg_getBool(message, "test_bool", 10, &resultBool);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    mama_f64_t resultF64;
    ret = mamaMsg_getF64(message, "test_f32", 25, &resultF64);
    ASSERT_EQ(MAMA_STATUS_NOT_FOUND, ret);
    mama_i32_t resultI32;
    ret = mamaMsg_getI32(message, "test_i32", 66, &resultI32);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    const char* resultString;
    ret = mamaMsg_getString(message, "test_string", 90, &resultString);
    ASSERT_EQ(MAMA_STATUS_OK, ret);

    ASSERT_EQ(1, resultBool);
    ASSERT_DOUBLE_EQ(-100, resultI32);
    ASSERT_STREQ("hello world", resultString);

    mamaMsg_destroy (message);
    ret = mamaFieldCache_destroy(fieldCache);
}
Ejemplo n.º 2
1
TEST_F(MamaFieldCacheTestC, getDeltaMsgTrackingModif)
{
    mama_size_t size = 0;
    mama_bool_t modified = 0;
    mamaFieldCache fieldCache = NULL;
    mama_status ret = mamaFieldCache_create(&fieldCache);

    // tracking modification state globally at cache level
    mamaFieldCache_setTrackModified(fieldCache, 1);

    mamaFieldCacheField field = NULL;
    // This field must be always published
    mamaFieldCacheField_create(&field, 66, MAMA_FIELD_TYPE_I32, NULL);
    mamaFieldCacheField_setI32(field, -100);
    // Enable publishing
    mamaFieldCacheField_setPublish(field, 1);
    // Don't check if modified before publishing -> always publish
    mamaFieldCacheField_setCheckModified(field, 0);
    mamaFieldCache_applyField(fieldCache, field);
    mamaFieldCacheField_destroy(field);

    size = 0;
    mamaFieldCacheList_getSize(fieldCache->mAlwaysPublishFields, &size);
    ASSERT_EQ(1, size);
    size = 0;
    mamaFieldCacheList_getSize(fieldCache->mModifiedFields, &size);
    ASSERT_EQ(0, size);

    mamaMsg message;
    mamaMsg_create(&message);

    // reset the modified field and remove from list for field 66
    mamaFieldCache_getDeltaMessage(fieldCache, message);
    mamaMsg_destroy(message);
    message = NULL;

    size = 0;
    mamaFieldCacheList_getSize(fieldCache->mAlwaysPublishFields, &size);
    ASSERT_EQ(1, size);
    size = 0;
    mamaFieldCacheList_getSize(fieldCache->mModifiedFields, &size);
    ASSERT_EQ(0, size);

    // This field will be published
    mamaFieldCacheField_create(&field, 10, MAMA_FIELD_TYPE_BOOL, NULL);
    mamaFieldCacheField_setBool(field, 1);
    // Enable publishing
    mamaFieldCacheField_setPublish(field, 1);
    // Check if modified before publishing
    mamaFieldCacheField_setCheckModified(field, 1);
    mamaFieldCache_applyField(fieldCache, field);
    mamaFieldCacheField_destroy(field);

    size = 0;
    mamaFieldCacheList_getSize(fieldCache->mModifiedFields, &size);
    ASSERT_EQ(1, size);

    // This field must never be published because publish is false
    mamaFieldCacheField_create(&field, 25, MAMA_FIELD_TYPE_F64, NULL);
    mamaFieldCacheField_setF64(field, 3.1);
    // Disable publishing
    mamaFieldCacheField_setPublish(field, 0);
    // Check modified can be anything - no publishing anyway... see above
    mamaFieldCacheField_setCheckModified(field, 1);
    mamaFieldCache_applyField(fieldCache, field);
    mamaFieldCacheField_destroy(field);

    size = 0;
    mamaFieldCacheList_getSize(fieldCache->mModifiedFields, &size);
    ASSERT_EQ(1, size);

    // This field will always be published
    mamaFieldCacheField_create(&field, 90, MAMA_FIELD_TYPE_STRING, NULL);
    mamaFieldCacheField_setString(field, "hello world", 0);
    // Enable publishing
    mamaFieldCacheField_setPublish(field, 1);
    // Don't check if modified
    mamaFieldCacheField_setCheckModified(field, 0);
    mamaFieldCache_applyField(fieldCache, field);
    mamaFieldCacheField_destroy(field);

    size = 0;
    mamaFieldCacheList_getSize(fieldCache->mModifiedFields, &size);
    ASSERT_EQ(1, size);

    // This field will always be published
    mamaFieldCacheField_create(&field, 91, MAMA_FIELD_TYPE_STRING, NULL);
    mamaFieldCacheField_setString(field, "hello world again", 0);
    // Enable publishing
    mamaFieldCacheField_setPublish(field, 1);
    // Don't check if modified
    mamaFieldCacheField_setCheckModified(field, 0);
    mamaFieldCache_applyField(fieldCache, field);
    mamaFieldCacheField_destroy(field);

    size = 0;
    mamaFieldCacheList_getSize(fieldCache->mModifiedFields, &size);
    ASSERT_EQ(1, size);

    mamaMsg_create(&message);

    mamaFieldCache_getDeltaMessage(fieldCache, message);

    size = 0;
    mamaFieldCacheList_getSize(fieldCache->mModifiedFields, &size);
    ASSERT_EQ(0, size);

    ASSERT_EQ(MAMA_STATUS_OK, mamaFieldCache_find(fieldCache, 10, "", &field));
    mamaFieldCacheField_isModified(field, &modified);
    ASSERT_FALSE(modified);

    mama_bool_t resultBool;
    ret = mamaMsg_getBool(message, "test_bool", 10, &resultBool);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(1, resultBool);
    mama_f64_t resultF64;
    ret = mamaMsg_getF64(message, "test_f32", 25, &resultF64);
    ASSERT_EQ(MAMA_STATUS_NOT_FOUND, ret);
    mama_i32_t resultI32;
    ret = mamaMsg_getI32(message, "test_i32", 66, &resultI32);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(-100, resultI32);
    const char* resultString;
    ret = mamaMsg_getString(message, "test_string", 90, &resultString);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_STREQ("hello world", resultString);
    ret = mamaMsg_getString(message, "test_string", 91, &resultString);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_STREQ("hello world again", resultString);

    mamaMsg_destroy (message);

    ret = mamaFieldCache_destroy(fieldCache);
}
Ejemplo n.º 3
0
TEST_F(MamaFieldCacheTestC, getDeltaMsgAlwaysPublishFields)
{
    mama_bool_t modified = 0;
    mama_size_t numFields = 0;
    mamaFieldCache fieldCache = NULL;
    mama_status ret = mamaFieldCache_create(&fieldCache);

    // tracking modification state globally at cache level
    mamaFieldCache_setTrackModified(fieldCache, 1);

    mamaFieldCacheField field = NULL;
    // This field must be always published
    mamaFieldCacheField_create(&field, 66, MAMA_FIELD_TYPE_I32, NULL);
    mamaFieldCacheField_setI32(field, -100);
    // Enable publishing
    mamaFieldCacheField_setPublish(field, 1);
    // Don't check if modified before publishing -> always publish
    mamaFieldCacheField_setCheckModified(field, 0);
    mamaFieldCache_applyField(fieldCache, field);
    mamaFieldCacheField_destroy(field);

    mama_size_t size = 0;
    mamaFieldCacheList_getSize(fieldCache->mModifiedFields, &size);
    ASSERT_EQ(0, size);
    mamaFieldCacheList_getSize(fieldCache->mAlwaysPublishFields, &size);
    ASSERT_EQ(1, size);

    mamaMsg message;
    mamaMsg_create(&message);

    mamaFieldCache_getDeltaMessage(fieldCache, message);
    mamaMsg_getNumFields(message, &numFields);
    ASSERT_EQ(1, numFields);
    mamaMsg_destroy(message);
    message = NULL;

    mamaMsg_create(&message);

    ASSERT_EQ(MAMA_STATUS_OK, mamaFieldCache_find(fieldCache, 66, "", &field));
    mamaFieldCacheField_isModified(field, &modified);
    ASSERT_FALSE(modified);

    mamaFieldCache_getDeltaMessage(fieldCache, message);

    ASSERT_EQ(MAMA_STATUS_OK, mamaFieldCache_find(fieldCache, 66, "", &field));
    mamaFieldCacheField_isModified(field, &modified);
    ASSERT_FALSE(modified);

    mama_i32_t resultI32 = 0;
    ret = mamaMsg_getI32(message, "test_i32", 66, &resultI32);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(-100, resultI32);

    mamaMsg_destroy (message);
    ret = mamaFieldCache_destroy(fieldCache);
}
Ejemplo n.º 4
0
mama_status mamaFieldCache_updateCacheFromMsgField(mamaFieldCache fieldCache,
                                                   const mamaMsgField messageField)
{
    mama_status ret;
    mama_fid_t fid;
    mamaFieldType type = MAMA_FIELD_TYPE_UNKNOWN;
    const char* name = NULL;
    mamaFieldDescriptor descriptor = NULL;
    mamaFieldCacheField field = NULL;

    ret = mamaMsgField_getFid(messageField, &fid);
    if (ret != MAMA_STATUS_OK)
    {
        return ret;
    }

    if (MAMA_STATUS_OK != mamaFieldCacheMap_find(fieldCache->mMap, fid, type, name, &field))
    {
        ret = mamaMsgField_getType(messageField, &type);
        if (ret != MAMA_STATUS_OK)
        {
            return ret;
        }
        if (fieldCache->mUseFieldNames)
        {
            mamaMsgField_getName(messageField, &name);
        }
        mamaFieldCacheField_create(&field, fid, type, name);
        ret = mamaFieldCacheMap_add(fieldCache->mMap, field);
        if (ret != MAMA_STATUS_OK)
        {
            return ret;
        }
        fieldCache->mSize++;

        mamaMsgField_getDescriptor(messageField, &descriptor);
        if (descriptor)
        {
            mamaFieldCacheField_setDescriptor(field, descriptor);
        }
    }
    else
    {
        type = field->mType;
    }

    if (fieldCache->mTrackModified && field->mPublish && !field->mIsModified)
    {
        field->mIsModified = 1;
        mamaFieldCacheList_add(fieldCache->mModifiedFields, (void*)field);
    }

    switch (type)
    {
        case MAMA_FIELD_TYPE_BOOL:
        {
            mama_bool_t result;
            mamaMsgField_getBool(messageField, &result);
            mamaFieldCacheField_setBool(field, result);
            break;
        }
        case MAMA_FIELD_TYPE_CHAR:
        {
            char value;
            mamaMsgField_getChar(messageField, &value);
            mamaFieldCacheField_setChar(field, value);
            break;
        }
        case MAMA_FIELD_TYPE_I8:
        {
            mama_i8_t value;
            mamaMsgField_getI8(messageField, &value);
            mamaFieldCacheField_setI8(field, value);
            break;
        }
        case MAMA_FIELD_TYPE_U8:
        {
            mama_u8_t value;
            mamaMsgField_getU8(messageField, &value);
            mamaFieldCacheField_setU8(field, value);
            break;
        }
        case MAMA_FIELD_TYPE_I16:
        {
            mama_i16_t value;
            mamaMsgField_getI16(messageField, &value);
            mamaFieldCacheField_setI16(field, value);
            break;
        }
        case MAMA_FIELD_TYPE_U16:
        {
            mama_u16_t value;
            mamaMsgField_getU16(messageField, &value);
            mamaFieldCacheField_setU16(field, value);
            break;
        }
        case MAMA_FIELD_TYPE_I32:
        {
            mama_i32_t value;
            mamaMsgField_getI32(messageField, &value);
            mamaFieldCacheField_setI32(field, value);
            break;
        }
        case MAMA_FIELD_TYPE_U32:
        {
            mama_u32_t value;
            mamaMsgField_getU32(messageField, &value);
            mamaFieldCacheField_setU32(field, value);
            break;
        }
        case MAMA_FIELD_TYPE_I64:
        {
            mama_i64_t value;
            mamaMsgField_getI64(messageField, &value);
            mamaFieldCacheField_setI64(field, value);
            break;
        }
        case MAMA_FIELD_TYPE_U64:
        {
            mama_u64_t value;
            mamaMsgField_getU64(messageField, &value);
            mamaFieldCacheField_setU64(field, value);
            break;
        }
        case MAMA_FIELD_TYPE_F32:
        {
            mama_f32_t value;
            mamaMsgField_getF32(messageField, &value);
            mamaFieldCacheField_setF32(field, value);
            break;
        }
        case MAMA_FIELD_TYPE_QUANTITY:
        case MAMA_FIELD_TYPE_F64:
        {
            mama_f64_t value;
            mamaMsgField_getF64(messageField, &value);
            mamaFieldCacheField_setF64(field, value);
            break;
        }
        case MAMA_FIELD_TYPE_STRING:
        {
            const char* value = NULL;
            mamaMsgField_getString(messageField, &value);
            mamaFieldCacheField_setString(field, value, 0);
            break;
        }
        case MAMA_FIELD_TYPE_PRICE:
        {
            mamaMsgField_getPrice(messageField, fieldCache->mReusablePrice);
            mamaFieldCacheField_setPrice(field, fieldCache->mReusablePrice);
            break;
        }
        case MAMA_FIELD_TYPE_TIME:
        {
            mamaMsgField_getDateTime(messageField, fieldCache->mReusableDateTime);
            mamaFieldCacheField_setDateTime(field, fieldCache->mReusableDateTime);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_I8:
        {
            const mama_i8_t* values = NULL;
            mama_size_t size = 0;
            mamaMsgField_getVectorI8(messageField, &values, &size);
            mamaFieldCacheField_setI8Vector(field, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_U8:
        {
            const mama_u8_t* values = NULL;
            mama_size_t size = 0;
            mamaMsgField_getVectorU8(messageField, &values, &size);
            mamaFieldCacheField_setU8Vector(field, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_I16:
        {
            const mama_i16_t* values = NULL;
            mama_size_t size = 0;
            mamaMsgField_getVectorI16(messageField, &values, &size);
            mamaFieldCacheField_setI16Vector(field, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_U16:
        {
            const mama_u16_t* values = NULL;
            mama_size_t size = 0;
            mamaMsgField_getVectorU16(messageField, &values, &size);
            mamaFieldCacheField_setU16Vector(field, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_I32:
        {
            const mama_i32_t* values = NULL;
            mama_size_t size = 0;
            mamaMsgField_getVectorI32(messageField, &values, &size);
            mamaFieldCacheField_setI32Vector(field, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_U32:
        {
            const mama_u32_t* values = NULL;
            mama_size_t size = 0;
            mamaMsgField_getVectorU32(messageField, &values, &size);
            mamaFieldCacheField_setU32Vector(field, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_I64:
        {
            const mama_i64_t* values = NULL;
            mama_size_t size = 0;
            mamaMsgField_getVectorI64(messageField, &values, &size);
            mamaFieldCacheField_setI64Vector(field, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_U64:
        {
            const mama_u64_t* values = NULL;
            mama_size_t size = 0;
            mamaMsgField_getVectorU64(messageField, &values, &size);
            mamaFieldCacheField_setU64Vector(field, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_F32:
        {
            const mama_f32_t* values = NULL;
            mama_size_t size = 0;
            mamaMsgField_getVectorF32(messageField, &values, &size);
            mamaFieldCacheField_setF32Vector(field, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_F64:
        {
            const mama_f64_t* values = NULL;
            mama_size_t size = 0;
            mamaMsgField_getVectorF64(messageField, &values, &size);
            mamaFieldCacheField_setF64Vector(field, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_STRING:
        {
            const char** values = NULL;
            mama_size_t size = 0;
            mamaMsgField_getVectorString(messageField, &values, &size);
            mamaFieldCacheField_setStringVector(field, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_PRICE:
        {
            /* TODO: mamaMsgField does not provide methods to get price vector
            const mamaPrice* values = NULL;
            mama_size_t size;
            mamaMsgField_getVectorPrice(messageField, &values, &size);
            mamaFieldCacheField_setPriceVector(field, values, size);
             */
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_TIME:
        {
            /* TODO: mamaMsgField does not provide methods to get time vector
            const mamaDateTime* values = NULL;
            mama_size_t size;
            mamaMsgField_getVectorDateTime(messageField, &values, &size);
            mamaFieldCacheField_setDateTimeVector(field, values, size);
             */
            break;
        }
        default:
            break;
    }
    return ret;
}
Ejemplo n.º 5
0
mama_status
mamaFieldCacheField_copy(const mamaFieldCacheField field, mamaFieldCacheField copy)
{
    if (!field || !copy)
    {
        return MAMA_STATUS_NULL_ARG;
    }
    if (field == copy)
    {
        return MAMA_STATUS_OK;
    }
    if (field->mFid != copy->mFid || field->mType != copy->mType)
    {
        return MAMA_STATUS_INVALID_ARG;
    }

    copy->mIsModified = field->mIsModified;
    copy->mPublish = field->mPublish;
    copy->mCheckModified = field->mCheckModified;
    copy->mDescriptor = field->mDescriptor;
    if (field->mName)
    {
        if (copy->mName)
        {
            free((void*)copy->mName);
        }
        copy->mName = strdup(field->mName);
    }
    switch (field->mType)
    {
        case MAMA_FIELD_TYPE_BOOL:
        {
            mama_bool_t result;
            mamaFieldCacheField_getBool(field, &result);
            mamaFieldCacheField_setBool(copy, result);
            break;
        }
        case MAMA_FIELD_TYPE_CHAR:
        {
            char value;
            mamaFieldCacheField_getChar(field, &value);
            mamaFieldCacheField_setChar(copy, value);
            break;
        }
        case MAMA_FIELD_TYPE_I8:
        {
            mama_i8_t value;
            mamaFieldCacheField_getI8(field, &value);
            mamaFieldCacheField_setI8(copy, value);
            break;
        }
        case MAMA_FIELD_TYPE_U8:
        {
            mama_u8_t value;
            mamaFieldCacheField_getU8(field, &value);
            mamaFieldCacheField_setU8(copy, value);
            break;
        }
        case MAMA_FIELD_TYPE_I16:
        {
            mama_i16_t value;
            mamaFieldCacheField_getI16(field, &value);
            mamaFieldCacheField_setI16(copy, value);
            break;
        }
        case MAMA_FIELD_TYPE_U16:
        {
            mama_u16_t value;
            mamaFieldCacheField_getU16(field, &value);
            mamaFieldCacheField_setU16(copy, value);
            break;
        }
        case MAMA_FIELD_TYPE_I32:
        {
            mama_i32_t value;
            mamaFieldCacheField_getI32(field, &value);
            mamaFieldCacheField_setI32(copy, value);
            break;
        }
        case MAMA_FIELD_TYPE_U32:
        {
            mama_u32_t value;
            mamaFieldCacheField_getU32(field, &value);
            mamaFieldCacheField_setU32(copy, value);
            break;
        }
        case MAMA_FIELD_TYPE_I64:
        {
            mama_i64_t value;
            mamaFieldCacheField_getI64(field, &value);
            mamaFieldCacheField_setI64(copy, value);
            break;
        }
        case MAMA_FIELD_TYPE_U64:
        {
            mama_u64_t value;
            mamaFieldCacheField_getU64(field, &value);
            mamaFieldCacheField_setU64(copy, value);
            break;
        }
        case MAMA_FIELD_TYPE_F32:
        {
            mama_f32_t value;
            mamaFieldCacheField_getF32(field, &value);
            mamaFieldCacheField_setF32(copy, value);
            break;
        }
        case MAMA_FIELD_TYPE_QUANTITY:
        case MAMA_FIELD_TYPE_F64:
        {
            mama_f64_t value;
            mamaFieldCacheField_getF64(field, &value);
            mamaFieldCacheField_setF64(copy, value);
            break;
        }
        case MAMA_FIELD_TYPE_STRING:
        {
            const char* value;
            mama_size_t len;
            mamaFieldCacheField_getString(field, &value, &len);
            mamaFieldCacheField_setString(copy, value, len);
            break;
        }
        case MAMA_FIELD_TYPE_PRICE:
        {
            mamaPrice value = NULL;
            const mamaPrice* pvalue = &value;
            mamaFieldCacheField_getPrice(field, pvalue);
            mamaFieldCacheField_setPrice(copy, value);
            break;
        }
        case MAMA_FIELD_TYPE_TIME:
        {
            mamaDateTime value = NULL;
            const mamaDateTime* pvalue = &value;
            mamaFieldCacheField_getDateTime(field, pvalue);
            mamaFieldCacheField_setDateTime(copy, value);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_BOOL:
        {
            const mama_bool_t* values = NULL;
            mama_size_t size;
            mamaFieldCacheField_getBoolVector(field, &values, &size);
            mamaFieldCacheField_setBoolVector(copy, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_CHAR:
        {
            const char* values = NULL;
            mama_size_t size;
            mamaFieldCacheField_getCharVector(field, &values, &size);
            mamaFieldCacheField_setCharVector(copy, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_I8:
        {
            const mama_i8_t* values = NULL;
            mama_size_t size;
            mamaFieldCacheField_getI8Vector(field, &values, &size);
            mamaFieldCacheField_setI8Vector(copy, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_U8:
        {
            const mama_u8_t* values = NULL;
            mama_size_t size;
            mamaFieldCacheField_getU8Vector(field, &values, &size);
            mamaFieldCacheField_setU8Vector(copy, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_I16:
        {
            const mama_i16_t* values = NULL;
            mama_size_t size;
            mamaFieldCacheField_getI16Vector(field, &values, &size);
            mamaFieldCacheField_setI16Vector(copy, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_U16:
        {
            const mama_u16_t* values = NULL;
            mama_size_t size;
            mamaFieldCacheField_getU16Vector(field, &values, &size);
            mamaFieldCacheField_setU16Vector(copy, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_I32:
        {
            const mama_i32_t* values = NULL;
            mama_size_t size;
            mamaFieldCacheField_getI32Vector(field, &values, &size);
            mamaFieldCacheField_setI32Vector(copy, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_U32:
        {
            const mama_u32_t* values = NULL;
            mama_size_t size;
            mamaFieldCacheField_getU32Vector(field, &values, &size);
            mamaFieldCacheField_setU32Vector(copy, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_I64:
        {
            const mama_i64_t* values = NULL;
            mama_size_t size;
            mamaFieldCacheField_getI64Vector(field, &values, &size);
            mamaFieldCacheField_setI64Vector(copy, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_U64:
        {
            const mama_u64_t* values = NULL;
            mama_size_t size;
            mamaFieldCacheField_getU64Vector(field, &values, &size);
            mamaFieldCacheField_setU64Vector(copy, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_F32:
        {
            const mama_f32_t* values = NULL;
            mama_size_t size;
            mamaFieldCacheField_getF32Vector(field, &values, &size);
            mamaFieldCacheField_setF32Vector(copy, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_F64:
        {
            const mama_f64_t* values = NULL;
            mama_size_t size;
            mamaFieldCacheField_getF64Vector(field, &values, &size);
            mamaFieldCacheField_setF64Vector(copy, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_STRING:
        {
            const char** values = NULL;
            mama_size_t size;
            mamaFieldCacheField_getStringVector(field, &values, &size);
            mamaFieldCacheField_setStringVector(copy, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_PRICE:
        {
            const mamaPrice* values = NULL;
            mama_size_t size;
            mamaFieldCacheField_getPriceVector(field, &values, &size);
            mamaFieldCacheField_setPriceVector(copy, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_TIME:
        {
            const mamaDateTime* values = NULL;
            mama_size_t size;
            mamaFieldCacheField_getDateTimeVector(field, &values, &size);
            mamaFieldCacheField_setDateTimeVector(copy, values, size);
            break;
        }
        default:
            break;
    }
    return MAMA_STATUS_OK;
}
Ejemplo n.º 6
0
TEST_F(MamaFieldCacheTestC, getDeltaMsgMultipleUpdates)
{
    mama_size_t size = 0;
    mama_bool_t modified = 0;
    mamaFieldCache fieldCache = NULL;
    mama_status ret = mamaFieldCache_create(&fieldCache);

    // tracking modification state globally at cache level
//    mamaFieldCache_setTrackModified(fieldCache, 1);

    mamaFieldCacheField field = NULL;
    mamaFieldCacheField_create(&field, 66, MAMA_FIELD_TYPE_I32, NULL);
    mamaFieldCacheField_setI32(field, -100);
    // Enable publishing
    mamaFieldCacheField_setPublish(field, 1);
    // Check if modified before publishing
    mamaFieldCacheField_setCheckModified(field, 1);

    mamaFieldCache_applyField(fieldCache, field);

    size = 0;
    mamaFieldCacheList_getSize(fieldCache->mModifiedFields, &size);
    ASSERT_EQ(1, size);

    // apply a second time before getDeltaMsg is called
    mamaFieldCacheField_setI32(field, 80);
    mamaFieldCache_applyField(fieldCache, field);

    size = 0;
    mamaFieldCacheList_getSize(fieldCache->mModifiedFields, &size);
    ASSERT_EQ(1, size);

    mamaFieldCacheField_destroy(field);

    // This field must never be published because publish is false
    mamaFieldCacheField_create(&field, 25, MAMA_FIELD_TYPE_F64, NULL);
    mamaFieldCacheField_setF64(field, 3.1);
    // Disable publishing
    mamaFieldCacheField_setPublish(field, 0);
    // Check modified can be anything - no publishing anyway... see above
    mamaFieldCacheField_setCheckModified(field, 1);
    mamaFieldCache_applyField(fieldCache, field);
    mamaFieldCacheField_destroy(field);

    size = 0;
    mamaFieldCacheList_getSize(fieldCache->mModifiedFields, &size);
    ASSERT_EQ(1, size);

    size = 0;
    mamaFieldCacheList_getSize(fieldCache->mModifiedFields, &size);
    ASSERT_EQ(1, size);

    mamaMsg message = NULL;
    mamaMsg_create(&message);

    mamaFieldCache_getDeltaMessage(fieldCache, message);

    ASSERT_EQ(MAMA_STATUS_OK, mamaFieldCache_find(fieldCache, 66, "", &field));
    mamaFieldCacheField_isModified(field, &modified);
    ASSERT_FALSE(modified);

    mama_i32_t resultI32 = 0;
    ret = mamaMsg_getI32(message, "test_i32", 66, &resultI32);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(80, resultI32);

    mama_f64_t resultF64;
    ret = mamaMsg_getF64(message, "test_f32", 25, &resultF64);
    ASSERT_EQ(MAMA_STATUS_NOT_FOUND, ret);

    mamaMsg_destroy (message);

    ret = mamaFieldCache_destroy(fieldCache);
}
Ejemplo n.º 7
0
TEST_F(MamaFieldCacheTestC, getDeltaMsgNotTrackingModif)
{
    mama_bool_t modified = 0;
    mamaFieldCache fieldCache = NULL;
    mama_status ret = mamaFieldCache_create(&fieldCache);

    // setting explicitely to non-tracking mode
    mamaFieldCache_setTrackModified(fieldCache, 0);

    // This field will be published
    mamaFieldCacheField field = NULL;
    mamaFieldCacheField_create(&field, 10, MAMA_FIELD_TYPE_BOOL, NULL);
    mamaFieldCacheField_setBool(field, 1);
    // Enable publishing
    mamaFieldCacheField_setPublish(field, 1);
    // Check if modified before publishing - who cares... global check modified is disabled
    mamaFieldCacheField_setCheckModified(field, 1);
    mamaFieldCache_applyField(fieldCache, field);
    mamaFieldCacheField_destroy(field);

    // This field will not be published
    mamaFieldCacheField_create(&field, 25, MAMA_FIELD_TYPE_F64, NULL);
    mamaFieldCacheField_setF64(field, 3.1);
    // Disable publishing
    mamaFieldCacheField_setPublish(field, 0);
    // Check modified can be anything - no publishing anyway... see above
    mamaFieldCacheField_setCheckModified(field, 1);
    mamaFieldCache_applyField(fieldCache, field);
    mamaFieldCacheField_destroy(field);

    // This field will be published
    mamaFieldCacheField_create(&field, 66, MAMA_FIELD_TYPE_I32, NULL);
    mamaFieldCacheField_setI32(field, -100);
    // Enable publishing
    mamaFieldCacheField_setPublish(field, 1);
    // Check if modified - who cares... global check modified is disabled
    mamaFieldCacheField_setCheckModified(field, 1);
    mamaFieldCache_applyField(fieldCache, field);
    mamaFieldCacheField_destroy(field);

    // This field will be published
    mamaFieldCacheField_create(&field, 90, MAMA_FIELD_TYPE_STRING, NULL);
    mamaFieldCacheField_setString(field, "hello world", 0);
    // Enable publishing
    mamaFieldCacheField_setPublish(field, 1);
    // Don't check if modified - who cares... global check modified is disabled
    mamaFieldCacheField_setCheckModified(field, 0);
    mamaFieldCache_applyField(fieldCache, field);
    mamaFieldCacheField_destroy(field);

    // This field will be published
    mamaFieldCacheField_create(&field, 91, MAMA_FIELD_TYPE_STRING, NULL);
    mamaFieldCacheField_setString(field, "hello world again", 0);
    // Enable publishing
    mamaFieldCacheField_setPublish(field, 1);
    // Don't check if modified - who cares... global check modified is disabled
    mamaFieldCacheField_setCheckModified(field, 1);
    mamaFieldCache_applyField(fieldCache, field);
    mamaFieldCacheField_destroy(field);

    mamaMsg message;
    mamaMsg_create(&message);

    // This results in a Full message because track modified is false
    mamaFieldCache_getDeltaMessage(fieldCache, message);

    ASSERT_EQ(MAMA_STATUS_OK, mamaFieldCache_find(fieldCache, 10, "", &field));
    mamaFieldCacheField_isModified(field, &modified);
    // The modified flag is not modified if the cache is not tracking modifications
    ASSERT_FALSE(modified);

    mama_bool_t resultBool;
    ret = mamaMsg_getBool(message, "test_bool", 10, &resultBool);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(1, resultBool);
    mama_f64_t resultF64;
    ret = mamaMsg_getF64(message, "test_f32", 25, &resultF64);
    ASSERT_EQ(MAMA_STATUS_NOT_FOUND, ret);
    mama_i32_t resultI32;
    ret = mamaMsg_getI32(message, "test_i32", 66, &resultI32);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(-100, resultI32);
    const char* resultString;
    ret = mamaMsg_getString(message, "test_string", 90, &resultString);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_STREQ("hello world", resultString);
    ret = mamaMsg_getString(message, "test_string", 91, &resultString);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_STREQ("hello world again", resultString);

    mamaMsg_destroy (message);

    ret = mamaFieldCache_destroy(fieldCache);
}
Ejemplo n.º 8
0
TEST_F(MamaFieldCacheTestC, applyFieldNew)
{
    mama_status ret = MAMA_STATUS_OK;
    mamaFieldCache fieldCache = NULL;
    mamaFieldCacheField cachedField = NULL;
    mama_size_t size = 0;
    mama_bool_t boolValue = 0;
    mamaFieldCache_create(&fieldCache);

    mamaFieldCacheField field1 = NULL;
    mamaFieldCacheField_create(&field1, 2, MAMA_FIELD_TYPE_F32, NULL);
    mamaFieldCacheField_setF32(field1, 13.13);
    mamaFieldCacheField_setPublish(field1, 1);
    mamaFieldCacheField_setCheckModified(field1, 1);

    mamaFieldCache_getSize(fieldCache, &size);
    ASSERT_EQ(0, size);

    mamaFieldCache_applyField(fieldCache, field1);

    mamaFieldCache_getSize(fieldCache, &size);
    ASSERT_EQ(1, size);

    ret = mamaFieldCache_find(fieldCache, 2, NULL, &cachedField);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_TRUE(cachedField != NULL);

    mamaFieldCacheField_getPublish(cachedField, &boolValue);
    ASSERT_EQ(1, boolValue);
    boolValue = 0;
    mamaFieldCacheField_getCheckModified(cachedField, &boolValue);
    ASSERT_EQ(1, boolValue);
    boolValue = 0;
    mamaFieldCacheField_isModified(cachedField, &boolValue);
    ASSERT_EQ(1, boolValue);

    mamaFieldCacheField field2 = NULL;
    mamaFieldCacheField_create(&field2, 4, MAMA_FIELD_TYPE_I32, "name4");
    mamaFieldCacheField_setI32(field2, 321);
    mamaFieldCacheField_setPublish(field2, 0);
    mamaFieldCacheField_setCheckModified(field2, 0);

    mamaFieldCache_applyField(fieldCache, field2);

    mamaFieldCache_getSize(fieldCache, &size);
    ASSERT_EQ(2, size);

    cachedField = NULL;
    ret = mamaFieldCache_find(fieldCache, 4, "", &cachedField);
    ASSERT_TRUE(cachedField != NULL);
    ASSERT_EQ(MAMA_STATUS_OK, ret);

    boolValue = 0;
    mamaFieldCacheField_getPublish(cachedField, &boolValue);
    ASSERT_EQ(0, boolValue);
    boolValue = 0;
    mamaFieldCacheField_getCheckModified(cachedField, &boolValue);
    ASSERT_EQ(0, boolValue);
    boolValue = 0;
    mamaFieldCacheField_isModified(cachedField, &boolValue);
    ASSERT_EQ(0, boolValue);

    const char* cachedName = NULL;
    ret = mamaFieldCacheField_getName(cachedField, &cachedName);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_TRUE(cachedName != NULL);
    ASSERT_STREQ("name4", cachedName);

    mamaFieldCacheField_destroy(field1);
    mamaFieldCacheField_destroy(field2);
    mamaFieldCache_destroy(fieldCache);
}