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
 
328 andreas 29
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
325 andreas 30
#define TESTMODE    1
328 andreas 31
#endif
325 andreas 32
 
326 andreas 33
extern std::atomic<bool> __success;
34
extern std::atomic<bool> __done;
35
extern bool _testmode;
36
 
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();
327 andreas 44
        void setResult(const std::string& res) { verify = res; }
326 andreas 45
 
325 andreas 46
    private:
327 andreas 47
        typedef struct _TESTCMD
48
        {
49
            std::string command;    // The command to execute
50
            std::string result;     // The expected result
51
            bool compare{false};    // TRUE: Compare expected result with real result
52
        }_TESTCMD;
53
 
325 andreas 54
        void inject(int port, const std::string& c);
327 andreas 55
        void testSuccess(_TESTCMD& tc);
326 andreas 56
        void start();
57
        void inform(const std::string& msg);
58
 
59
        std::thread mThread;
60
        bool isRunning{false};
61
        std::string mPath;
62
        std::vector<std::string> mCmdFiles;
327 andreas 63
        std::string verify;         // The real result
325 andreas 64
};
65
 
326 andreas 66
extern _TestMode *_gTestMode;
67
 
328 andreas 68
#ifndef TESTMODE
69
extern bool _testmode;
70
#elif TESTMODE != 1
71
extern bool _testmode;
72
#endif  // TESTMODE
73
 
325 andreas 74
#endif