예제 #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);
}
예제 #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);
}
예제 #3
0
mama_status mamaFieldCache_updateCacheFromField(mamaFieldCache fieldCache,
                                                const mamaFieldCacheField field)
{
    mama_status ret;
    mama_fid_t fid;
    mamaFieldType type;
    mama_bool_t alreadyModified = 0;
    const char* name = NULL;
    mamaFieldCacheField cachedField = NULL;

    ret = mamaFieldCacheField_getFid(field, &fid);
    if (ret != MAMA_STATUS_OK)
    {
        return ret;
    }

    ret = mamaFieldCacheField_getType(field, &type);
    if (ret != MAMA_STATUS_OK)
    {
        return ret;
    }

    mamaFieldCacheField_getName(field, &name);
    if (MAMA_STATUS_OK != mamaFieldCacheMap_find(fieldCache->mMap, fid, type, name, &cachedField))
    {
        ret = mamaFieldCacheField_create(&cachedField, fid, type, NULL);
        if (ret != MAMA_STATUS_OK)
        {
            return ret;
        }
        ret = mamaFieldCacheMap_add(fieldCache->mMap, cachedField);
        if (ret != MAMA_STATUS_OK)
        {
            return ret;
        }
        fieldCache->mSize++;
        if (field->mPublish && !field->mCheckModified)
        {   /* Always publish */
            mamaFieldCacheList_add(fieldCache->mAlwaysPublishFields, (void*)cachedField);
        }
        alreadyModified = 0;
    }
    else
    {
        alreadyModified = cachedField->mIsModified;
    }

    mamaFieldCacheField_copy(field, cachedField);

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

    return ret;
}
예제 #4
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);
}
예제 #5
0
mama_status mamaFieldCacheRecord_add(mamaFieldCacheRecord record,
                                     mama_fid_t fid,
                                     mamaFieldType type,
                                     const char* name,
                                     mamaFieldCacheField* field)
{
    if (!record || !field)
    {
        return MAMA_STATUS_NULL_ARG;
    }
    *field = NULL;
    mamaFieldCacheVector_grow(record->mFields, record->mSize + 10);

    mamaFieldCacheField_create(field, fid, type, name);
    mamaFieldCacheVector_set(record->mFields, record->mSize, *field);
    record->mSize++;
    return MAMA_STATUS_OK;
}
예제 #6
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;
}
예제 #7
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);
}
예제 #8
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);
}
예제 #9
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);
}