[LDTP-Dev] [PATCH] fix for bug #316681

A Nagappan anagappan at novell.com
Mon Sep 19 05:09:34 PDT 2005


Hi Prem,

Few comments:
1. No need to do strdup value once again in table.c, tree_table.c and
corresponding free has to be removed
2. Alignment has to be taken care
3. Inside for loop (j in tre_table.c) do first decleration and then do
variable value assignments
4. Accessible_unref (cell) should not be done inside for loop, as you
are once again doing it just after the for loop - both table.c and
tree_table.c
5. does_row_exist function argument has been changed only in
tree_table.c. The same should be done in table.c too

Please do the changes and check in to local cvs only. Once freedesktop
cvs access is available you can check in there.

Thanks
Nagappan

>>> jpremkumar <jpremkumar at novell.com> 09/19/05 1:54 PM >>>
Hi

I have attached patch for bug #316681. With this patch, we can use an
optional string parameter with the doesrowexist component function. This
function will now return 1 if there exist a row with the given value as
its substring in any of its cell. I have attached patch for both table.c
and tree-table.c.

Please review them.

Thanks
Premkumar

Index: tree_table.c
===================================================================
RCS file: /cvs/pyldtp/tree_table.c,v
retrieving revision 1.39
diff -u -p -r1.39 tree_table.c
--- tree_table.c	15 Sep 2005 14:14:25 -0000	1.39
+++ tree_table.c	19 Sep 2005 15:46:16 -0000
@@ -531,21 +531,86 @@ static int get_row_count (Accessible *ob
   
 }
 
-static int does_row_exists (Accessible *object)
+static int does_row_exists (Accessible *object, char **param)
 {
-  long n_rows;
+  long n_rows, n_cols;
+  long i,j;
   AccessibleTable *table;
-  
+  Accessible *cell;
+  char *value;
+  int flag = 0;  
+
   table = Accessible_getTable (object);
   n_rows = AccessibleTable_getNRows (table);
-  Accessible_unref (table);
+  n_cols = AccessibleTable_getNColumns (table);
   
-  if (n_rows != 0)
-    {
-      log_msg (LOG_WARNING, "Rows available in Table cell");
+  value = g_strdup (param[0]);
+
+  if (!value)
+  {
+      if (n_rows != 0)
+      {
+	  log_msg (LOG_WARNING, "Rows available in Table cell");
+	  Accessible_unref (table);
+	  return 1;
+      }
+      Accessible_unref (table);
       return 0;
-    }
-  return 1;
+  }
+  else
+  {
+      for ( i = 0; i < n_rows; i++)
+      {
+	  for ( j = 0; j < n_cols; j++)
+	  {
+	      long child_count;
+	      cell = AccessibleTable_getAccessibleAt (table, i, j);
+	      child_count = Accessible_getChildCount (cell);
+	      int i;
+	      char *name;
+	      Accessible *child;
+	      if (child_count > 0)
+	      {
+		  for (i = 0; i < child_count; i++)
+		  {
+		      child = Accessible_getChildAtIndex (cell, i);
+		      name = Accessible_getName (child);
+		      if (name && strstr (name, value) != NULL)
+		      {
+			  SPI_freeString (name);
+			  Accessible_unref (child);
+			  Accessible_unref (cell);
+			  flag = 1;
+			  break;
+		      } // if
+		      SPI_freeString (name);
+		      Accessible_unref (child);
+		  } // for
+		  Accessible_unref (cell);
+		  if (flag == 1)
+		      break;
+	      }
+	      else
+	      {
+		  name = Accessible_getName (cell);
+		  if (name && strstr (name, value) != NULL)
+		  {
+		      SPI_freeString (name);
+		      Accessible_unref (cell);
+		      flag = 1;
+		      break;
+		  } // if
+		  SPI_freeString (name);
+		  Accessible_unref (cell);
+	      }
+	  } // for j
+	  if (flag == 1)
+	      break;
+      } // for i
+      Accessible_unref (table);
+      g_free (value);
+      return flag;
+  }
 }
 
 static int verify_cell_value (Accessible *object, char **params)
@@ -874,7 +939,7 @@ int tree_table_main (Accessible *object,
     case SETCELLVALUE:
       return set_cell_value (object, params);
     case DOESROWEXIST:
-      return does_row_exists (object);
+      return does_row_exists (object, params);
     case VERIFYPARTIALTABLECELL:
       return verify_partial_cell_value (object, params);
     case GETCELLVALUE:


Index: table.c
===================================================================
RCS file: /cvs/pyldtp/table.c,v
retrieving revision 1.40
diff -u -p -r1.40 table.c
--- table.c	5 Sep 2005 12:17:55 -0000	1.40
+++ table.c	19 Sep 2005 15:46:44 -0000
@@ -278,23 +278,86 @@ static int select_last_row (Accessible *
 
 static int does_row_exist (Accessible *object)
 {
-  long n_rows;
-  AccessibleTable *table;
-
-  table = Accessible_getTable (object);
-  n_rows = AccessibleTable_getNRows (table);
+    long n_rows, n_cols;
+    long i,j;
+    AccessibleTable *table;
+    Accessible *cell;
+    char *value;
+    int flag = 0;  
+  
+    table = Accessible_getTable (object);
+    n_rows = AccessibleTable_getNRows (table);
+    n_cols = AccessibleTable_getNColumns (table);
+  
+    value = g_strdup (param[0]);
   
-  g_print ("Number of rows:%ld\n", n_rows);
-  if (n_rows>0)
+    if (!value)
     {
-      Accessible_unref (table);	
-      return 1;
-    } 
-  log_msg (LOG_CAUSE, "No rows present in the table"); 
-  Accessible_unref (table);
-  return 0;
+	if (n_rows != 0)
+	{
+	    log_msg (LOG_WARNING, "Rows available in Table cell");
+	    Accessible_unref (table);
+	    return 1;
+	}
+	Accessible_unref (table);
+	return 0;
+    }
+    else
+    {
+	for ( i = 0; i < n_rows; i++)
+	{
+	    for ( j = 0; j < n_cols; j++)
+	    {
+		long child_count;
+		cell = AccessibleTable_getAccessibleAt (table, i, j);
+		child_count = Accessible_getChildCount (cell);
+		int i;
+		char *name;
+		Accessible *child;
+		if (child_count > 0)
+		{
+		    for (i = 0; i < child_count; i++)
+		    {
+			child = Accessible_getChildAtIndex (cell, i);
+			name = Accessible_getName (child);
+			if (name && strstr (name, value) != NULL)
+			{
+			    SPI_freeString (name);
+			    Accessible_unref (child);
+			    Accessible_unref (cell);
+			    flag = 1;
+			    break;
+			} // if
+			SPI_freeString (name);
+			Accessible_unref (child);
+		    } // for
+		    Accessible_unref (cell);
+		    if (flag == 1)
+			break;
+		}
+		else
+		{
+		    name = Accessible_getName (cell);
+		    if (name && strstr (name, value) != NULL)
+		    {
+			SPI_freeString (name);
+			Accessible_unref (cell);
+			flag = 1;
+			break;
+		    } // if
+		    SPI_freeString (name);
+		    Accessible_unref (cell);
+		}
+	    } // for j
+	    if (flag == 1)
+		break;
+	} // for i
+	Accessible_unref (table);
+	g_free (value);
+	return flag;
+    }
 }
-		 
+
 static int verify_cell_value (Accessible *object, char **params)
 {
   char *text;

Index: ldtp.c
===================================================================
RCS file: /cvs/pyldtp/ldtp.c,v
retrieving revision 1.124
diff -u -p -r1.124 ldtp.c
--- ldtp.c	14 Sep 2005 17:49:14 -0000	1.124
+++ ldtp.c	19 Sep 2005 15:46:05 -0000
@@ -604,7 +604,7 @@ static PyObject *ldtp_main (int command)
       command == VERIFYCHECK || command == VERIFYUNCHECK || 
       command == VERIFYSELECT || command == COMPARETEXTPROPERTY || 
       command == CONTAINSTEXTPROPERTY || command == VERIFYCHECKROW ||
-      command == VERIFYUNCHECKROW)
+      command == VERIFYUNCHECKROW || command == DOESROWEXIST)
     {
       Accessible_unref (accessible);
       return Py_BuildValue ("i", status);
@@ -1772,11 +1772,21 @@ static PyObject *select_event_index (PyO
 static PyObject *does_row_exist (PyObject *self, PyObject *args)
 {
   PyObject *status;
-  if (!PyArg_ParseTuple (args, "ss", &window_name, &component_name))
+  char *value = NULL;
+  if (!PyArg_ParseTuple (args, "ss|s", &window_name, 
+			 &component_name, &value))
     {
       return PyErr_Format (ldtp_error, "%s", "Argument missing /
invalid");
     }
+
+  params = malloc (sizeof (char *) * 1);
+  params[0] = g_strdup (value);
+
   status = ldtp_main (DOESROWEXIST);
+
+  g_free (params [0]);
+  g_free (params);
+  params = NULL;
   return status;
 } 	
 

_______________________________________________
ldtp-dev mailing list
ldtp-dev at forge.novell.com
http://forge.novell.com/mailman/listinfo/ldtp-dev



More information about the Ldtp-dev mailing list