END_TEST

/* ----- Test case for set_day -----*/

/**
 * Purpose: test setting a regular value for day for
 * hildon_date_editor_get_day
 * Cases considered:
 *    - Set day 30
 */
START_TEST (test_set_day_regular)
{
  guint day;
  guint ret_day;

  day = 25;

  /* Test 1: Try day 30 */
  hildon_date_editor_set_day (date_editor, day);
  ret_day = hildon_date_editor_get_day (date_editor);

  fail_if (ret_day != day,
	   "hildon-date-editor: set_day failed. The returned day is %u and should be %u", 
	   ret_day, day);
}
END_TEST

/**
 * Purpose: test getting a day set over the limits for
 * hildon_date_editor_get_day
 * Cases considered:
 *    - Get day 31 for March
 *    - Get day 30 for June
 *    - Get day 29 for February for a leap year
 *    - Get day 28 for February for a common year
 *    - Get day 1
 */
START_TEST (test_get_day_limits)
{
  guint day, month, year;

  year = 1981;
  month = 3;
  day = 31;

  /* Test 1: 31 of February */
  hildon_date_editor_set_date (date_editor, year, month, day);
  fail_if (hildon_date_editor_get_day (date_editor) != day,
	   "hildon-date-editor: get_day failed. The returned day is %u and should be %u", 
	   hildon_date_editor_get_day (date_editor), day);

  /* Test 2: 30 of February */
  month = 6;
  day = 30;
  hildon_date_editor_set_date (date_editor, year, month, day);
  fail_if (hildon_date_editor_get_day (date_editor) != day,
	   "hildon-date-editor: get_day failed. The returned day is %u and should be %u", 
	   hildon_date_editor_get_day (date_editor), day);

  /* Test 3: 29 of February */
  year = 1980;
  month = 2;
  day = 29;
  hildon_date_editor_set_date (date_editor, year, month, day);
  fail_if (hildon_date_editor_get_day (date_editor) != day,
	   "hildon-date-editor: get_day failed. The returned day is %u and should be %u", 
	   hildon_date_editor_get_day (date_editor), day);

  /* Test 3: 28 of February */
  year = 1981;
  month = 2;
  day = 28;
  hildon_date_editor_set_date (date_editor, year, month, day);
  fail_if (hildon_date_editor_get_day (date_editor) != day,
	   "hildon-date-editor: get_day failed. The returned day is %u and should be %u", 
	   hildon_date_editor_get_day (date_editor), day);

  /* Test 5: day 1 */
  hildon_date_editor_set_day (date_editor, 1);

  fail_if (hildon_date_editor_get_day (date_editor) != 1,
	   "hildon-date-editor: get_day failed. The returned day is %u and should be %u", 
	   hildon_date_editor_get_day (date_editor), 1);
}
END_TEST

/* ----- Test case for get_day -----*/

/**
 * Purpose: test getting regular values for day for
 * hildon_date_editor_get_day
 * Cases considered:
 *    - Get a day set with set_date 30/03/1981
 *    - Get a day set with set_day 6
 *    - Get a day set with set_property 10
 */
START_TEST (test_get_day_regular)
{
  guint year, month, day;
  GValue value = {0, };

  year = 1981;
  month = 3;
  day = 30;

  /* Test 1: Set day with set_date */
  hildon_date_editor_set_date (date_editor, year, month, day);

  fail_if (hildon_date_editor_get_day (date_editor) != day,
	   "hildon-date-editor: The returned day is %u and should be %u", 
	   hildon_date_editor_get_day (date_editor), day);

  /* Test 2: set day with set_day */
  day = 6;
  hildon_date_editor_set_day (date_editor, day);

  fail_if (hildon_date_editor_get_day (date_editor) != day,
	   "hildon-date-editor: The returned day is %u and should be %u", 
	   hildon_date_editor_get_day (date_editor), day);


  /* Test 3: set day with set_property */
  day = 10;
  g_value_init (&value, G_TYPE_UINT);
  g_value_set_uint (&value, day);
  g_object_set_property (G_OBJECT (date_editor), "day", &value);

  fail_if (hildon_date_editor_get_day (date_editor) != day,
	   "hildon-date-editor: The returned day is %u and should be %u", 
	   hildon_date_editor_get_day (date_editor), day);

}
END_TEST

/**
 * Purpose: test seeting a day over the limits for
 * hildon_date_editor_get_day
 * Cases considered:
 *    - Set day 31
 *    - Set day 30
 *    - Set day 29
 *    - Set day 28
 *    - Set day 1
 */
START_TEST (test_set_day_limits)
{
  guint day, year, month;
  GValue value = { 0, };

  year = 1981;
  month = 3;
  day = 31;

  /* Set init date */
  hildon_date_editor_set_date (date_editor, year, month, MIN_DAY);

  /* Test 1: Test 31/03 */
  g_value_init (&value, G_TYPE_UINT);
  hildon_date_editor_set_day (date_editor, day);
  g_object_get_property (G_OBJECT (date_editor), "day", &value);
  fail_if (g_value_get_uint (&value) != day,
	   "hildon-date-editor: The returned day is %u and should be %u",
	   g_value_get_uint (&value), day);

  /* Test 2: Test 30/06 */
  month = 6;
  day = 30;
  hildon_date_editor_set_date (date_editor, year, month, 1);
  g_value_unset (&value);
  g_value_init (&value, G_TYPE_UINT);
  hildon_date_editor_set_day (date_editor, day);
  g_object_get_property (G_OBJECT (date_editor), "day", &value);
  fail_if (g_value_get_uint (&value) != day,
	   "hildon-date-editor: The returned day is %u and should be %u",
	   g_value_get_uint (&value), day);

  /* Test 3: Test 29/02/1980 */
  year = 1980;
  month = 2;
  day = 29;
  hildon_date_editor_set_date (date_editor, year, month, 1);
  g_value_unset (&value);
  g_value_init (&value, G_TYPE_UINT);
  hildon_date_editor_set_day (date_editor, day);
  g_object_get_property (G_OBJECT (date_editor), "day", &value);
  fail_if (g_value_get_uint (&value) != day,
	   "hildon-date-editor: The returned day is %u and should be %u",
	   g_value_get_uint (&value), day);

  /* Test 4: Test 28/02/1981 */
  year = 1981;
  month = 2;
  day = 28;
  hildon_date_editor_set_date (date_editor, year, month, 1);
  g_value_unset (&value);
  g_value_init (&value, G_TYPE_UINT);
  hildon_date_editor_set_day (date_editor, day);
  g_object_get_property (G_OBJECT (date_editor), "day", &value);
  fail_if (g_value_get_uint (&value) != day,
	   "hildon-date-editor: The returned day is %u and should be %u",
	   g_value_get_uint (&value), day);

  /* Test 5: Test 1/02/1980 */
  year = 1980;
  month = 2;
  day = 1;
  hildon_date_editor_set_date (date_editor, year, month, 10);
  g_value_unset (&value);
  g_value_init (&value, G_TYPE_UINT);
  hildon_date_editor_set_day (date_editor, day);
  g_object_get_property (G_OBJECT (date_editor), "day", &value);
  fail_if (g_value_get_uint (&value) != day,
	   "hildon-date-editor: The returned day is %u and should be %u",
	   g_value_get_uint (&value), day);
}
示例#5
0
void
dates_details_time_cb (DatesData *d, ECalComponentDateTime *time)
{
#ifndef WITH_HILDON
    gint i, hour, minute;
    gchar buffer[33];
    GtkCalendar *calendar;
	
    calendar = GTK_CALENDAR (d->time_calendar);
	
    /* Set time widgets */	
    gtk_calendar_select_month (calendar, time->value->month - 1,
			       time->value->year);
    gtk_calendar_select_day (calendar, time->value->day);

    g_snprintf (buffer, 33, "%d", time->value->hour);
    gtk_entry_set_text (GTK_ENTRY (d->hour_entry), buffer);
    i = time->value->minute / 10;
    g_snprintf (buffer, 33, "%d", i);
    gtk_entry_set_text (GTK_ENTRY (d->lminute_entry), buffer);
    i = time->value->minute - (i * 10);
    g_snprintf (buffer, 33, "%d", i);
    gtk_entry_set_text (GTK_ENTRY (d->rminute_entry), buffer);
    gtk_widget_show (d->time_table);
#else
    HildonDateEditor *date_edit = HILDON_DATE_EDITOR (d->time_date_editor);
    HildonTimeEditor *time_edit = HILDON_TIME_EDITOR (d->time_time_editor);
	
    /* Set date */
    hildon_date_editor_set_year (date_edit, time->value->year);
    hildon_date_editor_set_month (date_edit, time->value->month);
    hildon_date_editor_set_day (date_edit, time->value->day);
	
    /* Set time */
    hildon_time_editor_set_time (time_edit, time->value->hour,
				 time->value->minute, 0);
    hildon_time_editor_set_show_seconds (time_edit, FALSE);
#endif
	
    gtk_widget_hide (d->time_forever_checkbutton);

    /* Run dialog */
	dates_platform_time_dlg (d, TRUE);
	
    /* Retrieve time */
#ifndef WITH_HILDON
    gtk_calendar_get_date (calendar,
			   (guint *)(&time->value->year),
			   (guint *)(&time->value->month),
			   (guint *)(&time->value->day));
    time->value->month += 1;
	
    hour = atoi (gtk_entry_get_text (GTK_ENTRY (d->hour_entry)));
    if ((hour >= 0) && (hour <= 23))
	time->value->hour = hour;
    minute = (atoi (gtk_entry_get_text (GTK_ENTRY (d->lminute_entry))) * 10) +
	atoi (gtk_entry_get_text (GTK_ENTRY (d->rminute_entry)));
    if ((minute >= 0) && (minute <= 59))
	time->value->minute = minute;
#else
    time->value->year = hildon_date_editor_get_year (date_edit);
    time->value->month = hildon_date_editor_get_month (date_edit);
    time->value->day = hildon_date_editor_get_day (date_edit);
	
    hildon_time_editor_get_time (time_edit,
				 (guint *)(&time->value->hour),
				 (guint *)(&time->value->minute),
				 (guint *)(&time->value->second));
#endif
}