Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / form / submission / _XSubmission.java
blob194319580c7f2760b96ec9dad7f1833cfc26c0b1
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package ifc.form.submission;
20 import com.sun.star.form.submission.XSubmission;
21 import com.sun.star.form.submission.XSubmissionVetoListener;
23 import lib.MultiMethodTest;
26 public class _XSubmission extends MultiMethodTest {
27 public XSubmission oObj = null;
28 public boolean HandlerWasCalled = false;
30 public void _addSubmissionVetoListener() {
31 log.println(
32 "submitting with VetoListener ... exception should appear");
34 boolean res = true;
35 XSubmissionVetoListener aListener = new MyListener();
37 try {
38 oObj.addSubmissionVetoListener(aListener);
39 oObj.submit();
40 res = false;
41 log.println(
42 "the expected exception wasn't thrown ... FAILED");
43 } catch (com.sun.star.lang.WrappedTargetException e) {
44 log.println(
45 "Expected exception was thrown while calling submit() "
46 + e.getMessage() + "FAILED");
47 res = false;
48 } catch (com.sun.star.lang.NoSupportException e) {
49 log.println(
50 "NoSupportExpected exception was thrown while calling submit() "
51 + e.getMessage() + "FAILED");
52 res = false;
53 } catch (com.sun.star.util.VetoException e) {
54 log.println(
55 "VetoException was thrown while calling submit() "
56 + e.getMessage() + "OK");
59 try {
60 oObj.removeSubmissionVetoListener(aListener);
61 } catch (com.sun.star.lang.NoSupportException e) {
62 log.println(
63 "NoSupportExpected exception was thrown while removing the listener) "
64 + e.getMessage() + "FAILED");
65 res = false;
68 tRes.tested("addSubmissionVetoListener()", res);
71 public void _removeSubmissionVetoListener() {
72 log.println(
73 "submitting with VetoListener ... exception should appear");
75 boolean res = true;
76 XSubmissionVetoListener aListener = new MyListener();
78 try {
79 oObj.addSubmissionVetoListener(aListener);
80 oObj.submit();
81 res = false;
82 log.println(
83 "the expected exception wasn't thrown ... FAILED");
84 } catch (com.sun.star.lang.WrappedTargetException e) {
85 log.println(
86 "WrappedTargetException exception was thrown while calling submit() "
87 + e.getMessage() + "FAILED");
88 res = false;
89 } catch (com.sun.star.lang.NoSupportException e) {
90 log.println(
91 "NoSupportExpected exception was thrown while calling submit() "
92 + e.getMessage() + "FAILED");
93 res = false;
94 } catch (com.sun.star.util.VetoException e) {
95 log.println(
96 "VetoException was thrown while calling submit() "
97 + e.getMessage() + "OK");
100 log.println("removing the listener");
102 try {
103 oObj.removeSubmissionVetoListener(aListener);
104 } catch (com.sun.star.lang.NoSupportException e) {
105 log.println(
106 "NoSupportExpected exception was thrown while removing the listener) "
107 + e.getMessage() + "FAILED");
108 res = false;
111 log.println("Sleeping 2s");
113 util.utils.pause(2000);
115 log.println("... done");
117 log.println(
118 "submitting after VetoListener has been removed... no exception should appear");
120 try {
121 oObj.submit();
122 log.println("No Exception ... OK");
123 } catch (com.sun.star.lang.WrappedTargetException e) {
124 log.println(
125 "WrappedTargetException was thrown while calling submit() "
126 + e.getMessage() + "FAILED");
127 res = false;
128 } catch (com.sun.star.util.VetoException e) {
129 log.println(
130 "VetoException was thrown while calling submit() "
131 + e.getMessage() + "FAILED");
132 res = false;
135 tRes.tested("removeSubmissionVetoListener()", res);
138 /** Calls submit and returns true if no exception was thrown
139 * then adds a SubmissionVetoListener and checks if the
140 * exception is thrown in case of a veto of this listener.
142 public void _submit() {
143 boolean res = true;
144 log.println(
145 "submitting without VetoListener ... no exception should appear");
147 try {
148 oObj.submit();
149 log.println("No Exception ... OK");
150 } catch (com.sun.star.lang.WrappedTargetException e) {
151 log.println(
152 "Exception was thrown while calling submit() "
153 + e.getMessage() + "FAILED");
154 res = false;
155 } catch (com.sun.star.util.VetoException e) {
156 log.println(
157 "VetoException was thrown while calling submit() "
158 + e.getMessage() + "FAILED");
159 res = false;
162 tRes.tested("submit()", res);
165 public class MyListener implements XSubmissionVetoListener {
166 public void disposing(
167 com.sun.star.lang.EventObject eventObject) {
170 public void submitting(
171 com.sun.star.lang.EventObject eventObject)
172 throws com.sun.star.util.VetoException {
173 log.println("MyVetoListener was called");
174 throw new com.sun.star.util.VetoException(
175 "submission isn't allowed ...");