446 |
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 |
#if TESTMODE == 1
|
|
|
23 |
|
|
|
24 |
#include <string>
|
|
|
25 |
#include <thread>
|
|
|
26 |
#include <atomic>
|
|
|
27 |
#include <vector>
|
|
|
28 |
|
|
|
29 |
#include <QtGlobal>
|
|
|
30 |
|
|
|
31 |
extern bool __success;
|
|
|
32 |
extern bool __done;
|
|
|
33 |
extern bool _test_screen;
|
|
|
34 |
extern bool _testmode;
|
|
|
35 |
extern bool _run_test_ready;
|
|
|
36 |
extern bool _block_screen;
|
|
|
37 |
class _TestMode
|
|
|
38 |
{
|
|
|
39 |
public:
|
|
|
40 |
_TestMode(const std::string& path);
|
|
|
41 |
~_TestMode();
|
|
|
42 |
|
|
|
43 |
void run();
|
|
|
44 |
void setMouseClick(int x, int y, bool pressed);
|
|
|
45 |
void setResult(const std::string& res) { mVerify = res; }
|
|
|
46 |
|
|
|
47 |
private:
|
|
|
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
|
|
|
53 |
bool nowait{false}; // TRUE: Don't wait until the command finished (no compare!)
|
|
|
54 |
bool reverse{false}; // TRUE: This changes the meaning of success and failure.
|
|
|
55 |
bool waitscreen{false}; // TRUE: Wait for screen finished even if no comparison is made.
|
|
|
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
|
|
|
58 |
}_TESTCMD;
|
|
|
59 |
|
|
|
60 |
typedef struct _VARS
|
|
|
61 |
{
|
|
|
62 |
std::string name;
|
|
|
63 |
std::string content;
|
|
|
64 |
}_VARS;
|
|
|
65 |
|
|
|
66 |
void inject(int port, const std::string& c);
|
|
|
67 |
void testSuccess(_TESTCMD& tc);
|
|
|
68 |
void start();
|
|
|
69 |
void inform(const std::string& msg);
|
|
|
70 |
void saveVariable(const std::string& name, const std::string& content);
|
|
|
71 |
std::string getVariable(const std::string& name);
|
|
|
72 |
void deleteVariable(const std::string& name);
|
|
|
73 |
|
|
|
74 |
std::thread mThread;
|
|
|
75 |
bool isRunning{false};
|
|
|
76 |
std::string mPath;
|
|
|
77 |
std::vector<std::string> mCmdFiles;
|
|
|
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
|
|
|
83 |
std::string mVarName;
|
|
|
84 |
std::vector<_VARS> mVariables;
|
|
|
85 |
};
|
|
|
86 |
|
|
|
87 |
extern _TestMode *_gTestMode;
|
|
|
88 |
|
|
|
89 |
#define setDone() if (_testmode) { __done = true; }
|
|
|
90 |
#define setScreenDone() if (_testmode && !_block_screen) { MSG_DEBUG("setScreenDone(); at module " << __FILE__ << ": " << __LINE__); _test_screen = true; }
|
|
|
91 |
#define setAllDone() if (_testmode) { MSG_DEBUG("setAllDone(); at module " << __FILE__ << ": " << __LINE__); _test_screen = true; __done = true; }
|
|
|
92 |
|
|
|
93 |
#else
|
|
|
94 |
extern bool _testmode;
|
|
|
95 |
#endif // TESTMODE == 1
|
|
|
96 |
#endif // __TESTMODE_H__
|