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

« back to all changes in this revision

Viewing changes to src/check-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
 
 *    Nagappan Alagappan <nagappan@gmail.com>
7
 
 *    Poornima <pnayak@novell.com>
8
 
 *
9
 
 * Copyright 2004 - 2006 Novell, Inc.
10
 
 * Copyright 2007 - 2008 Nagappan Alagappan
11
 
 *
12
 
 * This program is free software; you can redistribute it and/or
13
 
 * modify it under the terms of the GNU Lesser General Public
14
 
 * License as published by the Free Software Foundation; either
15
 
 * version 2 of the License, or (at your option) any later version.
16
 
 *
17
 
 * This program is distributed in the hope that it will be useful,
18
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20
 
 * Lesser General Public License for more details.
21
 
 *
22
 
 * You should have received a copy of the GNU Lesser General Public
23
 
 * License along with this program; if not, write to the
24
 
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25
 
 * Boston, MA 02110, USA.
26
 
 */
27
 
 
28
 
#include "ldtp.h"
29
 
#include "ldtp-gui.h"
30
 
#include "ldtp-error.h"
31
 
#include "ldtp-logger.h"
32
 
#include "ldtp-command.h"
33
 
#include "ldtp-gui-comp.h"
34
 
 
35
 
/*
36
 
  Get the check box state of the given object
37
 
*/
38
 
static gboolean
39
 
get_check_box_state (Accessible *object)
40
 
{
41
 
        AccessibleStateSet *state;
42
 
        
43
 
        state = Accessible_getStateSet (object);
44
 
 
45
 
        /*
46
 
          Check, if check box state is already checked
47
 
        */
48
 
        if (AccessibleStateSet_contains (state, SPI_STATE_CHECKED))
49
 
                return TRUE; // Checked state
50
 
        else
51
 
                return FALSE; // Unchecked state
52
 
}
53
 
 
54
 
static gboolean
55
 
is_check_box_enabled (Accessible *object)
56
 
{
57
 
        AccessibleStateSet *state;
58
 
 
59
 
        if (!object)
60
 
                return FALSE;
61
 
        if (wait_till_object_state_contains (object, CHECK_BOX, NULL) == -1) {
62
 
                LDTPErrorCode error;
63
 
                error = LDTP_ERROR_INVALID_OBJECT_STATE;
64
 
                log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), NULL);
65
 
                return FALSE;
66
 
        }
67
 
        state = Accessible_getStateSet (object);
68
 
 
69
 
        /* Verifies it is enabled or not */
70
 
        if (AccessibleStateSet_contains (state, SPI_STATE_ENABLED) == TRUE)
71
 
                return TRUE;
72
 
        else
73
 
                return FALSE;
74
 
}
75
 
 
76
 
static LDTPErrorCode
77
 
check_check_box (Accessible *object, FILE *log_fp)
78
 
{
79
 
        LDTPErrorCode error;
80
 
        AccessibleAction *action;
81
 
 
82
 
        if (wait_till_object_state_contains (object, CHECK_BOX, log_fp) != 0) {
83
 
                error = LDTP_ERROR_INVALID_OBJECT_STATE;
84
 
                goto error;
85
 
        }
86
 
        /*
87
 
          Pre-condition
88
 
          If state already selected then unselect ?
89
 
        */
90
 
        if (get_check_box_state (object) == FALSE) {
91
 
                SPIBoolean flag;
92
 
                action = Accessible_getAction (object);
93
 
                flag = AccessibleAction_doAction (action, 0);
94
 
                Accessible_unref (action);
95
 
                if (flag)
96
 
                        return LDTP_ERROR_SUCCESS;
97
 
                else {
98
 
                        error = LDTP_ERROR_CHECK_ACTION_FAILED;
99
 
                        goto error;
100
 
                }
101
 
        }
102
 
        else 
103
 
                log_msg (LDTP_LOG_WARNING, "Check box is already checked", log_fp);
104
 
        return LDTP_ERROR_SUCCESS;
105
 
 error:
106
 
        log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
107
 
        return error;
108
 
}
109
 
 
110
 
static LDTPErrorCode
111
 
uncheck_check_box (Accessible *object, FILE *log_fp)
112
 
{
113
 
        LDTPErrorCode error;
114
 
        AccessibleAction *action;
115
 
 
116
 
        if (wait_till_object_state_contains (object, CHECK_BOX, log_fp) != 0) {
117
 
                error = LDTP_ERROR_INVALID_OBJECT_STATE;
118
 
                goto error;
119
 
        }
120
 
        /*
121
 
          Pre-condition
122
 
          If state is checked then only uncheck it 
123
 
        */
124
 
        if (get_check_box_state (object) == TRUE) {
125
 
                SPIBoolean flag;
126
 
                action = Accessible_getAction (object);
127
 
                flag = AccessibleAction_doAction (action, 0);
128
 
                Accessible_unref (action);
129
 
                if (flag)
130
 
                        return LDTP_ERROR_SUCCESS;
131
 
                else {
132
 
                        error = LDTP_ERROR_UNCHECK_ACTION_FAILED;
133
 
                        goto error;
134
 
                }
135
 
        }
136
 
        else
137
 
                log_msg (LDTP_LOG_WARNING, "Check box state already unchecked", log_fp);
138
 
        return LDTP_ERROR_SUCCESS;
139
 
 error:
140
 
        log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
141
 
        return error;
142
 
}
143
 
 
144
 
static LDTPErrorCode
145
 
click (Accessible *object, FILE *log_fp)
146
 
{
147
 
        LDTPErrorCode error;
148
 
        SPIBoolean flag = FALSE;
149
 
        AccessibleAction *action;
150
 
        
151
 
        if (wait_till_object_state_contains (object, CHECK_BOX, log_fp) != 0) {
152
 
                error = LDTP_ERROR_INVALID_OBJECT_STATE;
153
 
                log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
154
 
                return error;
155
 
        }
156
 
 
157
 
        action = Accessible_getAction (object);
158
 
        flag = AccessibleAction_doAction (action, 0);
159
 
        Accessible_unref (action);
160
 
 
161
 
        if (flag)
162
 
                return LDTP_ERROR_SUCCESS;
163
 
        else
164
 
                return LDTP_ERROR_CLICK_FAILED;
165
 
}
166
 
        
167
 
static LDTPErrorCode
168
 
verify_check_check_box (Accessible *object, FILE *log_fp)
169
 
{
170
 
        LDTPErrorCode error;
171
 
        if (wait_till_object_state_contains (object, CHECK_BOX, log_fp) != 0) {
172
 
                error = LDTP_ERROR_INVALID_OBJECT_STATE;
173
 
                log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
174
 
                return error;
175
 
        }
176
 
        if (get_check_box_state (object) == FALSE)
177
 
                return LDTP_ERROR_STATE_UNCHECKED;
178
 
        else
179
 
                return LDTP_ERROR_SUCCESS;
180
 
}
181
 
 
182
 
static LDTPErrorCode
183
 
verify_uncheck_check_box (Accessible *object, FILE *log_fp)
184
 
{
185
 
        LDTPErrorCode error;
186
 
        if (wait_till_object_state_contains (object, CHECK_BOX, log_fp) != 0) {
187
 
                error = LDTP_ERROR_INVALID_OBJECT_STATE;
188
 
                log_msg (LDTP_LOG_CAUSE, ldtp_error_get_message (error), log_fp);
189
 
                return error;
190
 
        }
191
 
        if (get_check_box_state (object) == TRUE)
192
 
                return LDTP_ERROR_STATE_CHECKED;
193
 
        else
194
 
                return LDTP_ERROR_SUCCESS;
195
 
}
196
 
 
197
 
LDTPErrorCode
198
 
check_box_main (LDTPClientContext* cctxt, int command)
199
 
{
200
 
        LDTPErrorCode error;
201
 
        switch (command) {
202
 
        case LDTP_CMD_CHECK:
203
 
                error = check_check_box (cctxt->gui_handle->handle, cctxt->log_fp);
204
 
                break;
205
 
        case LDTP_CMD_UNCHECK:
206
 
                error = uncheck_check_box (cctxt->gui_handle->handle, cctxt->log_fp);
207
 
                break;
208
 
        case LDTP_CMD_GRABFOCUS:
209
 
                error = grab_focus (cctxt->gui_handle->handle, cctxt->log_fp);
210
 
                break;
211
 
        case LDTP_CMD_STATEENABLED:
212
 
                if (is_check_box_enabled (cctxt->gui_handle->handle))
213
 
                        error = LDTP_ERROR_SUCCESS;
214
 
                else
215
 
                        error = LDTP_ERROR_CHECK_BOX_STATE_NOT_ENABLED;
216
 
                break;
217
 
        case LDTP_CMD_CLICK:
218
 
                error = click (cctxt->gui_handle->handle, cctxt->log_fp);
219
 
                break;
220
 
        case LDTP_CMD_VERIFYCHECK:
221
 
                error = verify_check_check_box (cctxt->gui_handle->handle, cctxt->log_fp);
222
 
                break;
223
 
        case LDTP_CMD_VERIFYUNCHECK:
224
 
                error = verify_uncheck_check_box (cctxt->gui_handle->handle, cctxt->log_fp);
225
 
                break;
226
 
        case LDTP_CMD_GETOBJECTSIZE:
227
 
                cctxt->resp->data_len = 0;
228
 
                cctxt->resp->data = get_size (cctxt->gui_handle->handle, &error);
229
 
                if (cctxt->resp->data) {
230
 
                        cctxt->resp->data_len = g_utf8_strlen (cctxt->resp->data, -1);
231
 
                }
232
 
                break;
233
 
        default:
234
 
                error = LDTP_ERROR_COMMAND_NOT_IMPLEMENTED;
235
 
        }
236
 
        return error;
237
 
}