int main(void){ char name[80]; char failMsg[80]; int result = 0; int rc; // the ESMC_Clock object ESMC_Clock clock; //---------------------------------------------------------------------------- ESMC_TestStart(__FILE__, __LINE__, 0); //---------------------------------------------------------------------------- ESMC_TimeInterval timeStep,runDuration; ESMC_Time startTime, stopTime, refTime; ESMC_Calendar calendar; ESMC_I4 yy1=2006; ESMC_I4 h1=0; ESMC_I4 h2=1; ESMC_CalendarType calType1=ESMC_CAL_GREGORIAN; int tZ1=-6; const ESMC_I4 one=1; ESMC_TimeInterval currSimTime; ESMC_I8 advanceCount, advanceCount1; ESMC_I8 initSec, currSec1; ESMC_R8 initHour, currHour1; //---------------------------------------------------------------------------- //NEX_UTest strcpy(name, "Create ESMC_Calendar object"); strcpy(failMsg, "Did not return ESMF_SUCCESS"); calendar = ESMC_CalendarCreate("Gregorian", ESMC_CAL_GREGORIAN, &rc); ESMC_Test((rc==ESMF_SUCCESS), name, failMsg, &result, __FILE__, __LINE__, 0); //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- //NEX_UTest strcpy(name, "Set Start Time"); strcpy(failMsg, "Did not return ESMF_SUCCESS"); rc = ESMC_TimeSet(&startTime, yy1, h1, calendar, calType1, tZ1); ESMC_Test((rc==ESMF_SUCCESS), name, failMsg, &result, __FILE__, __LINE__, 0); //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- //NEX_UTest strcpy(name, "Set Stop Time"); strcpy(failMsg, "Did not return ESMF_SUCCESS"); rc = ESMC_TimeSet(&stopTime, yy1, h2, calendar, calType1, tZ1); ESMC_Test((rc==ESMF_SUCCESS), name, failMsg, &result, __FILE__, __LINE__, 0); //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- //NEX_UTest strcpy(name, "Set a TimeInterval"); strcpy(failMsg, "Did not return ESMF_SUCCESS"); rc = ESMC_TimeIntervalSet(&timeStep, one); ESMC_Test((rc==ESMF_SUCCESS), name, failMsg, &result, __FILE__, __LINE__, 0); //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- //NEX_UTest strcpy(name, "Create ESMC_Clock object"); strcpy(failMsg, "Did not return ESMF_SUCCESS"); clock = ESMC_ClockCreate("TEST_CLOCK", timeStep, startTime, stopTime, &rc); ESMC_Test((rc==ESMF_SUCCESS), name, failMsg, &result, __FILE__, __LINE__, 0); //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- //NEX_UTest strcpy(name, "Print ESMC_Clock object"); strcpy(failMsg, "Did not return ESMF_SUCCESS"); rc = ESMC_ClockPrint(clock); ESMC_Test((rc==ESMF_SUCCESS), name, failMsg, &result, __FILE__, __LINE__, 0); //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- //NEX_UTest strcpy(name, "Get ESMC_Clock object current time and advance count"); strcpy(failMsg, "Did not return ESMF_SUCCESS"); rc = ESMC_ClockGet(clock, &currSimTime, &advanceCount); ESMC_Test((rc==ESMF_SUCCESS), name, failMsg, &result, __FILE__, __LINE__, 0); //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- //NEX_UTest strcpy(name, "Advance the Clock object"); strcpy(failMsg, "Did not return ESMF_SUCCESS"); rc = ESMC_ClockAdvance(clock); ESMC_Test((rc==ESMF_SUCCESS), name, failMsg, &result, __FILE__, __LINE__, 0); //---------------------------------------------------------------------------- #ifdef ESMF_TESTEXHAUSTIVE //---------------------------------------------------------------------------- //EX_UTest strcpy(name, "Get ESMC_Clock object current time and advance count"); strcpy(failMsg, "Did not return ESMF_SUCCESS"); rc = ESMC_ClockGet(clock, &currSimTime, &advanceCount1); ESMC_Test((rc==ESMF_SUCCESS), name, failMsg, &result, __FILE__, __LINE__, 0); //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- //EX_UTest strcpy(name, "Get currSimTime in seconds and in hours"); strcpy(failMsg, "Did not return ESMF_SUCCESS"); rc = ESMC_TimeIntervalGet(currSimTime, &currSec1, &currHour1); ESMC_Test((rc==ESMF_SUCCESS), name, failMsg, &result, __FILE__, __LINE__, 0); //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- //EX_UTest strcpy(name, "Verify that currSimTime in second units"); strcpy(failMsg, "Did not return 3600"); ESMC_Test((int(currSec1)==3600), name, failMsg, &result, __FILE__, __LINE__, 0); //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- //EX_UTest strcpy(name, "Verify that currSimTime in hour units"); strcpy(failMsg, "Did not return 1"); ESMC_Test((int(currHour1)==1), name, failMsg, &result, __FILE__, __LINE__, 0); //---------------------------------------------------------------------------- #endif //---------------------------------------------------------------------------- //NEX_UTest strcpy(name, "Destroy ESMC_Clock object"); strcpy(failMsg, "Did not return ESMF_SUCCESS"); rc = ESMC_ClockDestroy(&clock); ESMC_Test((rc==ESMF_SUCCESS), name, failMsg, &result, __FILE__, __LINE__, 0); //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- //NEX_UTest strcpy(name, "Destroy ESMC_Calendar object"); strcpy(failMsg, "Did not return ESMF_SUCCESS"); rc = ESMC_CalendarDestroy(&calendar); ESMC_Test((rc==ESMF_SUCCESS), name, failMsg, &result, __FILE__, __LINE__, 0); //---------------------------------------------------------------------------- /* #ifdef ESMF_TESTEXHAUSTIVE #if 0 // perform exhaustive tests here; // see #else below for non-exhaustive tests // future release will use run-time switching mechanism // test dynamic allocation of ESMC_Clock // also tests default constructor clock_ptr = ESMC_ClockCreate(args, &rc); sprintf(name, "ESMC_ClockCreate"); sprintf(failMsg, "rc = %d, clock_ptr = %p, args = %f", rc, clock_ptr, args); ESMC_Test((clock_ptr!=0 && rc==ESMF_SUCCESS), name, failMsg, &result, ESMF_SRCLINE); // test internal dynamic allocation within statically allocated // ESMC_Clock rc = clock_ptr->ESMC_ClockConstruct(args); sprintf(name, "ESMC_ClockConstruct"); sprintf(failMsg, "rc = %d, args = %f", rc, args); ESMC_Test((rc==ESMF_SUCCESS), name, failMsg, &result, ESMF_SRCLINE); // test initialization of members of statically allocated ESMC_Clock // may want to read back values via Get methods for comparison rc = clock_ptr->ESMC_ClockSet(args); sprintf(name, "ESMC_ClockSet"); sprintf(failMsg, "rc = %d, args = %f", rc, args); ESMC_Test((rc==ESMF_SUCCESS), name, failMsg, &result, ESMF_SRCLINE); // test setting of configuration values ESMC_ClockConfig config_set; rc = clock_ptr->ESMC_ClockSetConfig(config_set); sprintf(name, "ESMC_ClockSetConfig"); sprintf(failMsg, "rc = %d, config_set = %f", rc, config_set); ESMC_Test((rc==ESMF_SUCCESS), name, failMsg, &result, ESMF_SRCLINE); // test getting of configuration values, // compare to values set previously ESMC_ClockConfig config_get; rc = clock_ptr->ESMC_ClockGetConfig(&config_get); sprintf(name, "ESMC_ClockGetConfig"); sprintf(failMsg, "rc = %d, config_get = %f", rc, config_get); ESMC_Test((rc==ESMF_SUCCESS && config_get == config_set), name, failMsg, &result, ESMF_SRCLINE); // test setting of ESMC_Clock members values <value type> value_set; rc = clock_ptr->ESMC_ClockSet<Value>(value_set); sprintf(name, "ESMC_ClockSet<Value>"); sprintf(failMsg, "rc = %d, value_set = %f", rc, value_set); ESMC_Test((rc==ESMF_SUCCESS), name, failMsg, &result, ESMF_SRCLINE); // test getting of ESMC_Clock members values, // compare to values set previously <value type> value_get; rc = clock_ptr->ESMC_ClockGet<Value>(&value_get); sprintf(name, "ESMC_ClockGet<Value>"); sprintf(failMsg, "rc = %d, value_get = %f", rc, value_get); ESMC_Test((rc==ESMF_SUCCESS && value_get == value_set), name, failMsg, &result, ESMF_SRCLINE); // test validate method via option string char validate_options[ESMF_MAXSTR]; rc = clock_ptr->ESMC_ClockValidate(validate_options); sprintf(name, "ESMC_ClockValidate"); sprintf(failMsg, "rc = %d, validate_options = %s", rc, validate_options); ESMC_Test((rc==ESMF_SUCCESS), name, failMsg, &result, ESMF_SRCLINE); // test print method via option string char print_options[ESMF_MAXSTR]; rc = clock_ptr->ESMC_ClockPrint(print_options); sprintf(name, "ESMC_ClockPrint"); sprintf(failMsg, "rc = %d, print_options = %s", rc, print_options); ESMC_Test((rc==ESMF_SUCCESS), name, failMsg, &result, ESMF_SRCLINE); // test internal dynamic deallocation within statically allocated // ESMC_Clock rc = clock_ptr->ESMC_ClockDestruct(); sprintf(name, "ESMC_ClockDestruct"); sprintf(failMsg, "rc = %d", rc); ESMC_Test((rc==ESMF_SUCCESS), name, failMsg, &result, ESMF_SRCLINE); // test dynamic deallocation of ESMC_Clock // also tests destructor rc = ESMC_ClockDestroy(clock_ptr); sprintf(name, "ESMC_ClockDestroy"); sprintf(failMsg, "rc = %d, clock_ptr = %p", rc, clock_ptr); ESMC_Test((rc==ESMF_SUCCESS), name, failMsg, &result, ESMF_SRCLINE); #endif #else // perform non-exhaustive tests here; // use same templates as above #endif */ //---------------------------------------------------------------------------- ESMC_TestEnd(result, __FILE__, __LINE__, 0); //---------------------------------------------------------------------------- // return number of failures to environment; 0 = success (all pass) printf("result = %d\n",result); return(result); }
int main(int argc, char *argv[]) { // result code int rc; //Set finalrc to success int finalrc=ESMF_SUCCESS; // instantiate a clock ESMC_Clock *clock; // instantiate a calendar ESMC_Calendar *gregorianCalendar; // instantiate timestep, start and stop times ESMCI::TimeInterval timeStep; ESMCI::Time startTime; ESMCI::Time stopTime; // initialize calendar to be Gregorian type gregorianCalendar = ESMC_CalendarCreate(9, "Gregorian", ESMC_CAL_GREGORIAN, &rc); if (rc != ESMF_SUCCESS) { finalrc = ESMF_FAILURE; } // initialize time interval to 1 hour int h = 1; rc = timeStep.ESMCI::TimeInterval::set(0, 0, 0, 0, 0, 0, &h); if (rc != ESMF_SUCCESS) { finalrc = ESMF_FAILURE; } // initialize start time to 3/27/2003 int yy = 2003; int mm = 3, dd = 27; rc = startTime.ESMCI::Time::set(&yy, 0, &mm, &dd, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &gregorianCalendar); if (rc != ESMF_SUCCESS) { finalrc = ESMF_FAILURE; } // initialize stop time to 3/29/2003 yy = 2003; mm = 3; dd = 29; rc = stopTime.ESMCI::Time::set(&yy, 0, &mm, &dd, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &gregorianCalendar); if (rc != ESMF_SUCCESS) { finalrc = ESMF_FAILURE; } // initialize the clock with the above values clock = ESMC_ClockCreate(7, "Clock 1", &timeStep, &startTime, &stopTime, 0, 0, 0, &rc); if (rc != ESMF_SUCCESS) { finalrc = ESMF_FAILURE; } // time step from start time to stop time while (!clock->ESMC_ClockIsStopTime(&rc)) { rc = clock->ESMC_ClockAdvance(); if (rc != ESMF_SUCCESS) { finalrc = ESMF_FAILURE; } } // get the number of times the clock was advanced ESMC_I8 advanceCount; rc = clock->ESMC_ClockGet(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &advanceCount); if (rc != ESMF_SUCCESS) { finalrc = ESMF_FAILURE; } printf("The clock was advanced %d times.\n", advanceCount); // Test for the correct number of advance counts. if (advanceCount != 48) { finalrc = ESMF_FAILURE; } rc = ESMC_ClockDestroy(&clock); if (rc != ESMF_SUCCESS) { finalrc = ESMF_FAILURE; } rc = ESMC_CalendarDestroy(&gregorianCalendar); if (rc != ESMF_SUCCESS) { finalrc = ESMF_FAILURE; } if (finalrc == ESMF_SUCCESS) { printf("PASS: ESMC_ClockEx.C\n"); return(ESMF_SUCCESS); } else { printf("FAIL: ESMC_ClockEx.C\n"); return(ESMF_FAILURE); } } // end ESMC_ClockEx