tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / qadevOOo / runner / complexlib / MethodThread.java
blob28ea770eb96800d8af191f3e2a8e8d6f44e48917
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 .
19 package complexlib;
21 import java.io.PrintWriter;
22 import java.lang.reflect.Method;
24 /**
25 * Invoke a method of a class in an own thread. Provide a method to end
26 * the thread.
28 public class MethodThread extends Thread
31 /** The method that should be executed **/
32 private final Method mTestMethod;
33 /** The object that implements the method **/
34 private final Object mInvokeClass;
35 /** A PrintWriter for debug Output **/
36 private final PrintWriter mLog;
37 /** An Error String **/
38 private String mErrMessage = null;
39 /** Did an Exception happen? **/
40 private boolean mExceptionHappened = false;
41 private Object[] mParameter = null;
43 public MethodThread(Method testMethod, Object invokeClass, Object[] parameter, PrintWriter log)
45 mTestMethod = testMethod;
46 mInvokeClass = invokeClass;
47 mParameter = parameter;
48 mLog = log;
51 /**
52 * Invoke the method.
54 @Override
55 public void run()
57 try
59 mTestMethod.invoke(mInvokeClass, mParameter);
61 catch (IllegalAccessException e)
63 e.printStackTrace(mLog);
64 mErrMessage = e.getMessage();
65 mExceptionHappened = true;
67 catch (java.lang.reflect.InvocationTargetException e)
69 Throwable t = e.getTargetException();
70 if (!(t instanceof ComplexTestCase.AssureException))
72 t.printStackTrace(mLog);
73 mErrMessage = t.getMessage();
74 if (mErrMessage == null)
76 mErrMessage = t.toString();
78 mExceptionHappened = true;
84 /**
85 * Get the error message
86 * @return The error message.
88 public String getErrorMessage()
90 return mErrMessage;
93 /**
94 * Is there an error message?
95 * @return True, if an error did happen.
97 public boolean hasErrorMessage()
99 return mExceptionHappened;
103 * Stop the running method.
105 public void stopRunning()
109 interrupt();
111 catch (SecurityException e)
113 e.printStackTrace(mLog);
114 mErrMessage = e.getMessage();
115 mExceptionHappened = true;