[LDTP-Dev] Code changes in Pyldtp to fix issues in calendar
testcases automation
Poornima Nayak
pnayak at novell.com
Fri Oct 21 23:26:48 PDT 2005
Hi
Please reveiew the patch pasted here. It includes following
1. A new api select_event, now event is selected based on 'text'
parameter passed.
2, A new api open_event, this function is implemented to select and open
an event. For eg if summary of an appointment is passed as argument,
that appointment is selected and then opened.
3.Modified verify_event_exist, this function needs a parameter now to
check if an event exist in calendar with given summary/text. Previously
it was just checking if there is any appointment in the calendar. While
typing this description I felt now I should have kept it as it is, we
might require it in future. I need your comments on this.
4.Separated API's of calendar and calendar view object. Before i
modified both where in same file calendar_view.c. But both are not same
object types, the type of API support required for both are different.
Nagappan: Should i check in gui.c modifcations which you have done ?
Based on the above 4 requirements following files are modified.
1.calendar_view.c
2.calendar.c
3.gui.h
4.ldtp.h
5.ldtp.c
6.setup.py
Thanks
Poornima
? build
? calendar.c
? diffrence.patch
Index: calendar_view.c
===================================================================
RCS file: /cvs/pyldtp/calendar_view.c,v
retrieving revision 1.18
diff -u -p -r1.18 calendar_view.c
--- calendar_view.c 19 Oct 2005 13:15:33 -0000 1.18
+++ calendar_view.c 22 Oct 2005 05:31:11 -0000
@@ -67,117 +67,194 @@ static int select_event_index (Accessibl
return 0;
}
-static int verify_event_exist (Accessible *object)
+static int verify_event_exist (Accessible *object, char **params)
{
long child_count;
+ char *event_text;
+ int i;
+ AccessibleText *child_text;
+ Accessible *child;
+
child_count = Accessible_getChildCount (object);
+
if (child_count >= 2)
- return 1;
+ {
+ for (i = 1; i < child_count; i++)
+ {
+ child = Accessible_getChildAtIndex (object, i);
+ child_text = Accessible_getText (child);
+ event_text = AccessibleText_getText (child_text,
0, LONG_MAX);
+
+ if (g_utf8_collate (event_text, params[0]) == 0)
+ {
+ Accessible_unref (child);
+ AccessibleText_unref (child_text);
+ SPI_freeString (event_text);
+ return 1;
+ }
+ else
+ {
+ Accessible_unref (child);
+ AccessibleText_unref (child_text);
+ SPI_freeString (event_text);
+ }
+ }
+ }
else //childcount = 1 (implies, calendar_view has a child (i.e,
table))
- {
- gchar *msg;
- msg = g_strdup_printf ("No appointments in calendar");
- log_msg (LOG_CAUSE, msg);
- g_print ("%s\n", msg);
- g_free (msg);
- }
+ {
+ gchar *msg;
+ msg = g_strdup_printf ("No appointments in calendar");
+ log_msg (LOG_CAUSE, msg);
+ g_print ("%s\n", msg);
+ g_free (msg);
+ }
return 0;
}
-static int select_calendar_date (Accessible *object, char **params)
+static int select_event (Accessible *object, char **params)
{
- int day, month, year;
- int child_count, i;
- Accessible *child = NULL;
- char *msg = NULL;
- char *date = NULL;
- char *child_name = NULL;
- time_t timer;
- struct tm *current_time;
-
- day = atoi (params[0]);
- month = atoi (params[1]);
- year = atoi (params[2]);
-
- date = g_strdup_printf ("%d-%d-%d", year, month, day);
-
- timer = time (NULL);
- current_time = localtime (&timer);
-
- if (day == 0)
- day = current_time->tm_mday;
- if (month == 0)
- {
- /*
- *Adding 1 since the localtime API returns
- *the month index between 0 and 11
- */
- month = current_time->tm_mon + 1;
- }
- if (year == 0)
- {
- /*
- *Adding 1900 since the localtime API returns
- *years passed since 1900 as the year value
- */
- year = current_time->tm_year + 1900;
- }
- g_print ("Date to be selected: %s\n", date);
- child_count = Accessible_getChildCount (object);
- for (i = 0; i < child_count; i++)
- {
- child = Accessible_getChildAtIndex (object, i);
- child_name = Accessible_getName (child);
- /*
- How this can be handled in local format ?
- */
- if (g_strcasecmp (child_name, date) == 0)
- {
- if (Accessible_isComponent (child))
- {
- SPIBoolean flag = FALSE;
- AccessibleComponent *accessible_component;
- accessible_component = Accessible_getComponent (child);
- flag = AccessibleComponent_grabFocus
(accessible_component);
- Accessible_unref (accessible_component);
- SPI_freeString (child_name);
- Accessible_unref (child);
- g_free (date);
- if (flag == TRUE)
- return 1;
- else
+ long child_count;
+ int i;
+ gchar *text = NULL;
+ Accessible *event = NULL;
+ AccessibleComponent *event_component = NULL;
+ AccessibleText *event_text = NULL;
+
+ if (verify_event_exist (object, params))
+ {
+ child_count = Accessible_getChildCount (object);
+
+ for (i = 1; i < child_count; i++)
{
- log_msg (LOG_CAUSE, "Failed during grabing focus on
given date");
- g_print ("Failed during grabing focus on given
date!!\n");
- return 0;
+
+ event = Accessible_getChildAtIndex (object, i);
+ event_text = Accessible_getText (event);
+ text = AccessibleText_getText (event_text, 0,
LONG_MAX);
+
+ if (g_utf8_collate (text, params[0]) == 0)
+ {
+ event_component =
Accessible_getComponent (event);
+ if (AccessibleComponent_grabFocus
(event_component))
+ {
+ AccessibleComponent_unref
(event_component);
+ AccessibleText_unref
(event_text);
+ Accessible_unref (event);
+ return 1;
+ }
+ else
+ {
+ AccessibleComponent_unref
(event_component);
+ AccessibleText_unref
(event_text);
+ Accessible_unref (event);
+
+ gchar *msg;
+ msg = g_strdup ("Event object
cannot be grabfocus");
+ log_msg (LOG_CAUSE, msg);
+ g_print ("%s\n", msg);
+ g_free (msg);
+ return 0;
+ }
+ }
}
- }
- else
- {
- g_free (date);
- SPI_freeString (child_name);
- Accessible_unref (child);
- msg = g_strdup ("Object to be selected is not a
component");
- log_msg (LOG_CAUSE, msg);
- g_print ("%s\n", msg);
- g_free (msg);
- return 0;
- }
}
- else
+ else
{
- g_free (date);
- SPI_freeString (child_name);
- Accessible_unref (child);
+ gchar *msg;
+ msg = g_strdup_printf ("Appointment does not exist in calendar");
+ log_msg (LOG_CAUSE, msg);
+ g_print ("%s\n", msg);
+ g_free (msg);
+ }
+ return 0;
+}
+
+static int get_event_index (Accessible *object, char **params)
+{
+ long count;
+ int i;
+ char *text = NULL;
+ Accessible *event = NULL;
+ AccessibleText *event_text = NULL;
+
+ count = Accessible_getChildCount (object);
+ for (i = 1; i < count; i++)
+ {
+ event = Accessible_getChildAtIndex (object, i);
+ event_text = Accessible_getText (event);
+ text = AccessibleText_getText (event_text, 0, LONG_MAX);
+
+ if (g_utf8_collate (text, params[0]) == 0)
+ {
+ AccessibleText_unref (event_text);
+ Accessible_unref (event);
+ SPI_freeString (text);
+ return i;
+ }
}
- }
- g_free (date);
- msg = g_strdup_printf ("Given date for selection is invalid");
- log_msg (LOG_CAUSE, msg);
- g_print ("%s\n", msg);
- g_free (msg);
- return 0;
+
+ AccessibleText_unref (event_text);
+ Accessible_unref (event);
+ SPI_freeString (text);
+ log_msg (LOG_CAUSE, "Not able to get index of specified event in
calendar");
+ return -1;
+}
+
+static int double_click (Accessible *object)
+{
+ long int x, y, width, height;
+ AccessibleComponent *component = NULL;
+
+ AccessibleComponent_getExtents (component, &x, &y, &width,
&height, SPI_COORD_TYPE_WINDOW);
+ x = x + width / 2;
+ y = y + height / 2;
+
+ SPIBoolean flag = SPI_generateMouseEvent (x, y, "b1d");
+ Accessible_unref (object);
+ Accessible_unref (component);
+ if(flag == TRUE)
+ return 1;
+ else
+ {
+ log_msg (LOG_CAUSE, "Could not perform double click on
the object");
+ return 0;
+ }
+
+ Accessible_unref (object);
+ Accessible_unref (component);
+ log_msg (LOG_CAUSE, "Could not grab focus on the object");
+ return 0;
+
+}
+
+static int open_event (Accessible *object, char **params)
+{
+ int index = 0;
+ Accessible *event = NULL;
+
+ if (select_event (object, params))
+ {
+ index = get_event_index (object, params);
+ if (index != -1)
+ {
+ event = Accessible_getChildAtIndex (object,
index);
+ if (double_click (event))
+ {
+ Accessible_unref (event);
+ return 1;
+ }
+ else
+ {
+ Accessible_unref (event);
+ log_msg (LOG_CAUSE, "Unable to open
calendar event");
+ return 0;
+ }
+ }
+ else
+ return 0;
+ }
+
+ return 0;
}
int calendar_view_main (Accessible *object, int command, char **params)
@@ -187,9 +264,11 @@ int calendar_view_main (Accessible *obje
case SELECTEVENTINDEX :
return select_event_index (object, params);
case VERIFYEVENTEXIST :
- return verify_event_exist (object);
- case SELECTCALENDARDATE :
- return select_calendar_date (object, params);
+ return verify_event_exist (object, params);
+ case SELECTEVENT :
+ return select_event (object, params);
+ case OPENEVENT :
+ return open_event (object, params);
default:
{
log_msg (LOG_CAUSE, "Calendar view: Command not implemented");
Index: gui.c
===================================================================
RCS file: /cvs/pyldtp/gui.c,v
retrieving revision 1.56
diff -u -p -r1.56 gui.c
--- gui.c 19 Oct 2005 13:15:33 -0000 1.56
+++ gui.c 22 Oct 2005 05:31:11 -0000
@@ -437,23 +437,26 @@ int is_object_matching (Accessible *obje
{
long len = -1;
gint collate = -1;
- gchar *under_score = NULL;
gchar *utf8_string = NULL;
accessible_label = Accessible_getName (object);
utf8_string = _(hash_label);
if (Accessible_isText (object))
{
+ char *str = NULL;
AccessibleText *text = NULL;
text = Accessible_getText (object);
len = AccessibleText_getCharacterCount (text);
+ str = AccessibleText_getText (text, 0, len);
+ g_print ("DEBUG: %s\n", str);
+ SPI_freeString (str);
Accessible_unref (text);
}
/*
* If a label has _ (underscore) we need to remove them, since
Accessible_getName gives
* output without _, but _() gives label in localized string with
_
*/
- if ((under_score = g_utf8_strchr (utf8_string, len, '_')) !=
NULL)
+ if (g_utf8_strchr (utf8_string, len, '_') != NULL)
{
gchar *str = NULL;
str = escape_under_score (utf8_string);
@@ -463,7 +466,7 @@ int is_object_matching (Accessible *obje
}
else
collate = g_utf8_collate (accessible_label, utf8_string);
- g_print ("Label: %s %s %s %d\n", accessible_label, hash_label,
_(hash_label), collate);
+ g_print ("Label: %s %s %s %d %ld\n", accessible_label,
hash_label, utf8_string, collate, len);
SPI_freeString (accessible_label);
if (collate == 0)
{
@@ -483,7 +486,6 @@ int is_object_matching (Accessible *obje
if (accessible_label)
{
gint collate = -1;
- gchar *under_score = NULL;
gchar *utf8_string = NULL;
utf8_string = _(hash_label);
@@ -491,7 +493,7 @@ int is_object_matching (Accessible *obje
* If a label has _ (underscore) we need to remove them,
since Accessible_getName gives
* output without _, but _() gives label in localized
string with _
*/
- if ((under_score = g_utf8_strchr (utf8_string, len, '_'))
!= NULL)
+ if (g_utf8_strchr (utf8_string, len, '_') != NULL)
{
gchar *str = NULL;
str = escape_under_score (utf8_string);
@@ -501,7 +503,7 @@ int is_object_matching (Accessible *obje
}
else
collate = g_utf8_collate (accessible_label,
utf8_string);
- g_print ("Label By: %s %s %s\n", accessible_label,
hash_label, _(hash_label));
+ g_print ("Label By: %s %s %s %ld\n", accessible_label,
hash_label, utf8_string, len);
g_free (accessible_label);
if (collate == 0)
{
Index: gui.h
===================================================================
RCS file: /cvs/pyldtp/gui.h,v
retrieving revision 1.27
diff -u -p -r1.27 gui.h
--- gui.h 19 Oct 2005 13:15:33 -0000 1.27
+++ gui.h 22 Oct 2005 05:31:11 -0000
@@ -209,6 +209,8 @@
#define SELECTTABINDEX 287
#define SORTCOLUMNINDEX 288
#define SORTCOLUMN 289
+#define SELECTEVENT 290
+#define OPENEVENT 291
//EXTRA FUNCTIONS (not ldtp_methods)
Index: ldtp.c
===================================================================
RCS file: /cvs/pyldtp/ldtp.c,v
retrieving revision 1.139
diff -u -p -r1.139 ldtp.c
--- ldtp.c 19 Oct 2005 13:15:33 -0000 1.139
+++ ldtp.c 22 Oct 2005 05:31:11 -0000
@@ -489,7 +489,6 @@ static PyObject *ldtp_main (int command)
err = PyErr_Format (ldtp_error, "%s %s %d", "Unable to get gui
handle", __FILE__, __LINE__);
return err;
}
-
switch (class_id)
{
case SPI_ROLE_COMBO_BOX:
@@ -587,7 +586,7 @@ static PyObject *ldtp_main (int command)
case SPI_ROLE_CALENDAR:
{
flag = 1;
- status = calendar_view_main (accessible, command, params);
+ status = calendar_main (accessible, command, params);
break;
}
case SPI_ROLE_SPIN_BUTTON:
@@ -632,7 +631,13 @@ static PyObject *ldtp_main (int command)
status = tool_bar_main (accessible, command, params);
break;
}
- }
+ case CALENDAR_VIEW:
+ {
+ flag = 1;
+ status = calendar_view_main (accessible,
command, params);
+ break;
+ }
+ }
if (status || command == STATEENABLED || command == VERIFYSETTEXT ||
command == GETTABLEROWINDEX || command == GETROWCOUNT ||
command == VERIFYCHECK || command == VERIFYUNCHECK ||
@@ -1719,6 +1724,40 @@ static PyObject *select_event_index (PyO
return status;
}
+static PyObject *select_event (PyObject *self, PyObject *args)
+{
+ PyObject *status;
+ char *event_text = NULL;
+ if (!PyArg_ParseTuple (args, "sss", &window_name, &component_name,
&event_text))
+ return PyErr_Format (ldtp_error, "%s %s %d", "Argument missing /
invalid", __FILE__, __LINE__);
+
+ params = malloc (sizeof (char ) * 1);
+ params[0] = g_strdup_printf ("%s", event_text);
+
+ status = ldtp_main (SELECTEVENT);
+
+ free (params [0]);
+ free (params);params = NULL;
+ return status;
+}
+
+static PyObject *open_event (PyObject *self, PyObject *args)
+{
+ PyObject *status;
+ char *event_text = NULL;
+ if (!PyArg_ParseTuple (args, "sss", &window_name, &component_name,
&event_text))
+ return PyErr_Format (ldtp_error, "%s %s %d", "Argument missing /
invalid", __FILE__, __LINE__);
+
+ params = malloc (sizeof (char ) * 1);
+ params[0] = g_strdup_printf ("%s", event_text);
+
+ status = ldtp_main (OPENEVENT);
+
+ free (params [0]);
+ free (params);params = NULL;
+ return status;
+}
+
static PyObject *does_row_exist (PyObject *self, PyObject *args)
{
PyObject *status;
@@ -2574,7 +2613,11 @@ static PyMethodDef ldtp_methods[] = {
"Revert appmap entries to the original values"},
{"bindtext", (PyCFunction) bind_text, METH_VARARGS,
"Bind text to locale domain"},
- {NULL, NULL, 0, NULL} /* sentinel */
+ {"selectevent", (PyCFunction) select_event, METH_VARARGS,
+ "to select calendar event based on summary"},
+ {"openevent", (PyCFunction) open_event, METH_VARARGS,
+ "to open calendar event based on summary"},
+ {NULL, NULL, 0, NULL} /* sentinel */
};
void ldtp_print (const char *string)
Index: ldtp.h
===================================================================
RCS file: /cvs/pyldtp/ldtp.h,v
retrieving revision 1.22
diff -u -p -r1.22 ldtp.h
--- ldtp.h 19 Oct 2005 13:15:33 -0000 1.22
+++ ldtp.h 22 Oct 2005 05:31:11 -0000
@@ -46,6 +46,9 @@
#include "log.h"
+//calendar.c
+int calendar_main (Accessible *object, int command, char **params);
+
//calendar_view.c
int calendar_view_main (Accessible *object, int command, char
**params);
Index: setup.py
===================================================================
RCS file: /cvs/pyldtp/setup.py,v
retrieving revision 1.31
diff -u -p -r1.31 setup.py
--- setup.py 23 Sep 2005 19:06:05 -0000 1.31
+++ setup.py 22 Oct 2005 05:31:11 -0000
@@ -74,7 +74,7 @@ status, inc_other = commands.getstatusou
if status != 0:
sys.exit ('Unable to get: pkg-config --cflags-only-other cspi-1.0')
-source_files = ['appmap.c', 'calendar_view.c', 'check_box.c',
'check_menu_item.c', 'combo_box.c', 'gui.c', 'icon.c', 'label.c',
'layered_pane.c', 'ldtp.c', 'list.c', 'log.c', 'menu.c', 'menu_item.c',
'panel.c', 'page_tab_list.c', 'push_button.c', 'radio_button.c',
'radio_menu_item.c', 'remap.c', 'scroll_bar.c', 'slider.c',
'spin_button.c', 'status_bar.c', 'table.c', 'text.c', 'toggle_button.c',
'tool_bar.c', 'tree_table.c']
+source_files = ['appmap.c', 'calendar.c', 'calendar_view.c',
'check_box.c', 'check_menu_item.c', 'combo_box.c', 'gui.c', 'icon.c',
'label.c', 'layered_pane.c', 'ldtp.c', 'list.c', 'log.c', 'menu.c',
'menu_item.c', 'panel.c', 'page_tab_list.c', 'push_button.c',
'radio_button.c', 'radio_menu_item.c', 'remap.c', 'scroll_bar.c',
'slider.c', 'spin_button.c', 'status_bar.c', 'table.c', 'text.c',
'toggle_button.c', 'tool_bar.c', 'tree_table.c']
ldtp_module = Extension ('ldtp',
library_dirs=lib_path,
The new file has to be checked in calendar.c
/*
* Linux Desktop Testing Project http://www.gnomebangalore.org/ldtp
*
* Author:
* jpremkumar at novell.com
*
* Copyright 2004, 2005 Novell, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "ldtp.h"
#include "gui.h"
#include "log.h"
static int select_calendar_date (Accessible *object, char **params)
{
int day, month, year;
int child_count, i;
Accessible *child = NULL;
char *msg = NULL;
char *date = NULL;
char *child_name = NULL;
time_t timer;
struct tm *current_time;
day = atoi (params[0]);
month = atoi (params[1]);
year = atoi (params[2]);
date = g_strdup_printf ("%d-%d-%d", year, month, day);
timer = time (NULL);
current_time = localtime (&timer);
if (day == 0)
day = current_time->tm_mday;
if (month == 0)
{
/*
*Adding 1 since the localtime API returns
*the month index between 0 and 11
*/
month = current_time->tm_mon + 1;
}
if (year == 0)
{
/*
*Adding 1900 since the localtime API returns
*years passed since 1900 as the year value
*/
year = current_time->tm_year + 1900;
}
g_print ("Date to be selected: %s\n", date);
child_count = Accessible_getChildCount (object);
for (i = 0; i < child_count; i++)
{
child = Accessible_getChildAtIndex (object, i);
child_name = Accessible_getName (child);
/*
How this can be handled in local format ?
*/
if (g_strcasecmp (child_name, date) == 0)
{
if (Accessible_isComponent (child))
{
SPIBoolean flag = FALSE;
AccessibleComponent *accessible_component;
accessible_component = Accessible_getComponent (child);
flag = AccessibleComponent_grabFocus
(accessible_component);
Accessible_unref (accessible_component);
SPI_freeString (child_name);
Accessible_unref (child);
g_free (date);
if (flag == TRUE)
return 1;
else
{
log_msg (LOG_CAUSE, "Failed during grabing focus on
given date");
g_print ("Failed during grabing focus on given
date!!\n");
return 0;
}
}
else
{
g_free (date);
SPI_freeString (child_name);
Accessible_unref (child);
msg = g_strdup ("Object to be selected is not a
component");
log_msg (LOG_CAUSE, msg);
g_print ("%s\n", msg);
g_free (msg);
return 0;
}
}
else
{
g_free (date);
SPI_freeString (child_name);
Accessible_unref (child);
}
}
g_free (date);
msg = g_strdup_printf ("Given date for selection is invalid");
log_msg (LOG_CAUSE, msg);
g_print ("%s\n", msg);
g_free (msg);
return 0;
}
int calendar_main (Accessible *object, int command, char **params)
{
switch(command)
{
case SELECTCALENDARDATE :
return select_calendar_date (object, params);
default:
{
log_msg (LOG_CAUSE, "Calendar: Command not
implemented");
g_print ("Calendar: Command not implemented\n");
return 0;
}
}
}
More information about the Ldtp-dev
mailing list