Diffstat (limited to 'pwmanager/pwmanager/selftest.h') (more/less context) (ignore 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 @@ | |||
1 | /*************************************************************************** | ||
2 | * * | ||
3 | * copyright (C) 2004 by Michael Buesch * | ||
4 | * email: mbuesch@freenet.de * | ||
5 | * * | ||
6 | * This program is free software; you can redistribute it and/or modify * | ||
7 | * it under the terms of the GNU General Public License version 2 * | ||
8 | * as published by the Free Software Foundation. * | ||
9 | * * | ||
10 | ***************************************************************************/ | ||
11 | |||
12 | #ifndef __SELFTEST_H | ||
13 | #define __SELFTEST_H | ||
14 | |||
15 | #include <qthread.h> | ||
16 | #include <qtimer.h> | ||
17 | #include <qobject.h> | ||
18 | |||
19 | // timeout in seconds | ||
20 | #define SCHEDULE_TIMEOUT3 | ||
21 | |||
22 | /* internal wrapper to workaround MOC issues */ | ||
23 | class __SelfTest : public QThread | ||
24 | , public QObject | ||
25 | { | ||
26 | public: | ||
27 | __SelfTest() {} | ||
28 | }; | ||
29 | |||
30 | /** PwManager algorithm selftest */ | ||
31 | class SelfTest : public __SelfTest | ||
32 | { | ||
33 | Q_OBJECT | ||
34 | public: | ||
35 | SelfTest(); | ||
36 | ~SelfTest(); | ||
37 | |||
38 | /** schedule a new test. Only one test can run at once! */ | ||
39 | static void schedule(); | ||
40 | /** cancel the running test (if there is one) */ | ||
41 | static void cancel(); | ||
42 | |||
43 | protected: | ||
44 | /** start the sched timer */ | ||
45 | void startTimer() | ||
46 | { schedTimer.start(SCHEDULE_TIMEOUT * 1000, true); } | ||
47 | /** stop the sched timer */ | ||
48 | void stopTimer() | ||
49 | { schedTimer.stop(); } | ||
50 | |||
51 | protected slots: | ||
52 | void doSelfTest() | ||
53 | { start(); } | ||
54 | void doCancel(); | ||
55 | |||
56 | protected: | ||
57 | /** print the "failed" message and exit the app */ | ||
58 | void failed(const char *algo); | ||
59 | /** worker thread */ | ||
60 | void run(); | ||
61 | |||
62 | protected: | ||
63 | /** schedule timer */ | ||
64 | QTimer schedTimer; | ||
65 | }; | ||
66 | |||
67 | #endif | ||