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