Diffstat (limited to 'pwmanager/pwmanager/selftest.h') (more/less context) (show whitespace changes)
-rw-r--r-- | pwmanager/pwmanager/selftest.h | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/pwmanager/pwmanager/selftest.h b/pwmanager/pwmanager/selftest.h new file mode 100644 index 0000000..4f3ea51 --- a/dev/null +++ b/pwmanager/pwmanager/selftest.h @@ -0,0 +1,67 @@ +/*************************************************************************** + * * + * copyright (C) 2004 by Michael Buesch * + * email: mbuesch@freenet.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License version 2 * + * as published by the Free Software Foundation. * + * * + ***************************************************************************/ + +#ifndef __SELFTEST_H +#define __SELFTEST_H + +#include <qthread.h> +#include <qtimer.h> +#include <qobject.h> + +// timeout in seconds +#define SCHEDULE_TIMEOUT 3 + +/* internal wrapper to workaround MOC issues */ +class __SelfTest : public QThread + , public QObject +{ +public: + __SelfTest() {} +}; + +/** PwManager algorithm selftest */ +class SelfTest : public __SelfTest +{ + Q_OBJECT +public: + SelfTest(); + ~SelfTest(); + + /** schedule a new test. Only one test can run at once! */ + static void schedule(); + /** cancel the running test (if there is one) */ + static void cancel(); + +protected: + /** start the sched timer */ + void startTimer() + { schedTimer.start(SCHEDULE_TIMEOUT * 1000, true); } + /** stop the sched timer */ + void stopTimer() + { schedTimer.stop(); } + +protected slots: + void doSelfTest() + { start(); } + void doCancel(); + +protected: + /** print the "failed" message and exit the app */ + void failed(const char *algo); + /** worker thread */ + void run(); + +protected: + /** schedule timer */ + QTimer schedTimer; +}; + +#endif |