Example #1
0
void 
DateTimeRangeTests::HasDateAndTimeTest(const mamaDateTime& t)
{
   mamaDateTime cpy;
   mama_bool_t b;

   // Copy t
   // Set it to NOW
   // Test that HAs Date and Has Time are both true
   // Clear copy
   // Test that Has Date and Has TIme are both False.
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_create(&cpy) );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_copy(cpy,t) );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_setToNow(cpy) );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_hasTime(cpy, &b) );
   EXPECT_TRUE ( b );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_hasDate(cpy, &b) );
   EXPECT_TRUE ( b );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_clear(cpy) );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_hasTime(cpy, &b) );
   EXPECT_FALSE ( b );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_hasDate(cpy, &b) );
   EXPECT_FALSE ( b );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_destroy(cpy) );
}
Example #2
0
mama_status mamaFieldCacheField_destroy(mamaFieldCacheField field)
{
    if (!field)
    {
        return MAMA_STATUS_NULL_ARG;
    }

    if (field->mName)
    {
        free((void*)field->mName);
    }

    if (field->mDataSize)
    {
        free(field->mData.data);
    }
    else
    {
        switch (field->mType)
        {
        case MAMA_FIELD_TYPE_PRICE:
            mamaPrice_destroy((mamaPrice)field->mData.data);
            break;
        case MAMA_FIELD_TYPE_TIME:
            mamaDateTime_destroy((mamaDateTime)field->mData.data);
            break;
        case MAMA_FIELD_TYPE_VECTOR_STRING:
            if (field->mData.data)
            {
                mamaFieldCacheVector_free((mamaFieldCacheVector)field->mData.data);
                mamaFieldCacheVector_destroy((mamaFieldCacheVector)field->mData.data);
            }
            break;
        case MAMA_FIELD_TYPE_VECTOR_PRICE:
            if (field->mData.data)
            {
                mamaFieldCacheField_destroyPriceVector(
                        (mamaFieldCacheVector)field->mData.data);
            }
            break;
        case MAMA_FIELD_TYPE_VECTOR_TIME:
            if (field->mData.data)
            {
                mamaFieldCacheField_destroyDateTimeVector(
                        (mamaFieldCacheVector)field->mData.data);
            }
            break;
        default:
            break;
        }
    }

    free(field);

    return MAMA_STATUS_OK;
}
Example #3
0
void
DateTimeRangeTests::DestroyTestData()
{
   for (TestDataMap::iterator itr = m_TestData.begin(); itr != m_TestData.end(); ++itr)
   {
      mamaDateTime t = (*itr).first;   

      ASSERT_EQ ( MAMA_STATUS_OK, mamaDateTime_destroy(t) );
   }
}
Example #4
0
mama_status
mamaFieldCacheField_destroyDateTimeVector(mamaFieldCacheVector dateTimeVector)
{
    mama_size_t i;
    mama_size_t size = 0;
    void* dateTime = NULL;
    
    mamaFieldCacheVector_getSize(dateTimeVector, &size);
    for (i = 0; i < size; i++)
    {
        mamaFieldCacheVector_get(dateTimeVector, i, &dateTime);
        mamaDateTime_destroy((mamaDateTime)dateTime);
    }
    mamaFieldCacheVector_destroy(dateTimeVector);
    return MAMA_STATUS_OK;
}
TEST_F(MamaDateTimeTestC, CompareDates)
{
	// Get todays date in a date time
	mamaDateTime today = NULL;
	
    ASSERT_EQ(mamaDateTime_create(&today), MAMA_STATUS_OK);
    ASSERT_EQ(mamaDateTime_setToNow(today), MAMA_STATUS_OK);

	// Get the string representation of the data
	char stringDate[100] = "";
	ASSERT_EQ(mamaDateTime_getAsFormattedString(today, stringDate, 100, "%Y-%m-%d"), MAMA_STATUS_OK);

	// Destroy the date
	ASSERT_EQ(mamaDateTime_destroy(today), MAMA_STATUS_OK);

	// Format a string using today's date and a time, this should be as "2010-07-04 10:00:00.000"
	const char *time = "10:00:00.000000";
	char completeDateTime[100] = "";
    mamaDateTime m_cDateTime = NULL;
	sprintf(completeDateTime, "%s %s", stringDate, time);

	// Set the date from this string
	ASSERT_EQ(mamaDateTime_setFromString(m_cDateTime, completeDateTime), MAMA_STATUS_OK);

	// Get the number of seconds
	mama_f64_t completeDateSeconds = 0;
	ASSERT_EQ(mamaDateTime_getEpochTimeSecondsWithCheck(m_cDateTime, &completeDateSeconds), MAMA_STATUS_OK);

	// Set the date using just the time string
	ASSERT_EQ(mamaDateTime_clear(m_cDateTime), MAMA_STATUS_OK);
	
    ASSERT_EQ(mamaDateTime_setFromString(m_cDateTime, time), MAMA_STATUS_OK);

	// Get the number of seconds from this
	mama_f64_t timeSeconds = 0;
	ASSERT_EQ(mamaDateTime_getEpochTimeSecondsWithCheck(m_cDateTime, &timeSeconds), MAMA_STATUS_OK);
    
	// These must be the same
	ASSERT_EQ(completeDateSeconds, timeSeconds);
}
Example #6
0
void 
DateTimeRangeTests::EqualAndCompareTest(const mamaDateTime& t)
{

   mamaDateTime cpy;
   mama_u32_t year, month, day;

   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_create(&cpy) );

   // Copy t
   // Chek both date times are eaual
   // Change the value of Copy
   // Check they do not equal each other
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_copy(cpy,t) );
   EXPECT_EQ ( 1, mamaDateTime_equal(t, cpy) );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_setToNow(cpy) );
   EXPECT_NE ( 1, mamaDateTime_equal(t, cpy) );

   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_getYear(cpy, &year) );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_getMonth(cpy, &month) );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_getDay(cpy, &day) );

   // Copy t
   // Check that Compare is ZERO
   // Set cpy to be less that t
   // Check that compare = 1
   // Set cpy to be greater than t
   // Check that compare = -1
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_copy(cpy,t) );
   EXPECT_EQ ( 0, mamaDateTime_compare(t, cpy) );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_setDate(cpy, year - 20, month, day) );
   EXPECT_EQ ( 1, mamaDateTime_compare(t, cpy) );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_copy(cpy,t) );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_setDate(cpy, year + 20, month, day) );
   EXPECT_EQ ( -1, mamaDateTime_compare(t, cpy) );

   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_destroy(cpy) );
   
}
void MamaDateTimeTestC::TearDown(void)
{
	ASSERT_EQ(mamaDateTime_destroy(m_DateTime), MAMA_STATUS_OK);
}
Example #8
0
void 
DateTimeRangeTests::ClearAndCopyTest(const mamaDateTime& t)
{
   mamaDateTime t1, t2;
   mama_bool_t b;

   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_create(&t1) );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_create(&t2) );

   // t is not equal to t1 or t2
   EXPECT_NE ( 1, mamaDateTime_equal(t,t1) );
   EXPECT_NE ( 1, mamaDateTime_equal(t,t2) );

   // Copy t into t1 and t2
   // Check they are equal
   // clear t1
   // check they are not equal
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_copy(t1,t) );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_copy(t2,t) );
   EXPECT_EQ ( 1, mamaDateTime_equal(t1,t2) );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_clear(t2) );
   EXPECT_NE ( 1, mamaDateTime_equal(t1,t2) );

   // Test Copy Time
   // Change the time of t1
   // copy the time from t1 into t2
   // Check that the time components of t2 are as expected
   // Clear t2
   // Check that the time compoents of t2 do not equal the original values.
   mama_u32_t expHour = 10, expMinute = 6, expSecond = 18, expMicrosecond = 123,
              actHour,      actMinute,     actSecond,      actMicrosecond;

   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_setTime(t1, expHour, expMinute, expSecond, expMicrosecond) );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_copyTime(t2,t1) );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_getHour(t2, &actHour) );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_getMinute(t2, &actMinute) );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_getSecond(t2, &actSecond) );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_getMicrosecond(t2, &actMicrosecond) );
   EXPECT_EQ ( actHour, expHour);
   EXPECT_EQ ( actMinute, expMinute);
   EXPECT_EQ ( actSecond, expSecond);
   EXPECT_EQ ( actMicrosecond, expMicrosecond);
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_hasTime(t2, &b) );  
   EXPECT_TRUE ( b );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_clearTime(t2) );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_hasTime(t2, &b) );  
   EXPECT_FALSE ( b );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_getHour(t2, &actHour) );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_getMinute(t2, &actMinute) );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_getSecond(t2, &actSecond) );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_getMicrosecond(t2, &actMicrosecond) );
   EXPECT_NE ( actHour, expHour);
   EXPECT_NE ( actMinute, expMinute);
   EXPECT_NE ( actSecond, expSecond);
   EXPECT_NE ( actMicrosecond, expMicrosecond);

   // Test Copy Date
   // Change the date of t1
   // copy the date from t1 into t2
   // Check that the time components of t2 are as expected
   // Clear t2
   // Check that the Date compoents of t2 do not equal the original values.
   mama_u32_t expYear = 2009, expMonth = 6, expDay = 18,
              actYear,        actMonth,     actDay;

   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_setDate(t1, expYear, expMonth, expDay) );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_copyDate(t2,t1) );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_getYear(t2, &actYear) );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_getMonth(t2, &actMonth) );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_getDay(t2, &actDay) );
   EXPECT_EQ ( actYear, expYear);
   EXPECT_EQ ( actMonth, expMonth);
   EXPECT_EQ ( actDay, expDay);
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_hasDate(t2, &b) );  
   EXPECT_TRUE ( b );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_clearDate(t2) );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_hasDate(t2, &b) );  
   EXPECT_FALSE ( b );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_getYear(t2, &actYear) );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_getMonth(t2, &actMonth) );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_getDay(t2, &actDay) );
   EXPECT_NE ( actYear, expYear);
   EXPECT_NE ( actMonth, expMonth);
   EXPECT_NE ( actDay, expDay);

   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_destroy(t1) );
   EXPECT_EQ ( MAMA_STATUS_OK, mamaDateTime_destroy(t2) );
}
void populateMessageFromDictionary (mamaDictionaryImpl* impl,
                                    mamaMsg             msg)
{
    int         i      = 0;
    mama_status status = MAMA_STATUS_OK;

    const mama_bool_t bool_vector[] = {0};
    const char char_vector[] = {' '};
    const mama_i8_t i8_vector[] = {1};
    const mama_u8_t u8_vector[] = {1};
    const mama_i16_t i16_vector[] = {1};
    const mama_u16_t u16_vector[] = {1};
    const mama_i32_t i32_vector[] = {1};
    const mama_u32_t u32_vector[] = {1};
    const mama_i64_t i64_vector[] = {1};
    const mama_u64_t u64_vector[] = {1};
    const mama_f32_t f32_vector[] = {1.0f};
    const mama_f64_t f64_vector[] = {1.0};
    const char*      string_vector[] = {" "};

    mamaMsg msgArray[1];
    mamaMsg tempMsg   =   NULL;

    mamaPrice price_vector[1];
    mamaPrice price = NULL;

    mamaDateTime dateTime_vector[1];
    mamaDateTime dateTime = NULL;


    mamaMsg_create (&tempMsg);
    mamaMsg_addI32 (tempMsg, NULL, 1, 0);
    msgArray[0] = tempMsg;

    mamaPrice_create (&price);
    mamaPrice_setValue (price,123.45);
    price_vector[0] = price;

    mamaDateTime_create (&dateTime);
    mamaDateTime_setToNow (dateTime);
    dateTime_vector[0] = dateTime;
    
    for (i=0;i<impl->mDictSize;i++)
    {
        if (impl->mDict[i])
        {
            mamaFieldDescriptor fd = impl->mDict[i];
            mama_fid_t      fid     = mamaFieldDescriptor_getFid  (fd);
            const char*     name    = mamaFieldDescriptor_getName (fd);
            mamaFieldType   type    = mamaFieldDescriptor_getType (fd);

            switch (type)
            {
                case MAMA_FIELD_TYPE_MSG:
                    ADD_TO_DICT (Msg, tempMsg);
                    break;
                case MAMA_FIELD_TYPE_OPAQUE:
                    mamaMsg_addOpaque (msg, name, fid, (void*)" ", 2);
                    break;
                case MAMA_FIELD_TYPE_STRING:
                    ADD_TO_DICT (String, "");
                    break;
                case MAMA_FIELD_TYPE_BOOL:
                    ADD_TO_DICT (Bool, 0);
                    break;
                case MAMA_FIELD_TYPE_CHAR:
                    ADD_TO_DICT (Char, ' ');
                    break;
                case MAMA_FIELD_TYPE_I8:
                    ADD_TO_DICT (I8, 0);
                    break;
                case MAMA_FIELD_TYPE_U8:
                    ADD_TO_DICT (U8, 0);
                    break;
                case MAMA_FIELD_TYPE_I16:
                    ADD_TO_DICT (I16, 0);
                    break;
                case MAMA_FIELD_TYPE_U16:
                    ADD_TO_DICT (U16, 0);
                    break;
                case MAMA_FIELD_TYPE_I32:
                    ADD_TO_DICT (I32, 0);
                    break;
                case MAMA_FIELD_TYPE_U32:
                    ADD_TO_DICT (U32, 0);
                    break;
                case MAMA_FIELD_TYPE_I64:
                    ADD_TO_DICT (I64, 0);
                    break;
                case MAMA_FIELD_TYPE_U64:
                    ADD_TO_DICT (U64, 0);
                    break;
                case MAMA_FIELD_TYPE_F32:
                    ADD_TO_DICT (F32, 0.0f);
                    break;
                case MAMA_FIELD_TYPE_F64:
                    ADD_TO_DICT (F64, 0.0);
                    break;
                case MAMA_FIELD_TYPE_TIME:
                    ADD_TO_DICT (DateTime, dateTime);
                    break;
                case MAMA_FIELD_TYPE_PRICE:
                    ADD_TO_DICT (Price, price);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_BOOL:
                    ADD_VECTOR_TO_DICT (Bool, bool_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_CHAR:
                    ADD_VECTOR_TO_DICT (Char, char_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_I8:
                    ADD_VECTOR_TO_DICT (I8, i8_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_U8:
                    ADD_VECTOR_TO_DICT (U8, u8_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_I16:
                    ADD_VECTOR_TO_DICT (I16, i16_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_U16:
                    ADD_VECTOR_TO_DICT (U16, u16_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_I32:
                    ADD_VECTOR_TO_DICT (I32, i32_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_U32:
                    ADD_VECTOR_TO_DICT (U32, u32_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_I64:
                    ADD_VECTOR_TO_DICT (I64, i64_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_U64:
                    ADD_VECTOR_TO_DICT (U64, u64_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_F32:
                    ADD_VECTOR_TO_DICT (F32, f32_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_F64:
                    ADD_VECTOR_TO_DICT (F64, f64_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_STRING:
                    ADD_VECTOR_TO_DICT (String, string_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_MSG:
                    ADD_VECTOR_TO_DICT (Msg, msgArray);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_TIME:
                    ADD_VECTOR_TO_DICT (DateTime, dateTime_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_PRICE:
                    ADD_VECTOR_TO_DICT (Price, price_vector);
                    break;
                default:
					/* error with unknown type */
                    mama_log (MAMA_LOG_LEVEL_NORMAL, "Could not add type to "
                              "dict message - not supported. [%s] fid=%d name=%s",
                              mamaFieldTypeToString (type), fid, name);
                    break;
            }
        }
    }

    mamaPrice_destroy (price);
    mamaDateTime_destroy (dateTime);
    mamaMsg_destroy (tempMsg);
}