1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package ifc.accessibility;
25 
26 import com.sun.star.accessibility.XAccessibleAction;
27 
28 public class _XAccessibleAction extends lib.MultiMethodTest {
29 
30     public XAccessibleAction oObj = null;
31     public int count = 0;
32 
33     /**
34      * calls the method and stores the result in the <br>
35      * variable count. Is OK if no excpetion occurs
36      */
37 
_getAccessibleActionCount()38     public void _getAccessibleActionCount() {
39         count = oObj.getAccessibleActionCount();
40         tRes.tested("getAccessibleActionCount()",count > 0);
41     }
42 
43     /**
44      * calls the method with invalid argument and check if the <br>
45      * expected Exception is thrown.<br>
46      * Calls the method afterwards the first valid parameter.<br>
47      * This is the last method called and the environment is disposed<br>
48      * afterwards.
49      */
50 
_doAccessibleAction()51     public void _doAccessibleAction() {
52         requiredMethod("getAccessibleActionKeyBinding()");
53         boolean res = true;
54 
55         log.println("Calling method with wrong argument");
56         try {
57             oObj.doAccessibleAction(count);
58             log.println("Exception expected -- FAILED");
59             res &= false;
60         } catch (com.sun.star.lang.IndexOutOfBoundsException ioe) {
61             log.println("Expected exception -- OK");
62             res &= true;
63         }
64 
65         try {
66             boolean act = false;
67             for (int i = 0; i< count; i++) {
68                 log.println("do Action "+ oObj.getAccessibleActionDescription(i));
69                 act = oObj.doAccessibleAction(i);
70                 log.println("Worked: "+act);
71             }
72             log.println("Did action: "+act);
73             res &= act ;
74         } catch (com.sun.star.lang.IndexOutOfBoundsException ioe) {
75             log.println("Unexepected exception -- FAILED");
76             res &= false;
77         }
78 
79         tRes.tested("doAccessibleAction()",res);
80     }
81 
82     /**
83      * calls the method with invalid argument and check if the <br>
84      * expected Exception is thrown.<br>
85      * Calls the method afterwards all valid parameters.<br>
86      * Is ok if the exception is thrown and the resulting value
87      * for the calls with valid parameters aren't null.
88      */
89 
_getAccessibleActionDescription()90     public void _getAccessibleActionDescription() {
91         requiredMethod("getAccessibleActionCount()");
92         boolean res = true;
93 
94         log.println("Calling method with wrong argument");
95         try {
96             oObj.getAccessibleActionDescription(count);
97             log.println("Exception expected -- FAILED");
98             res &= false;
99         } catch (com.sun.star.lang.IndexOutOfBoundsException ioe) {
100             log.println("Expected exception -- OK");
101             res &= true;
102         }
103 
104         for (int i=0;i<count;i++) {
105             try {
106                 String desc = oObj.getAccessibleActionDescription(i);
107                 log.println("Found action: "+desc);
108                 res &= desc!=null ;
109             } catch (com.sun.star.lang.IndexOutOfBoundsException ioe) {
110                 log.println("Unexepected exception -- FAILED");
111                 res &= false;
112             }
113         }
114 
115         tRes.tested("getAccessibleActionDescription()",res);
116     }
117 
118     /**
119      * calls the method with invalid argument and check if the <br>
120      * expected Exception is thrown.<br>
121      * Calls the method afterwards all valid parameters.<br>
122      * Is ok if the exception is thrown and the resulting value
123      * for the calls with valid parameters aren't null.
124      */
125 
_getAccessibleActionKeyBinding()126     public void _getAccessibleActionKeyBinding() {
127         requiredMethod("getAccessibleActionDescription()");
128         boolean res = true;
129 
130         log.println("Calling method with wrong argument");
131         try {
132             oObj.getAccessibleActionKeyBinding(count);
133             log.println("Exception expected -- FAILED");
134             res &= false;
135         } catch (com.sun.star.lang.IndexOutOfBoundsException ioe) {
136             log.println("Expected exception -- OK");
137             res &= true;
138         }
139 
140         for (int i=0;i<count;i++) {
141             try {
142                 Object key = oObj.getAccessibleActionKeyBinding(i);
143                 if (key != null ) {
144                     log.println("Found key: "+key.toString());
145                 }
146                 res &= true;
147             } catch (com.sun.star.lang.IndexOutOfBoundsException ioe) {
148                 log.println("Unexepected exception -- FAILED");
149                 res &= false;
150             }
151         }
152 
153         tRes.tested("getAccessibleActionKeyBinding()",res);
154     }
155 
156     /**
157     * Forces environment recreation.
158     */
after()159     protected void after() {
160         disposeEnvironment();
161     }
162 
163 }
164