END_TEST

/**
 * Purpose: test setting values for month over the limits for
 * hildon_date_editor_get_month
 * Cases considered:
 *    - Set month 12
 *    - Set month 1
 */
START_TEST (test_set_month_limits)
{
  GValue value = { 0, };

  /* Test 1: Test upper limit */
  g_value_init (&value, G_TYPE_UINT);
  hildon_date_editor_set_month (date_editor, MAX_MONTH);
  g_object_get_property (G_OBJECT (date_editor), "month", &value);
  fail_if (g_value_get_uint (&value) != MAX_MONTH,
	   "hildon-date-editor: The returned month is %u and should be %u",
	   g_value_get_uint (&value), MAX_MONTH);

  /* Test 2: Test lower limit */
  g_value_unset (&value);
  g_value_init (&value, G_TYPE_UINT);
  hildon_date_editor_set_month (date_editor, MIN_MONTH);
  g_object_get_property (G_OBJECT (date_editor), "month", &value);
  fail_if (g_value_get_uint (&value) != MIN_MONTH,
	   "hildon-date-editor: The returned month is %u and should be %u",
	   g_value_get_uint (&value), MIN_MONTH);
}
END_TEST

/**
 * Purpose: test getting values of the month over the limits for
 * hildon_date_editor_get_month
 * Cases considered:
 *    - Get month 12
 *    - Get month 1
 */
START_TEST (test_get_month_limits)
{

  /* Test 1: Upper limit */
  hildon_date_editor_set_month (date_editor, MAX_MONTH);

  fail_if (hildon_date_editor_get_month (date_editor) != MAX_MONTH,
	   "hildon-date-editor: get_month failed. The returned month is %u and should be %u", 
	   hildon_date_editor_get_month (date_editor), MAX_MONTH);

  /* Test 2: Lower limit */
  hildon_date_editor_set_month (date_editor, MIN_MONTH);

  fail_if (hildon_date_editor_get_month (date_editor) != MIN_MONTH,
	   "hildon-date-editor: get_month failed. The returned month is %u and should be %u", 
	   hildon_date_editor_get_month (date_editor), MIN_MONTH);
}
END_TEST

/* ----- Test case for set_month -----*/

/**
 * Purpose: test setting regular values for month for
 * hildon_date_editor_set_month
 * Cases considered:
 *    - Set month 3
 */
START_TEST (test_set_month_regular)
{
  guint month;
  guint ret_month;

  month = 3;

  /* Test 1: Try month March (3) */
  hildon_date_editor_set_month (date_editor, month);
  ret_month = hildon_date_editor_get_month (date_editor);

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

/* ----- Test case for get_month -----*/

/**
 * Purpose: test getting a year for regular values for
 * hildon_date_editor_get_month
 * Cases considered:
 *    - set month with set_date 30/03/1981
 *    - set month with set_month 1
 *    - set month with set_property 7
 */
START_TEST (test_get_month_regular)
{
  guint year, month, day;
  GValue value = {0, };

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

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

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

  /* Test 2: set month with set_month */
  month = 1;
  hildon_date_editor_set_month (date_editor, month);

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

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

  fail_if (hildon_date_editor_get_month (date_editor) != month,
	   "hildon-date-editor: The returned month is %u and should be %u", 
	   hildon_date_editor_get_month (date_editor), month);
}
Esempio n. 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
}