1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
3
* Linux Desktop Testing Project http://ldtp.freedesktop.org
6
* Nagappan Alagappan <nagappan@gmail.com>
8
* Copyright 2004 - 2006 Novell, Inc.
9
* Copyright 2007 - 2008 Nagappan Alagappan
11
* This program is free software; you can redistribute it and/or
12
* modify it under the terms of the GNU Lesser General Public
13
* License as published by the Free Software Foundation; either
14
* version 2 of the License, or (at your option) any later version.
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
* Lesser General Public License for more details.
21
* You should have received a copy of the GNU Lesser General Public
22
* License along with this program; if not, write to the
23
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24
* Boston, MA 02110, USA.
29
#include "ldtp-error.h"
30
#include "ldtp-logger.h"
31
#include "ldtp-command.h"
32
#include "ldtp-gui-comp.h"
34
extern gboolean ldtp_debug;
37
is_text_state_enabled (Accessible *object, FILE *log_fp)
40
AccessibleStateSet *state;
41
state = Accessible_getStateSet (object);
43
if (AccessibleStateSet_contains (state, SPI_STATE_EDITABLE))
44
error = LDTP_ERROR_SUCCESS;
46
error = LDTP_ERROR_TEXT_STATE_NOT_ENABLED;
47
log_msg (LDTP_LOG_INFO, ldtp_error_get_message (error), log_fp);
52
set_text_value (Accessible *object, char *text, FILE *log_fp)
56
if (text && Accessible_isEditableText (object)) {
57
SPIBoolean flag = FALSE;
58
AccessibleEditableText *editable_text;
59
if (Accessible_isComponent (object)) {
60
AccessibleComponent *accessible_component;
61
accessible_component = Accessible_getComponent (object);
62
flag = AccessibleComponent_grabFocus (accessible_component);
63
Accessible_unref (accessible_component);
65
editable_text = Accessible_getEditableText (object);
67
g_print ("Text: %s\n", text);
68
flag = AccessibleEditableText_setTextContents (editable_text, text);
69
Accessible_unref (editable_text);
72
g_print ("%s - %d\n", __FILE__, __LINE__);
73
error = LDTP_ERROR_UNABLE_TO_SET_TEXT;
74
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
77
return LDTP_ERROR_SUCCESS;
79
g_print ("%s - %d\n", __FILE__, __LINE__);
80
error = LDTP_ERROR_UNABLE_TO_SET_TEXT;
81
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
87
cut_text (Accessible *object, int startpos, int endpos, FILE *log_fp)
90
AccessibleEditableText *editableText;
92
if (Accessible_isEditableText (object)) {
93
AccessibleText *text = NULL;
94
editableText = Accessible_getEditableText (object);
96
SPIBoolean flag = FALSE;
98
text = Accessible_getText (object);
100
endpos = AccessibleText_getCharacterCount (text);
101
Accessible_unref (text);
104
Accessible_unref (editableText);
105
return LDTP_ERROR_TEXT_NOT_ACCESSIBLE;
108
flag = AccessibleEditableText_cutText (editableText, startpos, endpos);
109
Accessible_unref (editableText);
111
return LDTP_ERROR_SUCCESS;
113
error = LDTP_ERROR_UNABLE_TO_CUT_TEXT;
114
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
119
error = LDTP_ERROR_UNABLE_TO_CUT_TEXT;
120
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
125
activate_text (Accessible *object, FILE *log_fp)
131
SPIBoolean result = FALSE;
132
AccessibleAction *action;
134
name = Accessible_getName (object);
135
g_print ("Text name: %s\n", name);
136
SPI_freeString (name);
139
Get action handle of the given object
141
action = Accessible_getAction (object);
142
action_count = AccessibleAction_getNActions (action);
143
g_print ("action count: %ld\n", action_count);
144
for (i = 0; i < action_count; i++) {
146
name = AccessibleAction_getName (action, i);
147
desc = AccessibleAction_getDescription (action, i);
148
g_print ("Name: %s\tDesc: %s\n", name, desc);
149
if (g_ascii_strcasecmp (name, "activate") == 0) {
150
SPI_freeString (name);
151
SPI_freeString (desc);
153
To execute activate action
155
result = AccessibleAction_doAction (action, i);
156
Accessible_unref (action);
159
SPI_freeString (name);
160
SPI_freeString (desc);
164
g_print ("Activate: success\n");
166
error = LDTP_ERROR_UNABLE_TO_ACTIVATE_TEXT;
167
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
170
return LDTP_ERROR_SUCCESS;
174
paste_text (Accessible *object, long pos, FILE *log_fp)
177
AccessibleEditableText *editableText;
179
if (Accessible_isEditableText (object)) {
180
SPIBoolean flag = FALSE;
181
editableText = Accessible_getEditableText (object);
182
flag = AccessibleEditableText_pasteText (editableText, pos);
183
Accessible_unref (editableText);
185
return LDTP_ERROR_SUCCESS;
187
error = LDTP_ERROR_UNABLE_TO_PASTE_TEXT;
188
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
192
error = LDTP_ERROR_UNABLE_TO_PASTE_TEXT;
193
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
198
delete_text (Accessible *object, long startpos, long endpos, FILE *log_fp)
201
AccessibleEditableText *editableText;
203
if (Accessible_isEditableText (object)) {
204
AccessibleText *text = NULL;
205
editableText = Accessible_getEditableText (object);
207
SPIBoolean flag = FALSE;
209
text = Accessible_getText (object);
211
endpos = AccessibleText_getCharacterCount (text);
212
Accessible_unref (text);
215
Accessible_unref (editableText);
216
return LDTP_ERROR_TEXT_NOT_ACCESSIBLE;
219
flag = AccessibleEditableText_deleteText (editableText, startpos, endpos);
220
Accessible_unref (editableText);
222
return LDTP_ERROR_SUCCESS;
224
error = LDTP_ERROR_UNABLE_TO_DELETE_TEXT;
225
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
230
error = LDTP_ERROR_UNABLE_TO_DELETE_TEXT;
231
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
236
select_text_by_index_and_region (Accessible *object, long startpos,
237
long endpos, long selection_num,
241
AccessibleEditableText *editableText;
243
if (Accessible_isEditableText (object)) {
244
AccessibleText *text = NULL;
245
editableText = Accessible_getEditableText (object);
247
SPIBoolean flag = FALSE;
249
text = Accessible_getText (object);
251
endpos = AccessibleText_getCharacterCount (text);
252
Accessible_unref (text);
255
Accessible_unref (editableText);
256
return LDTP_ERROR_TEXT_NOT_ACCESSIBLE;
259
flag = AccessibleText_setSelection (editableText, selection_num, startpos, endpos);
260
Accessible_unref (editableText);
262
return LDTP_ERROR_SUCCESS;
264
error = LDTP_ERROR_UNABLE_TO_SELECT_TEXT;
265
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
270
error = LDTP_ERROR_UNABLE_TO_SELECT_TEXT;
271
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
276
select_text_by_name (Accessible *object, FILE *log_fp)
279
SPIBoolean flag = FALSE;
280
AccessibleText *text;
282
text = Accessible_getText (object);
284
error = LDTP_ERROR_UNABLE_TO_SELECT_TEXT;
287
flag = AccessibleText_addSelection (text, 0,
288
AccessibleText_getCharacterCount (text));
290
error = LDTP_ERROR_SUCCESS;
292
error = LDTP_ERROR_UNABLE_TO_SELECT_TEXT_ITEM;
293
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
295
Accessible_unref (text);
300
get_text_value (Accessible *object)
304
AccessibleText *accessibleText;
305
g_print ("GETTEXTVALUE\n");
306
accessibleText = Accessible_getText (object);
307
if (accessibleText) {
309
tmp = AccessibleText_getText (accessibleText, 0,
310
AccessibleText_getCharacterCount (accessibleText));
313
g_print ("Text: %s\n", tmp);
314
text = g_strdup (tmp);
315
SPI_freeString (tmp);
317
Accessible_unref (accessibleText);
323
append_text (Accessible *object, char *text, FILE *log_fp)
327
char *available_text = NULL;
329
error = LDTP_ERROR_ARGUMENT_NULL;
330
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
333
available_text = get_text_value (object);
334
if (!available_text) {
335
error = LDTP_ERROR_UNABLE_TO_APPEND_TEXT;
336
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
339
tmp = g_strdup_printf ("%s%s", available_text, text);
340
free (available_text);
341
error = set_text_value (object, tmp, log_fp);
343
if (error == LDTP_ERROR_SUCCESS)
345
error = LDTP_ERROR_UNABLE_TO_APPEND_TEXT;
346
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
351
verify_set_text_value (Accessible *object, char *verify_text, FILE *log_fp)
354
AccessibleText *text_object = NULL;
357
text_object = Accessible_getText (object);
359
text = AccessibleText_getText (text_object, 0, AccessibleText_getCharacterCount (text_object));
360
Accessible_unref (text_object);
361
g_print ("Text: %s\n", text);
364
error = LDTP_ERROR_TEXT_NOT_ACCESSIBLE;
365
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
369
if (verify_text == NULL || text == NULL ||
370
g_utf8_collate (verify_text, text) != 0) {
372
SPI_freeString (text);
373
error = LDTP_ERROR_VERIFY_SET_TEXT_FAILED;
374
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
378
SPI_freeString (text);
379
return LDTP_ERROR_SUCCESS;
383
verify_partial_match (Accessible *object, char *textvalue, FILE *log_fp)
385
char *tmp = NULL,*sub = NULL;
387
AccessibleText *accessibleText;
391
accessibleText = Accessible_getText (object);
392
if (accessibleText == NULL) {
393
error = LDTP_ERROR_TEXT_NOT_ACCESSIBLE;
394
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
398
tmp = AccessibleText_getText (accessibleText, 0, -1);
399
Accessible_unref (accessibleText);
401
for (i = 0 ; tmp[i] != '\0' ; i++) {
402
for(j = i, k=0; sub && sub[k] != '\0' && tmp[j] == sub[k] ; j++ , k++)
404
if( k > 0 && sub[k] == '\0')
405
return LDTP_ERROR_SUCCESS;
407
error = LDTP_ERROR_VERIFY_PARTIAL_MATCH_FAILED;
408
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
413
get_text (Accessible *object, GSList **l)
418
GSList *tmp_list = *l;
419
AccessibleText *accessibleText;
422
accessibleText = Accessible_getText (object);
423
if (accessibleText == NULL) {
424
error = LDTP_ERROR_TEXT_NOT_ACCESSIBLE;
428
if (tmp_list && tmp_list->data) {
429
startpos = atol (tmp_list->data);
430
tmp_list = tmp_list->next;
432
if (tmp_list && tmp_list->data && atol (tmp_list->data) > 0)
433
endpos = atol (tmp_list->data);
435
endpos = AccessibleText_getCharacterCount (accessibleText);
436
g_print ("Start: %ld, End: %ld\n", startpos, endpos);
437
tmp = AccessibleText_getText (accessibleText, startpos, endpos);
439
Accessible_unref (accessibleText);
441
*l = g_slist_prepend (*l, g_strdup (tmp));
442
g_print ("GetTextValue: %s\n", tmp);
443
SPI_freeString (tmp);
444
return LDTP_ERROR_SUCCESS;
447
return LDTP_ERROR_GETTEXTVALUE_FAILED;
451
get_character_count (Accessible *object)
453
AccessibleText *accessibleText;
455
accessibleText = Accessible_getText (object);
456
if (accessibleText == NULL)
459
len = AccessibleText_getCharacterCount (accessibleText);
460
Accessible_unref (accessibleText);
465
get_cursor_position (Accessible *object)
467
AccessibleText *accessibleText;
469
accessibleText = Accessible_getText (object);//cctxt->gui_handle->handle);
471
if (accessibleText == NULL)
474
pos = AccessibleText_getCaretOffset (accessibleText);
475
g_print ("Setting Caret position to %ld\n",pos);
476
Accessible_unref (accessibleText);
481
set_cursor_position (LDTPClientContext *cctxt)
483
AccessibleText *accessibleText;
488
FILE *log_fp = cctxt->log_fp;
490
if (!cctxt->req->arg_list || !cctxt->req->arg_list->data) {
491
error = LDTP_ERROR_ARGUMENT_NULL;
492
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
495
offset = atol (cctxt->req->arg_list->data);
496
count = get_character_count (cctxt->gui_handle->handle);
497
if (count < offset) {
498
error = LDTP_ERROR_OFFSET_OUT_OF_BOUND;
499
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
503
accessibleText = Accessible_getText (cctxt->gui_handle->handle);
504
if (accessibleText == NULL) {
505
error = LDTP_ERROR_TEXT_NOT_ACCESSIBLE;
506
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
510
flag = AccessibleText_setCaretOffset (accessibleText, offset);
512
error = LDTP_ERROR_UNABLE_TO_SET_CARET;
513
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
516
Accessible_unref (accessibleText);
518
return LDTP_ERROR_SUCCESS;
522
copy_text (Accessible *object, int startpos, int endpos, FILE *log_fp)
525
AccessibleText *editableText;
527
if (Accessible_isEditableText (object)) {
528
AccessibleText *text = NULL;
529
editableText = Accessible_getEditableText (object);
531
SPIBoolean flag = FALSE;
533
text = Accessible_getText (object);
535
endpos = AccessibleText_getCharacterCount (text);
536
Accessible_unref (text);
539
Accessible_unref (editableText);
540
return LDTP_ERROR_TEXT_NOT_ACCESSIBLE;
543
flag = AccessibleEditableText_copyText (editableText, startpos, endpos);
544
Accessible_unref (editableText);
546
return LDTP_ERROR_SUCCESS;
548
error = LDTP_ERROR_UNABLE_TO_COPY_TEXT;
549
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
554
error = LDTP_ERROR_UNABLE_TO_COPY_TEXT;
555
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
560
insert_text (Accessible *object, char *text, int pos, FILE *log_fp)
564
AccessibleEditableText *editableText;
565
long present_length = 0;
568
error = LDTP_ERROR_TEXT_TO_INSERT_IS_EMPTY;
569
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
572
present_length = get_character_count (object);
573
if (pos>present_length)
574
log_msg (LDTP_LOG_WARNING, "Inserting text in earlier position due to inadequate text present", log_fp);
577
g_print ("Length of text = %ld\n", len +1);
578
if (Accessible_isEditableText (object)) {
579
SPIBoolean flag = FALSE;
580
editableText = Accessible_getEditableText (object);
581
flag = AccessibleEditableText_insertText (editableText, pos, text, len);
582
Accessible_unref (editableText);
584
return LDTP_ERROR_SUCCESS;
586
error = LDTP_ERROR_UNABLE_TO_INSERT_TEXT;
587
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
592
get_text_property (Accessible *object, GSList **l, FILE *log_fp)
596
long int diff, zero = 0;
598
char *text_prop = NULL;
599
AccessibleText *accessibleText;
602
accessibleText = Accessible_getText (object);
603
if (accessibleText == NULL) {
604
error = LDTP_ERROR_TEXT_NOT_ACCESSIBLE;
605
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
609
if (tmp && tmp->data) {
610
start_pos = atol (tmp->data);
612
if (tmp && tmp->data && (atol (tmp->data) > 0))
613
end_pos = atol (tmp->data);
615
end_pos = AccessibleText_getCharacterCount (accessibleText);
618
diff = end_pos - start_pos;
619
text_prop = AccessibleText_getAttributes (accessibleText, start_pos, &zero, &diff);
620
/* AccessibleText_getAttributes doesn't seem to be taking the
621
end position i.e. the diff value into account. It only checks
622
from the start position */
626
We don't have to free params[0] as they are just pointers
627
to actual parameters in LDTPRequest structure.
629
*l = g_slist_prepend (*l, g_strdup (text_prop));
630
SPI_freeString (text_prop);
631
Accessible_unref (accessibleText);
632
return LDTP_ERROR_SUCCESS;
637
We don't have to free params[0] as they are just pointers
638
to actual parameters in LDTPRequest structure.
640
Accessible_unref (accessibleText);
641
error = LDTP_ERROR_UNABLE_TO_GET_TEXT_PROPERTY;
642
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
648
compare_text_property (Accessible *object, GSList *l, FILE *log_fp)
656
char *text_prop = NULL;
657
char *specimen_prop = NULL;
659
gboolean flag = FALSE;
660
GHashTable *property_table;
661
AccessibleText *accessibleText;
663
accessibleText = Accessible_getText (object);
664
if (accessibleText == NULL) {
665
error = LDTP_ERROR_TEXT_NOT_ACCESSIBLE;
666
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
670
if (tmp && tmp->data) {
671
start_pos = atol (tmp->data);
673
if (tmp && tmp->data && (atol (tmp->data) > 0))
674
end_pos = atol (tmp->data);
676
end_pos = AccessibleText_getCharacterCount (accessibleText);
679
specimen_prop = g_strdup (tmp->data);
680
text_prop = AccessibleText_getAttributes (accessibleText, 0, &start_pos, &end_pos);
683
property_table = g_hash_table_new (&g_str_hash, &g_str_equal);
684
key = strtok (g_strdup (specimen_prop), ":");
686
key = g_strdup (g_strstrip (key));
687
value = strtok (NULL, ";");
689
value = g_strdup (g_strstrip (value));
690
g_hash_table_insert (property_table, g_strdup (key), g_strdup (value));
694
key = strtok (NULL, ":");
696
g_print ("Obtained text property: %s\n", text_prop);
697
key = strtok (strdup (text_prop), ":");
700
key = g_strdup (g_strstrip (key));
701
value = strtok (NULL, ";");
703
value = g_strdup (g_strstrip (value));
704
hash_value = g_hash_table_lookup (property_table, key);
706
if (g_utf8_collate (value, hash_value) == 0)
719
key = strtok (NULL, ":");
721
g_hash_table_destroy (property_table);
722
SPI_freeString (text_prop);
723
g_free (specimen_prop);
724
Accessible_unref (accessibleText);
726
if (total == 0 && flag == FALSE)
727
return LDTP_ERROR_SUCCESS;
728
error = LDTP_ERROR_ONE_OR_MORE_PROPERTIES_DOES_NOT_MATCH;
729
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
732
g_free (specimen_prop);
733
Accessible_unref (accessibleText);
734
error = LDTP_ERROR_UNABLE_TO_GET_TEXT_PROPERTY;
735
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
740
contains_text_property (Accessible *object, GSList *l, FILE *log_fp)
747
char *text_prop = NULL;
748
char *property = NULL;
749
char *prop_key = NULL;
750
char *prop_value = NULL;
751
GHashTable *property_table;
752
AccessibleText *accessibleText;
754
accessibleText = Accessible_getText (object);
755
if (accessibleText == NULL) {
756
error = LDTP_ERROR_TEXT_NOT_ACCESSIBLE;
757
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
762
start_pos = atol (l->data);
764
if (l && l->data && (atol (l->data) > 0))
765
end_pos = atol (l->data);
767
end_pos = AccessibleText_getCharacterCount (accessibleText);
771
property = strdup (l->data);
772
text_prop = AccessibleText_getAttributes (accessibleText, 0, &start_pos, &end_pos);
775
property_table = g_hash_table_new (&g_str_hash, &g_str_equal);
776
g_print ("Obtained text property: %s\n", text_prop);
777
key = strtok (strdup (text_prop), ":");
779
key = g_strdup (g_strstrip (key));
780
value = strtok (NULL, ";");
782
value = g_strdup (g_strstrip (value));
783
g_hash_table_insert (property_table, g_strdup (key), g_strdup (value));
786
key = strtok (NULL, ":");
788
prop_key = strtok (strdup (property), ":");
789
prop_value = strtok (NULL, ";");
790
if (prop_key && prop_value) {
791
value = g_hash_table_lookup (property_table, prop_key);
793
if (g_utf8_collate (value, prop_value) == 0) {
796
Accessible_unref (accessibleText);
797
g_hash_table_destroy (property_table);
798
SPI_freeString (text_prop);
799
log_msg (LDTP_LOG_INFO, "Property matches", log_fp);
800
return LDTP_ERROR_SUCCESS;
805
Accessible_unref (accessibleText);
806
g_hash_table_destroy (property_table);
807
SPI_freeString (text_prop);
808
error = LDTP_ERROR_TEXT_OBJECT_VALUE_CONTAINS_DIFF_PROEPRTY;
809
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
816
Accessible_unref (accessibleText);
817
SPI_freeString (text_prop);
818
error = LDTP_ERROR_TEXT_OBJECT_DOES_NOT_CONTAIN_PROEPRTY;
819
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
825
Accessible_unref (accessibleText);
826
SPI_freeString (text_prop);
827
error = LDTP_ERROR_TEXT_PROEPRTY_VALUE_PAIR_IS_INVALID;
828
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
834
Accessible_unref (accessibleText);
835
error = LDTP_ERROR_UNABLE_TO_GET_TEXT_PROPERTY;
836
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
842
right_click (Accessible *object)
844
gboolean flag = FALSE;
845
long x, y, height, width;
846
if (Accessible_isComponent (object)) {
847
AccessibleComponent *accessible_component;
848
accessible_component = Accessible_getComponent (object);
849
AccessibleComponent_getExtents (accessible_component,
850
&x, &y, &height, &width,
851
SPI_COORD_TYPE_WINDOW);
853
g_print ("X = %ld, Y = %ld, Width = %ld, Height = %ld\n",
854
x, y, width, height);
855
g_print ("X = %ld, Y = %ld, Width / 2 = %ld, Height / 2 = %ld\n",
856
x, y, (x + width) / 2, (y + height) / 2);
858
flag = AccessibleComponent_grabFocus (accessible_component);
859
Accessible_unref (accessible_component);
861
if (flag && SPI_generateMouseEvent ((x + width) / 2, (y + height) / 2, "b3c"))
862
return LDTP_ERROR_SUCCESS;
864
return LDTP_ERROR_RIGHT_CLICK_FAILED;
868
text_main (LDTPClientContext* cctxt, int command)
872
case LDTP_CMD_SETTEXTVALUE:
873
if (cctxt->req->arg_list == NULL || cctxt->req->arg_list->data == NULL)
874
error = set_text_value (cctxt->gui_handle->handle,
877
error = set_text_value (cctxt->gui_handle->handle,
878
cctxt->req->arg_list->data,
881
case LDTP_CMD_CUTTEXT: {
884
GSList *l = cctxt->req->arg_list;
886
startpos = atol (l->data);
889
endpos = atol (l->data);
891
/*TODO: Check if the given positions are within the character length*/
892
error = cut_text (cctxt->gui_handle->handle, startpos, endpos, cctxt->log_fp);
895
case LDTP_CMD_PASTETEXT: {
897
if (cctxt->req->arg_list && cctxt->req->arg_list->data)
898
pos = atol (cctxt->req->arg_list->data);
899
error = paste_text (cctxt->gui_handle->handle, pos, cctxt->log_fp);
902
case LDTP_CMD_ACTIVATETEXT:
903
error = activate_text (cctxt->gui_handle->handle, cctxt->log_fp);
905
case LDTP_CMD_DELETETEXT: {
908
GSList *l = cctxt->req->arg_list;
910
startpos = atol (l->data);
913
endpos = atol (l->data);
915
/*TODO: check if the given positions are within the available text length*/
916
error = delete_text (cctxt->gui_handle->handle, startpos, endpos, cctxt->log_fp);
919
case LDTP_CMD_SELECTTEXTBYINDEXANDREGION: {
921
Select text based on index and optional region text
925
long selection_num = 0;
926
GSList *l = cctxt->req->arg_list;
928
startpos = atol (l->data);
931
endpos = atol (l->data);
934
selection_num = atol (l->data);
937
/*TODO: check if the given positions are within the available text length*/
938
error = select_text_by_index_and_region (cctxt->gui_handle->handle,
939
selection_num, startpos,
940
endpos, cctxt->log_fp);
943
case LDTP_CMD_SELECTTEXTBYNAME:
944
error = select_text_by_name (cctxt->gui_handle->handle, cctxt->log_fp);
946
case LDTP_CMD_APPENDTEXT:
947
if (cctxt->req->arg_list == NULL || cctxt->req->arg_list->data == NULL)
948
error = append_text (cctxt->gui_handle->handle,
951
error = append_text (cctxt->gui_handle->handle,
952
cctxt->req->arg_list->data, cctxt->log_fp);
954
case LDTP_CMD_VERIFYPARTIALMATCH:
955
if (cctxt->req->arg_list == NULL || cctxt->req->arg_list->data == NULL)
956
error = verify_partial_match (cctxt->gui_handle->handle,
959
error = verify_partial_match (cctxt->gui_handle->handle,
960
cctxt->req->arg_list->data,
963
case LDTP_CMD_GETTEXTVALUE:
964
error = get_text (cctxt->gui_handle->handle, &cctxt->req->arg_list);
965
if (error == LDTP_ERROR_SUCCESS) {
966
if (cctxt->req->arg_list && cctxt->req->arg_list->data) {
967
cctxt->resp->data = cctxt->req->arg_list->data;
968
cctxt->resp->data_len = g_utf8_strlen (cctxt->resp->data, -1);
969
cctxt->req->arg_list = g_slist_remove (cctxt->req->arg_list, cctxt->req->arg_list->data);
971
error = LDTP_ERROR_GETTEXTVALUE_FAILED;
972
log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), cctxt->log_fp);
977
case LDTP_CMD_VERIFYSETTEXT:
978
if (cctxt->req->arg_list == NULL || cctxt->req->arg_list->data == NULL)
979
error = verify_set_text_value (cctxt->gui_handle->handle,
982
error = verify_set_text_value (cctxt->gui_handle->handle,
983
cctxt->req->arg_list->data,
986
case LDTP_CMD_GRABFOCUS:
987
error = grab_focus (cctxt->gui_handle->handle, cctxt->log_fp);
989
case LDTP_CMD_GETCHARCOUNT:
990
cctxt->resp->data = g_strdup_printf ("%ld", get_character_count (cctxt->gui_handle->handle));
991
cctxt->resp->data_len = strlen (cctxt->resp->data);
992
error = (LDTP_ERROR_SUCCESS);
994
case LDTP_CMD_COPYTEXT: {
997
GSList *l = cctxt->req->arg_list;
999
startpos = atol (l->data);
1002
endpos = atol (l->data);
1004
/*TODO: check if the given positions are within the available text length*/
1005
error = copy_text (cctxt->gui_handle->handle, startpos, endpos,
1009
case LDTP_CMD_INSERTTEXT: {
1012
GSList *l = cctxt->req->arg_list;
1014
pos = atol(l->data);
1022
error = insert_text (cctxt->gui_handle->handle, "",
1023
pos, cctxt->log_fp);
1025
error = insert_text (cctxt->gui_handle->handle, text,
1026
pos, cctxt->log_fp);
1029
case LDTP_CMD_GETTEXTPROPERTY:
1030
error = get_text_property (cctxt->gui_handle->handle,
1031
&cctxt->req->arg_list, cctxt->log_fp);
1032
if (error == LDTP_ERROR_SUCCESS) {
1033
cctxt->resp->data = cctxt->req->arg_list->data;
1034
cctxt->resp->data_len = g_utf8_strlen (cctxt->resp->data, -1);
1035
cctxt->req->arg_list = g_slist_remove (cctxt->req->arg_list, cctxt->req->arg_list->data);
1038
case LDTP_CMD_COMPARETEXTPROPERTY:
1039
error = compare_text_property (cctxt->gui_handle->handle,
1040
cctxt->req->arg_list, cctxt->log_fp);
1042
case LDTP_CMD_CONTAINSTEXTPROPERTY:
1043
error = contains_text_property (cctxt->gui_handle->handle,
1044
cctxt->req->arg_list, cctxt->log_fp);
1046
case LDTP_CMD_ISTEXTSTATEENABLED:
1047
error = is_text_state_enabled (cctxt->gui_handle->handle, cctxt->log_fp);
1049
case LDTP_CMD_RIGHTCLICK:
1050
error = right_click (cctxt->gui_handle->handle);
1052
case LDTP_CMD_MOUSELEFTCLICK:
1053
case LDTP_CMD_MOUSERIGHTCLICK:
1054
error = is_text_state_enabled (cctxt->gui_handle->handle, cctxt->log_fp);
1055
if (error != LDTP_ERROR_SUCCESS)
1056
error = device_main (cctxt, command);
1058
case LDTP_CMD_MOUSEMOVE:
1059
case LDTP_CMD_KBDENTER:
1060
error = device_main (cctxt, command);
1062
case LDTP_CMD_SETCURSORPOSITION:
1063
error = set_cursor_position (cctxt);
1065
case LDTP_CMD_GETCURSORPOSITION: {
1067
position = get_cursor_position (cctxt->gui_handle->handle);
1069
error = LDTP_ERROR_TEXT_NOT_ACCESSIBLE;
1071
cctxt->resp->data = g_strdup_printf ("%ld", position);
1072
cctxt->resp->data_len = g_utf8_strlen (cctxt->resp->data, -1);
1073
error = LDTP_ERROR_SUCCESS;
1078
error = LDTP_ERROR_COMMAND_NOT_IMPLEMENTED;