Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
325 andreas 1
/*
2
 * Copyright (C) 2023 by Andreas Theofilu <andreas@theosys.at>
3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software Foundation,
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
17
 */
18
 
19
#ifndef __TESTMODE_H__
20
#define __TESTMODE_H__
21
 
22
#include <string>
326 andreas 23
#include <thread>
24
#include <atomic>
25
#include <vector>
325 andreas 26
 
329 andreas 27
#include <QtGlobal>
28
 
334 andreas 29
extern bool __success;
30
extern bool __done;
31
extern bool _test_screen;
326 andreas 32
extern bool _testmode;
330 andreas 33
extern bool _run_test_ready;
326 andreas 34
 
325 andreas 35
class _TestMode
36
{
37
    public:
326 andreas 38
        _TestMode(const std::string& path);
39
        ~_TestMode();
325 andreas 40
 
326 andreas 41
        void run();
334 andreas 42
        void setMouseClick(int x, int y, bool pressed);
43
        void setResult(const std::string& res) { mVerify = res; }
326 andreas 44
 
325 andreas 45
    private:
327 andreas 46
        typedef struct _TESTCMD
47
        {
48
            std::string command;    // The command to execute
49
            std::string result;     // The expected result
50
            bool compare{false};    // TRUE: Compare expected result with real result
331 andreas 51
            bool nowait{false};     // TRUE: Don't wait until the command finished (no compare!)
334 andreas 52
            bool reverse{false};    // TRUE: This changes the meaning of success and failure.
335 andreas 53
            bool waitscreen{false}; // TRUE: Wait for screen finished even if no comparison is made.
327 andreas 54
        }_TESTCMD;
55
 
325 andreas 56
        void inject(int port, const std::string& c);
327 andreas 57
        void testSuccess(_TESTCMD& tc);
326 andreas 58
        void start();
59
        void inform(const std::string& msg);
60
 
61
        std::thread mThread;
62
        bool isRunning{false};
63
        std::string mPath;
64
        std::vector<std::string> mCmdFiles;
334 andreas 65
        std::string mVerify;         // The real result
66
        int mX{0};
67
        int mY{0};
68
        bool mPressed{false};
69
        int mCaseNumber{0};         // The number of the test case
325 andreas 70
};
71
 
326 andreas 72
extern _TestMode *_gTestMode;
73
 
334 andreas 74
#define setDone()       __done = true;
335 andreas 75
#define setScreenDone() { MSG_DEBUG("setScreenDone(); at module " << __FILE__ << ": " << __LINE__); _test_screen = true; }
76
#define setAllDone()    { MSG_DEBUG("setAllDone(); at module " << __FILE__ << ": " << __LINE__); _test_screen = true; __done = true; }
334 andreas 77
 
328 andreas 78
#ifndef TESTMODE
79
extern bool _testmode;
80
#elif TESTMODE != 1
81
extern bool _testmode;
82
#endif  // TESTMODE
83
 
325 andreas 84
#endif