~ubuntu-branches/ubuntu/maverick/ldtp/maverick

« back to all changes in this revision

Viewing changes to src/combo-box.c

  • Committer: Bazaar Package Importer
  • Author(s): Kartik Mistry
  • Date: 2010-02-04 10:36:08 UTC
  • mfrom: (1.4.2 upstream)
  • mto: This revision was merged to the branch mainline in revision 19.
  • Revision ID: james.westby@ubuntu.com-20100204103608-dhqdo7jk10ygwt40
Tags: 2.0.2-1
* New upstream release:
  + Packaging is based on Ubuntu packages, Thanks Ubuntu!
  + LDTPv2 is a complete rewrite of LDTPv1 in Python
  + LTFX is completely removed in LDTP v2 in favor of wnck
* debian/control:
  + Updated to Standards-Version 3.8.4 (no changes needed)
  + Fixed typo in description python->Python
  + ldtp is now arch: all package
* debian/rules:
  + Using dh to make it simple
* Removed unused manpages
* Updated package to use new source format 3.0 (quilt)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2
 
/*
3
 
 * Linux Desktop Testing Project http://ldtp.freedesktop.org
4
 
 *
5
 
 * Author:
6
 
 *    Poornima Nayak<pnayak@novell.com>
7
 
 *    Nagappan Alagappan <nagappan@gmail.com>
8
 
 *    Veerapuram Varadhan <v.varadhan@gmail.com>
9
 
 *
10
 
 * Copyright 2004 - 2006 Novell, Inc.
11
 
 * Copyright 2007 - 2008 Nagappan Alagappan
12
 
 *
13
 
 * This program is free software; you can redistribute it and/or
14
 
 * modify it under the terms of the GNU Lesser General Public
15
 
 * License as published by the Free Software Foundation; either
16
 
 * version 2 of the License, or (at your option) any later version.
17
 
 *
18
 
 * This program is distributed in the hope that it will be useful,
19
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21
 
 * Lesser General Public License for more details.
22
 
 *
23
 
 * You should have received a copy of the GNU Lesser General Public
24
 
 * License along with this program; if not, write to the
25
 
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26
 
 * Boston, MA 02110, USA.
27
 
 */
28
 
 
29
 
#include "ldtp.h"
30
 
#include "ldtp-gui.h"
31
 
#include "ldtp-error.h"
32
 
#include "ldtp-utils.h"
33
 
#include "ldtp-logger.h"
34
 
#include "ldtp-command.h"
35
 
#include "ldtp-gui-comp.h"
36
 
 
37
 
static LDTPErrorCode
38
 
click (Accessible *object, FILE *log_fp)
39
 
{
40
 
        SPIBoolean flag = FALSE;
41
 
        AccessibleAction *action;
42
 
  
43
 
        if (wait_till_object_state_contains (object, COMBO_BOX, log_fp) != 0) {
44
 
                log_msg (LDTP_LOG_CAUSE, "Not all combo box object properties enabled", log_fp);
45
 
                return LDTP_ERROR_CLICK_FAILED;
46
 
        }
47
 
        action = Accessible_getAction (object);
48
 
        flag = AccessibleAction_doAction (action, 0);
49
 
        Accessible_unref (action);
50
 
        if (flag)
51
 
                return LDTP_ERROR_SUCCESS;
52
 
        else
53
 
                return LDTP_ERROR_CLICK_FAILED;
54
 
}
55
 
 
56
 
static gboolean 
57
 
get_state_visible (Accessible *object)
58
 
{
59
 
        SPIBoolean visible = FALSE;
60
 
        AccessibleStateSet *state;
61
 
  
62
 
        state = Accessible_getStateSet (object);
63
 
        if (state)
64
 
                visible = AccessibleStateSet_contains (state, SPI_STATE_VISIBLE);
65
 
        
66
 
        if (visible)
67
 
                return TRUE;
68
 
        else
69
 
                return FALSE;
70
 
}
71
 
 
72
 
static LDTPErrorCode
73
 
hide_list (Accessible *object, FILE *log_fp)
74
 
{
75
 
        int type;
76
 
        SPIBoolean flag = FALSE;
77
 
        Accessible *hide_object;
78
 
        AccessibleAction *action;
79
 
 
80
 
        if (wait_till_object_state_contains (object, COMBO_BOX, log_fp) != 0) {
81
 
                log_msg (LDTP_LOG_CAUSE, "Not all combo box object properties enabled", log_fp);
82
 
                return LDTP_ERROR_HIDELIST_FAILED;
83
 
        }
84
 
 
85
 
        type = get_child_object_type (object);
86
 
        if (type == SPI_ROLE_LIST) {
87
 
                hide_object = get_list_handle (object);
88
 
                if (get_state_visible (hide_object) == FALSE) {
89
 
                        /*
90
 
                          If object is already in hidden state, we can't proceed hiding the object.
91
 
                        */
92
 
                        log_msg (LDTP_LOG_WARNING, "List already in hidden state", log_fp);
93
 
                        Accessible_unref (hide_object);
94
 
                        return LDTP_ERROR_SUCCESS;
95
 
                }
96
 
 
97
 
                action = Accessible_getAction (hide_object);
98
 
                if (action) {
99
 
                        flag = AccessibleAction_doAction (action, 0);
100
 
                        Accessible_unref (action);
101
 
                }
102
 
                Accessible_unref (hide_object);
103
 
        } else if (type == SPI_ROLE_MENU) {
104
 
                hide_object = get_menu_handle (object);
105
 
                if (get_state_visible (hide_object) == FALSE) {
106
 
                        /*
107
 
                          If object is already in hidden state, we can't proceed hiding the object.
108
 
                        */
109
 
                        log_msg (LDTP_LOG_WARNING, "Menu already in hidden state", log_fp);
110
 
                        Accessible_unref (hide_object);
111
 
                        return LDTP_ERROR_SUCCESS;
112
 
                }
113
 
 
114
 
                action = Accessible_getAction (object);
115
 
                if (action) {
116
 
                        flag = AccessibleAction_doAction (action, 0);
117
 
                        Accessible_unref (action);
118
 
                }
119
 
                Accessible_unref (hide_object);
120
 
        }
121
 
        if (flag)
122
 
                return LDTP_ERROR_SUCCESS;
123
 
        else
124
 
                return LDTP_ERROR_HIDELIST_FAILED;
125
 
}       
126
 
 
127
 
static LDTPErrorCode
128
 
show_list (Accessible *object, FILE *log_fp)
129
 
{
130
 
        int type;
131
 
        SPIBoolean flag = FALSE;
132
 
        Accessible *show_object;
133
 
        AccessibleAction *action;
134
 
  
135
 
        if (wait_till_object_state_contains (object, COMBO_BOX, log_fp) != 0) {
136
 
                g_print ("Not all combo box object properties enabled\n");
137
 
                log_msg (LDTP_LOG_CAUSE, "Not all combo box object properties enabled", log_fp);
138
 
                return LDTP_ERROR_SHOWLIST_FAILED;
139
 
        }
140
 
 
141
 
        type = get_child_object_type (object);
142
 
 
143
 
        if (type == SPI_ROLE_LIST) {
144
 
                show_object = get_list_handle (object);
145
 
                if (get_state_visible (show_object) == TRUE) {
146
 
                        /*
147
 
                          If object is already in visible state, we can't proceed with this step.
148
 
                        */
149
 
                        log_msg (LDTP_LOG_WARNING, "List already in visible state", log_fp);
150
 
                        Accessible_unref (show_object);
151
 
                        return LDTP_ERROR_SUCCESS;
152
 
                }
153
 
                action = Accessible_getAction (show_object);
154
 
                if (action) {
155
 
                        flag = AccessibleAction_doAction (action, 0);
156
 
                        Accessible_unref (action);
157
 
                }
158
 
                Accessible_unref (show_object);
159
 
        }
160
 
 
161
 
        if (type == SPI_ROLE_MENU) {
162
 
                show_object = get_menu_handle (object);
163
 
                if (get_state_visible (show_object) == TRUE) {
164
 
                        /*
165
 
                          If object is already in visible state, we can't proceed with this step.
166
 
                        */
167
 
                        log_msg (LDTP_LOG_WARNING, "Menu already in visible state", log_fp);
168
 
                        Accessible_unref (show_object);
169
 
                        return LDTP_ERROR_SUCCESS;
170
 
                }
171
 
                action = Accessible_getAction (object);
172
 
                if (action) {
173
 
                        flag = AccessibleAction_doAction (action, 0);
174
 
                        Accessible_unref (action);
175
 
                }
176
 
                Accessible_unref (show_object);
177
 
       }
178
 
        g_print ("Flag: %d\n", flag);
179
 
        if (flag)
180
 
                return LDTP_ERROR_SUCCESS;
181
 
        else
182
 
                return LDTP_ERROR_SHOWLIST_FAILED;
183
 
}
184
 
 
185
 
static LDTPErrorCode
186
 
select_item (LDTPClientContext* cctxt)
187
 
{
188
 
        int type, count, i;
189
 
        LDTPErrorCode error;
190
 
        char *name = NULL;
191
 
        Accessible *object = cctxt->gui_handle->handle;
192
 
        Accessible *text = NULL;
193
 
        Accessible *child = NULL;
194
 
        Accessible *menu_object = NULL;
195
 
        char msg [256];
196
 
 
197
 
        if (wait_till_object_state_contains (object, COMBO_BOX, cctxt->log_fp) != 0) {
198
 
                g_print ("Not all combo box object properties enabled\n");
199
 
                log_msg (LDTP_LOG_CAUSE, "Not all combo box object properties enabled", cctxt->log_fp);
200
 
                return LDTP_ERROR_SELECTITEM_FAILED;
201
 
        }
202
 
  
203
 
        type = get_child_object_type (object);
204
 
        g_print ("Object type: %d\n", type);
205
 
        if (type == SPI_ROLE_LIST) {
206
 
                child = get_list_handle (object);
207
 
                if (child) {
208
 
                        cctxt->gui_handle->handle = child;
209
 
                        error = list_main (cctxt, LDTP_CMD_SELECTTEXTITEM);
210
 
                        Accessible_unref (child);
211
 
                        cctxt->gui_handle->handle = object;
212
 
                        if (error != LDTP_ERROR_SUCCESS) {
213
 
                                g_print ("Combo box SelectItem action failed\n");
214
 
                                log_msg (LDTP_LOG_CAUSE, "Combo box SelectItem action failed", cctxt->log_fp);
215
 
                                return LDTP_ERROR_SELECTITEM_FAILED;
216
 
                        }
217
 
                }
218
 
                text = get_text_handle (object);
219
 
                if (text) {
220
 
                        cctxt->gui_handle->handle = text;
221
 
                        error = text_main (cctxt, LDTP_CMD_VERIFYSETTEXT);
222
 
                        Accessible_unref (text);
223
 
                        cctxt->gui_handle->handle = object;
224
 
                        if (error == LDTP_ERROR_SUCCESS)
225
 
                                return LDTP_ERROR_SUCCESS;
226
 
                }
227
 
                g_print ("Combo box select verify action failed\n");
228
 
                log_msg (LDTP_LOG_CAUSE, "Combo box select verify action failed", cctxt->log_fp);
229
 
                return LDTP_ERROR_VERIFY_SETTEXTVALUE_FAILED;
230
 
        } else if (type == SPI_ROLE_MENU) {
231
 
                menu_object = get_menu_handle (object);
232
 
                if (menu_object == NULL) {
233
 
                        g_sprintf (msg, "Combobox: %s item does not exist\n",
234
 
                                   (char *)cctxt->req->arg_list->data);
235
 
                        log_msg (LDTP_LOG_CAUSE, msg, cctxt->log_fp);
236
 
                        return LDTP_ERROR_ITEM_NOT_FOUND;
237
 
                }
238
 
                count = Accessible_getChildCount (menu_object);
239
 
                for (i = 0; i < count; i++) {
240
 
                        child = Accessible_getChildAtIndex (menu_object, i);
241
 
                        if (child) {
242
 
                                char *tmp = NULL;
243
 
                                name = Accessible_getName (child);
244
 
                                g_print ("Combobox - name: %s - param: %s\n",
245
 
                                         name, (char *) cctxt->req->arg_list->data);
246
 
                                if (g_utf8_strchr (name, -1, ' ') != NULL)
247
 
                                        tmp = escape_character (name, ' ');
248
 
                                /*
249
 
                                  FIXME: Use g_utf8_*
250
 
                                */
251
 
                                if (strcasecmp (name, cctxt->req->arg_list->data) == 0 ||
252
 
                                    (tmp && strcasecmp (tmp, cctxt->req->arg_list->data) == 0)) {
253
 
                                        free (tmp);
254
 
                                        SPI_freeString (name);
255
 
                                        
256
 
                                        cctxt->gui_handle->handle = child;
257
 
                                        error = menu_item_main (cctxt, LDTP_CMD_SELECTMENUITEM);
258
 
                                        Accessible_unref (menu_object);
259
 
                                        Accessible_unref (child);
260
 
                                        cctxt->gui_handle->handle = object;
261
 
                                        if (error != LDTP_ERROR_SUCCESS) {
262
 
                                                g_print ("Combo Box: SelectItem action failed\n");
263
 
                                                log_msg (LDTP_LOG_CAUSE, "Combo Box: SelectItem action failed", cctxt->log_fp);
264
 
                                                return LDTP_ERROR_SELECTITEM_FAILED;
265
 
                                        } else {
266
 
                                                return LDTP_ERROR_SUCCESS;
267
 
                                        }
268
 
                                }
269
 
                                g_free (tmp);
270
 
                                SPI_freeString (name);
271
 
                                Accessible_unref (child);
272
 
                        } // if
273
 
                } // for
274
 
                Accessible_unref (menu_object);
275
 
                cctxt->gui_handle->handle = object;
276
 
                g_sprintf (msg, "Combobox: %s item does not exist\n",
277
 
                           (char *)cctxt->req->arg_list->data);
278
 
                log_msg (LDTP_LOG_CAUSE, msg, cctxt->log_fp);
279
 
                return LDTP_ERROR_ITEM_NOT_FOUND;
280
 
        }
281
 
        g_print ("Verify combo box click child type is unidentified\n");
282
 
        log_msg (LDTP_LOG_CAUSE, "Verify combo box click child type is unidentified", cctxt->log_fp);
283
 
        return LDTP_ERROR_CHILD_TYPE_UNIDENTIFIED;
284
 
}
285
 
 
286
 
static LDTPErrorCode 
287
 
capture_to_file (Accessible *object, char *file_name, FILE *log_fp)
288
 
{
289
 
        int type;
290
 
        long count, i;
291
 
        long child_count;
292
 
        char *name;
293
 
        FILE *fp = NULL;
294
 
        Accessible *child, *menu_object;
295
 
        Accessible *child_object, *child_text;
296
 
  
297
 
        if (file_name)
298
 
                fp = fopen (file_name, "w");
299
 
        else
300
 
                fp = fopen ("comboboxitem.lst", "w");
301
 
        if (fp == NULL) {
302
 
                log_msg (LDTP_LOG_CAUSE, "Combo box: Cannot open output file", log_fp);
303
 
                return LDTP_ERROR_FILECAPTURE_FAILED_OPEN_OUTPUT_FILE;
304
 
        }
305
 
        if (wait_till_object_state_contains (object, COMBO_BOX, log_fp) != 0) {
306
 
                log_msg (LDTP_LOG_CAUSE, "Combo Box: SelectItem action failed", log_fp);
307
 
                return LDTP_ERROR_SELECTITEM_FAILED;
308
 
        }
309
 
  
310
 
        type = get_child_object_type (object);
311
 
        g_print ("Object type: %d\n", type);
312
 
        if (type == SPI_ROLE_LIST) {
313
 
                child = get_list_handle (object);
314
 
                if (child != NULL) {
315
 
                        child_count = Accessible_getChildCount (child);
316
 
                        for (i = 0; i < child_count; i++) {
317
 
                                child_object = Accessible_getChildAtIndex (child, i);
318
 
                                child_text = Accessible_getText (child_object);
319
 
                                name = AccessibleText_getText (child_text, 0, LONG_MAX);
320
 
                                g_print ("Item-ID: %ld -- NAME: %s\n", i, name);
321
 
                                g_fprintf (fp, "%s\n", name);
322
 
                                SPI_freeString (name);
323
 
                                Accessible_unref (child_text);
324
 
                                Accessible_unref (child_object);
325
 
                        }
326
 
                }
327
 
                Accessible_unref (child);
328
 
        } else if (type == SPI_ROLE_MENU) {
329
 
                menu_object = get_menu_handle (object);
330
 
                if (menu_object) {
331
 
                        count = Accessible_getChildCount (menu_object);
332
 
                        if (count > 0) {
333
 
                                for (i = 0; i < count; i++) {
334
 
                                        child = Accessible_getChildAtIndex (menu_object, i);
335
 
                                        if (child) {
336
 
                                                name = Accessible_getName (child);
337
 
                                                g_print ("Item-ID: %ld -- NAME: %s\n", i, name);
338
 
                                                g_fprintf (fp, "%s\n", name);
339
 
                                                SPI_freeString (name);
340
 
                                                Accessible_unref (child);
341
 
                                        } 
342
 
                                } 
343
 
                                Accessible_unref (menu_object);
344
 
                        }
345
 
                }
346
 
        } else {
347
 
                fclose (fp);
348
 
                log_msg (LDTP_LOG_CAUSE, "Verify combo box click child type is unidentified", log_fp);
349
 
                return LDTP_ERROR_CHILD_TYPE_UNIDENTIFIED;
350
 
        }
351
 
        fclose (fp);
352
 
        return LDTP_ERROR_SUCCESS;
353
 
}
354
 
 
355
 
static LDTPErrorCode
356
 
select_index (LDTPClientContext* cctxt)
357
 
{
358
 
        LDTPErrorCode error;
359
 
        Accessible *child;
360
 
        Accessible *object = cctxt->gui_handle->handle;
361
 
 
362
 
        if (wait_till_object_state_contains (object, COMBO_BOX, cctxt->log_fp) != 0) {
363
 
                log_msg (LDTP_LOG_CAUSE, "Not all combo box object properties enabled", cctxt->log_fp);
364
 
                return LDTP_ERROR_SELECTINDEX_FAILED;
365
 
        }
366
 
 
367
 
        child = get_list_handle (object);
368
 
        if (child) {
369
 
                cctxt->gui_handle->handle = child;
370
 
                error = list_main (cctxt, LDTP_CMD_SELECTINDEX);
371
 
                Accessible_unref (child);
372
 
                cctxt->gui_handle->handle = object;
373
 
                if (error != LDTP_ERROR_SUCCESS) {
374
 
                        log_msg (LDTP_LOG_CAUSE, "Combo Box: SelectIndex action failed", cctxt->log_fp);
375
 
                        error = LDTP_ERROR_SELECTINDEX_FAILED;
376
 
                        log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), cctxt->log_fp);
377
 
                        return error;
378
 
                }
379
 
        } else {
380
 
                error = LDTP_ERROR_SELECTINDEX_FAILED;
381
 
                log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), cctxt->log_fp);
382
 
                return error;
383
 
        }
384
 
        return LDTP_ERROR_SUCCESS;
385
 
}
386
 
 
387
 
static LDTPErrorCode
388
 
set_text_value (LDTPClientContext* cctxt)
389
 
{
390
 
        Accessible *text_obj;
391
 
        LDTPErrorCode error;
392
 
        Accessible *object = cctxt->gui_handle->handle;
393
 
 
394
 
        if (wait_till_object_state_contains (object, COMBO_BOX, cctxt->log_fp) != 0) {
395
 
                log_msg (LDTP_LOG_CAUSE, "Not all combo box object properties enabled", cctxt->log_fp);
396
 
                return LDTP_ERROR_SETTEXTVALUE_FAILED;
397
 
        }
398
 
        if (!cctxt->req->arg_list->data) {
399
 
                error = LDTP_ERROR_SETTEXTVALUE_FAILED;
400
 
                log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), cctxt->log_fp);
401
 
                return error;
402
 
        }
403
 
        text_obj = get_text_handle (object);
404
 
        if (!text_obj) {
405
 
                error = LDTP_ERROR_SETTEXTVALUE_FAILED;
406
 
                log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), cctxt->log_fp);
407
 
                return error;
408
 
        }
409
 
        cctxt->gui_handle->handle = text_obj;
410
 
        error = text_main (cctxt, LDTP_CMD_SETTEXTVALUE);
411
 
        if (error != LDTP_ERROR_SUCCESS) {
412
 
                Accessible_unref (text_obj);
413
 
                cctxt->gui_handle->handle = object;
414
 
                log_msg (LDTP_LOG_CAUSE, "Combo Box: SetTextValue action failed during setting", cctxt->log_fp);
415
 
                return LDTP_ERROR_SETTEXTVALUE_FAILED;
416
 
        }
417
 
        error = text_main (cctxt, LDTP_CMD_VERIFYSETTEXT);
418
 
        if (error != LDTP_ERROR_SUCCESS) {
419
 
                Accessible_unref (text_obj);
420
 
                cctxt->gui_handle->handle = object;
421
 
                log_msg (LDTP_LOG_CAUSE, "Combo Box: SetTextValue verify action failed during verifying", cctxt->log_fp);
422
 
                return LDTP_ERROR_VERIFY_SETTEXTVALUE_FAILED;
423
 
        }
424
 
        Accessible_unref (text_obj);
425
 
        cctxt->gui_handle->handle = object;
426
 
        return LDTP_ERROR_SUCCESS;
427
 
}
428
 
 
429
 
static LDTPErrorCode
430
 
verify_drop_down (Accessible *object, FILE *log_fp)
431
 
432
 
        int focused, child_type;
433
 
        int showing, visible;
434
 
        Accessible *child_object;
435
 
        AccessibleStateSet *state;
436
 
  
437
 
        if (wait_till_object_state_contains (object, COMBO_BOX, log_fp) != 0) {
438
 
                log_msg (LDTP_LOG_CAUSE, "Not all combo box object properties enabled", log_fp);
439
 
                return LDTP_ERROR_CLICK_FAILED;
440
 
        }
441
 
 
442
 
        child_type = get_child_object_type (object);
443
 
        if (child_type == SPI_ROLE_LIST) {
444
 
                child_object = (Accessible *) get_list_handle (object);
445
 
                if (child_object) {
446
 
                        state = Accessible_getStateSet (object);
447
 
                        focused = AccessibleStateSet_contains (state, SPI_STATE_FOCUSABLE); 
448
 
                        Accessible_unref (child_object);
449
 
                        if (focused == 0) {
450
 
                                log_msg (LDTP_LOG_CAUSE, "Verify Combo box list child is not focused", log_fp);
451
 
                                return LDTP_ERROR_CHILD_NOT_FOCUSSED;
452
 
                        } else
453
 
                                return LDTP_ERROR_SUCCESS;
454
 
                }
455
 
        } else if (child_type == SPI_ROLE_MENU) {
456
 
                child_object = (Accessible *) get_menu_handle (object);
457
 
                if (child_object) {
458
 
                        state = Accessible_getStateSet (object);
459
 
                        showing = AccessibleStateSet_contains (state, SPI_STATE_SHOWING);
460
 
                        visible = AccessibleStateSet_contains (state, SPI_STATE_VISIBLE); 
461
 
                        Accessible_unref (child_object);
462
 
                        if ((showing == 0) && (visible == 0)) {
463
 
                                log_msg (LDTP_LOG_CAUSE, "Verify combo box menu child is not showing", log_fp);
464
 
                                return LDTP_ERROR_MENU_NOT_VISIBLE;
465
 
                        } else
466
 
                                return LDTP_ERROR_SUCCESS;
467
 
                }
468
 
        } else {          
469
 
                log_msg (LDTP_LOG_CAUSE, "Verify combo box click child type is unidentified", log_fp);
470
 
                return LDTP_ERROR_CHILD_TYPE_UNIDENTIFIED;
471
 
        }
472
 
        return LDTP_ERROR_VERIFY_DROPDOWN_FAILED;
473
 
}
474
 
 
475
 
static LDTPErrorCode
476
 
verify_hide_list (Accessible *object, FILE *log_fp)
477
 
{
478
 
        int child_type;
479
 
        Accessible *child_object;
480
 
        AccessibleStateSet *state;
481
 
        SPIBoolean visible;
482
 
        SPIBoolean showing;
483
 
        SPIBoolean focused;
484
 
  
485
 
        if (wait_till_object_state_contains (object, COMBO_BOX, log_fp) != 0) {
486
 
                log_msg (LDTP_LOG_CAUSE, "Not all combo box object properties enabled", log_fp);
487
 
                return LDTP_ERROR_CLICK_FAILED;
488
 
        }
489
 
 
490
 
        child_type = get_child_object_type (object);
491
 
        if (child_type == SPI_ROLE_LIST) {
492
 
                child_object = get_list_handle (object);
493
 
                if (child_object) {
494
 
                        state = Accessible_getStateSet (object);
495
 
                        focused = AccessibleStateSet_contains (state, SPI_STATE_FOCUSABLE); 
496
 
                        Accessible_unref (child_object);
497
 
                        if (focused == TRUE) {
498
 
                                log_msg (LDTP_LOG_CAUSE, "Verify Combo box list child is focused", log_fp);
499
 
                                return LDTP_ERROR_CHILD_IN_FOCUS;
500
 
                        }
501
 
                        return LDTP_ERROR_SUCCESS;
502
 
                }
503
 
        }
504
 
        else if (child_type == SPI_ROLE_MENU) {
505
 
                child_object = get_menu_handle (object);
506
 
                if (child_object) {
507
 
                        state = Accessible_getStateSet (object);
508
 
                        showing = AccessibleStateSet_contains (state, SPI_STATE_SHOWING);
509
 
                        visible = AccessibleStateSet_contains (state, SPI_STATE_VISIBLE); 
510
 
                        Accessible_unref (child_object);
511
 
                        if (showing == FALSE && visible == FALSE) {
512
 
                                /* Varadhan
513
 
                                   Are we checking for visibility or invisibility?
514
 
                                */
515
 
                                log_msg (LDTP_LOG_CAUSE, "Verify combo box menu child is showing & visible", log_fp);
516
 
                                return LDTP_ERROR_MENU_VISIBLE;
517
 
                        }
518
 
                        return LDTP_ERROR_SUCCESS;
519
 
                }
520
 
        }
521
 
        log_msg (LDTP_LOG_CAUSE, "Verify combo box hidelist child type is unidentified", log_fp);
522
 
        return LDTP_ERROR_CHILD_TYPE_UNIDENTIFIED;
523
 
}
524
 
 
525
 
static LDTPErrorCode 
526
 
verify_show_list (Accessible *object, FILE *log_fp)
527
 
{
528
 
        if (verify_drop_down (object, log_fp) != 0) {
529
 
                log_msg (LDTP_LOG_CAUSE, "Verify combo box showlist action failed", log_fp);
530
 
                return LDTP_ERROR_VERIFY_SHOWLIST_FAILED;
531
 
        }
532
 
        else
533
 
                return LDTP_ERROR_SUCCESS;
534
 
}                
535
 
 
536
 
static LDTPErrorCode
537
 
verify_set_text_value (LDTPClientContext* cctxt)
538
 
{
539
 
        int child_type;
540
 
        LDTPErrorCode error;
541
 
        Accessible *text_object;
542
 
        Accessible *object = cctxt->gui_handle->handle;
543
 
 
544
 
        child_type = get_child_object_type (object);
545
 
        if (child_type == SPI_ROLE_LIST) {
546
 
                if (wait_till_object_state_contains (object, COMBO_BOX, cctxt->log_fp) != 0) {
547
 
                        g_print ("Verify Combo box SetTextValue action failed\n");
548
 
                        log_msg (LDTP_LOG_CAUSE, "Verify Combo box SetTextValue action failed", cctxt->log_fp);
549
 
                        return LDTP_ERROR_VERIFY_SETTEXTVALUE_FAILED;
550
 
                }
551
 
                text_object = get_text_handle (object);
552
 
                if (text_object) {
553
 
                        cctxt->gui_handle->handle = text_object;
554
 
                        error = text_main (cctxt, LDTP_CMD_VERIFYSETTEXT);
555
 
                        Accessible_unref (text_object);
556
 
                        cctxt->gui_handle->handle = object;
557
 
                        if (error != LDTP_ERROR_SUCCESS) {
558
 
                                g_print ("Verify Combo box SetTextValue action failed\n");
559
 
                                log_msg (LDTP_LOG_CAUSE, "Verify Combo box SetTextValue action failed", cctxt->log_fp);
560
 
                                return LDTP_ERROR_VERIFY_SETTEXTVALUE_FAILED;
561
 
                        }
562
 
                        return LDTP_ERROR_SUCCESS;
563
 
                } else {
564
 
                        g_print ("Verify Combo box SetTextValue child object is NULL\n");
565
 
                        log_msg (LDTP_LOG_CAUSE, "Verify Combo box SetTextValue child object is NULL", cctxt->log_fp);
566
 
                        return LDTP_ERROR_VERIFY_SETTEXTVALUE_FAILED;
567
 
                }
568
 
        } else if (child_type == SPI_ROLE_MENU) {
569
 
                gboolean flag = FALSE;
570
 
                char *name = Accessible_getName (object);
571
 
                if (name) {
572
 
                        if (cctxt && cctxt->req && cctxt->req->arg_list &&
573
 
                            cctxt->req->arg_list->data &&
574
 
                            (g_utf8_collate (cctxt->req->arg_list->data, name) == 0)) {
575
 
                                g_print ("Name: %s - %s\n", name, (char *)cctxt->req->arg_list->data);
576
 
                                flag = TRUE;
577
 
                        }
578
 
                        SPI_freeString (name);
579
 
                }
580
 
                if (flag)
581
 
                        return LDTP_ERROR_SUCCESS;
582
 
                else {
583
 
                        g_print ("Ldtp error verify settextvalue failed\n");
584
 
                        return LDTP_ERROR_VERIFY_SETTEXTVALUE_FAILED;
585
 
                }
586
 
        }
587
 
        g_print ("Object type not matched: Ldtp error verify settextvalue failed\n");
588
 
        return LDTP_ERROR_VERIFY_SETTEXTVALUE_FAILED;
589
 
}
590
 
 
591
 
static LDTPErrorCode
592
 
verify_select_item (LDTPClientContext* cctxt)
593
 
{
594
 
        LDTPErrorCode error;
595
 
 
596
 
        error = verify_set_text_value (cctxt);
597
 
 
598
 
        if (error != LDTP_ERROR_SUCCESS) {
599
 
                g_print ("verify combo box select action failed\n");
600
 
                log_msg (LDTP_LOG_CAUSE, "verify combo box select action failed", cctxt->log_fp);
601
 
                return LDTP_ERROR_VERIFY_ITEM_FAILED;
602
 
        }
603
 
        return LDTP_ERROR_SUCCESS;
604
 
}
605
 
 
606
 
static LDTPErrorCode
607
 
combo_select_index (LDTPClientContext* cctxt, int index)
608
 
{
609
 
        int type;
610
 
        long count;
611
 
        Accessible *child, *menu_object;
612
 
        Accessible *object = cctxt->gui_handle->handle;
613
 
  
614
 
        if (wait_till_object_state_contains (object, COMBO_BOX, cctxt->log_fp) != 0) {
615
 
                log_msg (LDTP_LOG_CAUSE, "Not all combo box object properties enabled", cctxt->log_fp);
616
 
                return LDTP_ERROR_SELECTITEM_FAILED;
617
 
        }
618
 
 
619
 
        type = get_child_object_type (object);
620
 
        if (type == SPI_ROLE_MENU) {
621
 
                menu_object = get_menu_handle (object);
622
 
                if (menu_object) {
623
 
                        count = Accessible_getChildCount (menu_object);
624
 
                        if (count > 0) {          
625
 
                                child = Accessible_getChildAtIndex (menu_object, index);
626
 
                                Accessible_unref (menu_object);
627
 
                                if (child) {
628
 
                                        LDTPErrorCode error;
629
 
                                        cctxt->gui_handle->handle = child;
630
 
                                        error = menu_item_main (cctxt, LDTP_CMD_SELECTMENUITEM);
631
 
                                        cctxt->gui_handle->handle = object;
632
 
                                        Accessible_unref (child);
633
 
                                        if (error != LDTP_ERROR_SUCCESS) {
634
 
                                                log_msg (LDTP_LOG_CAUSE, "Combo Box: SelectItem action failed", cctxt->log_fp);
635
 
                                                return LDTP_ERROR_SELECTITEM_FAILED;
636
 
                                        }
637
 
                                        else
638
 
                                                return LDTP_ERROR_SUCCESS;
639
 
                                }
640
 
                        }// if
641
 
                        else
642
 
                                Accessible_unref (menu_object);
643
 
                }
644
 
                log_msg (LDTP_LOG_CAUSE, "Combo Box: SelectItem does not exist in", cctxt->log_fp);
645
 
                /* 
646
 
                   Varadhan
647
 
                   FIXME: Item does not exist or action failed? 
648
 
                */
649
 
                return LDTP_ERROR_SELECTITEM_FAILED;
650
 
        }
651
 
        /* Varadhan
652
 
           FIXME: More specific error should be returned 
653
 
        */
654
 
        log_msg (LDTP_LOG_CAUSE, "Verify combo box click child type is unidentified", cctxt->log_fp);
655
 
        return LDTP_ERROR_SELECTITEM_FAILED;
656
 
}
657
 
 
658
 
static LDTPErrorCode
659
 
get_text_value (LDTPClientContext* cctxt)
660
 
{
661
 
        int type;
662
 
        long child_count, i;
663
 
        Accessible *child;
664
 
        char *item = NULL;
665
 
        AccessibleRole role;
666
 
        Accessible *object = cctxt->gui_handle->handle;
667
 
  
668
 
        if (wait_till_object_state_contains (object, COMBO_BOX, cctxt->log_fp) != 0) {
669
 
                log_msg (LDTP_LOG_CAUSE, "Not all combo box object properties enabled", cctxt->log_fp);
670
 
                return LDTP_ERROR_GETTEXTVALUE_FAILED;
671
 
        }
672
 
 
673
 
        type = get_child_object_type (object);
674
 
 
675
 
        if (type == SPI_ROLE_LIST) {
676
 
                child = NULL;
677
 
                child_count = Accessible_getChildCount (object);
678
 
                for (i = 0; i < child_count; i++) {
679
 
                        child = Accessible_getChildAtIndex (object, i);
680
 
                        role = Accessible_getRole (child);
681
 
                        if (role == SPI_ROLE_TEXT)
682
 
                                break;
683
 
                        else {
684
 
                                Accessible_unref (child);
685
 
                                child = NULL;
686
 
                        }
687
 
                }
688
 
                if (child) {
689
 
                        LDTPErrorCode error;
690
 
                        cctxt->req->arg_list = g_slist_prepend (cctxt->req->arg_list,
691
 
                                                               "0");
692
 
                        cctxt->req->arg_list = g_slist_prepend (cctxt->req->arg_list,
693
 
                                                               "0");
694
 
                        cctxt->gui_handle->handle = child;
695
 
                        error = text_main (cctxt, LDTP_CMD_GETTEXTVALUE);
696
 
                        cctxt->req->arg_list = g_slist_remove (cctxt->req->arg_list, "0");
697
 
                        cctxt->req->arg_list = g_slist_remove (cctxt->req->arg_list, "0");
698
 
                        cctxt->gui_handle->handle = object;
699
 
                        Accessible_unref (child);
700
 
                        if (error != LDTP_ERROR_SUCCESS) {
701
 
                                log_msg (LDTP_LOG_CAUSE, 
702
 
                                         "Combo box gettextvalue action failed",
703
 
                                         cctxt->log_fp);
704
 
                                return LDTP_ERROR_GETTEXTVALUE_FAILED;
705
 
                        }
706
 
                        cctxt->resp->data_len = g_utf8_strlen (cctxt->req->arg_list->data, -1);
707
 
                        cctxt->resp->data = g_strdup (cctxt->req->arg_list->data);
708
 
                        cctxt->req->arg_list = g_slist_remove (cctxt->req->arg_list->data, cctxt->resp->data);
709
 
                        return LDTP_ERROR_SUCCESS;
710
 
                } else {
711
 
                        log_msg (LDTP_LOG_CAUSE, 
712
 
                                 "Combo box gettextvalue  action failed",
713
 
                                 cctxt->log_fp);
714
 
                        return LDTP_ERROR_GETTEXTVALUE_FAILED;
715
 
                }
716
 
        } else if (type == SPI_ROLE_MENU) {
717
 
                child = Accessible_getText (object);
718
 
                item = AccessibleText_getText (child, 0, LONG_MAX);
719
 
                cctxt->resp->data = g_strdup (item);
720
 
                cctxt->resp->data_len = AccessibleText_getCharacterCount (child);
721
 
                SPI_freeString (item);
722
 
                Accessible_unref (child);
723
 
                return LDTP_ERROR_SUCCESS;
724
 
        } else {
725
 
                log_msg (LDTP_LOG_CAUSE, "Combo box child type is unidentified", cctxt->log_fp);
726
 
                return LDTP_ERROR_CHILD_TYPE_UNIDENTIFIED;
727
 
        }
728
 
}
729
 
 
730
 
LDTPErrorCode 
731
 
combo_box_main (LDTPClientContext* cctxt, int command)
732
 
{
733
 
        LDTPErrorCode error;
734
 
        switch (command) {
735
 
        case LDTP_CMD_CLICK:
736
 
                error = click (cctxt->gui_handle->handle, cctxt->log_fp);
737
 
                break;
738
 
        case LDTP_CMD_HIDELIST:
739
 
                error = hide_list (cctxt->gui_handle->handle, cctxt->log_fp);
740
 
                break;
741
 
        case LDTP_CMD_COMBOSELECT:
742
 
                error = select_item (cctxt);
743
 
                break;
744
 
        case LDTP_CMD_SELECTINDEX:
745
 
                error = select_index (cctxt);
746
 
                break;
747
 
        case LDTP_CMD_SETTEXTVALUE: 
748
 
                error = set_text_value (cctxt);
749
 
                break;
750
 
        case LDTP_CMD_SHOWLIST: 
751
 
                error = show_list (cctxt->gui_handle->handle, cctxt->log_fp);
752
 
                break;
753
 
        case LDTP_CMD_VERIFYDROPDOWN:
754
 
                error = verify_drop_down (cctxt->gui_handle->handle, cctxt->log_fp);
755
 
                break;
756
 
        case LDTP_CMD_VERIFYHIDELIST:
757
 
                error = verify_hide_list (cctxt->gui_handle->handle, cctxt->log_fp);
758
 
                break;
759
 
        case LDTP_CMD_VERIFYSHOWLIST:
760
 
                error = verify_show_list (cctxt->gui_handle->handle, cctxt->log_fp);
761
 
                break;
762
 
        case LDTP_CMD_VERIFYSELECT:
763
 
                error = verify_select_item (cctxt);
764
 
                break;
765
 
        case LDTP_CMD_VERIFYSETTEXT:
766
 
                error = verify_set_text_value (cctxt);
767
 
                break;
768
 
        case LDTP_CMD_COMBOSELECTINDEX: {
769
 
                long index = 0;
770
 
                if (cctxt->req->arg_list && cctxt->req->arg_list->data)
771
 
                        index = atol (cctxt->req->arg_list->data);
772
 
                error = combo_select_index (cctxt, index);
773
 
                break;
774
 
        }       
775
 
        case LDTP_CMD_CAPTURETOFILE: {
776
 
                char *filename = NULL;
777
 
                if (cctxt->req->arg_list && cctxt->req->arg_list->data)
778
 
                        filename = cctxt->req->arg_list->data;
779
 
                error = capture_to_file (cctxt->gui_handle->handle,
780
 
                                         filename, cctxt->log_fp);
781
 
                break;
782
 
        }
783
 
        case LDTP_CMD_GETTEXTVALUE:
784
 
                error = get_text_value (cctxt);
785
 
                break;
786
 
        case LDTP_CMD_KBDENTER:
787
 
                error = device_main (cctxt, command);
788
 
                break;
789
 
        case LDTP_CMD_GETOBJECTSIZE:
790
 
                cctxt->resp->data_len = 0;
791
 
                cctxt->resp->data = get_size (cctxt->gui_handle->handle, &error);
792
 
                if (cctxt->resp->data) {
793
 
                        cctxt->resp->data_len = g_utf8_strlen (cctxt->resp->data, -1);
794
 
                }
795
 
                break;
796
 
        default:
797
 
                error = LDTP_ERROR_COMMAND_NOT_IMPLEMENTED;
798
 
        }
799
 
        return error;
800
 
}