1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package ifc.accessibility;
29 
30 import com.sun.star.accessibility.XAccessibleAction;
31 
32 public class _XAccessibleAction extends lib.MultiMethodTest {
33 
34     public XAccessibleAction oObj = null;
35     public int count = 0;
36 
37     /**
38      * calls the method and stores the result in the <br>
39      * variable count. Is OK if no excpetion occurs
40      */
41 
42     public void _getAccessibleActionCount() {
43         count = oObj.getAccessibleActionCount();
44         tRes.tested("getAccessibleActionCount()",count > 0);
45     }
46 
47     /**
48      * calls the method with invalid argument and check if the <br>
49      * expected Exception is thrown.<br>
50      * Calls the method afterwards the first valid parameter.<br>
51      * This is the last method called and the environment is disposed<br>
52      * afterwards.
53      */
54 
55     public void _doAccessibleAction() {
56         requiredMethod("getAccessibleActionKeyBinding()");
57         boolean res = true;
58 
59         log.println("Calling method with wrong argument");
60         try {
61             oObj.doAccessibleAction(count);
62             log.println("Exception expected -- FAILED");
63             res &= false;
64         } catch (com.sun.star.lang.IndexOutOfBoundsException ioe) {
65             log.println("Expected exception -- OK");
66             res &= true;
67         }
68 
69         try {
70             boolean act = false;
71             for (int i = 0; i< count; i++) {
72                 log.println("do Action "+ oObj.getAccessibleActionDescription(i));
73                 act = oObj.doAccessibleAction(i);
74                 log.println("Worked: "+act);
75             }
76             log.println("Did action: "+act);
77             res &= act ;
78         } catch (com.sun.star.lang.IndexOutOfBoundsException ioe) {
79             log.println("Unexepected exception -- FAILED");
80             res &= false;
81         }
82 
83         tRes.tested("doAccessibleAction()",res);
84     }
85 
86     /**
87      * calls the method with invalid argument and check if the <br>
88      * expected Exception is thrown.<br>
89      * Calls the method afterwards all valid parameters.<br>
90      * Is ok if the exception is thrown and the resulting value
91      * for the calls with valid parameters aren't null.
92      */
93 
94     public void _getAccessibleActionDescription() {
95         requiredMethod("getAccessibleActionCount()");
96         boolean res = true;
97 
98         log.println("Calling method with wrong argument");
99         try {
100             oObj.getAccessibleActionDescription(count);
101             log.println("Exception expected -- FAILED");
102             res &= false;
103         } catch (com.sun.star.lang.IndexOutOfBoundsException ioe) {
104             log.println("Expected exception -- OK");
105             res &= true;
106         }
107 
108         for (int i=0;i<count;i++) {
109             try {
110                 String desc = oObj.getAccessibleActionDescription(i);
111                 log.println("Found action: "+desc);
112                 res &= desc!=null ;
113             } catch (com.sun.star.lang.IndexOutOfBoundsException ioe) {
114                 log.println("Unexepected exception -- FAILED");
115                 res &= false;
116             }
117         }
118 
119         tRes.tested("getAccessibleActionDescription()",res);
120     }
121 
122     /**
123      * calls the method with invalid argument and check if the <br>
124      * expected Exception is thrown.<br>
125      * Calls the method afterwards all valid parameters.<br>
126      * Is ok if the exception is thrown and the resulting value
127      * for the calls with valid parameters aren't null.
128      */
129 
130     public void _getAccessibleActionKeyBinding() {
131         requiredMethod("getAccessibleActionDescription()");
132         boolean res = true;
133 
134         log.println("Calling method with wrong argument");
135         try {
136             oObj.getAccessibleActionKeyBinding(count);
137             log.println("Exception expected -- FAILED");
138             res &= false;
139         } catch (com.sun.star.lang.IndexOutOfBoundsException ioe) {
140             log.println("Expected exception -- OK");
141             res &= true;
142         }
143 
144         for (int i=0;i<count;i++) {
145             try {
146                 Object key = oObj.getAccessibleActionKeyBinding(i);
147                 if (key != null ) {
148                     log.println("Found key: "+key.toString());
149                 }
150                 res &= true;
151             } catch (com.sun.star.lang.IndexOutOfBoundsException ioe) {
152                 log.println("Unexepected exception -- FAILED");
153                 res &= false;
154             }
155         }
156 
157         tRes.tested("getAccessibleActionKeyBinding()",res);
158     }
159 
160     /**
161     * Forces environment recreation.
162     */
163     protected void after() {
164         disposeEnvironment();
165     }
166 
167 }
168