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
 
343 andreas 22
#if TESTMODE == 1
23
 
325 andreas 24
#include <string>
326 andreas 25
#include <thread>
26
#include <atomic>
27
#include <vector>
325 andreas 28
 
329 andreas 29
#include <QtGlobal>
30
 
334 andreas 31
extern bool __success;
32
extern bool __done;
33
extern bool _test_screen;
326 andreas 34
extern bool _testmode;
330 andreas 35
extern bool _run_test_ready;
348 andreas 36
extern bool _block_screen;
325 andreas 37
class _TestMode
38
{
39
    public:
326 andreas 40
        _TestMode(const std::string& path);
41
        ~_TestMode();
325 andreas 42
 
326 andreas 43
        void run();
334 andreas 44
        void setMouseClick(int x, int y, bool pressed);
45
        void setResult(const std::string& res) { mVerify = res; }
326 andreas 46
 
325 andreas 47
    private:
327 andreas 48
        typedef struct _TESTCMD
49
        {
50
            std::string command;    // The command to execute
51
            std::string result;     // The expected result
52
            bool compare{false};    // TRUE: Compare expected result with real result
331 andreas 53
            bool nowait{false};     // TRUE: Don't wait until the command finished (no compare!)
334 andreas 54
            bool reverse{false};    // TRUE: This changes the meaning of success and failure.
335 andreas 55
            bool waitscreen{false}; // TRUE: Wait for screen finished even if no comparison is made.
341 andreas 56
            bool saveresult{false}; // TRUE: The result is saved into the named variable
57
            bool compresult{false}; // TRUE: The result is compared against the named variable
327 andreas 58
        }_TESTCMD;
59
 
341 andreas 60
        typedef struct _VARS
61
        {
62
            std::string name;
63
            std::string content;
64
        }_VARS;
65
 
325 andreas 66
        void inject(int port, const std::string& c);
327 andreas 67
        void testSuccess(_TESTCMD& tc);
326 andreas 68
        void start();
69
        void inform(const std::string& msg);
341 andreas 70
        void saveVariable(const std::string& name, const std::string& content);
71
        std::string getVariable(const std::string& name);
342 andreas 72
        void deleteVariable(const std::string& name);
326 andreas 73
 
74
        std::thread mThread;
75
        bool isRunning{false};
76
        std::string mPath;
77
        std::vector<std::string> mCmdFiles;
334 andreas 78
        std::string mVerify;         // The real result
79
        int mX{0};
80
        int mY{0};
81
        bool mPressed{false};
82
        int mCaseNumber{0};         // The number of the test case
341 andreas 83
        std::string mVarName;
84
        std::vector<_VARS> mVariables;
325 andreas 85
};
86
 
326 andreas 87
extern _TestMode *_gTestMode;
88
 
343 andreas 89
#define setDone()       if (_testmode) { __done = true; }
348 andreas 90
#define setScreenDone() if (_testmode && !_block_screen) { MSG_DEBUG("setScreenDone(); at module " << __FILE__ << ": " << __LINE__); _test_screen = true; }
343 andreas 91
#define setAllDone()    if (_testmode) { MSG_DEBUG("setAllDone(); at module " << __FILE__ << ": " << __LINE__); _test_screen = true; __done = true; }
334 andreas 92
 
343 andreas 93
#else
328 andreas 94
extern bool _testmode;
343 andreas 95
#endif  // TESTMODE == 1
96
#endif  // __TESTMODE_H__