Example #1
0
/*  Description: Create a mamaDictionary from a file and write to a msg.
 *  The dictionary file includes a field type of UNKNOWN, which is logged with name and fid.
 *                   
 *  Expected Result: MAMA_STATUS_OK
 */
TEST_F (MamaDictionaryTestC, LoadFromFileAndWriteToMsg)
{
    mamaDictionary dictionary;
    mamaMsg msg;
    char buf[1024];
    const char* path = getenv("WOMBAT_PATH");
    size_t dictionarySize;
    size_t msgSize;
    
    ASSERT_EQ (MAMA_STATUS_OK, mamaDictionary_create(&dictionary));

    ASSERT_NE (path, (const char*) NULL);
    snprintf(buf, sizeof(buf), "%s/dictionary1.txt", path);
    ASSERT_EQ (MAMA_STATUS_OK, mamaDictionary_populateFromFile(dictionary, buf));

    ASSERT_EQ (MAMA_STATUS_OK, mamaDictionary_getDictionaryMessage(dictionary, &msg));

    ASSERT_EQ (MAMA_STATUS_OK, mamaDictionary_getSize(dictionary, &dictionarySize));

    ASSERT_EQ (MAMA_STATUS_OK, mamaMsg_getNumFields(msg, &msgSize));

    /* Expect one less in msg since there is an unknown in the dictionary */
    ASSERT_EQ (dictionarySize-1, msgSize);

    ASSERT_EQ (MAMA_STATUS_OK, mamaMsg_destroy(msg));

    ASSERT_EQ (MAMA_STATUS_OK, mamaDictionary_destroy(dictionary));
}
Example #2
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);
}