END_TEST START_TEST (test_Date_setOffsetSign) { Date_t * date = Date_createFromValues(2005, 12, 30, 12, 15, 45, 1, 2, 0); fail_unless(date != NULL); int i = Date_setSignOffset(date, 2); fail_unless( i == LIBSBML_INVALID_ATTRIBUTE_VALUE ); fail_unless( Date_getSignOffset(date) == 0); i = Date_setSignOffset(date, -4); fail_unless( i == LIBSBML_INVALID_ATTRIBUTE_VALUE ); fail_unless( Date_getSignOffset(date) == 0); i = Date_setSignOffset(date, 0); fail_unless( i == LIBSBML_OPERATION_SUCCESS ); fail_unless( Date_getSignOffset(date) == 0); fail_unless(!strcmp(Date_getDateAsString(date), "2005-12-30T12:15:45-02:00")); Date_free(date); }
END_TEST START_TEST (test_ModelHistory_setModifiedDate1) { ModelHistory_t * mh = ModelHistory_create(); fail_unless(mh != NULL); Date_t *date = Date_createFromString("2005-12-30T12:15:32+02:00"); int i = ModelHistory_setModifiedDate(mh, date); fail_unless( i == LIBSBML_OPERATION_SUCCESS ); fail_unless(ModelHistory_isSetModifiedDate(mh) == 1); fail_unless(date != ModelHistory_getModifiedDate(mh)); const char * dateChar = Date_getDateAsString(ModelHistory_getModifiedDate(mh)); fail_unless(!strcmp(dateChar, "2005-12-30T12:15:32+02:00")); i = ModelHistory_setModifiedDate(mh, NULL); fail_unless( i == LIBSBML_OPERATION_FAILED ); fail_unless(ModelHistory_isSetModifiedDate(mh) == 1); Date_free(date); ModelHistory_free(mh); }
double Date_secondsSinceNow(const Date *self) { Date *now = Date_new(); double s = Date_secondsSince_(now, self); Date_free(now); return s; }
END_TEST START_TEST (test_ModelHistory_setModifiedDate) { ModelHistory_t * history = ModelHistory_create(); fail_unless(history != NULL); fail_unless(ModelHistory_isSetModifiedDate(history) == 0); Date_t * date = Date_createFromValues(2005, 12, 30, 12, 15, 45, 1, 2, 0); ModelHistory_setModifiedDate(history, date); Date_free(date); fail_unless(ModelHistory_isSetModifiedDate(history) == 1); Date_t * newdate = ModelHistory_getModifiedDate(history); fail_unless(Date_getYear(newdate) == 2005); fail_unless(Date_getMonth(newdate) == 12); fail_unless(Date_getDay(newdate) == 30); fail_unless(Date_getHour(newdate) == 12); fail_unless(Date_getMinute(newdate) == 15); fail_unless(Date_getSecond(newdate) == 45); fail_unless(Date_getSignOffset(newdate) == 1); fail_unless(Date_getHoursOffset(newdate) == 2); fail_unless(Date_getMinutesOffset(newdate) == 0); ModelHistory_free(history); }
END_TEST START_TEST (test_Date_accessWithNULL) { fail_unless( Date_clone(NULL) == NULL ); fail_unless( Date_createFromString(NULL) == NULL ); // ensure that we don't crash Date_free(NULL); fail_unless( Date_getDateAsString(NULL) == NULL ); fail_unless( Date_getDay(NULL) == SBML_INT_MAX ); fail_unless( Date_getHour(NULL) == SBML_INT_MAX ); fail_unless( Date_getHoursOffset(NULL) == SBML_INT_MAX ); fail_unless( Date_getMinute(NULL) == SBML_INT_MAX ); fail_unless( Date_getMinutesOffset(NULL) == SBML_INT_MAX ); fail_unless( Date_getMonth(NULL) == SBML_INT_MAX ); fail_unless( Date_getSecond(NULL) == SBML_INT_MAX ); fail_unless( Date_getSignOffset(NULL) == SBML_INT_MAX ); fail_unless( Date_getYear(NULL) == SBML_INT_MAX ); fail_unless( Date_representsValidDate(NULL) == 0 ); fail_unless( Date_setDateAsString(NULL, NULL) == LIBSBML_INVALID_OBJECT ); fail_unless( Date_setDay(NULL, 0) == LIBSBML_INVALID_OBJECT ); fail_unless( Date_setHour(NULL, 0) == LIBSBML_INVALID_OBJECT ); fail_unless( Date_setHoursOffset(NULL, 0) == LIBSBML_INVALID_OBJECT ); fail_unless( Date_setMinute(NULL, 0) == LIBSBML_INVALID_OBJECT ); fail_unless( Date_setMinutesOffset(NULL, 0) == LIBSBML_INVALID_OBJECT ); fail_unless( Date_setMonth(NULL, 0) == LIBSBML_INVALID_OBJECT ); fail_unless( Date_setSecond(NULL, 0) == LIBSBML_INVALID_OBJECT ); fail_unless( Date_setSignOffset(NULL, 0) == LIBSBML_INVALID_OBJECT ); fail_unless( Date_setYear(NULL, 0) == LIBSBML_INVALID_OBJECT ); }
LIBSBML_CPP_NAMESPACE_USE CK_CPPSTART #endif START_TEST (test_Date_setYear) { Date_t * date = Date_createFromValues(2005, 12, 30, 12, 15, 45, 1, 2, 0); fail_unless(date != NULL); int i = Date_setYear(date, 434); fail_unless( i == LIBSBML_INVALID_ATTRIBUTE_VALUE ); fail_unless( Date_getYear(date) == 2000); i = Date_setYear(date, 12121); fail_unless( i == LIBSBML_INVALID_ATTRIBUTE_VALUE ); fail_unless( Date_getYear(date) == 2000); i = Date_setYear(date, 2008); fail_unless( i == LIBSBML_OPERATION_SUCCESS ); fail_unless( Date_getYear(date) == 2008); fail_unless(!strcmp(Date_getDateAsString(date), "2008-12-30T12:15:45+02:00")); Date_free(date); }
END_TEST START_TEST (test_Date_setDay) { Date_t * date = Date_createFromValues(2005, 2, 12, 12, 15, 45, 1, 2, 0); fail_unless(date != NULL); int i = Date_setDay(date, 29); fail_unless( i == LIBSBML_INVALID_ATTRIBUTE_VALUE ); fail_unless( Date_getDay(date) == 1); i = Date_setDay(date, 31); fail_unless( i == LIBSBML_INVALID_ATTRIBUTE_VALUE ); fail_unless( Date_getDay(date) == 1); i = Date_setDay(date, 15); fail_unless( i == LIBSBML_OPERATION_SUCCESS ); fail_unless( Date_getDay(date) == 15); fail_unless(!strcmp(Date_getDateAsString(date), "2005-02-15T12:15:45+02:00")); Date_free(date); }
END_TEST START_TEST (test_Date_setters) { Date_t * date = Date_createFromValues(2005, 12, 30, 12, 15, 45, 1, 2, 0); fail_unless(date != NULL); Date_setYear(date, 2012); Date_setMonth(date, 3); Date_setDay(date, 28); Date_setHour(date, 23); Date_setMinute(date, 4); Date_setSecond(date, 32); Date_setSignOffset(date, 1); Date_setHoursOffset(date, 2); Date_setMinutesOffset(date, 32); fail_unless(Date_getYear(date) == 2012); fail_unless(Date_getMonth(date) == 3); fail_unless(Date_getDay(date) == 28); fail_unless(Date_getHour(date) == 23); fail_unless(Date_getMinute(date) == 4); fail_unless(Date_getSecond(date) == 32); fail_unless(Date_getSignOffset(date) == 1); fail_unless(Date_getHoursOffset(date) == 2); fail_unless(Date_getMinutesOffset(date) == 32); fail_unless(!strcmp(Date_getDateAsString(date), "2012-03-28T23:04:32+02:32")); Date_free(date); }
END_TEST START_TEST (test_Date_setMinute) { Date_t * date = Date_createFromValues(2005, 12, 30, 12, 15, 45, 1, 2, 0); fail_unless(date != NULL); int i = Date_setMinute(date, 434); fail_unless( i == LIBSBML_INVALID_ATTRIBUTE_VALUE ); fail_unless( Date_getMinute(date) == 0); i = Date_setMinute(date, 12121); fail_unless( i == LIBSBML_INVALID_ATTRIBUTE_VALUE ); fail_unless( Date_getMinute(date) == 0); i = Date_setMinute(date, 32); fail_unless( i == LIBSBML_OPERATION_SUCCESS ); fail_unless( Date_getMinute(date) == 32); fail_unless(!strcmp(Date_getDateAsString(date), "2005-12-30T12:32:45+02:00")); Date_free(date); }
END_TEST START_TEST (test_Date_getDateAsString) { const char * dd = "2005-02-02T14:56:11Z"; Date_t * date = Date_createFromString(dd); fail_unless(date != NULL); fail_unless(Date_getYear(date) == 2005); fail_unless(Date_getMonth(date) == 2); fail_unless(Date_getDay(date) == 2); fail_unless(Date_getHour(date) == 14); fail_unless(Date_getMinute(date) == 56); fail_unless(Date_getSecond(date) == 11); fail_unless(Date_getSignOffset(date) == 0); fail_unless(Date_getHoursOffset(date) == 0); fail_unless(Date_getMinutesOffset(date) == 0); Date_setYear(date, 2012); Date_setMonth(date, 3); Date_setDay(date, 28); Date_setHour(date, 23); Date_setMinute(date, 4); Date_setSecond(date, 32); Date_setSignOffset(date, 1); Date_setHoursOffset(date, 2); Date_setMinutesOffset(date, 32); fail_unless(!strcmp(Date_getDateAsString(date), "2012-03-28T23:04:32+02:32")); Date_free(date); }
END_TEST START_TEST (test_Date_setHoursOffset_neg_arg) { Date_t * date = Date_createFromValues(2005, 12, 30, 12, 15, 45, 1, 2, 0); fail_unless(date != NULL); int i = Date_setHoursOffset(date, -3); fail_unless( i == LIBSBML_INVALID_ATTRIBUTE_VALUE ); fail_unless( Date_getHoursOffset(date) == 0); Date_free(date); }
END_TEST START_TEST (test_ModelHistory_setCreatedDate2) { ModelHistory_t * mh = ModelHistory_create(); fail_unless(mh != NULL); Date_t *date = Date_createFromString("Jan 12"); int i = ModelHistory_setCreatedDate(mh, date); fail_unless( i == LIBSBML_INVALID_OBJECT ); fail_unless(ModelHistory_isSetCreatedDate(mh) == 0); Date_free(date); ModelHistory_free(mh); }
END_TEST START_TEST (test_ModelHistory_setModifiedDate2) { ModelHistory_t * mh = ModelHistory_create(); fail_unless(mh != NULL); Date_t *date = Date_createFromValues(200, 13, 76, 56, 89, 90, 0, 0, 0); int i = ModelHistory_setModifiedDate(mh, date); fail_unless( i == LIBSBML_INVALID_OBJECT ); fail_unless(ModelHistory_isSetModifiedDate(mh) == 0); Date_free(date); ModelHistory_free(mh); }
END_TEST START_TEST (test_Date_setDateAsString) { Date_t * date = Date_createFromValues(2007, 10, 23, 14, 15, 16, 1, 3, 0); fail_unless(date != NULL); int i = Date_setDateAsString(date, "20081-12-30T12:15:45+02:00"); fail_unless( i == LIBSBML_INVALID_ATTRIBUTE_VALUE ); fail_unless(!strcmp(Date_getDateAsString(date), "2007-10-23T14:15:16+03:00")); i = Date_setDateAsString(date, "200-12-30T12:15:45+02:00"); fail_unless( i == LIBSBML_INVALID_ATTRIBUTE_VALUE ); fail_unless(!strcmp(Date_getDateAsString(date), "2007-10-23T14:15:16+03:00")); i = Date_setDateAsString(date, NULL); fail_unless( i == LIBSBML_OPERATION_SUCCESS ); fail_unless(!strcmp(Date_getDateAsString(date), "2000-01-01T00:00:00Z")); i = Date_setDateAsString(date, "2008-12-30T12:15:45+02:00"); fail_unless( i == LIBSBML_OPERATION_SUCCESS ); fail_unless( Date_getYear(date) == 2008); fail_unless( Date_getMonth(date) == 12); fail_unless( Date_getDay(date) == 30); fail_unless( Date_getHour(date) == 12); fail_unless( Date_getMinute(date) == 15); fail_unless( Date_getSecond(date) == 45); fail_unless( Date_getSignOffset(date) == 1); fail_unless( Date_getHoursOffset(date) == 2); fail_unless( Date_getMinutesOffset(date) == 0); Date_free(date); }
LIBSBML_CPP_NAMESPACE_USE CK_CPPSTART #endif START_TEST (test_Date_create) { Date_t * date = Date_createFromValues(2005, 12, 30, 12, 15, 45, 1, 2, 0); fail_unless(date != NULL); fail_unless(Date_getYear(date) == 2005); fail_unless(Date_getMonth(date) == 12); fail_unless(Date_getDay(date) == 30); fail_unless(Date_getHour(date) == 12); fail_unless(Date_getMinute(date) == 15); fail_unless(Date_getSecond(date) == 45); fail_unless(Date_getSignOffset(date) == 1); fail_unless(Date_getHoursOffset(date) == 2); fail_unless(Date_getMinutesOffset(date) == 0); Date_free(date); }
END_TEST START_TEST (test_L3_Species_ModelHistory) { ModelHistory_t * history = ModelHistory_create(); SBase_setMetaId((SBase_t *)(S), "_3"); int i = SBase_setModelHistory((SBase_t *)(S), history); fail_unless( i == LIBSBML_INVALID_OBJECT ); fail_unless( !SBase_isSetModelHistory((SBase_t *)(S)) ); ModelCreator_t * mc = ModelCreator_create(); Date_t * date = Date_createFromValues(2005, 12, 30, 12, 15, 45, 1, 2, 0); ModelCreator_setFamilyName(mc, "Keating"); ModelCreator_setGivenName(mc, "Sarah"); ModelCreator_setEmail(mc, "*****@*****.**"); ModelCreator_setOrganisation(mc, "UH"); ModelHistory_addCreator(history, mc); ModelHistory_setCreatedDate(history, date); ModelHistory_setModifiedDate(history, date); i = SBase_setModelHistory((SBase_t *)(S), history); fail_unless( i == LIBSBML_OPERATION_SUCCESS ); fail_unless( SBase_isSetModelHistory((SBase_t *)(S)) ); i = SBase_unsetModelHistory((SBase_t *)(S)); fail_unless( i == LIBSBML_OPERATION_SUCCESS ); fail_unless( !SBase_isSetModelHistory((SBase_t *)(S)) ); fail_unless( SBase_getModelHistory((SBase_t *)(S)) == NULL ); ModelHistory_free(history); ModelCreator_free(mc); Date_free(date); }
void IoDate_free(IoDate *self) { Date_free(DATA(self)); }